aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-27 22:01:31 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-27 22:01:31 +0000
commit10457b90db925369739a900445b640364eda5e4c (patch)
tree6d6f18564291257738360d97712724868175167e /networking
parentf4d40c87d3a18fccb8c0946fc09f1d8f24a2bcf3 (diff)
downloadbusybox-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')
-rw-r--r--networking/inetd.c10
-rw-r--r--networking/udhcp/common.c45
2 files changed, 18 insertions, 37 deletions
diff --git a/networking/inetd.c b/networking/inetd.c
index 4faa4203a..fd72aa726 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -1212,7 +1212,7 @@ static void goaway(int sig ATTRIBUTE_UNUSED)
1212 } 1212 }
1213 (void) close(sep->se_fd); 1213 (void) close(sep->se_fd);
1214 } 1214 }
1215 (void) unlink(_PATH_INETDPID); 1215 remove_pidfile(_PATH_INETDPID);
1216 exit(0); 1216 exit(0);
1217} 1217}
1218 1218
@@ -1301,13 +1301,7 @@ int inetd_main(int argc, char *argv[])
1301 setgroups(1, &gid); 1301 setgroups(1, &gid);
1302 } 1302 }
1303 1303
1304 { 1304 write_pidfile(_PATH_INETDPID);
1305 FILE *fp = fopen(_PATH_INETDPID, "w");
1306 if (fp != NULL) {
1307 fprintf(fp, "%u\n", getpid());
1308 fclose(fp);
1309 }
1310 }
1311 1305
1312 if (getrlimit(RLIMIT_NOFILE, &rlim_ofile) < 0) { 1306 if (getrlimit(RLIMIT_NOFILE, &rlim_ofile) < 0) {
1313 bb_perror_msg("getrlimit"); 1307 bb_perror_msg("getrlimit");
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
26static const char *saved_pidfile; 26static const char *saved_pidfile;
27 27
28static void pidfile_delete(void) 28static 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
34static int pidfile_acquire(const char *pidfile) 35static 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);
52static 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
62void udhcp_make_pidfile(const char *pidfile) 52void 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}