chiark / gitweb /
fileio: in envfiles, do not skip lines following empty lines
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 14 Apr 2013 00:22:53 +0000 (20:22 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 14 Apr 2013 00:24:39 +0000 (20:24 -0400)
https://bugs.freedesktop.org/show_bug.cgi?id=63477

src/binfmt/binfmt.c
src/journal/catalog.c
src/modules-load/modules-load.c
src/shared/conf-parser.c
src/shared/install.c
src/shared/util.h
src/sysctl/sysctl.c
src/test/test-unit-file.c

index 9ca1e604c498aa095fda3200d41af79c8f90406c..5a42b3dbef769b9561b09ef8a5be52b19095fb81 100644 (file)
@@ -110,7 +110,7 @@ static int apply_file(const char *path, bool ignore_enoent) {
                 p = strstrip(l);
                 if (!*p)
                         continue;
                 p = strstrip(l);
                 if (!*p)
                         continue;
-                if (strchr(COMMENTS, *p))
+                if (strchr(COMMENTS "\n", *p))
                         continue;
 
                 k = apply_rule(p);
                         continue;
 
                 k = apply_rule(p);
index ebf0622609434fba90fc77f43539ae281635eccc..7681af66299b18370bed94f6e6c324a7170631aa 100644 (file)
@@ -180,7 +180,7 @@ int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) {
                         continue;
                 }
 
                         continue;
                 }
 
-                if (strchr(COMMENTS, line[0]))
+                if (strchr(COMMENTS "\n", line[0]))
                         continue;
 
                 if (empty_line &&
                         continue;
 
                 if (empty_line &&
index 9ee260302e123602226ee0beacfd94e8ed79c187..b3f7af0ef84a3efe718ef7a3e72d71b89638d96b 100644 (file)
@@ -206,7 +206,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
                 l = strstrip(line);
                 if (!*l)
                         continue;
                 l = strstrip(line);
                 if (!*l)
                         continue;
-                if (strchr(COMMENTS, *l))
+                if (strchr(COMMENTS "\n", *l))
                         continue;
 
                 k = load_module(ctx, l);
                         continue;
 
                 k = load_module(ctx, l);
index fbacf986a515b3e30ceeb0a1c5fe1c958733d283..fea2e5624ef2806c68d4b7ccfdd8dfdf4ec041cc 100644 (file)
@@ -174,7 +174,7 @@ static int parse_line(
         if (!*l)
                 return 0;
 
         if (!*l)
                 return 0;
 
-        if (strchr(COMMENTS, *l))
+        if (strchr(COMMENTS "\n", *l))
                 return 0;
 
         if (startswith(l, ".include ")) {
                 return 0;
 
         if (startswith(l, ".include ")) {
index f9d223eee6ac49188f07a2f34a834297b844a904..71e04335ef57371cd84d2c661ae419759fbaac3d 100644 (file)
@@ -1699,7 +1699,7 @@ int unit_file_query_preset(UnitFileScope scope, const char *name) {
                         if (!*l)
                                 continue;
 
                         if (!*l)
                                 continue;
 
-                        if (strchr(COMMENTS, *l))
+                        if (strchr(COMMENTS "\n", *l))
                                 continue;
 
                         if (first_word(l, "enable")) {
                                 continue;
 
                         if (first_word(l, "enable")) {
index 99ec0a39bdc4ee1212d4f6aec5ab974c3468d4a9..ad9753655a9300524911b9710db53e68d0498551 100644 (file)
@@ -52,7 +52,7 @@ union dirent_storage {
 #define WHITESPACE " \t\n\r"
 #define NEWLINE "\n\r"
 #define QUOTES "\"\'"
 #define WHITESPACE " \t\n\r"
 #define NEWLINE "\n\r"
 #define QUOTES "\"\'"
-#define COMMENTS "#;\n"
+#define COMMENTS "#;"
 
 #define FORMAT_BYTES_MAX 8
 
 
 #define FORMAT_BYTES_MAX 8
 
index e0ba78a2fe240ea13df2bc4eb384f5c53638a46d..db18dd9f6e69f7436813ae59de99a5844932f731 100644 (file)
@@ -149,7 +149,7 @@ static int parse_file(Hashmap *sysctl_options, const char *path, bool ignore_eno
                 if (!*p)
                         continue;
 
                 if (!*p)
                         continue;
 
-                if (strchr(COMMENTS, *p))
+                if (strchr(COMMENTS "\n", *p))
                         continue;
 
                 value = strchr(p, '=');
                         continue;
 
                 value = strchr(p, '=');
index 3cf84637e8fb8beb29f2381e618645d974235f62..1bf11e66a5515a5011b96e633fd749c849a31e1d 100644 (file)
@@ -199,6 +199,17 @@ static void test_config_parse_exec(void) {
         "#--nouser-config                                     \\\n" \
         "normal=line"
 
         "#--nouser-config                                     \\\n" \
         "normal=line"
 
+#define env_file_4 \
+       "# Generated\n" \
+       "\n" \
+       "HWMON_MODULES=\"coretemp f71882fg\"\n" \
+       "\n" \
+       "# For compatibility reasons\n" \
+       "\n" \
+       "MODULE_0=coretemp\n" \
+       "MODULE_1=f71882fg"
+
+
 static void test_load_env_file_1(void) {
         char _cleanup_strv_free_ **data = NULL;
         int r;
 static void test_load_env_file_1(void) {
         char _cleanup_strv_free_ **data = NULL;
         int r;
@@ -251,6 +262,25 @@ static void test_load_env_file_3(void) {
         unlink(name);
 }
 
         unlink(name);
 }
 
+static void test_load_env_file_4(void) {
+        char _cleanup_strv_free_ **data = NULL;
+        int r;
+
+        char name[] = "/tmp/test-load-env-file.XXXXXX";
+        int _cleanup_close_ fd = mkstemp(name);
+        assert(fd >= 0);
+        assert_se(write(fd, env_file_4, sizeof(env_file_4)) == sizeof(env_file_4));
+
+        r = load_env_file(name, NULL, &data);
+        assert(r == 0);
+        assert(streq(data[0], "HWMON_MODULES=coretemp f71882fg"));
+        assert(streq(data[1], "MODULE_0=coretemp"));
+        assert(streq(data[2], "MODULE_1=f71882fg"));
+        assert(data[3] == NULL);
+        unlink(name);
+}
+
+
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wnonnull"
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wnonnull"
 
@@ -327,6 +357,7 @@ int main(int argc, char *argv[]) {
         test_load_env_file_1();
         test_load_env_file_2();
         test_load_env_file_3();
         test_load_env_file_1();
         test_load_env_file_2();
         test_load_env_file_3();
+        test_load_env_file_4();
         test_install_printf();
 
         return 0;
         test_install_printf();
 
         return 0;