]>
git.ipfire.org Git - thirdparty/systemd.git/blob - udevsend.c
6 * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
7 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation version 2 of the License.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <sys/types.h>
40 static inline char *get_action(void)
44 action
= getenv("ACTION");
48 static inline char *get_devpath(void)
52 devpath
= getenv("DEVPATH");
56 static inline char *get_seqnum(void)
60 seqnum
= getenv("SEQNUM");
64 static int build_hotplugmsg(struct hotplug_msg
*msg
, char *action
,
65 char *devpath
, char *subsystem
, int seqnum
)
67 memset(msg
, 0x00, sizeof(msg
));
68 msg
->mtype
= HOTPLUGMSGTYPE
;
70 strncpy(msg
->action
, action
, 8);
71 strncpy(msg
->devpath
, devpath
, 128);
72 strncpy(msg
->subsystem
, subsystem
, 16);
73 return sizeof(struct hotplug_msg
);
76 static int start_daemon(void)
91 execl(UDEVD_EXEC
, "udevd", NULL
);
92 dbg("exec of daemon failed");
95 dbg("fork of daemon failed");
102 dbg("fork of helper failed");
111 int main(int argc
, char* argv
[])
115 struct msqid_ds msg_queue
;
116 struct hotplug_msg message
;
122 int retval
= -EINVAL
;
125 struct timespec tspec
;
128 if (subsystem
== NULL
) {
133 devpath
= get_devpath();
134 if (devpath
== NULL
) {
139 action
= get_action();
140 if (action
== NULL
) {
145 seqnum
= get_seqnum();
146 if (seqnum
== NULL
) {
152 /* create ipc message queue or get id of our existing one */
153 key
= ftok(UDEVD_EXEC
, IPC_KEY_ID
);
154 size
= build_hotplugmsg(&message
, action
, devpath
, subsystem
, seq
);
155 msgid
= msgget(key
, IPC_CREAT
);
157 dbg("error open ipc queue");
161 /* send ipc message to the daemon */
162 retval
= msgsnd(msgid
, &message
, size
, 0);
164 dbg("error sending ipc message");
168 /* get state of ipc queue */
170 tspec
.tv_nsec
= 10000000; /* 10 millisec */
173 retval
= msgctl(msgid
, IPC_STAT
, &msg_queue
);
175 dbg("error getting info on ipc queue");
178 if (msg_queue
.msg_qnum
== 0)
180 nanosleep(&tspec
, NULL
);
183 info("message is still in the ipc queue, starting daemon...");
184 retval
= start_daemon();