4 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <sys/types.h>
22 #include <sys/socket.h>
32 #include <linux/stddef.h>
37 /* global variables */
39 static int udev_log = 0;
42 void log_message (int priority, const char *format, ...)
46 if (priority > udev_log)
49 va_start(args, format);
50 vsyslog(priority, format, args);
56 int main(int argc, char *argv[], char *envp[])
58 static struct udevd_msg usend_msg;
59 struct sockaddr_un saddr;
67 env = getenv("UDEV_LOG");
69 udev_log = log_priority(env);
71 logging_init("udevcontrol");
72 dbg("version %s", UDEV_VERSION);
75 fprintf(stderr, "missing command\n\n");
79 memset(&usend_msg, 0x00, sizeof(struct udevd_msg));
80 strcpy(usend_msg.magic, UDEV_MAGIC);
82 for (i = 1 ; i < argc; i++) {
85 if (!strcmp(arg, "stop_exec_queue"))
86 usend_msg.type = UDEVD_STOP_EXEC_QUEUE;
87 else if (!strcmp(arg, "start_exec_queue"))
88 usend_msg.type = UDEVD_START_EXEC_QUEUE;
89 else if (!strcmp(arg, "reload_rules"))
90 usend_msg.type = UDEVD_RELOAD_RULES;
91 else if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
92 intval = (int *) usend_msg.envbuf;
93 val = &arg[strlen("log_priority=")];
94 usend_msg.type = UDEVD_SET_LOG_LEVEL;
95 *intval = log_priority(val);
96 info("send log_priority=%i", *intval);
97 } else if (!strncmp(arg, "max_childs=", strlen("max_childs="))) {
98 intval = (int *) usend_msg.envbuf;
99 val = &arg[strlen("max_childs=")];
100 usend_msg.type = UDEVD_SET_MAX_CHILDS;
102 info("send max_childs=%i", *intval);
103 } else if (strcmp(arg, "help") == 0 || strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) {
104 printf("Usage: udevcontrol COMMAND\n"
105 " log_priority=<level> set the udev log level for the daemon\n"
106 " stop_exec_queue keep udevd from executing events, queue only\n"
107 " start_exec_queue execute events, flush queue\n"
108 " reload_rules reloads the rules files\n"
109 " max_childs=<N> maximum number of childs running at the same time\n"
110 " --help print this help text\n\n");
113 fprintf(stderr, "unknown option\n\n");
119 fprintf(stderr, "need to be root, exit\n\n");
123 sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
125 err("error getting socket: %s", strerror(errno));
129 memset(&saddr, 0x00, sizeof(struct sockaddr_un));
130 saddr.sun_family = AF_LOCAL;
131 /* use abstract namespace for socket path */
132 strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
133 addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
136 retval = sendto(sock, &usend_msg, sizeof(usend_msg), 0, (struct sockaddr *)&saddr, addrlen);
138 err("error sending message: %s", strerror(errno));
141 dbg("sent message type=0x%02x, %u bytes sent", usend_msg.type, retval);