diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-27 22:01:31 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-27 22:01:31 +0000 |
commit | 10457b90db925369739a900445b640364eda5e4c (patch) | |
tree | 6d6f18564291257738360d97712724868175167e /networking/udhcp | |
parent | f4d40c87d3a18fccb8c0946fc09f1d8f24a2bcf3 (diff) | |
download | busybox-w32-10457b90db925369739a900445b640364eda5e4c.tar.gz busybox-w32-10457b90db925369739a900445b640364eda5e4c.tar.bz2 busybox-w32-10457b90db925369739a900445b640364eda5e4c.zip |
make pidfile writing configurable.
[ui]toa_to_buf: change API. No users yet.
Diffstat (limited to 'networking/udhcp')
-rw-r--r-- | networking/udhcp/common.c | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 7b2e19c42..46cc0348f 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -22,47 +22,35 @@ long uptime(void) | |||
22 | return info.uptime; | 22 | return info.uptime; |
23 | } | 23 | } |
24 | 24 | ||
25 | 25 | #if ENABLE_FEATURE_PIDFILE | |
26 | static const char *saved_pidfile; | 26 | static const char *saved_pidfile; |
27 | 27 | ||
28 | static void pidfile_delete(void) | 28 | static void pidfile_delete(void) |
29 | { | 29 | { |
30 | if (saved_pidfile) | 30 | if (saved_pidfile) |
31 | unlink(saved_pidfile); | 31 | remove_pidfile(saved_pidfile); |
32 | } | 32 | } |
33 | #endif | ||
33 | 34 | ||
34 | static int pidfile_acquire(const char *pidfile) | 35 | static void create_pidfile(const char *pidfile) |
35 | { | 36 | { |
36 | int pid_fd; | 37 | if (!pidfile) |
37 | if (!pidfile) return -1; | 38 | return; |
38 | 39 | ||
39 | pid_fd = open(pidfile, O_CREAT|O_WRONLY|O_TRUNC, 0644); | 40 | if (!write_pidfile(pidfile)) { |
40 | if (pid_fd < 0) { | 41 | bb_perror_msg("cannot create pidfile %s", pidfile); |
41 | bb_perror_msg("cannot open pidfile %s", pidfile); | 42 | return; |
42 | } else { | ||
43 | /* lockf(pid_fd, F_LOCK, 0); */ | ||
44 | if (!saved_pidfile) | ||
45 | atexit(pidfile_delete); | ||
46 | saved_pidfile = pidfile; | ||
47 | } | 43 | } |
48 | 44 | #if ENABLE_FEATURE_PIDFILE | |
49 | return pid_fd; | 45 | /* lockf(pid_fd, F_LOCK, 0); */ |
50 | } | 46 | if (!saved_pidfile) |
51 | 47 | atexit(pidfile_delete); | |
52 | static void pidfile_write_release(int pid_fd) | 48 | saved_pidfile = pidfile; |
53 | { | 49 | #endif |
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); | ||
59 | } | 50 | } |
60 | 51 | ||
61 | |||
62 | void udhcp_make_pidfile(const char *pidfile) | 52 | void udhcp_make_pidfile(const char *pidfile) |
63 | { | 53 | { |
64 | int pid_fd; | ||
65 | |||
66 | /* Make sure fd 0,1,2 are open */ | 54 | /* Make sure fd 0,1,2 are open */ |
67 | bb_sanitize_stdio(); | 55 | bb_sanitize_stdio(); |
68 | 56 | ||
@@ -70,8 +58,7 @@ void udhcp_make_pidfile(const char *pidfile) | |||
70 | setlinebuf(stdout); | 58 | setlinebuf(stdout); |
71 | 59 | ||
72 | /* Create pidfile */ | 60 | /* Create pidfile */ |
73 | pid_fd = pidfile_acquire(pidfile); | 61 | create_pidfile(pidfile); |
74 | pidfile_write_release(pid_fd); | ||
75 | 62 | ||
76 | bb_info_msg("%s (v%s) started", applet_name, BB_VER); | 63 | bb_info_msg("%s (v%s) started", applet_name, BB_VER); |
77 | } | 64 | } |