[systemd-commits] 3 commits - src/udev

Tom Gundersen tomegun at kemper.freedesktop.org
Fri Nov 28 12:58:23 PST 2014


 src/udev/udev-rules.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

New commits:
commit 9f5ecdb0b11557be41c065f460bb22ab52bb0034
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Nov 28 21:51:45 2014 +0100

    udev: rules - ignore the lack of trailing newline
    
    Also accept '\r' as newline character.
    
    This dropps warnings of the type:
    
      invalid key/value pair in file /usr/lib/udev/rules.d/40-usb-media-players.rules
      on line 26, starting at character 25 ('')

diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 131abd6..447a868 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1067,7 +1067,7 @@ static int add_rule(struct udev_rules *rules, char *line,
 
                         /* If we aren't at the end of the line, this is a parsing error.
                          * Make a best effort to describe where the problem is. */
-                        if (*linepos != '\n') {
+                        if (!strchr(NEWLINE "\0", *linepos)) {
                                 char buf[2] = {*linepos};
                                 _cleanup_free_ char *tmp;
 

commit 6501b52d358aa2c7fe28e477f9d5acf0a2991d32
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Nov 28 21:46:34 2014 +0100

    udev: rules - print the first invalid character
    
    The current code would print the character following the first invalid
    character.
    
    Given an udev rules-file without a trailing newline we would otherwise print
    garbage:
    
      invalid key/value pair in file /usr/lib/udev/rules.d/40-usb-media-players.rules
      on line 26, starting at character 25 ('m')
    
    This is now changed to print
    
      invalid key/value pair in file /usr/lib/udev/rules.d/40-usb-media-players.rules
      on line 26, starting at character 25 ('')
    
    (still not very good as printing \0 just gives the empty string)

diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index a261fbf..131abd6 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1068,13 +1068,13 @@ static int add_rule(struct udev_rules *rules, char *line,
                         /* If we aren't at the end of the line, this is a parsing error.
                          * Make a best effort to describe where the problem is. */
                         if (*linepos != '\n') {
-                                char buf[2] = {linepos[1]};
+                                char buf[2] = {*linepos};
                                 _cleanup_free_ char *tmp;
 
                                 tmp = cescape(buf);
                                 log_error("invalid key/value pair in file %s on line %u, starting at character %tu ('%s')",
                                           filename, lineno, linepos - line + 1, tmp);
-                                if (linepos[1] == '#')
+                                if (*linepos == '#')
                                         log_error("hint: comments can only start at beginning of line");
                         }
                         break;

commit 84198c1892cce2cb27d22bfa816da5d43c05add0
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Nov 28 21:44:31 2014 +0100

    udev: rules - modernise add_rule a bit

diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index ff2d4ec..a261fbf 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1042,11 +1042,11 @@ static int add_rule(struct udev_rules *rules, char *line,
                     const char *filename, unsigned int filename_off, unsigned int lineno) {
         char *linepos;
         const char *attr;
-        struct rule_tmp rule_tmp;
+        struct rule_tmp rule_tmp = {
+                .rules = rules,
+                .rule.type = TK_RULE,
+        };
 
-        memzero(&rule_tmp, sizeof(struct rule_tmp));
-        rule_tmp.rules = rules;
-        rule_tmp.rule.type = TK_RULE;
         /* the offset in the rule is limited to unsigned short */
         if (filename_off < USHRT_MAX)
                 rule_tmp.rule.rule.filename_off = filename_off;



More information about the systemd-commits mailing list