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 :)
This commit is contained in:
@ -22,40 +22,56 @@ long uptime(void)
|
||||
return info.uptime;
|
||||
}
|
||||
|
||||
void udhcp_background(const char *pidfile)
|
||||
{
|
||||
#ifdef __uClinux__
|
||||
bb_error_msg("cannot background in uclinux (yet)");
|
||||
#else /* __uClinux__ */
|
||||
int pid_fd;
|
||||
|
||||
/* hold lock during fork. */
|
||||
pid_fd = pidfile_acquire(pidfile);
|
||||
setsid();
|
||||
xdaemon(0, 0);
|
||||
logmode &= ~LOGMODE_STDIO;
|
||||
pidfile_write_release(pid_fd);
|
||||
#endif /* __uClinux__ */
|
||||
static const char *saved_pidfile;
|
||||
|
||||
static void pidfile_delete(void)
|
||||
{
|
||||
if (saved_pidfile)
|
||||
unlink(saved_pidfile);
|
||||
}
|
||||
|
||||
void udhcp_start_log_and_pid(const char *pidfile)
|
||||
static int pidfile_acquire(const char *pidfile)
|
||||
{
|
||||
int pid_fd;
|
||||
if (!pidfile) return -1;
|
||||
|
||||
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_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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user