chiark / gitweb /
udevtrigger: fix pattern match
[elogind.git] / udevd.c
diff --git a/udevd.c b/udevd.c
index de7cace3e191a962d5746efec0957c13436e1b4a..a21d2ab77d6cfe050bad776f66ca96be9948d80b 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -1,10 +1,7 @@
 /*
- * udevd.c - event listener and serializer
- *
  * Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
  * Copyright (C) 2004 Chris Friesen <chris_friesen@sympatico.ca>
  *
- *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the
  *     Free Software Foundation version 2 of the License.
@@ -16,7 +13,7 @@
  *
  *     You should have received a copy of the GNU General Public License along
  *     with this program; if not, write to the Free Software Foundation, Inc.,
- *     675 Mass Ave, Cambridge, MA 02139, USA.
+ *     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  */
 
@@ -158,9 +155,9 @@ static void export_event_state(struct udevd_uevent_msg *msg, enum event_state st
 {
        char filename[PATH_SIZE];
        char filename_failed[PATH_SIZE];
-       char target[PATH_SIZE];
        size_t start, end, i;
        struct udevd_uevent_msg *loop_msg;
+       int fd;
 
        /* add location of queue files */
        strlcpy(filename, udev_root, sizeof(filename));
@@ -192,11 +189,10 @@ static void export_event_state(struct udevd_uevent_msg *msg, enum event_state st
        case EVENT_QUEUED:
                unlink(filename_failed);
                delete_path(filename_failed);
-
-               strlcpy(target, sysfs_path, sizeof(target));
-               strlcat(target, msg->devpath, sizeof(target));
                create_path(filename);
-               symlink(target, filename);
+               fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0644);
+               if (fd > 0)
+                       close(fd);
                return;
        case EVENT_FINISHED:
        case EVENT_FAILED:
@@ -567,8 +563,8 @@ static struct udevd_uevent_msg *get_msg_from_envbuf(const char *buf, int buf_siz
        int i;
        struct udevd_uevent_msg *msg;
        char *physdevdriver_key = NULL;
-       int major = 0;
-       int minor = 0;
+       int maj = 0;
+       int min = 0;
 
        msg = malloc(sizeof(struct udevd_uevent_msg) + buf_size);
        if (msg == NULL)
@@ -604,13 +600,13 @@ static struct udevd_uevent_msg *get_msg_from_envbuf(const char *buf, int buf_siz
                else if (strncmp(key, "PHYSDEVDRIVER=", 14) == 0)
                        physdevdriver_key = key;
                else if (strncmp(key, "MAJOR=", 6) == 0)
-                       major = strtoull(&key[6], NULL, 10);
+                       maj = strtoull(&key[6], NULL, 10);
                else if (strncmp(key, "MINOR=", 6) == 0)
-                       minor = strtoull(&key[6], NULL, 10);
+                       min = strtoull(&key[6], NULL, 10);
                else if (strncmp(key, "TIMEOUT=", 8) == 0)
                        msg->timeout = strtoull(&key[8], NULL, 10);
        }
-       msg->devt = makedev(major, minor);
+       msg->devt = makedev(maj, min);
        msg->envp[i++] = "UDEVD_EVENT=1";
 
        if (msg->driver == NULL && msg->physdevpath == NULL && physdevdriver_key != NULL) {
@@ -929,12 +925,6 @@ int main(int argc, char *argv[], char *envp[])
        selinux_init();
        dbg("version %s", UDEV_VERSION);
 
-       if (getuid() != 0) {
-               fprintf(stderr, "root privileges required\n");
-               err("root privileges required");
-               goto exit;
-       }
-
        /* parse commandline options */
        for (i = 1 ; i < argc; i++) {
                char *arg = argv[i];
@@ -949,6 +939,12 @@ int main(int argc, char *argv[], char *envp[])
                }
        }
 
+       if (getuid() != 0) {
+               fprintf(stderr, "root privileges required\n");
+               err("root privileges required");
+               goto exit;
+       }
+
        /* init sockets to receive events */
        if (init_udevd_socket() < 0) {
                if (errno == EADDRINUSE) {