summaryrefslogtreecommitdiff
path: root/init/pidfilehack.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-05-11 14:52:39 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-05-11 14:52:39 +0000
commit1e11c34be4decfef8fbda8a8e01cd60def8232e5 (patch)
tree6e93956fef2bcd4c1db18031dc081dcaf689f2d1 /init/pidfilehack.c
parent8c6887c855460ee9e688e2a51e29f99faa2a2d8c (diff)
downloadbusybox-w32-1e11c34be4decfef8fbda8a8e01cd60def8232e5.tar.gz
busybox-w32-1e11c34be4decfef8fbda8a8e01cd60def8232e5.tar.bz2
busybox-w32-1e11c34be4decfef8fbda8a8e01cd60def8232e5.zip
minit, a Minimal init system.
Diffstat (limited to '')
-rw-r--r--init/pidfilehack.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/init/pidfilehack.c b/init/pidfilehack.c
new file mode 100644
index 000000000..a2d905b55
--- /dev/null
+++ b/init/pidfilehack.c
@@ -0,0 +1,78 @@
1/*
2 * minit version 0.9.1 by Felix von Leitner
3 * ported to busybox by Glenn McGrath <bug1@optushome.com.au>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include <unistd.h>
21#include <errno.h>
22#include <stdlib.h>
23#include <sys/fcntl.h>
24
25#include "busybox.h"
26/* purpose: argv[1] is the full path to a PID file,
27 * argv+2 is the daemon to run.
28 * the daemon is expected to fork in the background and write its PID in
29 * the pid file.
30 */
31
32extern int pidfilehack_main(int argc, char **argv)
33{
34 int count = 0;
35
36 if (argc < 3) {
37 bb_show_usage();
38
39 }
40 if (unlink(argv[2]) && (errno != ENOENT)) {
41 bb_perror_msg("could not remove pid file");
42 }
43 switch (fork()) {
44 case -1:
45 bb_perror_msg("could not fork");
46 return 2;
47 case 0: /* child */
48 execv(argv[3], argv + 3);
49 bb_perror_msg("execvp failed");
50 return 3;
51 }
52 do {
53 int fd = open(argv[2], O_RDONLY);
54
55 if (fd >= 0) {
56 static char buf[100] = "-P";
57 int len = read(fd, buf + 2, 100);
58
59 close(fd);
60 if (len > 0) {
61 char *_argv[] = { "msvc", 0, 0, 0 };
62 if (buf[len + 1] == '\n') {
63 buf[len + 1] = 0;
64 } else {
65 buf[len + 2] = 0;
66 }
67 _argv[1] = buf;
68 _argv[2] = argv[1];
69 execvp(_argv[0], _argv);
70 bb_perror_msg("execvp failed");
71 return 0;
72 }
73 }
74 sleep(1);
75 } while (++count < 30);
76
77 return(0);
78}