chiark / gitweb /
fstab_import: add program to IMPORT matching fstab entry
[elogind.git] / udevtrigger.c
index 7584e02a67dbeee9ce6e097b64f868a9afbf70b7..72464c838159e50b0a0f0ea05723839c000195b1 100644 (file)
@@ -70,7 +70,7 @@ static int device_list_insert(const char *path)
        char devpath[PATH_SIZE];
        struct stat statbuf;
 
-       dbg("add '%s'" , path);
+       dbg("add '%s'\n" , path);
 
        /* we only have a device, if we have an uevent file */
        strlcpy(filename, path, sizeof(filename));
@@ -110,12 +110,12 @@ static void trigger_uevent(const char *devpath, const char *action)
 
        fd = open(filename, O_WRONLY);
        if (fd < 0) {
-               dbg("error on opening %s: %s", filename, strerror(errno));
+               dbg("error on opening %s: %s\n", filename, strerror(errno));
                return;
        }
 
        if (write(fd, action, strlen(action)) < 0)
-               info("error writing '%s' to '%s': %s", action, filename, strerror(errno));
+               info("error writing '%s' to '%s': %s\n", action, filename, strerror(errno));
 
        close(fd);
 }
@@ -133,6 +133,9 @@ static int pass_to_socket(const char *devpath, const char *action)
        int len;
        int err = 0;
 
+       if (verbose)
+               printf("%s\n", devpath);
+
        udev_device_init(&udev);
        udev_db_get_device(&udev, devpath);
 
@@ -235,7 +238,7 @@ static void exec_list(const char *action)
        list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) {
                if (delay_device(loop_device->name))
                        continue;
-               if (sock)
+               if (sock >= 0)
                        pass_to_socket(loop_device->name, action);
                else
                        trigger_uevent(loop_device->name, action);
@@ -245,7 +248,7 @@ static void exec_list(const char *action)
 
        /* trigger remaining delayed devices */
        list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) {
-               if (sock)
+               if (sock >= 0)
                        pass_to_socket(loop_device->name, action);
                else
                        trigger_uevent(loop_device->name, action);
@@ -571,7 +574,7 @@ int udevtrigger(int argc, char *argv[], char *envp[])
 
        logging_init("udevtrigger");
        udev_config_init();
-       dbg("version %s", UDEV_VERSION);
+       dbg("version %s\n", UDEV_VERSION);
        sysfs_init();
 
        while (1) {
@@ -628,12 +631,24 @@ int udevtrigger(int argc, char *argv[], char *envp[])
        }
 
        if (sockpath != NULL) {
+               struct stat stats;
+
                sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
                memset(&saddr, 0x00, sizeof(struct sockaddr_un));
                saddr.sun_family = AF_LOCAL;
-               /* abstract namespace only */
-               strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1);
-               saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
+               if (sockpath[0] == '@') {
+                       /* abstract namespace socket requested */
+                       strlcpy(&saddr.sun_path[1], &sockpath[1], sizeof(saddr.sun_path)-1);
+                       saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
+               } else if (stat(sockpath, &stats) == 0 && S_ISSOCK(stats.st_mode)) {
+                       /* existing socket file */
+                       strlcpy(saddr.sun_path, sockpath, sizeof(saddr.sun_path));
+                       saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path);
+               } else {
+                       /* no socket file, assume abstract namespace socket */
+                       strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1);
+                       saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
+               }
        }
 
        if (failed) {