+- add patches.suse/early_userspace-instead-of-linuxrc
[linux-flexiantxendom0-3.2.10.git] / usr / sbin / hotplug.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7
8 #define BUFSIZE 12345
9 int
10 main(int argc, char **argv, char **envp)
11 {
12         int fd, i;
13         char **ep = envp;
14         char *buf, *p;
15         buf = malloc(42);
16         if (!buf)
17                 exit(1);
18         p = getenv("SEQNUM");
19         snprintf(buf, 42, "/events/dbg.%08u.%s", getpid(), p ? p : "");
20         if ((fd = open(buf, O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) {
21                 //perror(buf);
22                 exit(1);
23         }
24         free(buf);
25         p = malloc(BUFSIZE);
26         buf = p;
27         for (i = 0; i < argc; ++i) {
28                 buf += snprintf(buf, p + BUFSIZE - buf, " %s", argv[i]);
29                 if (buf > p + BUFSIZE)
30                         goto full;
31         }
32         buf += snprintf(buf, p + BUFSIZE - buf, "\n");
33         if (buf > p + BUFSIZE)
34                 goto full;
35         while (*ep) {
36                 buf += snprintf(buf, p + BUFSIZE - buf, "%s\n", *ep++);
37                 if (buf > p + BUFSIZE)
38                         break;
39         }
40       full:
41         buf = p;
42         write(fd, buf, strlen(buf));
43         close(fd);
44         free(buf);
45         return 0;
46 }