|
88 | 88 | /* The period to insert between posting changes for coalescing */ |
89 | 89 | #define POST_CHANGE_TIMER_INTERVAL_USEC (250*USEC_PER_MSEC) |
90 | 90 |
|
| 91 | +/* Pick a good default that is likely to fit into AF_UNIX and AF_INET SOCK_DGRAM datagrams, and even leaves some room |
| 92 | + * for a bit of additional metadata. */ |
| 93 | +#define DEFAULT_LINE_MAX (48*1024) |
| 94 | + |
91 | 95 | static int determine_path_usage(Server *s, const char *path, uint64_t *ret_used, uint64_t *ret_free) { |
92 | 96 | _cleanup_closedir_ DIR *d = NULL; |
93 | 97 | struct dirent *de; |
@@ -1689,6 +1693,8 @@ int server_init(Server *s) { |
1689 | 1693 | s->max_level_console = LOG_INFO; |
1690 | 1694 | s->max_level_wall = LOG_EMERG; |
1691 | 1695 |
|
| 1696 | + s->line_max = DEFAULT_LINE_MAX; |
| 1697 | + |
1692 | 1698 | journal_reset_metrics(&s->system_storage.metrics); |
1693 | 1699 | journal_reset_metrics(&s->runtime_storage.metrics); |
1694 | 1700 |
|
@@ -1963,3 +1969,55 @@ static const char* const split_mode_table[_SPLIT_MAX] = { |
1963 | 1969 |
|
1964 | 1970 | DEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode); |
1965 | 1971 | DEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting"); |
| 1972 | + |
| 1973 | +int config_parse_line_max( |
| 1974 | + const char* unit, |
| 1975 | + const char *filename, |
| 1976 | + unsigned line, |
| 1977 | + const char *section, |
| 1978 | + unsigned section_line, |
| 1979 | + const char *lvalue, |
| 1980 | + int ltype, |
| 1981 | + const char *rvalue, |
| 1982 | + void *data, |
| 1983 | + void *userdata) { |
| 1984 | + |
| 1985 | + size_t *sz = data; |
| 1986 | + int r; |
| 1987 | + |
| 1988 | + assert(filename); |
| 1989 | + assert(lvalue); |
| 1990 | + assert(rvalue); |
| 1991 | + assert(data); |
| 1992 | + |
| 1993 | + if (isempty(rvalue)) |
| 1994 | + /* Empty assignment means default */ |
| 1995 | + *sz = DEFAULT_LINE_MAX; |
| 1996 | + else { |
| 1997 | + uint64_t v; |
| 1998 | + |
| 1999 | + r = parse_size(rvalue, 1024, &v); |
| 2000 | + if (r < 0) { |
| 2001 | + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse LineMax= value, ignoring: %s", rvalue); |
| 2002 | + return 0; |
| 2003 | + } |
| 2004 | + |
| 2005 | + if (v < 79) { |
| 2006 | + /* Why specify 79 here as minimum line length? Simply, because the most common traditional |
| 2007 | + * terminal size is 80ch, and it might make sense to break one character before the natural |
| 2008 | + * line break would occur on that. */ |
| 2009 | + log_syntax(unit, LOG_WARNING, filename, line, 0, "LineMax= too small, clamping to 79: %s", rvalue); |
| 2010 | + *sz = 79; |
| 2011 | + } else if (v > (uint64_t) (SSIZE_MAX-1)) { |
| 2012 | + /* So, why specify SSIZE_MAX-1 here? Because that's one below the largest size value read() |
| 2013 | + * can return, and we need one extra byte for the trailing NUL byte. Of course IRL such large |
| 2014 | + * memory allocations will fail anyway, hence this limit is mostly theoretical anyway, as we'll |
| 2015 | + * fail much earlier anyway. */ |
| 2016 | + log_syntax(unit, LOG_WARNING, filename, line, 0, "LineMax= too large, clamping to %" PRIu64 ": %s", (uint64_t) (SSIZE_MAX-1), rvalue); |
| 2017 | + *sz = SSIZE_MAX-1; |
| 2018 | + } else |
| 2019 | + *sz = (size_t) v; |
| 2020 | + } |
| 2021 | + |
| 2022 | + return 0; |
| 2023 | +} |
0 commit comments