diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-10-03 10:41:51 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-11-23 08:11:42 +0100 |
commit | 3344b839df8fe2dd2b4a4f470225e4c407cf2faa (patch) | |
tree | a64c86cfe6adc5718143f5604fef893cfd94a865 /src/shared/conf-parser.c | |
parent | 7d729de3a70bc7a7fef69f5cea03fcbf835e118a (diff) |
build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.
$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build
squash! build-sys: use #if Y instead of #ifdef Y everywhere
v2:
- fix incorrect setting of HAVE_LIBIDN2
Diffstat (limited to 'src/shared/conf-parser.c')
-rw-r--r-- | src/shared/conf-parser.c | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index ab66bfe60..8dff2886c 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -43,6 +43,10 @@ #include "time-util.h" #include "utf8.h" +/// Additional includes needed by elogind +#include "def.h" +#include "fileio.h" + int config_item_table_lookup( const void *table, const char *section, @@ -315,24 +319,44 @@ int config_parse(const char *unit, fd_warn_permissions(filename, fileno(f)); for (;;) { - char buf[LINE_MAX], *l, *p, *c = NULL, *e; + _cleanup_free_ char *buf = NULL; + char *l, *p, *c = NULL, *e; bool escaped = false; - if (!fgets(buf, sizeof buf, f)) { - if (feof(f)) - break; + r = read_line(f, LONG_LINE_MAX, &buf); + if (r == 0) + break; + if (r == -ENOBUFS) { + if (warn) + log_error_errno(r, "%s:%u: Line too long", filename, line); - return log_error_errno(errno, "Failed to read configuration file '%s': %m", filename); + return r; + } + if (r < 0) { + if (warn) + log_error_errno(r, "%s:%u: Error while reading configuration file: %m", filename, line); + + return r; } l = buf; - if (allow_bom && startswith(l, UTF8_BYTE_ORDER_MARK)) - l += strlen(UTF8_BYTE_ORDER_MARK); - allow_bom = false; + if (allow_bom) { + char *q; - truncate_nl(l); + q = startswith(buf, UTF8_BYTE_ORDER_MARK); + if (q) { + l = q; + allow_bom = false; + } + } if (continuation) { + if (strlen(continuation) + strlen(l) > LONG_LINE_MAX) { + if (warn) + log_error("%s:%u: Continuation line too long", filename, line); + return -ENOBUFS; + } + c = strappend(continuation, l); if (!c) { if (warn) @@ -386,8 +410,7 @@ int config_parse(const char *unit, if (r < 0) { if (warn) - log_warning_errno(r, "Failed to parse file '%s': %m", - filename); + log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line); return r; } } |