aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/common.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-26 13:22:35 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-26 13:22:35 +0000
commitaf1c84360f08f2ee32799ba266b0c384dde68173 (patch)
tree4272fbe921bc693c52197ac5d227fcbc42b3c154 /networking/udhcp/common.c
parent5a142025d372ae5dff7d7cf98f442edaafd1dc30 (diff)
downloadbusybox-w32-af1c84360f08f2ee32799ba266b0c384dde68173.tar.gz
busybox-w32-af1c84360f08f2ee32799ba266b0c384dde68173.tar.bz2
busybox-w32-af1c84360f08f2ee32799ba266b0c384dde68173.zip
Move udhcp to new NOMMU helpers.
Fix server part to compile under NOMMU. Client is not compilable yet. On MMU everything compiles (and maybe even works :)
Diffstat (limited to 'networking/udhcp/common.c')
-rw-r--r--networking/udhcp/common.c60
1 files changed, 38 insertions, 22 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index 3704ba71a..7b2e19c42 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -22,40 +22,56 @@ long uptime(void)
22 return info.uptime; 22 return info.uptime;
23} 23}
24 24
25void udhcp_background(const char *pidfile) 25
26static const char *saved_pidfile;
27
28static void pidfile_delete(void)
29{
30 if (saved_pidfile)
31 unlink(saved_pidfile);
32}
33
34static int pidfile_acquire(const char *pidfile)
26{ 35{
27#ifdef __uClinux__
28 bb_error_msg("cannot background in uclinux (yet)");
29#else /* __uClinux__ */
30 int pid_fd; 36 int pid_fd;
37 if (!pidfile) return -1;
31 38
32 /* hold lock during fork. */ 39 pid_fd = open(pidfile, O_CREAT|O_WRONLY|O_TRUNC, 0644);
33 pid_fd = pidfile_acquire(pidfile); 40 if (pid_fd < 0) {
34 setsid(); 41 bb_perror_msg("cannot open pidfile %s", pidfile);
35 xdaemon(0, 0); 42 } else {
36 logmode &= ~LOGMODE_STDIO; 43 /* lockf(pid_fd, F_LOCK, 0); */
37 pidfile_write_release(pid_fd); 44 if (!saved_pidfile)
38#endif /* __uClinux__ */ 45 atexit(pidfile_delete);
46 saved_pidfile = pidfile;
47 }
48
49 return pid_fd;
50}
51
52static void pidfile_write_release(int pid_fd)
53{
54 if (pid_fd < 0) return;
55
56 fdprintf(pid_fd, "%d\n", getpid());
57 /* lockf(pid_fd, F_UNLCK, 0); */
58 close(pid_fd);
39} 59}
40 60
41void udhcp_start_log_and_pid(const char *pidfile) 61
62void udhcp_make_pidfile(const char *pidfile)
42{ 63{
43 int pid_fd; 64 int pid_fd;
44 65
45 /* Make sure our syslog fd isn't overwritten */ 66 /* Make sure fd 0,1,2 are open */
46 bb_sanitize_stdio(); 67 bb_sanitize_stdio();
47 68
48 /* do some other misc startup stuff while we are here to save bytes */ 69 /* Equivalent of doing a fflush after every \n */
49 pid_fd = pidfile_acquire(pidfile);
50 pidfile_write_release(pid_fd);
51
52 /* equivelent of doing a fflush after every \n */
53 setlinebuf(stdout); 70 setlinebuf(stdout);
54 71
55 if (ENABLE_FEATURE_UDHCP_SYSLOG) { 72 /* Create pidfile */
56 openlog(applet_name, LOG_PID, LOG_LOCAL0); 73 pid_fd = pidfile_acquire(pidfile);
57 logmode |= LOGMODE_SYSLOG; 74 pidfile_write_release(pid_fd);
58 }
59 75
60 bb_info_msg("%s (v%s) started", applet_name, BB_VER); 76 bb_info_msg("%s (v%s) started", applet_name, BB_VER);
61} 77}