chiark / gitweb /
udevd: clarify worker exit status
[elogind.git] / libudev / libudev-util.c
index 3a67b0cd5d0f15a43c75221bc2750a003f1762b8..48eea0b8981282bd25d692de973293910be4c6f3 100644 (file)
@@ -18,6 +18,7 @@
 #include <dirent.h>
 #include <ctype.h>
 #include <fcntl.h>
+#include <time.h>
 #include <sys/stat.h>
 
 #include "libudev.h"
 static ssize_t get_sys_link(struct udev *udev, const char *slink, const char *syspath, char *value, size_t size)
 {
        char path[UTIL_PATH_SIZE];
+       char target[UTIL_PATH_SIZE];
        ssize_t len;
        const char *pos;
 
        util_strscpyl(path, sizeof(path), syspath, "/", slink, NULL);
-       len = readlink(path, path, sizeof(path));
-       if (len <= 0 || len == (ssize_t)sizeof(path))
+       len = readlink(path, target, sizeof(target));
+       if (len <= 0 || len == (ssize_t)sizeof(target))
                return -1;
-       path[len] = '\0';
-       pos = strrchr(path, '/');
+       target[len] = '\0';
+       pos = strrchr(target, '/');
        if (pos == NULL)
                return -1;
        pos = &pos[1];
@@ -87,13 +89,13 @@ int util_log_priority(const char *priority)
        int prio;
 
        prio = strtol(priority, &endptr, 10);
-       if (endptr[0] == '\0')
+       if (endptr[0] == '\0' || isspace(endptr[0]))
                return prio;
        if (strncmp(priority, "err", 3) == 0)
                return LOG_ERR;
-       if (strcmp(priority, "info") == 0)
+       if (strncmp(priority, "info", 4) == 0)
                return LOG_INFO;
-       if (strcmp(priority, "debug") == 0)
+       if (strncmp(priority, "debug", 5) == 0)
                return LOG_DEBUG;
        return 0;
 }
@@ -552,3 +554,15 @@ uint64_t util_string_bloom64(const char *str)
        bits |= 1LLU << ((hash >> 18) & 63);
        return bits;
 }
+
+#define USEC_PER_SEC  1000000ULL
+#define NSEC_PER_USEC 1000ULL
+unsigned long long now_usec(void)
+{
+       struct timespec ts;
+
+       if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
+               return 0;
+       return (unsigned long long) ts.tv_sec * USEC_PER_SEC +
+              (unsigned long long) ts.tv_nsec / NSEC_PER_USEC;
+}