X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fconf-parser.c;h=4ce4707451715aa9df8fbead358caa3398971c76;hb=b1aedf6d6e37dbc537c22dfa399da181ab21e5ec;hp=0899509d7a03f9413e6b460e0c349a1ea3901024;hpb=756c392103bc01d409c1760146ac2df7dd8f8ede;p=elogind.git diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 0899509d7..4ce470745 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -20,15 +18,17 @@ ***/ #include +#include +#include #include #include #include - -#include "sd-messages.h" +#include #include "alloc-util.h" #include "conf-files.h" #include "conf-parser.h" +#include "extract-word.h" #include "fd-util.h" #include "fs-util.h" #include "log.h" @@ -40,8 +40,8 @@ #include "string-util.h" #include "strv.h" #include "syslog-util.h" +#include "time-util.h" #include "utf8.h" -#include "util.h" int config_item_table_lookup( const void *table, @@ -294,7 +294,7 @@ int config_parse(const char *unit, _cleanup_free_ char *section = NULL, *continuation = NULL; _cleanup_fclose_ FILE *ours = NULL; unsigned line = 0, section_line = 0; - bool section_ignored = false; + bool section_ignored = false, allow_bom = true; int r; assert(filename); @@ -314,11 +314,11 @@ int config_parse(const char *unit, fd_warn_permissions(filename, fileno(f)); - while (!feof(f)) { - char l[LINE_MAX], *p, *c = NULL, *e; + for (;;) { + char buf[LINE_MAX], *l, *p, *c = NULL, *e; bool escaped = false; - if (!fgets(l, sizeof(l), f)) { + if (!fgets(buf, sizeof buf, f)) { if (feof(f)) break; @@ -326,6 +326,11 @@ int config_parse(const char *unit, return -errno; } + l = buf; + if (allow_bom && startswith(l, UTF8_BYTE_ORDER_MARK)) + l += strlen(UTF8_BYTE_ORDER_MARK); + allow_bom = false; + truncate_nl(l); if (continuation) { @@ -459,8 +464,7 @@ DEFINE_PARSER(uint32, uint32_t, safe_atou32); DEFINE_PARSER(uint64, uint64_t, safe_atou64); DEFINE_PARSER(unsigned, unsigned, safe_atou); DEFINE_PARSER(double, double, safe_atod); -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind DEFINE_PARSER(nsec, nsec_t, parse_nsec); #endif // 0 DEFINE_PARSER(sec, usec_t, parse_sec); @@ -496,8 +500,7 @@ int config_parse_iec_size(const char* unit, return 0; } -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind int config_parse_si_size(const char* unit, const char *filename, unsigned line, @@ -584,8 +587,7 @@ int config_parse_bool(const char* unit, return 0; } -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind int config_parse_tristate( const char* unit, const char *filename, @@ -736,7 +738,7 @@ int config_parse_strv(const char *unit, for (;;) { char *word = NULL; int r; - r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES); + r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES|EXTRACT_RETAIN_ESCAPE); if (r == 0) break; if (r == -ENOMEM) @@ -759,8 +761,7 @@ int config_parse_strv(const char *unit, return 0; } -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind int config_parse_log_facility( const char *unit, const char *filename, @@ -852,8 +853,7 @@ int config_parse_signal( return 0; } -/// UNNEEDED by elogind -#if 0 +#if 0 /// UNNEEDED by elogind int config_parse_personality( const char *unit, const char *filename,