chiark / gitweb /
polkit: don't start polkit agent when running as root
[elogind.git] / src / shared / conf-parser.c
index 0899509d7a03f9413e6b460e0c349a1ea3901024..9c1a02241a95e358abb484fb9bab1ff4575ef585 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
 ***/
 
 #include <errno.h>
+#include <limits.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-
-#include "sd-messages.h"
+#include <sys/types.h>
 
 #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,
@@ -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,