6 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation version 2 of the License.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <sys/types.h>
25 #include <sys/socket.h>
35 #include <linux/stddef.h>
38 #include "udev_version.h"
40 #include "udev_utils.h"
43 /* global variables */
48 void log_message (int priority, const char *format, ...)
55 va_start(args, format);
56 vsyslog(priority, format, args);
62 int main(int argc, char *argv[], char *envp[])
64 static struct udevd_msg usend_msg;
65 struct sockaddr_un saddr;
70 env = getenv("UDEV_LOG");
72 log = log_priority(env);
74 logging_init("udevcontrol");
75 dbg("version %s", UDEV_VERSION);
78 info("usage: udevcontrol <cmd>");
82 memset(&usend_msg, 0x00, sizeof(struct udevd_msg));
83 strcpy(usend_msg.magic, UDEV_MAGIC);
85 if (!strcmp(argv[1], "stop_exec_queue"))
86 usend_msg.type = UDEVD_STOP_EXEC_QUEUE;
87 else if (!strcmp(argv[1], "start_exec_queue"))
88 usend_msg.type = UDEVD_START_EXEC_QUEUE;
89 else if (!strncmp(argv[1], "log_priority=", strlen("log_priority="))) {
90 int *level = (int *) usend_msg.envbuf;
91 char *prio = &argv[1][strlen("log_priority=")];
93 usend_msg.type = UDEVD_SET_LOG_LEVEL;
94 *level = log_priority(prio);
95 dbg("send log_priority=%i", *level);
97 err("unknown command\n");
101 sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
103 info("error getting socket");
107 memset(&saddr, 0x00, sizeof(struct sockaddr_un));
108 saddr.sun_family = AF_LOCAL;
109 /* use abstract namespace for socket path */
110 strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
111 addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
114 retval = sendto(sock, &usend_msg, sizeof(usend_msg), 0, (struct sockaddr *)&saddr, addrlen);
116 info("error sending message (%s)", strerror(errno));
119 dbg("sent message '%x' (%u bytes sent)", usend_msg.type, retval);