aboutsummaryrefslogtreecommitdiff
path: root/runit/svlogd.c
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-01-27 22:21:52 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-01-27 22:21:52 +0000
commit05b12d9661ff6a4f0181b971cd6c73b5797a9299 (patch)
tree4aa5cb8737ab74799096cb8560180890aa2bb5d7 /runit/svlogd.c
parentc6bbd895662dff96ca89c577623e8f1c234b015f (diff)
downloadbusybox-w32-05b12d9661ff6a4f0181b971cd6c73b5797a9299.tar.gz
busybox-w32-05b12d9661ff6a4f0181b971cd6c73b5797a9299.tar.bz2
busybox-w32-05b12d9661ff6a4f0181b971cd6c73b5797a9299.zip
runit cleanup part 1
git-svn-id: svn://busybox.net/trunk/busybox@17558 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to '')
-rw-r--r--runit/svlogd.c81
1 files changed, 45 insertions, 36 deletions
diff --git a/runit/svlogd.c b/runit/svlogd.c
index b089c5498..67ffc443c 100644
--- a/runit/svlogd.c
+++ b/runit/svlogd.c
@@ -100,11 +100,13 @@ static void warnx(char *m0, char *m1)
100} 100}
101static void pause_nomem(void) 101static void pause_nomem(void)
102{ 102{
103 bb_error_msg(PAUSE"out of memory"); sleep(3); 103 bb_error_msg(PAUSE"out of memory");
104 sleep(3);
104} 105}
105static void pause1cannot(char *m0) 106static void pause1cannot(char *m0)
106{ 107{
107 bb_perror_msg(PAUSE"cannot %s", m0); sleep(3); 108 bb_perror_msg(PAUSE"cannot %s", m0);
109 sleep(3);
108} 110}
109static void pause2cannot(char *m0, char *m1) 111static void pause2cannot(char *m0, char *m1)
110{ 112{
@@ -115,7 +117,8 @@ static void pause2cannot(char *m0, char *m1)
115static char* wstrdup(const char *str) 117static char* wstrdup(const char *str)
116{ 118{
117 char *s; 119 char *s;
118 while (!(s = strdup(str))) pause_nomem(); 120 while (!(s = strdup(str)))
121 pause_nomem();
119 return s; 122 return s;
120} 123}
121 124
@@ -135,12 +138,12 @@ static unsigned processorstart(struct logdir *ld)
135 int fd; 138 int fd;
136 139
137 /* child */ 140 /* child */
138 sig_uncatch(sig_term); 141 sig_uncatch(SIGTERM);
139 sig_uncatch(sig_alarm); 142 sig_uncatch(SIGALRM);
140 sig_uncatch(sig_hangup); 143 sig_uncatch(SIGHUP);
141 sig_unblock(sig_term); 144 sig_unblock(SIGTERM);
142 sig_unblock(sig_alarm); 145 sig_unblock(SIGALRM);
143 sig_unblock(sig_hangup); 146 sig_unblock(SIGHUP);
144 147
145 if (verbose) 148 if (verbose)
146 bb_error_msg(INFO"processing: %s/%s", ld->name, ld->fnsave); 149 bb_error_msg(INFO"processing: %s/%s", ld->name, ld->fnsave);
@@ -164,6 +167,7 @@ static unsigned processorstart(struct logdir *ld)
164 if (fd_move(5, fd) == -1) 167 if (fd_move(5, fd) == -1)
165 bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name); 168 bb_perror_msg_and_die(FATAL"cannot %s processor %s", "move filedescriptor for", ld->name);
166 169
170// getenv("SHELL")?
167 prog[0] = "sh"; 171 prog[0] = "sh";
168 prog[1] = "-c"; 172 prog[1] = "-c";
169 prog[2] = ld->processor; 173 prog[2] = ld->processor;
@@ -180,10 +184,10 @@ static unsigned processorstop(struct logdir *ld)
180 char f[28]; 184 char f[28];
181 185
182 if (ld->ppid) { 186 if (ld->ppid) {
183 sig_unblock(sig_hangup); 187 sig_unblock(SIGHUP);
184 while (wait_pid(&wstat, ld->ppid) == -1) 188 while (wait_pid(&wstat, ld->ppid) == -1)
185 pause2cannot("wait for processor", ld->name); 189 pause2cannot("wait for processor", ld->name);
186 sig_block(sig_hangup); 190 sig_block(SIGHUP);
187 ld->ppid = 0; 191 ld->ppid = 0;
188 } 192 }
189 if (ld->fddir == -1) return 1; 193 if (ld->fddir == -1) return 1;
@@ -212,7 +216,8 @@ static unsigned processorstop(struct logdir *ld)
212 bb_error_msg(WARNING"cannot unlink: %s/%s", ld->name, ld->fnsave); 216 bb_error_msg(WARNING"cannot unlink: %s/%s", ld->name, ld->fnsave);
213 while (rename("newstate", "state") == -1) 217 while (rename("newstate", "state") == -1)
214 pause2cannot("rename state", ld->name); 218 pause2cannot("rename state", ld->name);
215 if (verbose) bb_error_msg(INFO"processed: %s/%s", ld->name, f); 219 if (verbose)
220 bb_error_msg(INFO"processed: %s/%s", ld->name, f);
216 while (fchdir(fdwdir) == -1) 221 while (fchdir(fdwdir) == -1)
217 pause1cannot("change to initial working directory"); 222 pause1cannot("change to initial working directory");
218 return 1; 223 return 1;
@@ -242,11 +247,13 @@ static void rmoldest(struct logdir *ld)
242 errno = 0; 247 errno = 0;
243 } 248 }
244 } 249 }
245 if (errno) warn2("cannot read directory", ld->name); 250 if (errno)
251 warn2("cannot read directory", ld->name);
246 closedir(d); 252 closedir(d);
247 253
248 if (ld->nmax && (n > ld->nmax)) { 254 if (ld->nmax && (n > ld->nmax)) {
249 if (verbose) bb_error_msg(INFO"delete: %s/%s", ld->name, oldest); 255 if (verbose)
256 bb_error_msg(INFO"delete: %s/%s", ld->name, oldest);
250 if ((*oldest == '@') && (unlink(oldest) == -1)) 257 if ((*oldest == '@') && (unlink(oldest) == -1))
251 warn2("cannot unlink oldest logfile", ld->name); 258 warn2("cannot unlink oldest logfile", ld->name);
252 } 259 }
@@ -276,9 +283,10 @@ static unsigned rotate(struct logdir *ld)
276 ld->fnsave[27] = '\0'; 283 ld->fnsave[27] = '\0';
277 do { 284 do {
278 taia_now(&now); 285 taia_now(&now);
279 fmt_taia(ld->fnsave, &now); 286 fmt_taia25(ld->fnsave, &now);
280 errno = 0; 287 errno = 0;
281 } while ((stat(ld->fnsave, &st) != -1) || (errno != ENOENT)); 288 stat(ld->fnsave, &st);
289 } while (errno != ENOENT);
282 290
283 if (ld->tmax && taia_less(&ld->trotate, &now)) { 291 if (ld->tmax && taia_less(&ld->trotate, &now)) {
284 taia_uint(&ld->trotate, ld->tmax); 292 taia_uint(&ld->trotate, ld->tmax);
@@ -523,9 +531,10 @@ static unsigned logdir_open(struct logdir *ld, const char *fn)
523 ld->fnsave[27] = '\0'; 531 ld->fnsave[27] = '\0';
524 do { 532 do {
525 taia_now(&now); 533 taia_now(&now);
526 fmt_taia(ld->fnsave, &now); 534 fmt_taia25(ld->fnsave, &now);
527 errno = 0; 535 errno = 0;
528 } while ((stat(ld->fnsave, &st) != -1) || (errno != ENOENT)); 536 stat(ld->fnsave, &st);
537 } while (errno != ENOENT);
529 while (rename("current", ld->fnsave) == -1) 538 while (rename("current", ld->fnsave) == -1)
530 pause2cannot("rename current", ld->name); 539 pause2cannot("rename current", ld->name);
531 rmoldest(ld); 540 rmoldest(ld);
@@ -608,15 +617,15 @@ static int buffer_pread(int fd, char *s, unsigned len)
608 617
609 while (1) { 618 while (1) {
610 /* Comment? */ 619 /* Comment? */
611 sig_unblock(sig_term); 620 sig_unblock(SIGTERM);
612 sig_unblock(sig_child); 621 sig_unblock(SIGCHLD);
613 sig_unblock(sig_alarm); 622 sig_unblock(SIGALRM);
614 sig_unblock(sig_hangup); 623 sig_unblock(SIGHUP);
615 iopause(&in, 1, &trotate, &now); 624 iopause(&in, 1, &trotate, &now);
616 sig_block(sig_term); 625 sig_block(SIGTERM);
617 sig_block(sig_child); 626 sig_block(SIGCHLD);
618 sig_block(sig_alarm); 627 sig_block(SIGALRM);
619 sig_block(sig_hangup); 628 sig_block(SIGHUP);
620 i = safe_read(fd, s, len); 629 i = safe_read(fd, s, len);
621 if (i >= 0) break; 630 if (i >= 0) break;
622 if (errno != EAGAIN) { 631 if (errno != EAGAIN) {
@@ -764,14 +773,14 @@ int svlogd_main(int argc, char **argv)
764 in.events = IOPAUSE_READ; 773 in.events = IOPAUSE_READ;
765 ndelay_on(in.fd); 774 ndelay_on(in.fd);
766 775
767 sig_block(sig_term); 776 sig_block(SIGTERM);
768 sig_block(sig_child); 777 sig_block(SIGCHLD);
769 sig_block(sig_alarm); 778 sig_block(SIGALRM);
770 sig_block(sig_hangup); 779 sig_block(SIGHUP);
771 sig_catch(sig_term, sig_term_handler); 780 sig_catch(SIGTERM, sig_term_handler);
772 sig_catch(sig_child, sig_child_handler); 781 sig_catch(SIGCHLD, sig_child_handler);
773 sig_catch(sig_alarm, sig_alarm_handler); 782 sig_catch(SIGALRM, sig_alarm_handler);
774 sig_catch(sig_hangup, sig_hangup_handler); 783 sig_catch(SIGHUP, sig_hangup_handler);
775 784
776 logdirs_reopen(); 785 logdirs_reopen();
777 786
@@ -788,10 +797,10 @@ int svlogd_main(int argc, char **argv)
788 taia_now(&now); 797 taia_now(&now);
789 switch (timestamp) { 798 switch (timestamp) {
790 case 1: 799 case 1:
791 fmt_taia(stamp, &now); 800 fmt_taia25(stamp, &now);
792 break; 801 break;
793 default: /* case 2: */ 802 default: /* case 2: */
794 fmt_ptime(stamp, &now); 803 fmt_ptime30nul(stamp, &now);
795 break; 804 break;
796 } 805 }
797 memcpy(line, stamp, 25); 806 memcpy(line, stamp, 25);