2 * Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include <sys/types.h>
27 #include <sys/socket.h>
35 static int udev_log = 0;
38 void log_message (int priority, const char *format, ...)
42 if (priority > udev_log)
45 va_start(args, format);
46 vsyslog(priority, format, args);
51 int main(int argc, char *argv[], char *envp[])
53 static struct udevd_ctrl_msg ctrl_msg;
54 struct sockaddr_un saddr;
62 env = getenv("UDEV_LOG");
64 udev_log = log_priority(env);
66 logging_init("udevcontrol");
67 dbg("version %s", UDEV_VERSION);
70 fprintf(stderr, "missing command\n\n");
74 memset(&ctrl_msg, 0x00, sizeof(struct udevd_ctrl_msg));
75 strcpy(ctrl_msg.magic, UDEVD_CTRL_MAGIC);
77 for (i = 1 ; i < argc; i++) {
80 if (!strcmp(arg, "stop_exec_queue"))
81 ctrl_msg.type = UDEVD_CTRL_STOP_EXEC_QUEUE;
82 else if (!strcmp(arg, "start_exec_queue"))
83 ctrl_msg.type = UDEVD_CTRL_START_EXEC_QUEUE;
84 else if (!strcmp(arg, "reload_rules"))
85 ctrl_msg.type = UDEVD_CTRL_RELOAD_RULES;
86 else if (!strncmp(arg, "log_priority=", strlen("log_priority="))) {
87 intval = (int *) ctrl_msg.buf;
88 val = &arg[strlen("log_priority=")];
89 ctrl_msg.type = UDEVD_CTRL_SET_LOG_LEVEL;
90 *intval = log_priority(val);
91 info("send log_priority=%i", *intval);
92 } else if (!strncmp(arg, "max_childs=", strlen("max_childs="))) {
96 intval = (int *) ctrl_msg.buf;
97 val = &arg[strlen("max_childs=")];
98 ctrl_msg.type = UDEVD_CTRL_SET_MAX_CHILDS;
99 count = strtoul(val, &endp, 0);
100 if (endp[0] != '\0' || count < 1) {
101 fprintf(stderr, "invalid number\n");
105 info("send max_childs=%i", *intval);
106 } else if (!strncmp(arg, "max_childs_running=", strlen("max_childs_running="))) {
110 intval = (int *) ctrl_msg.buf;
111 val = &arg[strlen("max_childs_running=")];
112 ctrl_msg.type = UDEVD_CTRL_SET_MAX_CHILDS_RUNNING;
113 count = strtoul(val, &endp, 0);
114 if (endp[0] != '\0' || count < 1) {
115 fprintf(stderr, "invalid number\n");
119 info("send max_childs_running=%i", *intval);
120 } else if (strcmp(arg, "help") == 0 || strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) {
121 printf("Usage: udevcontrol COMMAND\n"
122 " log_priority=<level> set the udev log level for the daemon\n"
123 " stop_exec_queue keep udevd from executing events, queue only\n"
124 " start_exec_queue execute events, flush queue\n"
125 " reload_rules reloads the rules files\n"
126 " max_childs=<N> maximum number of childs\n"
127 " max_childs_running=<N> maximum number of childs running at the same time\n"
128 " --help print this help text\n\n");
131 fprintf(stderr, "unrecognized command '%s'\n", arg);
137 fprintf(stderr, "root privileges required\n");
141 sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
143 err("error getting socket: %s", strerror(errno));
147 memset(&saddr, 0x00, sizeof(struct sockaddr_un));
148 saddr.sun_family = AF_LOCAL;
149 /* use abstract namespace for socket path */
150 strcpy(&saddr.sun_path[1], UDEVD_CTRL_SOCK_PATH);
151 addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
153 retval = sendto(sock, &ctrl_msg, sizeof(ctrl_msg), 0, (struct sockaddr *)&saddr, addrlen);
155 err("error sending message: %s", strerror(errno));
158 dbg("sent message type=0x%02x, %u bytes sent", ctrl_msg.type, retval);