]>
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>
37 static inline char *get_action(void)
41 action
= getenv("ACTION");
45 static inline char *get_devpath(void)
49 devpath
= getenv("DEVPATH");
53 static inline char *get_seqnum(void)
57 seqnum
= getenv("SEQNUM");
61 static int build_hotplugmsg(struct hotplug_msg
**ppmsg
, char *action
,
62 char *devpath
, char *subsystem
, int seqnum
)
64 struct hotplug_msg
*pmsg
;
66 pmsg
= malloc(sizeof(struct hotplug_msg
));
67 pmsg
->mtype
= HOTPLUGMSGTYPE
;
68 pmsg
->seqnum
= seqnum
;
69 strncpy(pmsg
->action
, action
, 8);
70 strncpy(pmsg
->devpath
, devpath
, 128);
71 strncpy(pmsg
->subsystem
, subsystem
, 16);
73 return sizeof(struct hotplug_msg
);
76 static void free_hotplugmsg(struct hotplug_msg
*pmsg
)
81 int main(int argc
, char* argv
[])
85 struct msqid_ds msg_queue
;
96 if (subsystem
== NULL
) {
101 devpath
= get_devpath();
102 if (devpath
== NULL
) {
107 action
= get_action();
108 if (action
== NULL
) {
113 seqnum
= get_seqnum();
114 if (seqnum
== NULL
) {
120 key
= ftok(DEFAULT_EXEC_PROGRAM
, IPC_KEY_ID
);
121 size
= build_hotplugmsg( (struct hotplug_msg
**) &pmsg
, action
, devpath
, subsystem
, seq
);
122 msgid
= msgget(key
, IPC_CREAT
);
124 dbg("open ipc queue error");
128 /* get state of queue */
129 retval
= msgctl(msgid
, IPC_STAT
, &msg_queue
);
131 dbg("error getting info on ipc queue");
134 if (msg_queue
.msg_qnum
> 0)
135 dbg("%li messages already in the ipc queue", msg_queue
.msg_qnum
);
137 retval
= msgsnd(msgid
, pmsg
, size
, 0);
138 free_hotplugmsg( (struct hotplug_msg
*) pmsg
);
140 dbg("send ipc message error");