aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Dill <Russ.Dill@asu.edu>2003-12-15 21:57:44 +0000
committerRuss Dill <Russ.Dill@asu.edu>2003-12-15 21:57:44 +0000
commita1fece2c70898a1180f0506df6695e3077510731 (patch)
treed18739994a984c3d35edb73c936f015e0dbde631
parentd4f7a5edadb7529e407a5367fbb8af4c866e2598 (diff)
downloadbusybox-w32-a1fece2c70898a1180f0506df6695e3077510731.tar.gz
busybox-w32-a1fece2c70898a1180f0506df6695e3077510731.tar.bz2
busybox-w32-a1fece2c70898a1180f0506df6695e3077510731.zip
Get vfork_daemon_rexec working under uclinux
-rw-r--r--include/libbb.h3
-rw-r--r--libbb/vfork_daemon_rexec.c63
-rw-r--r--miscutils/crond.c10
-rw-r--r--sysklogd/klogd.c7
-rw-r--r--sysklogd/syslogd.c9
5 files changed, 72 insertions, 20 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 5ff49114b..1367ee624 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -473,7 +473,8 @@ extern llist_t *llist_add_to(llist_t *old_head, char *new_item);
473extern void print_login_issue(const char *issue_file, const char *tty); 473extern void print_login_issue(const char *issue_file, const char *tty);
474extern void print_login_prompt(void); 474extern void print_login_prompt(void);
475 475
476extern void vfork_daemon_rexec(int argc, char **argv, char *foreground_opt); 476extern void vfork_daemon_rexec(int nochdir, int noclose,
477 int argc, char **argv, char *foreground_opt);
477extern void get_terminal_width_height(int fd, int *width, int *height); 478extern void get_terminal_width_height(int fd, int *width, int *height);
478extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *)); 479extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *));
479extern void xregcomp(regex_t *preg, const char *regex, int cflags); 480extern void xregcomp(regex_t *preg, const char *regex, int cflags);
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index c8f9d277e..2fd70ba1a 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -1,27 +1,78 @@
1/* 1/*
2 * Rexec program for system have fork() as vfork() with foregound option 2 * Rexec program for system have fork() as vfork() with foregound option
3 * Copyright (C) Vladminr Oleynik and many different people. 3 *
4 * Copyright (C) Vladimir N. Oleynik <dzo@simtreas.ru>
5 * Copyright (C) 2003 Russ Dill <Russ.Dill@asu.edu>
6 *
7 * daemon() portion taken from uclibc:
8 *
9 * Copyright (c) 1991, 1993
10 * The Regents of the University of California. All rights reserved.
11 *
12 * Modified for uClibc by Erik Andersen <andersee@debian.org>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4 */ 27 */
5 28
6#include <unistd.h> 29#include <unistd.h>
30#include <stdio.h>
31#include <fcntl.h>
32#include <paths.h>
7#include "libbb.h" 33#include "libbb.h"
8 34
9 35
10#if defined(__uClinux__) 36#if defined(__uClinux__)
11void vfork_daemon_rexec(int argc, char **argv, char *foreground_opt) 37void vfork_daemon_rexec(int nochdir, int noclose,
38 int argc, char **argv, char *foreground_opt)
12{ 39{
40 int fd;
13 char **vfork_args; 41 char **vfork_args;
14 int a = 0; 42 int a = 0;
43
44 setsid();
45
46 if (!nochdir)
47 chdir("/");
48
49 if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
50 dup2(fd, STDIN_FILENO);
51 dup2(fd, STDOUT_FILENO);
52 dup2(fd, STDERR_FILENO);
53 if (fd > 2)
54 close(fd);
55 }
15 56
16 vfork_args = xcalloc(sizeof(char *), argc + 3); 57 vfork_args = xcalloc(sizeof(char *), argc + 3);
58 vfork_args[a++] = "/bin/busybox";
17 while(*argv) { 59 while(*argv) {
18 vfork_args[a++] = *argv; 60 vfork_args[a++] = *argv;
19 argv++; 61 argv++;
20 } 62 }
21 vfork_args[a] = foreground_opt; 63 vfork_args[a] = foreground_opt;
22 execvp("/proc/self/exe", vfork_args); 64 switch (vfork()) {
23 vfork_args[0] = "/bin/busybox"; 65 case 0: /* child */
24 execv(vfork_args[0], vfork_args); 66 /* Make certain we are not a session leader, or else we
25 bb_perror_msg_and_die("execv %s", vfork_args[0]); 67 * might reacquire a controlling terminal */
68 if (vfork())
69 _exit(0);
70 execv(vfork_args[0], vfork_args);
71 bb_perror_msg_and_die("execv %s", vfork_args[0]);
72 case -1: /* error */
73 bb_perror_msg_and_die("vfork");
74 default: /* parent */
75 exit(0);
76 }
26} 77}
27#endif /* uClinux */ 78#endif /* uClinux */
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 6de00dfde..81fd72b85 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -200,14 +200,12 @@ crond_main(int ac, char **av)
200 */ 200 */
201 201
202 if (!(opt & 4)) { 202 if (!(opt & 4)) {
203#if defined(__uClinux__)
204 /* reexec for vfork() do continue parent */
205 vfork_daemon_rexec(1, 0, ac, av, "-f");
206#else /* uClinux */
203 if(daemon(1, 0) < 0) { 207 if(daemon(1, 0) < 0) {
204 bb_perror_msg_and_die("daemon"); 208 bb_perror_msg_and_die("daemon");
205 }
206#if defined(__uClinux__)
207 else {
208 /* reexec for vfork() do continue parent */
209 vfork_daemon_rexec(ac, av, "-f");
210 }
211#endif /* uClinux */ 209#endif /* uClinux */
212 } 210 }
213 211
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index c132e065c..df3a668dd 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -147,11 +147,12 @@ extern int klogd_main(int argc, char **argv)
147 } 147 }
148 148
149 if (doFork) { 149 if (doFork) {
150#if defined(__uClinux__)
151 vfork_daemon_rexec(0, 1, argc, argv, "-n");
152#else /* __uClinux__ */
150 if (daemon(0, 1) < 0) 153 if (daemon(0, 1) < 0)
151 bb_perror_msg_and_die("daemon"); 154 bb_perror_msg_and_die("daemon");
152#if defined(__uClinux__) 155#endif /* __uClinux__ */
153 vfork_daemon_rexec(argc, argv, "-n");
154#endif
155 } 156 }
156 doKlogd(console_log_level); 157 doKlogd(console_log_level);
157 158
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 74b242c42..622500e48 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -681,11 +681,12 @@ extern int syslogd_main(int argc, char **argv)
681 umask(0); 681 umask(0);
682 682
683 if (doFork == TRUE) { 683 if (doFork == TRUE) {
684 if(daemon(0, 1) < 0)
685 bb_perror_msg_and_die("daemon");
686#if defined(__uClinux__) 684#if defined(__uClinux__)
687 vfork_daemon_rexec(argc, argv, "-n"); 685 vfork_daemon_rexec(0, 1, argc, argv, "-n");
688#endif 686#else /* __uClinux__ */
687 if(daemon(0, 1) < 0)
688 bb_perror_msg_and_die("daemon");
689#endif /* __uClinux__ */
689 } 690 }
690 doSyslogd(); 691 doSyslogd();
691 692