chiark / gitweb /
udevd: at startup write message including version number to kernel log
[elogind.git] / udevtrigger.c
index 7584e02a67dbeee9ce6e097b64f868a9afbf70b7..e50fd4ee04e9ea4915ed9d9b0d31d605fa3941cd 100644 (file)
@@ -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);
@@ -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) {