aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-08-15 20:05:37 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-08-15 20:05:37 +0000
commitbb23c069191f18ed11b826371ed3571e214b41e3 (patch)
tree8a7afbb2ead270f08c3fa4741da0522418142787 /libbb
parent9f7b92a2e13b184b1d6f7d9fbddc133666224bcf (diff)
downloadbusybox-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.
Diffstat (limited to 'libbb')
-rw-r--r--libbb/pidfile.c24
1 files changed, 16 insertions, 8 deletions
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
14int write_pidfile(const char *path) 14smallint wrote_pidfile;
15
16void 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}