1 /* vi: set sw=4 ts=4: */
4 * Functions for debugging and logging as well as some other
5 * simple helper functions.
7 * Russ Dill <Russ.Dill@asu.edu> 2001-2003
8 * Rewritten by Vladimir Oleynik <dzo@simtreas.ru> (C) 2003
10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
20 #include <sys/socket.h>
27 static int daemonized;
38 * This function makes sure our first socket calls
39 * aren't going to fd 1 (printf badness...) and are
40 * not later closed by daemon()
42 static inline void sanitize_fds(void)
45 if ((zero = open(bb_dev_null, O_RDWR, 0)) < 0)
53 void udhcp_background(const char *pidfile)
56 LOG(LOG_ERR, "Cannot background in uclinux (yet)");
57 #else /* __uClinux__ */
60 /* hold lock during fork. */
61 pid_fd = pidfile_acquire(pidfile);
62 if (daemon(0, 0) == -1) { /* bb_xdaemon? */
67 pidfile_write_release(pid_fd);
68 #endif /* __uClinux__ */
72 #ifdef CONFIG_FEATURE_UDHCP_SYSLOG
74 void udhcp_logging(int level, const char *fmt, ...)
85 vsyslog(level, fmt, p2);
92 static char *syslog_level_msg[] = {
93 [LOG_EMERG] = "EMERGENCY!",
94 [LOG_ALERT] = "ALERT!",
95 [LOG_CRIT] = "critical!",
96 [LOG_WARNING] = "warning",
103 void udhcp_logging(int level, const char *fmt, ...)
109 printf("%s, ", syslog_level_msg[level]);
118 void udhcp_start_log_and_pid(const char *client_server, const char *pidfile)
122 /* Make sure our syslog fd isn't overwritten */
125 /* do some other misc startup stuff while we are here to save bytes */
126 pid_fd = pidfile_acquire(pidfile);
127 pidfile_write_release(pid_fd);
129 /* equivelent of doing a fflush after every \n */
132 if (ENABLE_FEATURE_UDHCP_SYSLOG)
133 openlog(client_server, LOG_PID | LOG_CONS, LOG_LOCAL0);
135 udhcp_logging(LOG_INFO, "%s (v%s) started", client_server, BB_VER);