chiark / gitweb /
path_id: fix an harmless syntax error
[elogind.git] / udevcontrol.c
index f16f6a125ab40d96b1190f06ee1d4fe933a6638a..2d93f65ce8c33c4af6c8c8c42532b2e6a62826cc 100644 (file)
  *
  */
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/wait.h>
-#include <sys/un.h>
 #include <time.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stddef.h>
 #include <string.h>
 #include <unistd.h>
-#include <linux/stddef.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <sys/un.h>
 
 #include "udev.h"
-#include "udev_version.h"
 #include "udevd.h"
-#include "udev_utils.h"
-#include "logging.h"
 
-/* global variables */
 static int sock = -1;
-static int log = 0;
+static int udev_log = 0;
 
 #ifdef USE_LOG
 void log_message (int priority, const char *format, ...)
 {
        va_list args;
 
-       if (priority > log)
+       if (priority > udev_log)
                return;
 
        va_start(args, format);
@@ -55,6 +50,16 @@ void log_message (int priority, const char *format, ...)
 }
 #endif
 
+static void usage(void)
+{
+       printf("Usage: udevcontrol COMMAND\n"
+               "  log_priority=<level> set the udev log level for the daemon\n"
+               "  stop_exec_queue      keep udevd from executing events, queue only\n"
+               "  start_exec_queue     execute events, flush queue\n"
+               "  reload_rules         reloads the rules files\n"
+               "  max_childs=<N>       maximum number of childs running at the same time\n"
+               "  --help               print this help text\n\n");
+}
 
 int main(int argc, char *argv[], char *envp[])
 {
@@ -69,13 +74,14 @@ int main(int argc, char *argv[], char *envp[])
 
        env = getenv("UDEV_LOG");
        if (env)
-               log = log_priority(env);
+               udev_log = log_priority(env);
 
        logging_init("udevcontrol");
        dbg("version %s", UDEV_VERSION);
 
        if (argc < 2) {
                fprintf(stderr, "missing command\n\n");
+               usage();
                goto exit;
        }
 
@@ -89,6 +95,8 @@ int main(int argc, char *argv[], char *envp[])
                        usend_msg.type = UDEVD_STOP_EXEC_QUEUE;
                else if (!strcmp(arg, "start_exec_queue"))
                        usend_msg.type = UDEVD_START_EXEC_QUEUE;
+               else if (!strcmp(arg, "reload_rules"))
+                       usend_msg.type = UDEVD_RELOAD_RULES;
                else if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
                        intval = (int *) usend_msg.envbuf;
                        val = &arg[strlen("log_priority=")];
@@ -102,27 +110,23 @@ int main(int argc, char *argv[], char *envp[])
                        *intval = atoi(val);
                        info("send max_childs=%i", *intval);
                } else if (strcmp(arg, "help") == 0  || strcmp(arg, "--help") == 0  || strcmp(arg, "-h") == 0) {
-                       printf("Usage: udevcontrol COMMAND\n"
-                               "  log_priority=<level> set the udev log level for the daemon\n"
-                               "  stop_exec_queue      keep udevd from executing events, queue only\n"
-                               "  start_exec_queue     execute events, flush queue\n"
-                               "  max_childs=<N>       maximum number of childs running at the same time\n"
-                               "  --help               print this help text\n\n");
-                       exit(0);
+                       usage();
+                       goto exit;
                } else {
                        fprintf(stderr, "unknown option\n\n");
-                       exit(1);
+                       usage();
+                       goto exit;
                }
        }
 
        if (getuid() != 0) {
                fprintf(stderr, "need to be root, exit\n\n");
-               exit(1);
+               goto exit;
        }
 
        sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
        if (sock == -1) {
-               err("error getting socket");
+               err("error getting socket: %s", strerror(errno));
                goto exit;
        }
 
@@ -132,10 +136,9 @@ int main(int argc, char *argv[], char *envp[])
        strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
        addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
 
-
        retval = sendto(sock, &usend_msg, sizeof(usend_msg), 0, (struct sockaddr *)&saddr, addrlen);
        if (retval == -1) {
-               info("error sending message (%s)", strerror(errno));
+               err("error sending message: %s", strerror(errno));
                retval = 1;
        } else {
                dbg("sent message type=0x%02x, %u bytes sent", usend_msg.type, retval);
@@ -143,9 +146,7 @@ int main(int argc, char *argv[], char *envp[])
        }
 
        close(sock);
-
 exit:
        logging_close();
-
        return retval;
 }