chiark / gitweb /
Revert "udev-rules.c: remove 'first_token' variable"
[elogind.git] / udev / udev-rules.c
index 53baa187e6fed214112a85461d3e22b1b5119075..a92446403ff2604568814d455cd907ffd3c63895 100644 (file)
@@ -27,6 +27,7 @@
 #include <errno.h>
 #include <dirent.h>
 #include <fnmatch.h>
+#include <time.h>
 
 #include "udev.h"
 
@@ -814,6 +815,8 @@ static int wait_for_file(struct udev_device *dev, const char *file, int timeout)
 
        dbg(udev, "will wait %i sec for '%s'\n", timeout, file);
        while (--loop) {
+               const struct timespec duration = { 0, 1000 * 1000 * 1000 / WAIT_LOOP_PER_SECOND };
+
                /* lookup file */
                if (stat(file, &stats) == 0) {
                        info(udev, "file '%s' appeared after %i loops\n", file, (timeout * WAIT_LOOP_PER_SECOND) - loop-1);
@@ -825,7 +828,7 @@ static int wait_for_file(struct udev_device *dev, const char *file, int timeout)
                        return -2;
                }
                info(udev, "wait for '%s' for %i mseconds\n", file, 1000 / WAIT_LOOP_PER_SECOND);
-               usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND);
+               nanosleep(&duration, NULL);
        }
        info(udev, "waiting for '%s' failed\n", file);
        return -1;
@@ -875,7 +878,7 @@ static int get_key(struct udev *udev, char **line, char **key, enum operation_ty
        char *temp;
 
        linepos = *line;
-       if (linepos == NULL && linepos[0] == '\0')
+       if (linepos == NULL || linepos[0] == '\0')
                return -1;
 
        /* skip whitespace */
@@ -1406,6 +1409,9 @@ static int add_rule(struct udev_rules *rules, char *line,
                        } else {
                                if (value[0] == '\0')
                                        info(rules->udev, "name empty, node creation suppressed\n");
+                               else if (strcmp(value, "%k") == 0)
+                                       err(rules->udev, "NAME=\"%%k\" is superfluous and breaks "
+                                           "kernel supplied names, please remove it from %s:%u\n", filename, lineno);
                                rule_add_key(&rule_tmp, TK_A_NAME, op, value, NULL);
                                attr = get_key_attribute(rules->udev, key + sizeof("NAME")-1);
                                if (attr != NULL) {
@@ -1597,6 +1603,8 @@ static int parse_file(struct udev_rules *rules, const char *filename, unsigned s
                while (line[len-2] == '\\') {
                        if (fgets(&line[len-2], (sizeof(line)-len)+2, f) == NULL)
                                break;
+                       if (strlen(&line[len-2]) < 2)
+                               break;
                        line_nr++;
                        len = strlen(line);
                }
@@ -1795,7 +1803,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
                if (stat(filename, &statbuf) == 0 && statbuf.st_size > 0)
                        parse_file(rules, filename, filename_off);
                else
-                       info(udev, "can not read '%s'\n", filename);
+                       err(udev, "can not read '%s'\n", filename);
                udev_list_entry_delete(file_loop);
        }