]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
[PATCH] allow multiline rules by backslash at the end of the line
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Mon, 20 Dec 2004 06:38:33 +0000 (07:38 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 06:19:09 +0000 (23:19 -0700)
On Sun, 2004-12-19 at 18:31 +0100, Marco d'Itri wrote:
> > On Dec 19, Kay Sievers <kay.sievers@vrfy.org> wrote:
>
> > (Feature request: would it be possible to extend the rules files parser
> > to support continuation lines? I'd like it to consider lines starting
> > with white space as part of the previous line.)
>
> How about the usual backslash at the end of the line. Here is a simple
> patch.

namedev_parse.c
test/udev-test.pl
udev.8.in
udev.h
udev_config.c
udev_utils.c
udev_utils.h

index 7190cdd1a8702a538f5f454d96e3ca84a00f7b6f..3b14a6a50051a10e774b47f0dbbb5c0d8c311022 100644 (file)
@@ -126,14 +126,15 @@ static int namedev_parse(const char *filename, void *data)
        cur = 0;
        lineno = 0;
        while (cur < bufsize) {
+               int i, j;
+
                count = buf_get_line(buf, bufsize, cur);
                bufline = &buf[cur];
                cur += count+1;
                lineno++;
 
                if (count >= LINE_SIZE) {
-                       info("line too long, rule skipped %s, line %d",
-                            filename, lineno);
+                       info("line too long, rule skipped %s, line %d", filename, lineno);
                        continue;
                }
 
@@ -149,8 +150,14 @@ static int namedev_parse(const char *filename, void *data)
                if (bufline[0] == COMMENT_CHARACTER)
                        continue;
 
-               strncpy(line, bufline, count);
-               line[count] = '\0';
+               /* skip backslash and newline from multi line rules */
+               for (i = j = 0; i < count; i++) {
+                       if (bufline[i] == '\\' || bufline[i] == '\n')
+                               continue;
+
+                       line[j++] = bufline[i];
+               }
+               line[j] = '\0';
                dbg_parse("read '%s'", line);
 
                /* get all known keys */
index 9a581ce5276ff01d413c928fd369f5c01ee1bf54..53eee35457012fcd2575a11cbff727f4abca5521 100644 (file)
@@ -187,6 +187,36 @@ EOF
 
 KERNEL="ttyUSB0", NAME="visor"
 
+EOF
+       },
+       {
+               desc            => "Handle backslashed multi lines in config file (and replace kernel name)",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "visor" ,
+               conf            => <<EOF
+KERNEL="ttyUSB0", \\
+NAME="visor"
+
+EOF
+       },
+       {
+               desc            => "Handle stupid backslashed multi lines in config file (and replace kernel name)",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "visor" ,
+               conf            => <<EOF
+
+#
+\\
+
+\\\\
+
+#\\
+
+KERNEL="ttyUSB0", \\
+NAME="visor"
+
 EOF
        },
        {
index 5d55b3282c256326c899f281c70e4cb8af71eb79..0cc2f939e3fa77dc924263273e16386e4d1384cb 100644 (file)
--- a/udev.8.in
+++ b/udev.8.in
@@ -203,10 +203,10 @@ separate rules file, while the device nodes are maintained by the
 distribution provided rules file.
 .TP
 .B OWNER, GROUP, MODE
-The permissions for this device. Every specified value overwrites the default
-value specified in the config file.
+The permissions for the device node. Every specified value overwrites the
+default value specified in the config file.
 .P
-.RB "The " NAME " ," SYMLINK " and " PROGRAM
+.RB "The " NAME ", " SYMLINK ", " PROGRAM ", " OWNER " and " GROUP
 fields support simple printf-like string substitutions:
 .TP
 .B %n
diff --git a/udev.h b/udev.h
index 0111644efffd5612f77b37e99962f82ba0b2c844..80eafb0d46a25e7318b67f38fe0529c50ad789a6 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -37,7 +37,7 @@
 #define SUBSYSTEM_SIZE                 32
 #define SEQNUM_SIZE                    32
 
-#define LINE_SIZE                      256
+#define LINE_SIZE                      512
 
 #define DEVD_DIR                       "/etc/dev.d"
 #define DEVD_SUFFIX                    ".dev"
@@ -74,7 +74,6 @@ extern int udev_add_device(struct udevice *udev, struct sysfs_class_device *clas
 extern int udev_remove_device(struct udevice *udev);
 extern void udev_init_config(void);
 extern int udev_start(void);
-extern int parse_get_pair(char **orig_string, char **left, char **right);
 extern void udev_multiplex_directory(struct udevice *udev, const char *basedir, const char *suffix);
 
 extern char sysfs_path[SYSFS_PATH_MAX];
index 31c2a86ed1c1b3ce09ff99cd896a2a2c33b92837..da8c676d04f9a49f455f02e2053101fe3f758425 100644 (file)
@@ -91,41 +91,6 @@ static void init_variables(void)
                udev_hotplug_d = 0;
 }
 
-int parse_get_pair(char **orig_string, char **left, char **right)
-{
-       char *temp;
-       char *string = *orig_string;
-
-       if (!string)
-               return -ENODEV;
-
-       /* eat any whitespace */
-       while (isspace(*string) || *string == ',')
-               ++string;
-
-       /* split based on '=' */
-       temp = strsep(&string, "=");
-       *left = temp;
-       if (!string)
-               return -ENODEV;
-
-       /* take the right side and strip off the '"' */
-       while (isspace(*string))
-               ++string;
-       if (*string == '"')
-               ++string;
-       else
-               return -ENODEV;
-
-       temp = strsep(&string, "\"");
-       if (!string || *temp == '\0')
-               return -ENODEV;
-       *right = temp;
-       *orig_string = string;
-       
-       return 0;
-}
-
 static int parse_config_file(void)
 {
        char line[LINE_SIZE];
@@ -254,20 +219,13 @@ static void get_dirs(void)
                        strfieldcpy(udev_config_filename, temp);
        }
 
-       dbg("sysfs_path='%s'", sysfs_path);
-       dbg_parse("udev_root = %s", udev_root);
-       dbg_parse("udev_config_filename = %s", udev_config_filename);
-       dbg_parse("udev_db_path = %s", udev_db_path);
-       dbg_parse("udev_rules_filename = %s", udev_rules_filename);
-       dbg_parse("udev_log = %d", udev_log);
-
        parse_config_file();
-
-       dbg("udev_root = %s", udev_root);
-       dbg("udev_config_filename = %s", udev_config_filename);
-       dbg("udev_db_path = %s", udev_db_path);
-       dbg("udev_rules_filename = %s", udev_rules_filename);
-       dbg("udev_log = %d", udev_log);
+       dbg("sysfs_path='%s'", sysfs_path);
+       dbg("udev_root='%s'", udev_root);
+       dbg("udev_config_filename='%s'", udev_config_filename);
+       dbg("udev_db_path='%s'", udev_db_path);
+       dbg("udev_rules_filename='%s'", udev_rules_filename);
+       dbg("udev_log=%d", udev_log);
 }
 
 void udev_init_config(void)
index 0b730d565b666fd7f9f648a782de3d99d6b92d96..fe18892de19fa2eeb3332ad526b8b5c533430cd9 100644 (file)
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <ctype.h>
 #include <dirent.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
@@ -111,6 +112,41 @@ int create_path(const char *path)
        return mkdir(p, 0755);
 }
 
+int parse_get_pair(char **orig_string, char **left, char **right)
+{
+       char *temp;
+       char *string = *orig_string;
+
+       if (!string)
+               return -ENODEV;
+
+       /* eat any whitespace */
+       while (isspace(*string) || *string == ',')
+               ++string;
+
+       /* split based on '=' */
+       temp = strsep(&string, "=");
+       *left = temp;
+       if (!string)
+               return -ENODEV;
+
+       /* take the right side and strip off the '"' */
+       while (isspace(*string))
+               ++string;
+       if (*string == '"')
+               ++string;
+       else
+               return -ENODEV;
+
+       temp = strsep(&string, "\"");
+       if (!string || *temp == '\0')
+               return -ENODEV;
+       *right = temp;
+       *orig_string = string;
+       
+       return 0;
+}
+
 int file_map(const char *filename, char **buf, size_t *bufsize)
 {
        struct stat stats;
@@ -143,11 +179,21 @@ void file_unmap(char *buf, size_t bufsize)
        munmap(buf, bufsize);
 }
 
-size_t buf_get_line(char *buf, size_t buflen, size_t cur)
+/* return number of chars until the next newline, skip escaped newline */
+size_t buf_get_line(const char *buf, size_t buflen, size_t cur)
 {
-       size_t count = 0;
+       int escape = 0;
+       size_t count;
+
+       for (count = cur; count < buflen; count++) {
+               if (!escape && buf[count] == '\n')
+                       break;
 
-       for (count = cur; count < buflen && buf[count] != '\n'; count++);
+               if (buf[count] == '\\')
+                       escape = 1;
+               else
+                       escape = 0;
+       }
 
        return count - cur;
 }
index e36255f526f1e72b89d69eaf1c5dbcfd3e2ddc02..cc9dd704de50f06e2556b82faef172d0b6676f9f 100644 (file)
@@ -79,9 +79,10 @@ do { \
 extern void udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem);
 extern int kernel_release_satisfactory(int version, int patchlevel, int sublevel);
 extern int create_path(const char *path);
+extern int parse_get_pair(char **orig_string, char **left, char **right);
 extern int file_map(const char *filename, char **buf, size_t *bufsize);
 extern void file_unmap(char *buf, size_t bufsize);
-extern size_t buf_get_line(char *buf, size_t buflen, size_t cur);
+extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
 extern void no_trailing_slash(char *path);
 typedef int (*file_fnct_t)(const char *filename, void *data);
 extern int  call_foreach_file(file_fnct_t fnct, const char *dirname,