X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udevd.c;h=df6e2228106173db10212ee025cb1184bb633f6b;hb=b52a01ee39dad3b04aaa7e3af7435f062d3e887f;hp=de7cace3e191a962d5746efec0957c13436e1b4a;hpb=2f64aa4056835231ed297a79d39d5416e0045d0c;p=elogind.git diff --git a/udevd.c b/udevd.c index de7cace3e..df6e22281 100644 --- a/udevd.c +++ b/udevd.c @@ -1,10 +1,7 @@ /* - * udevd.c - event listener and serializer - * * Copyright (C) 2004-2006 Kay Sievers * Copyright (C) 2004 Chris Friesen * - * * 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. * */ @@ -32,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -79,6 +77,7 @@ void log_message(int priority, const char *format, ...) vsyslog(priority, format, args); va_end(args); } + #endif static void asmlinkage udev_event_sig_handler(int signum) @@ -158,9 +157,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 +191,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 +565,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 +602,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) { @@ -920,7 +918,12 @@ int main(int argc, char *argv[], char *envp[]) fd_set readfds; const char *value; int daemonize = 0; - int i; + int option; + static const struct option options[] = { + { "daemon", 0, NULL, 'd' }, + { "help", 0, NULL, 'h' }, + {} + }; int rc = 1; int maxfd; @@ -929,26 +932,30 @@ 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]; - if (strcmp(arg, "--daemon") == 0 || strcmp(arg, "-d") == 0) + while (1) { + option = getopt_long(argc, argv, "dtvh", options, NULL); + if (option == -1) + break; + + switch (option) { + case 'd': daemonize = 1; - else if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) { + break; + case 'h': printf("Usage: udevd [--help] [--daemon]\n"); goto exit; - } else { - fprintf(stderr, "unrecognized option '%s'\n", arg); - err("unrecognized option '%s'\n", arg); + default: + goto exit; } } + 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) {