chiark / gitweb /
udev: fix printf(3) type specifier
[elogind.git] / src / udev / udev-rules.c
index 8ace7050dbdf49432d4524bae049582d66877ef2..f14158b5006306ca03de12b035753b33f8932798 100644 (file)
@@ -34,6 +34,7 @@
 #include "conf-files.h"
 #include "strbuf.h"
 #include "strv.h"
+#include "util.h"
 
 #define PREALLOC_TOKEN          2048
 
@@ -1066,8 +1067,22 @@ static int add_rule(struct udev_rules *rules, char *line,
                 char *value;
                 enum operation_type op;
 
-                if (get_key(rules->udev, &linepos, &key, &op, &value) != 0)
+                if (get_key(rules->udev, &linepos, &key, &op, &value) != 0) {
+                        /* 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]};
+                                _cleanup_free_ char *tmp;
+
+                                tmp = cescape(buf);
+                                log_error("invalid key/value pair in file %s on line %u,"
+                                          "starting at character %tu ('%s')\n",
+                                          filename, lineno, linepos - line + 1, tmp);
+                                if (linepos[1] == '#')
+                                        log_info("hint: comments can only start at beginning of line");
+                        }
                         break;
+                }
 
                 if (streq(key, "ACTION")) {
                         if (op > OP_MATCH_MAX) {
@@ -2586,6 +2601,10 @@ int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
                                 }
                         }
 
+                        /* don't touch the permissions if only the tags were set */
+                        if (mode == 0 && uid == 0 && gid == 0)
+                                goto next;
+
                         if (mode == 0) {
                                 if (gid > 0)
                                         mode = 0660;
@@ -2593,13 +2612,21 @@ int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
                                         mode = 0600;
                         }
                         if (mode != (stats.st_mode & 01777)) {
-                                chmod(device_node, mode);
-                                log_debug("chmod '%s' %#o\n", device_node, mode);
+                                r = chmod(device_node, mode);
+                                if (r < 0) {
+                                        log_error("failed to chmod '%s' %#o\n", device_node, mode);
+                                        return -errno;
+                                } else
+                                        log_debug("chmod '%s' %#o\n", device_node, mode);
                         }
 
                         if ((uid != 0 && uid != stats.st_uid) || (gid != 0 && gid != stats.st_gid)) {
-                                chown(device_node, uid, gid);
-                                log_debug("chown '%s' %u %u\n", device_node, uid, gid);
+                                r = chown(device_node, uid, gid);
+                                if (r < 0) {
+                                        log_error("failed to chown '%s' %u %u \n", device_node, uid, gid);
+                                        return -errno;
+                                } else
+                                        log_debug("chown '%s' %u %u\n", device_node, uid, gid);
                         }
 
                         utimensat(AT_FDCWD, device_node, NULL, 0);