]>
git.ipfire.org Git - thirdparty/systemd.git/blob - udevsend.c
bdc8293df7a2d495d63071469b605240942fdd82
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 msg
->mtype
= HOTPLUGMSGTYPE
;
69 strncpy(msg
->action
, action
, 8);
70 strncpy(msg
->devpath
, devpath
, 128);
71 strncpy(msg
->subsystem
, subsystem
, 16);
72 return sizeof(struct hotplug_msg
);
75 static int start_daemon(void)
88 execl(DEFAULT_UDEVD_EXEC
, NULL
);
89 dbg("exec of daemon failed");
92 dbg("fork of daemon failed");
99 dbg("fork of helper failed");
108 int main(int argc
, char* argv
[])
112 struct msqid_ds msg_queue
;
113 struct hotplug_msg message
;
119 int retval
= -EINVAL
;
122 struct timespec tspec
;
125 if (subsystem
== NULL
) {
130 devpath
= get_devpath();
131 if (devpath
== NULL
) {
136 action
= get_action();
137 if (action
== NULL
) {
142 seqnum
= get_seqnum();
143 if (seqnum
== NULL
) {
149 /* create ipc message queue or get id of our existing one */
150 key
= ftok(DEFAULT_UDEVD_EXEC
, IPC_KEY_ID
);
151 size
= build_hotplugmsg(&message
, action
, devpath
, subsystem
, seq
);
152 msgid
= msgget(key
, IPC_CREAT
);
154 dbg("error open ipc queue");
158 /* send ipc message to the daemon */
159 retval
= msgsnd(msgid
, &message
, size
, 0);
161 dbg("error sending ipc message");
165 /* get state of ipc queue */
167 tspec
.tv_nsec
= 10000000; /* 10 millisec */
170 retval
= msgctl(msgid
, IPC_STAT
, &msg_queue
);
172 dbg("error getting info on ipc queue");
175 if (msg_queue
.msg_qnum
== 0)
177 nanosleep(&tspec
, NULL
);
180 info("message is still in the ipc queue, starting daemon...");
181 retval
= start_daemon();