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.
26 static const char *saved_pidfile;
28 static void pidfile_delete(void)
31 unlink(saved_pidfile);
34 static int pidfile_acquire(const char *pidfile)
37 if (!pidfile) return -1;
39 pid_fd = open(pidfile, O_CREAT|O_WRONLY|O_TRUNC, 0644);
41 bb_perror_msg("cannot open pidfile %s", pidfile);
43 /* lockf(pid_fd, F_LOCK, 0); */
45 atexit(pidfile_delete);
46 saved_pidfile = pidfile;
52 static void pidfile_write_release(int pid_fd)
54 if (pid_fd < 0) return;
56 fdprintf(pid_fd, "%d\n", getpid());
57 /* lockf(pid_fd, F_UNLCK, 0); */
62 void udhcp_make_pidfile(const char *pidfile)
66 /* Make sure fd 0,1,2 are open */
69 /* Equivalent of doing a fflush after every \n */
73 pid_fd = pidfile_acquire(pidfile);
74 pidfile_write_release(pid_fd);
76 bb_info_msg("%s (v%s) started", applet_name, BB_VER);