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 /* create ipc message queue or get id of our existing one */
121 key = ftok(DEFAULT_EXEC_PROGRAM, IPC_KEY_ID);
122 size = build_hotplugmsg( (struct hotplug_msg**) &pmsg, action, devpath, subsystem, seq);
123 msgid = msgget(key, IPC_CREAT);
125 dbg("error open ipc queue");
129 /* get state of ipc queue */
130 retval = msgctl(msgid, IPC_STAT, &msg_queue);
132 dbg("error getting info on ipc queue");
135 if (msg_queue.msg_qnum > 0)
136 dbg("%li messages already in the ipc queue", msg_queue.msg_qnum);
138 /* send ipc message to the daemon */
139 retval = msgsnd(msgid, pmsg, size, 0);
140 free_hotplugmsg( (struct hotplug_msg*) pmsg);
142 dbg("error sending ipc message");