chiark / gitweb /
load-fragment: properly parse size values denoted in bytes
authorLennart Poettering <lennart@poettering.net>
Tue, 31 Jan 2012 19:53:34 +0000 (20:53 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 31 Jan 2012 19:53:34 +0000 (20:53 +0100)
src/conf-parser.c
src/conf-parser.h
src/journal/journald-gperf.gperf
src/load-fragment-gperf.gperf.m4
src/load-fragment.c

index ac8d9f5..c7dd01a 100644 (file)
@@ -454,7 +454,7 @@ int config_parse_unsigned(
         return 0;
 }
 
-int config_parse_size(
+int config_parse_bytes_size(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -465,20 +465,47 @@ int config_parse_size(
                 void *userdata) {
 
         size_t *sz = data;
-        unsigned u;
-        int r;
+        off_t o;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atou(rvalue, &u)) < 0) {
-                log_error("[%s:%u] Failed to parse numeric value, ignoring: %s", filename, line, rvalue);
+        if (parse_bytes(rvalue, &o) < 0 || (off_t) (size_t) o != o) {
+                log_error("[%s:%u] Failed to parse byte value, ignoring: %s", filename, line, rvalue);
+                return 0;
+        }
+
+        *sz = (size_t) o;
+        return 0;
+}
+
+
+int config_parse_bytes_off(
+                const char *filename,
+                unsigned line,
+                const char *section,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        off_t *bytes = data;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        assert_cc(sizeof(off_t) == sizeof(uint64_t));
+
+        if (parse_bytes(rvalue, bytes) < 0) {
+                log_error("[%s:%u] Failed to parse bytes value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
 
-        *sz = (size_t) u;
         return 0;
 }
 
@@ -782,30 +809,3 @@ int config_parse_mode(
         *m = (mode_t) l;
         return 0;
 }
-
-int config_parse_bytes(
-                const char *filename,
-                unsigned line,
-                const char *section,
-                const char *lvalue,
-                int ltype,
-                const char *rvalue,
-                void *data,
-                void *userdata) {
-
-        off_t *bytes = data;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-        assert(data);
-
-        assert_cc(sizeof(off_t) == sizeof(uint64_t));
-
-        if (parse_bytes(rvalue, bytes) < 0) {
-                log_error("[%s:%u] Failed to parse bytes value, ignoring: %s", filename, line, rvalue);
-                return 0;
-        }
-
-        return 0;
-}
index 35edcb6..be7d708 100644 (file)
@@ -93,7 +93,8 @@ int config_parse_int(const char *filename, unsigned line, const char *section, c
 int config_parse_unsigned(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_long(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_uint64(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
-int config_parse_size(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
+int config_parse_bytes_size(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
+int config_parse_bytes_off(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_bool(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_tristate(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_string(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
@@ -102,7 +103,6 @@ int config_parse_strv(const char *filename, unsigned line, const char *section,
 int config_parse_path_strv(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_usec(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_mode(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
-int config_parse_bytes(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 
 #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg)                \
         int function(                                                   \
index e25ba2c..a56f6d9 100644 (file)
@@ -14,18 +14,18 @@ struct ConfigPerfItem;
 %struct-type
 %includes
 %%
-Journal.RateLimitInterval,  config_parse_usec,     0, offsetof(Server, rate_limit_interval)
-Journal.RateLimitBurst,     config_parse_unsigned, 0, offsetof(Server, rate_limit_burst)
-Journal.Compress,           config_parse_bool,     0, offsetof(Server, compress)
-Journal.SystemMaxUse,       config_parse_bytes,    0, offsetof(Server, system_metrics.max_use)
-Journal.SystemMaxFileSize,  config_parse_bytes,    0, offsetof(Server, system_metrics.max_size)
-Journal.SystemMinFileSize,  config_parse_bytes,    0, offsetof(Server, system_metrics.min_size)
-Journal.SystemKeepFree,     config_parse_bytes,    0, offsetof(Server, system_metrics.keep_free)
-Journal.RuntimeMaxUse,      config_parse_bytes,    0, offsetof(Server, runtime_metrics.max_use)
-Journal.RuntimeMaxFileSize, config_parse_bytes,    0, offsetof(Server, runtime_metrics.max_size)
-Journal.RuntimeMinFileSize, config_parse_bytes,    0, offsetof(Server, runtime_metrics.min_size)
-Journal.RuntimeKeepFree,    config_parse_bytes,    0, offsetof(Server, runtime_metrics.keep_free)
-Journal.ForwardToSyslog,    config_parse_bool,     0, offsetof(Server, forward_to_syslog)
-Journal.ForwardToKMsg,      config_parse_bool,     0, offsetof(Server, forward_to_kmsg)
-Journal.ForwardToConsole,   config_parse_bool,     0, offsetof(Server, forward_to_console)
-Journal.ImportKernel,       config_parse_bool,     0, offsetof(Server, import_proc_kmsg)
+Journal.RateLimitInterval,  config_parse_usec,      0, offsetof(Server, rate_limit_interval)
+Journal.RateLimitBurst,     config_parse_unsigned,  0, offsetof(Server, rate_limit_burst)
+Journal.Compress,           config_parse_bool,      0, offsetof(Server, compress)
+Journal.SystemMaxUse,       config_parse_bytes_off, 0, offsetof(Server, system_metrics.max_use)
+Journal.SystemMaxFileSize,  config_parse_bytes_off, 0, offsetof(Server, system_metrics.max_size)
+Journal.SystemMinFileSize,  config_parse_bytes_off, 0, offsetof(Server, system_metrics.min_size)
+Journal.SystemKeepFree,     config_parse_bytes_off, 0, offsetof(Server, system_metrics.keep_free)
+Journal.RuntimeMaxUse,      config_parse_bytes_off, 0, offsetof(Server, runtime_metrics.max_use)
+Journal.RuntimeMaxFileSize, config_parse_bytes_off, 0, offsetof(Server, runtime_metrics.max_size)
+Journal.RuntimeMinFileSize, config_parse_bytes_off, 0, offsetof(Server, runtime_metrics.min_size)
+Journal.RuntimeKeepFree,    config_parse_bytes_off, 0, offsetof(Server, runtime_metrics.keep_free)
+Journal.ForwardToSyslog,    config_parse_bool,      0, offsetof(Server, forward_to_syslog)
+Journal.ForwardToKMsg,      config_parse_bool,      0, offsetof(Server, forward_to_kmsg)
+Journal.ForwardToConsole,   config_parse_bool,      0, offsetof(Server, forward_to_console)
+Journal.ImportKernel,       config_parse_bool,      0, offsetof(Server, import_proc_kmsg)
index 8ca799e..14c0606 100644 (file)
@@ -171,12 +171,12 @@ Socket.Accept,                   config_parse_bool,                  0,
 Socket.MaxConnections,           config_parse_unsigned,              0,                             offsetof(Socket, max_connections)
 Socket.KeepAlive,                config_parse_bool,                  0,                             offsetof(Socket, keep_alive)
 Socket.Priority,                 config_parse_int,                   0,                             offsetof(Socket, priority)
-Socket.ReceiveBuffer,            config_parse_size,                  0,                             offsetof(Socket, receive_buffer)
-Socket.SendBuffer,               config_parse_size,                  0,                             offsetof(Socket, send_buffer)
+Socket.ReceiveBuffer,            config_parse_bytes_size,            0,                             offsetof(Socket, receive_buffer)
+Socket.SendBuffer,               config_parse_bytes_size,            0,                             offsetof(Socket, send_buffer)
 Socket.IPTOS,                    config_parse_ip_tos,                0,                             offsetof(Socket, ip_tos)
 Socket.IPTTL,                    config_parse_int,                   0,                             offsetof(Socket, ip_ttl)
 Socket.Mark,                     config_parse_int,                   0,                             offsetof(Socket, mark)
-Socket.PipeSize,                 config_parse_size,                  0,                             offsetof(Socket, pipe_size)
+Socket.PipeSize,                 config_parse_bytes_size,            0,                             offsetof(Socket, pipe_size)
 Socket.FreeBind,                 config_parse_bool,                  0,                             offsetof(Socket, free_bind)
 Socket.Transparent,              config_parse_bool,                  0,                             offsetof(Socket, transparent)
 Socket.Broadcast,                config_parse_bool,                  0,                             offsetof(Socket, broadcast)
index deae2dc..b2d43fb 100644 (file)
@@ -2337,7 +2337,7 @@ void unit_dump_config_items(FILE *f) {
         } table[] = {
                 { config_parse_int,                   "INTEGER" },
                 { config_parse_unsigned,              "UNSIGNED" },
-                { config_parse_size,                  "SIZE" },
+                { config_parse_bytes_size,            "SIZE" },
                 { config_parse_bool,                  "BOOLEAN" },
                 { config_parse_string,                "STRING" },
                 { config_parse_path,                  "PATH" },