]> git.ipfire.org Git - thirdparty/systemd.git/blob - udevcontrol.c
Makefile: fix DESTDIR
[thirdparty/systemd.git] / udevcontrol.c
1 /*
2 * udevcontrol.c
3 *
4 * Userspace devfs
5 *
6 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
7 *
8 *
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.
12 *
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.
17 *
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.
21 *
22 */
23
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <sys/wait.h>
27 #include <sys/un.h>
28 #include <time.h>
29 #include <errno.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stddef.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <linux/stddef.h>
36
37 #include "udev.h"
38 #include "udev_version.h"
39 #include "udevd.h"
40 #include "logging.h"
41
42 /* global variables */
43 static int sock = -1;
44
45 #ifdef USE_LOG
46 void log_message (int level, const char *format, ...)
47 {
48 va_list args;
49
50 va_start(args, format);
51 vsyslog(level, format, args);
52 va_end(args);
53 }
54 #endif
55
56
57 int main(int argc, char *argv[], char *envp[])
58 {
59 static struct udevd_msg usend_msg;
60 struct sockaddr_un saddr;
61 socklen_t addrlen;
62 int retval = 1;
63
64 logging_init("udevcontrol");
65 dbg("version %s", UDEV_VERSION);
66
67 if (argc != 2) {
68 info("usage: udevcontrol <cmd>\n");
69 goto exit;
70 }
71
72 memset(&usend_msg, 0x00, sizeof(struct udevd_msg));
73 strcpy(usend_msg.magic, UDEV_MAGIC);
74
75 if (strstr(argv[1], "stop_exec_queue"))
76 usend_msg.type = UDEVD_STOP_EXEC_QUEUE;
77 else if (strstr(argv[1], "start_exec_queue"))
78 usend_msg.type = UDEVD_START_EXEC_QUEUE;
79 else {
80 info("unknown command\n");
81 goto exit;
82 }
83
84 sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
85 if (sock == -1) {
86 info("error getting socket");
87 goto exit;
88 }
89
90 memset(&saddr, 0x00, sizeof(struct sockaddr_un));
91 saddr.sun_family = AF_LOCAL;
92 /* use abstract namespace for socket path */
93 strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
94 addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
95
96
97 retval = sendto(sock, &usend_msg, sizeof(usend_msg), 0, (struct sockaddr *)&saddr, addrlen);
98 if (retval == -1)
99 info("error sending message (%s)", strerror(errno));
100
101 close(sock);
102
103 exit:
104 logging_close();
105
106 return retval;
107 }