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-af1c84360f08f2ee32799ba266b0c384dde68173.tar.gz
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)
return info.uptime;
}
-void udhcp_background(const char *pidfile)
+
+static const char *saved_pidfile;
+
+static void pidfile_delete(void)
+{
+ if (saved_pidfile)
+ unlink(saved_pidfile);
+}
+
+static int pidfile_acquire(const char *pidfile)
{
-#ifdef __uClinux__
- bb_error_msg("cannot background in uclinux (yet)");
-#else /* __uClinux__ */
int pid_fd;
+ if (!pidfile) return -1;
- /* hold lock during fork. */
- pid_fd = pidfile_acquire(pidfile);
- setsid();
- xdaemon(0, 0);
- logmode &= ~LOGMODE_STDIO;
- pidfile_write_release(pid_fd);
-#endif /* __uClinux__ */
+ pid_fd = open(pidfile, O_CREAT|O_WRONLY|O_TRUNC, 0644);
+ if (pid_fd < 0) {
+ bb_perror_msg("cannot open pidfile %s", pidfile);
+ } else {
+ /* lockf(pid_fd, F_LOCK, 0); */
+ if (!saved_pidfile)
+ atexit(pidfile_delete);
+ saved_pidfile = pidfile;
+ }
+
+ return pid_fd;
+}
+
+static void pidfile_write_release(int pid_fd)
+{
+ if (pid_fd < 0) return;
+
+ fdprintf(pid_fd, "%d\n", getpid());
+ /* lockf(pid_fd, F_UNLCK, 0); */
+ close(pid_fd);
}
-void udhcp_start_log_and_pid(const char *pidfile)
+
+void udhcp_make_pidfile(const char *pidfile)
{
int pid_fd;
- /* Make sure our syslog fd isn't overwritten */
+ /* Make sure fd 0,1,2 are open */
bb_sanitize_stdio();
- /* do some other misc startup stuff while we are here to save bytes */
- pid_fd = pidfile_acquire(pidfile);
- pidfile_write_release(pid_fd);
-
- /* equivelent of doing a fflush after every \n */
+ /* Equivalent of doing a fflush after every \n */
setlinebuf(stdout);
- if (ENABLE_FEATURE_UDHCP_SYSLOG) {
- openlog(applet_name, LOG_PID, LOG_LOCAL0);
- logmode |= LOGMODE_SYSLOG;
- }
+ /* Create pidfile */
+ pid_fd = pidfile_acquire(pidfile);
+ pidfile_write_release(pid_fd);
bb_info_msg("%s (v%s) started", applet_name, BB_VER);
}