diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-15 20:05:37 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-15 20:05:37 +0000 |
commit | bb23c069191f18ed11b826371ed3571e214b41e3 (patch) | |
tree | 8a7afbb2ead270f08c3fa4741da0522418142787 | |
parent | 9f7b92a2e13b184b1d6f7d9fbddc133666224bcf (diff) | |
download | busybox-w32-bb23c069191f18ed11b826371ed3571e214b41e3.tar.gz busybox-w32-bb23c069191f18ed11b826371ed3571e214b41e3.tar.bz2 busybox-w32-bb23c069191f18ed11b826371ed3571e214b41e3.zip |
if pidfile turned out to be !regular file, do not unlink it.
It's most probably the /dev/null.
-rw-r--r-- | Config.in | 2 | ||||
-rw-r--r-- | include/libbb.h | 12 | ||||
-rw-r--r-- | libbb/pidfile.c | 24 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 2 |
4 files changed, 25 insertions, 15 deletions
@@ -144,7 +144,7 @@ config FEATURE_PIDFILE | |||
144 | bool "Support writing pidfiles" | 144 | bool "Support writing pidfiles" |
145 | default n | 145 | default n |
146 | help | 146 | help |
147 | This option makes some applets (crond, syslogd and inetd) write | 147 | This option makes some applets (e.g. crond, syslogd, inetd) write |
148 | a pidfile in /var/run. Some applications rely on them. | 148 | a pidfile in /var/run. Some applications rely on them. |
149 | 149 | ||
150 | config FEATURE_SUID | 150 | config FEATURE_SUID |
diff --git a/include/libbb.h b/include/libbb.h index fc0a0ae6c..d60b410ae 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -622,12 +622,14 @@ llist_t *llist_rev(llist_t *list); | |||
622 | /* start_stop_daemon and udhcpc are special - they want | 622 | /* start_stop_daemon and udhcpc are special - they want |
623 | * to create pidfiles regardless of FEATURE_PIDFILE */ | 623 | * to create pidfiles regardless of FEATURE_PIDFILE */ |
624 | #if ENABLE_FEATURE_PIDFILE || defined(WANT_PIDFILE) | 624 | #if ENABLE_FEATURE_PIDFILE || defined(WANT_PIDFILE) |
625 | int write_pidfile(const char *path); | 625 | /* True only if we created pidfile which is *file*, not /dev/null etc */ |
626 | #define remove_pidfile(f) ((void)unlink(f)) | 626 | extern smallint wrote_pidfile; |
627 | void write_pidfile(const char *path); | ||
628 | #define remove_pidfile(path) do { if (wrote_pidfile) unlink(path); } while (0) | ||
627 | #else | 629 | #else |
628 | /* Why? #defining it to 1 gives "warning: statement with no effect"... */ | 630 | enum { wrote_pidfile = 0 }; |
629 | static ALWAYS_INLINE int write_pidfile(const char *path) { return 1; } | 631 | #define write_pidfile(path) ((void)0) |
630 | #define remove_pidfile(f) ((void)0) | 632 | #define remove_pidfile(path) ((void)0) |
631 | #endif | 633 | #endif |
632 | 634 | ||
633 | enum { | 635 | enum { |
diff --git a/libbb/pidfile.c b/libbb/pidfile.c index 64e67c322..cafa7891f 100644 --- a/libbb/pidfile.c +++ b/libbb/pidfile.c | |||
@@ -11,22 +11,30 @@ | |||
11 | #define WANT_PIDFILE 1 | 11 | #define WANT_PIDFILE 1 |
12 | #include "libbb.h" | 12 | #include "libbb.h" |
13 | 13 | ||
14 | int write_pidfile(const char *path) | 14 | smallint wrote_pidfile; |
15 | |||
16 | void write_pidfile(const char *path) | ||
15 | { | 17 | { |
16 | int pid_fd; | 18 | int pid_fd; |
17 | char *end; | 19 | char *end; |
18 | char buf[sizeof(int)*3 + 2]; | 20 | char buf[sizeof(int)*3 + 2]; |
21 | struct stat sb; | ||
19 | 22 | ||
20 | if (!path) | 23 | if (!path) |
21 | return 1; | 24 | return; |
22 | /* we will overwrite stale pidfile */ | 25 | /* we will overwrite stale pidfile */ |
23 | pid_fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666); | 26 | pid_fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
24 | if (pid_fd < 0) | 27 | if (pid_fd < 0) |
25 | return 0; | 28 | return; |
26 | /* few bytes larger, but doesn't use stdio */ | 29 | |
27 | end = utoa_to_buf(getpid(), buf, sizeof(buf)); | 30 | /* path can be "/dev/null"! Test for such cases */ |
28 | *end = '\n'; | 31 | wrote_pidfile = (fstat(pid_fd, &sb) == 0) && S_ISREG(sb.st_mode); |
29 | full_write(pid_fd, buf, end - buf + 1); | 32 | |
33 | if (wrote_pidfile) { | ||
34 | /* few bytes larger, but doesn't use stdio */ | ||
35 | end = utoa_to_buf(getpid(), buf, sizeof(buf)); | ||
36 | *end = '\n'; | ||
37 | full_write(pid_fd, buf, end - buf + 1); | ||
38 | } | ||
30 | close(pid_fd); | 39 | close(pid_fd); |
31 | return 1; | ||
32 | } | 40 | } |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 7cb1dfe5d..7d38742b9 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -546,7 +546,7 @@ int udhcpc_main(int argc, char **argv) | |||
546 | ret0: | 546 | ret0: |
547 | retval = 0; | 547 | retval = 0; |
548 | ret: | 548 | ret: |
549 | if (client_config.pidfile) | 549 | /*if (client_config.pidfile) - remove_pidfile has it's own check */ |
550 | remove_pidfile(client_config.pidfile); | 550 | remove_pidfile(client_config.pidfile); |
551 | return retval; | 551 | return retval; |
552 | } | 552 | } |