chiark / gitweb /
Prep v239: Fix sleep-config.[hc] and sleep/sleep.c to utilize upstream updates.
[elogind.git] / src / shared / conf-parser.c
index a43e595cc190a8f796a38939ce20e6257fd7a620..aa6238ae50e6043bd049b4f0d87fde607e8ad884 100644 (file)
@@ -1,9 +1,4 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  This file is part of systemd.
-
-  Copyright 2010 Lennart Poettering
-***/
 
 #include <errno.h>
 #include <limits.h>
@@ -26,6 +21,7 @@
 #include "parse-util.h"
 #include "path-util.h"
 #include "process-util.h"
+//#include "rlimit-util.h"
 #include "signal-util.h"
 #include "socket-util.h"
 #include "string-util.h"
 /// Additional includes needed by elogind
 #include "def.h"
 #include "fileio.h"
-//#include "rlimit-util.h"
-//#include "rlimit-util.h"
-//#include "rlimit-util.h"
-//#include "rlimit-util.h"
-//#include "rlimit-util.h"
-//#include "rlimit-util.h"
-//#include "rlimit-util.h"
-//#include "rlimit-util.h"
-//#include "rlimit-util.h"
 
 int config_item_table_lookup(
                 const void *table,
@@ -315,8 +302,8 @@ int config_parse(const char *unit,
                         /* Only log on request, except for ENOENT,
                          * since we return 0 to the caller. */
                         if ((flags & CONFIG_PARSE_WARN) || errno == ENOENT)
-                                log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR,
-                                         "Failed to open configuration file '%s': %m", filename);
+                                log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno,
+                                               "Failed to open configuration file '%s': %m", filename);
                         return errno == ENOENT ? 0 : -errno;
                 }
         }
@@ -534,6 +521,7 @@ DEFINE_PARSER(nsec, nsec_t, parse_nsec);
 DEFINE_PARSER(sec, usec_t, parse_sec);
 DEFINE_PARSER(mode, mode_t, parse_mode);
 
+#if 0 /// UNNEEDED by elogind
 int config_parse_iec_size(const char* unit,
                             const char *filename,
                             unsigned line,
@@ -564,7 +552,6 @@ int config_parse_iec_size(const char* unit,
         return 0;
 }
 
-#if 0 /// UNNEEDED by elogind
 int config_parse_si_size(
                 const char* unit,
                 const char *filename,
@@ -652,7 +639,7 @@ int config_parse_bool(const char* unit,
                 return fatal ? -ENOEXEC : 0;
         }
 
-        *b = !!k;
+        *b = k;
         return 0;
 }
 
@@ -716,6 +703,7 @@ int config_parse_string(
         return 0;
 }
 
+#if 0 /// UNNEEDED by elogind
 int config_parse_path(
                 const char *unit,
                 const char *filename,
@@ -728,8 +716,9 @@ int config_parse_path(
                 void *data,
                 void *userdata) {
 
-        char **s = data, *n;
+        _cleanup_free_ char *n = NULL;
         bool fatal = ltype;
+        char **s = data;
         int r;
 
         assert(filename);
@@ -737,10 +726,8 @@ int config_parse_path(
         assert(rvalue);
         assert(data);
 
-        if (isempty(rvalue)) {
-                n = NULL;
+        if (isempty(rvalue))
                 goto finalize;
-        }
 
         n = strdup(rvalue);
         if (!n)
@@ -751,10 +738,9 @@ int config_parse_path(
                 return fatal ? -ENOEXEC : 0;
 
 finalize:
-        free_and_replace(*s, n);
-
-        return 0;
+        return free_and_replace(*s, n);
 }
+#endif // 0
 
 int config_parse_strv(
                 const char *unit,
@@ -802,6 +788,7 @@ int config_parse_strv(
         return 0;
 }
 
+#if 0 /// UNNEEDED by elogind
 int config_parse_warn_compat(
                 const char *unit,
                 const char *filename,
@@ -837,7 +824,6 @@ int config_parse_warn_compat(
         return 0;
 }
 
-#if 0 /// UNNEEDED by elogind
 int config_parse_log_facility(
                 const char *unit,
                 const char *filename,
@@ -867,7 +853,6 @@ int config_parse_log_facility(
 
         return 0;
 }
-#endif // 0
 
 int config_parse_log_level(
                 const char *unit,
@@ -931,7 +916,6 @@ int config_parse_signal(
         return 0;
 }
 
-#if 0 /// UNNEEDED by elogind
 int config_parse_personality(
                 const char *unit,
                 const char *filename,
@@ -1153,7 +1137,6 @@ int config_parse_join_controllers(
 
         return 0;
 }
-#endif // 0
 
 int config_parse_mtu(
                 const char *unit,
@@ -1228,3 +1211,35 @@ int config_parse_rlimit(
 
         return 0;
 }
+
+int config_parse_permille(const char* unit,
+                          const char *filename,
+                          unsigned line,
+                          const char *section,
+                          unsigned section_line,
+                          const char *lvalue,
+                          int ltype,
+                          const char *rvalue,
+                          void *data,
+                          void *userdata) {
+
+        unsigned *permille = data;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(permille);
+
+        r = parse_permille(rvalue);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, r,
+                           "Failed to parse permille value, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        *permille = (unsigned) r;
+
+        return 0;
+}
+#endif // 0