aboutsummaryrefslogtreecommitdiff
path: root/miscutils/update.c
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils/update.c')
-rw-r--r--miscutils/update.c60
1 files changed, 29 insertions, 31 deletions
diff --git a/miscutils/update.c b/miscutils/update.c
index a6550b05c..603740e38 100644
--- a/miscutils/update.c
+++ b/miscutils/update.c
@@ -65,46 +65,44 @@ extern int update_main(int argc, char **argv)
65 show_usage(); 65 show_usage();
66 } 66 }
67 } 67 }
68
69 if (daemon(0, 1) < 0)
70 perror_msg_and_die("daemon");
68 71
69 pid = fork(); 72 /* Become a proper daemon */
70 if (pid < 0) 73 setsid();
71 return EXIT_FAILURE; 74 chdir("/");
72 else if (pid == 0) {
73 /* Become a proper daemon */
74 setsid();
75 chdir("/");
76#ifdef OPEN_MAX 75#ifdef OPEN_MAX
77 for (pid = 0; pid < OPEN_MAX; pid++) close(pid); 76 for (pid = 0; pid < OPEN_MAX; pid++) close(pid);
78#else 77#else
79 /* glibc 2.1.92 requires using sysconf(_SC_OPEN_MAX) */ 78 /* glibc 2.1.92 requires using sysconf(_SC_OPEN_MAX) */
80 for (pid = 0; pid < sysconf(_SC_OPEN_MAX); pid++) close(pid); 79 for (pid = 0; pid < sysconf(_SC_OPEN_MAX); pid++) close(pid);
81#endif 80#endif
82 81
83 /* 82 /* This is no longer necessary since 1.3.5x, but it will harmlessly
84 * This is no longer necessary since 1.3.5x, but it will harmlessly 83 * exit if that is the case.
85 * exit if that is the case. 84 */
86 */
87 85
88 /* set the program name that will show up in a 'ps' listing */ 86 /* set the program name that will show up in a 'ps' listing */
89 argv[0] = "bdflush (update)"; 87 argv[0] = "bdflush (update)";
90 argv[1] = NULL; 88 argv[1] = NULL;
91 argv[2] = NULL; 89 argv[2] = NULL;
92 for (;;) { 90 for (;;) {
93 if (use_sync) { 91 if (use_sync) {
94 sleep(sync_duration); 92 sleep(sync_duration);
95 sync(); 93 sync();
96 } else { 94 } else {
97 sleep(flush_duration); 95 sleep(flush_duration);
98 if (bdflush(1, 0) < 0) { 96 if (bdflush(1, 0) < 0) {
99 openlog("update", LOG_CONS, LOG_DAEMON); 97 openlog("update", LOG_CONS, LOG_DAEMON);
100 syslog(LOG_INFO, 98 syslog(LOG_INFO,
101 "This kernel does not need update(8). Exiting."); 99 "This kernel does not need update(8). Exiting.");
102 closelog(); 100 closelog();
103 return EXIT_SUCCESS; 101 return EXIT_SUCCESS;
104 }
105 } 102 }
106 } 103 }
107 } 104 }
105
108 return EXIT_SUCCESS; 106 return EXIT_SUCCESS;
109} 107}
110 108