diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-27 22:21:52 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-27 22:21:52 +0000 |
commit | 05b12d9661ff6a4f0181b971cd6c73b5797a9299 (patch) | |
tree | 4aa5cb8737ab74799096cb8560180890aa2bb5d7 | |
parent | c6bbd895662dff96ca89c577623e8f1c234b015f (diff) | |
download | busybox-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
-rw-r--r-- | runit/runit_lib.c | 210 | ||||
-rw-r--r-- | runit/runit_lib.h | 97 | ||||
-rw-r--r-- | runit/runsv.c | 24 | ||||
-rw-r--r-- | runit/runsvdir.c | 12 | ||||
-rw-r--r-- | runit/sv.c | 37 | ||||
-rw-r--r-- | runit/svlogd.c | 81 |
6 files changed, 271 insertions, 190 deletions
diff --git a/runit/runit_lib.c b/runit/runit_lib.c index 2953235f0..ee69429b2 100644 --- a/runit/runit_lib.c +++ b/runit/runit_lib.c | |||
@@ -54,7 +54,8 @@ static int oneread(int (*op)(int fd,char *buf,unsigned len),int fd,char *buf,uns | |||
54 | 54 | ||
55 | for (;;) { | 55 | for (;;) { |
56 | r = op(fd,buf,len); | 56 | r = op(fd,buf,len); |
57 | if (r == -1) if (errno == EINTR) continue; | 57 | if (r == -1 && errno == EINTR) |
58 | continue; | ||
58 | return r; | 59 | return r; |
59 | } | 60 | } |
60 | } | 61 | } |
@@ -72,12 +73,15 @@ int buffer_feed(buffer *s) | |||
72 | { | 73 | { |
73 | int r; | 74 | int r; |
74 | 75 | ||
75 | if (s->p) return s->p; | 76 | if (s->p) |
77 | return s->p; | ||
76 | r = oneread(s->op,s->fd,s->x,s->n); | 78 | r = oneread(s->op,s->fd,s->x,s->n); |
77 | if (r <= 0) return r; | 79 | if (r <= 0) |
80 | return r; | ||
78 | s->p = r; | 81 | s->p = r; |
79 | s->n -= r; | 82 | s->n -= r; |
80 | if (s->n > 0) memmove(s->x + s->n,s->x,r); | 83 | if (s->n > 0) |
84 | memmove(s->x + s->n,s->x,r); | ||
81 | return r; | 85 | return r; |
82 | } | 86 | } |
83 | 87 | ||
@@ -85,9 +89,13 @@ int buffer_bget(buffer *s,char *buf,unsigned len) | |||
85 | { | 89 | { |
86 | int r; | 90 | int r; |
87 | 91 | ||
88 | if (s->p > 0) return getthis(s,buf,len); | 92 | if (s->p > 0) |
89 | if (s->n <= len) return oneread(s->op,s->fd,buf,s->n); | 93 | return getthis(s,buf,len); |
90 | r = buffer_feed(s); if (r <= 0) return r; | 94 | if (s->n <= len) |
95 | return oneread(s->op,s->fd,buf,s->n); | ||
96 | r = buffer_feed(s); | ||
97 | if (r <= 0) | ||
98 | return r; | ||
91 | return getthis(s,buf,len); | 99 | return getthis(s,buf,len); |
92 | } | 100 | } |
93 | 101 | ||
@@ -95,9 +103,13 @@ int buffer_get(buffer *s,char *buf,unsigned len) | |||
95 | { | 103 | { |
96 | int r; | 104 | int r; |
97 | 105 | ||
98 | if (s->p > 0) return getthis(s,buf,len); | 106 | if (s->p > 0) |
99 | if (s->n <= len) return oneread(s->op,s->fd,buf,len); | 107 | return getthis(s,buf,len); |
100 | r = buffer_feed(s); if (r <= 0) return r; | 108 | if (s->n <= len) |
109 | return oneread(s->op,s->fd,buf,len); | ||
110 | r = buffer_feed(s); | ||
111 | if (r <= 0) | ||
112 | return r; | ||
101 | return getthis(s,buf,len); | 113 | return getthis(s,buf,len); |
102 | } | 114 | } |
103 | 115 | ||
@@ -122,10 +134,11 @@ static int allwrite(int (*op)(int fd,char *buf,unsigned len),int fd,const char * | |||
122 | while (len) { | 134 | while (len) { |
123 | w = op(fd,(char*)buf,len); | 135 | w = op(fd,(char*)buf,len); |
124 | if (w == -1) { | 136 | if (w == -1) { |
125 | if (errno == EINTR) continue; | 137 | if (errno == EINTR) |
138 | continue; | ||
126 | return -1; /* note that some data may have been written */ | 139 | return -1; /* note that some data may have been written */ |
127 | } | 140 | } |
128 | if (w == 0) ; /* luser's fault */ | 141 | /* if (w == 0) ; luser's fault */ |
129 | buf += w; | 142 | buf += w; |
130 | len -= w; | 143 | len -= w; |
131 | } | 144 | } |
@@ -183,7 +196,8 @@ int buffer_put(buffer *s,const char *buf,unsigned len) | |||
183 | 196 | ||
184 | int buffer_putflush(buffer *s,const char *buf,unsigned len) | 197 | int buffer_putflush(buffer *s,const char *buf,unsigned len) |
185 | { | 198 | { |
186 | if (buffer_flush(s) == -1) return -1; | 199 | if (buffer_flush(s) == -1) |
200 | return -1; | ||
187 | return allwrite(s->op,s->fd,buf,len); | 201 | return allwrite(s->op,s->fd,buf,len); |
188 | } | 202 | } |
189 | 203 | ||
@@ -229,10 +243,10 @@ unsigned byte_chr(char *s,unsigned n,int c) | |||
229 | ch = c; | 243 | ch = c; |
230 | t = s; | 244 | t = s; |
231 | for (;;) { | 245 | for (;;) { |
232 | if (!n) break; if (*t == ch) break; ++t; --n; | 246 | if (!n) break; |
233 | if (!n) break; if (*t == ch) break; ++t; --n; | 247 | if (*t == ch) break; |
234 | if (!n) break; if (*t == ch) break; ++t; --n; | 248 | ++t; |
235 | if (!n) break; if (*t == ch) break; ++t; --n; | 249 | --n; |
236 | } | 250 | } |
237 | return t - s; | 251 | return t - s; |
238 | } | 252 | } |
@@ -250,10 +264,13 @@ int coe(int fd) | |||
250 | 264 | ||
251 | int fd_copy(int to,int from) | 265 | int fd_copy(int to,int from) |
252 | { | 266 | { |
253 | if (to == from) return 0; | 267 | if (to == from) |
254 | if (fcntl(from,F_GETFL,0) == -1) return -1; | 268 | return 0; |
269 | if (fcntl(from,F_GETFL,0) == -1) | ||
270 | return -1; | ||
255 | close(to); | 271 | close(to); |
256 | if (fcntl(from,F_DUPFD,to) == -1) return -1; | 272 | if (fcntl(from,F_DUPFD,to) == -1) |
273 | return -1; | ||
257 | return 0; | 274 | return 0; |
258 | } | 275 | } |
259 | 276 | ||
@@ -262,8 +279,10 @@ int fd_copy(int to,int from) | |||
262 | 279 | ||
263 | int fd_move(int to,int from) | 280 | int fd_move(int to,int from) |
264 | { | 281 | { |
265 | if (to == from) return 0; | 282 | if (to == from) |
266 | if (fd_copy(to,from) == -1) return -1; | 283 | return 0; |
284 | if (fd_copy(to,from) == -1) | ||
285 | return -1; | ||
267 | close(from); | 286 | close(from); |
268 | return 0; | 287 | return 0; |
269 | } | 288 | } |
@@ -271,29 +290,47 @@ int fd_move(int to,int from) | |||
271 | 290 | ||
272 | /*** fifo.c ***/ | 291 | /*** fifo.c ***/ |
273 | 292 | ||
274 | int fifo_make(const char *fn,int mode) { return mkfifo(fn,mode); } | 293 | int fifo_make(const char *fn,int mode) |
294 | { | ||
295 | return mkfifo(fn,mode); | ||
296 | } | ||
275 | 297 | ||
276 | 298 | ||
277 | /*** fmt_ptime.c ***/ | 299 | /*** fmt_ptime.c ***/ |
278 | 300 | ||
279 | unsigned fmt_ptime(char *s, struct taia *ta) { | 301 | void fmt_ptime30nul(char *s, struct taia *ta) { |
280 | struct tm *t; | 302 | struct tm *t; |
281 | unsigned long u; | 303 | unsigned long u; |
282 | 304 | ||
283 | if (ta->sec.x < 4611686018427387914ULL) return 0; /* impossible? */ | 305 | if (ta->sec.x < 4611686018427387914ULL) |
306 | return; /* impossible? */ | ||
284 | u = ta->sec.x -4611686018427387914ULL; | 307 | u = ta->sec.x -4611686018427387914ULL; |
285 | if (!(t = gmtime((time_t*)&u))) return 0; | 308 | t = gmtime((time_t*)&u); |
286 | fmt_ulong(s, 1900 + t->tm_year); | 309 | if (!t) |
287 | s[4] = '-'; fmt_uint0(&s[5], t->tm_mon+1, 2); | 310 | return; /* huh? */ |
288 | s[7] = '-'; fmt_uint0(&s[8], t->tm_mday, 2); | 311 | //fmt_ulong(s, 1900 + t->tm_year); |
289 | s[10] = '_'; fmt_uint0(&s[11], t->tm_hour, 2); | 312 | //s[4] = '-'; fmt_uint0(&s[5], t->tm_mon+1, 2); |
290 | s[13] = ':'; fmt_uint0(&s[14], t->tm_min, 2); | 313 | //s[7] = '-'; fmt_uint0(&s[8], t->tm_mday, 2); |
291 | s[16] = ':'; fmt_uint0(&s[17], t->tm_sec, 2); | 314 | //s[10] = '_'; fmt_uint0(&s[11], t->tm_hour, 2); |
292 | s[19] = '.'; fmt_uint0(&s[20], ta->nano, 9); | 315 | //s[13] = ':'; fmt_uint0(&s[14], t->tm_min, 2); |
293 | return 25; | 316 | //s[16] = ':'; fmt_uint0(&s[17], t->tm_sec, 2); |
294 | } | 317 | //s[19] = '.'; fmt_uint0(&s[20], ta->nano, 9); |
295 | 318 | sprintf(s, "%04u-%02u-%02u_%02u:%02u:%02u.%09u", | |
296 | unsigned fmt_taia(char *s, struct taia *t) { | 319 | (unsigned)(1900 + t->tm_year), |
320 | (unsigned)(t->tm_mon+1), | ||
321 | (unsigned)(t->tm_mday), | ||
322 | (unsigned)(t->tm_hour), | ||
323 | (unsigned)(t->tm_min), | ||
324 | (unsigned)(t->tm_sec), | ||
325 | (unsigned)(ta->nano) | ||
326 | ); | ||
327 | /* 4+1 + 2+1 + 2+1 + 2+1 + 2+1 + 2+1 + 9 = */ | ||
328 | /* 5 + 3 + 3 + 3 + 3 + 3 + 9 = */ | ||
329 | /* 20 (up to '.' inclusive) + 9 (not including '\0') */ | ||
330 | return; | ||
331 | } | ||
332 | |||
333 | unsigned fmt_taia25(char *s, struct taia *t) { | ||
297 | static char pack[TAIA_PACK]; | 334 | static char pack[TAIA_PACK]; |
298 | 335 | ||
299 | taia_pack(pack, t); | 336 | taia_pack(pack, t); |
@@ -303,6 +340,7 @@ unsigned fmt_taia(char *s, struct taia *t) { | |||
303 | } | 340 | } |
304 | 341 | ||
305 | 342 | ||
343 | #ifdef UNUSED | ||
306 | /*** fmt_uint.c ***/ | 344 | /*** fmt_uint.c ***/ |
307 | 345 | ||
308 | unsigned fmt_uint(char *s,unsigned u) | 346 | unsigned fmt_uint(char *s,unsigned u) |
@@ -316,13 +354,20 @@ unsigned fmt_uint(char *s,unsigned u) | |||
316 | unsigned fmt_uint0(char *s,unsigned u,unsigned n) | 354 | unsigned fmt_uint0(char *s,unsigned u,unsigned n) |
317 | { | 355 | { |
318 | unsigned len; | 356 | unsigned len; |
319 | len = fmt_uint(FMT_LEN,u); | 357 | len = fmt_uint(FMT_LEN, u); |
320 | while (len < n) { if (s) *s++ = '0'; ++len; } | 358 | while (len < n) { |
321 | if (s) fmt_uint(s,u); | 359 | if (s) |
360 | *s++ = '0'; | ||
361 | ++len; | ||
362 | } | ||
363 | if (s) | ||
364 | fmt_uint(s, u); | ||
322 | return len; | 365 | return len; |
323 | } | 366 | } |
367 | #endif | ||
324 | 368 | ||
325 | 369 | ||
370 | #ifdef UNUSED | ||
326 | /*** fmt_ulong.c ***/ | 371 | /*** fmt_ulong.c ***/ |
327 | 372 | ||
328 | unsigned fmt_ulong(char *s,unsigned long u) | 373 | unsigned fmt_ulong(char *s,unsigned long u) |
@@ -336,18 +381,22 @@ unsigned fmt_ulong(char *s,unsigned long u) | |||
336 | } | 381 | } |
337 | return len; | 382 | return len; |
338 | } | 383 | } |
384 | #endif | ||
339 | 385 | ||
340 | 386 | ||
387 | #ifdef UNUSED | ||
341 | /*** tai_now.c ***/ | 388 | /*** tai_now.c ***/ |
342 | 389 | ||
343 | void tai_now(struct tai *t) | 390 | void tai_now(struct tai *t) |
344 | { | 391 | { |
345 | tai_unix(t,time((time_t *) 0)); | 392 | tai_unix(t, time(NULL)); |
346 | } | 393 | } |
394 | #endif | ||
347 | 395 | ||
348 | 396 | ||
349 | /*** tai_pack.c ***/ | 397 | /*** tai_pack.c ***/ |
350 | 398 | ||
399 | static /* as it isn't used anywhere else */ | ||
351 | void tai_pack(char *s,const struct tai *t) | 400 | void tai_pack(char *s,const struct tai *t) |
352 | { | 401 | { |
353 | uint64_t x; | 402 | uint64_t x; |
@@ -364,12 +413,14 @@ void tai_pack(char *s,const struct tai *t) | |||
364 | } | 413 | } |
365 | 414 | ||
366 | 415 | ||
416 | #ifdef UNUSED | ||
367 | /*** tai_sub.c ***/ | 417 | /*** tai_sub.c ***/ |
368 | 418 | ||
369 | void tai_sub(struct tai *t,const struct tai *u,const struct tai *v) | 419 | void tai_sub(struct tai *t, const struct tai *u, const struct tai *v) |
370 | { | 420 | { |
371 | t->x = u->x - v->x; | 421 | t->x = u->x - v->x; |
372 | } | 422 | } |
423 | #endif | ||
373 | 424 | ||
374 | 425 | ||
375 | /*** tai_unpack.c ***/ | 426 | /*** tai_unpack.c ***/ |
@@ -410,19 +461,27 @@ void taia_add(struct taia *t,const struct taia *u,const struct taia *v) | |||
410 | } | 461 | } |
411 | 462 | ||
412 | 463 | ||
413 | /*** taia_approx.c ***/ | 464 | #ifdef UNUSED |
465 | /*** taia_frac.c ***/ | ||
414 | 466 | ||
415 | double taia_approx(const struct taia *t) | 467 | double taia_frac(const struct taia *t) |
416 | { | 468 | { |
417 | return tai_approx(&t->sec) + taia_frac(t); | 469 | return (t->atto * 0.000000001 + t->nano) * 0.000000001; |
418 | } | 470 | } |
419 | 471 | ||
420 | 472 | ||
421 | /*** taia_frac.c ***/ | 473 | /*** taia_approx.c ***/ |
422 | 474 | ||
423 | double taia_frac(const struct taia *t) | 475 | double taia_approx(const struct taia *t) |
424 | { | 476 | { |
425 | return (t->atto * 0.000000001 + t->nano) * 0.000000001; | 477 | return t->sec->x + taia_frac(t); |
478 | } | ||
479 | #endif | ||
480 | |||
481 | static | ||
482 | uint64_t taia2millisec(const struct taia *t) | ||
483 | { | ||
484 | return (t->sec.x * 1000) + (t->nano / 1000000); | ||
426 | } | 485 | } |
427 | 486 | ||
428 | 487 | ||
@@ -445,8 +504,8 @@ int taia_less(const struct taia *t,const struct taia *u) | |||
445 | void taia_now(struct taia *t) | 504 | void taia_now(struct taia *t) |
446 | { | 505 | { |
447 | struct timeval now; | 506 | struct timeval now; |
448 | gettimeofday(&now,(struct timezone *) 0); | 507 | gettimeofday(&now, NULL); |
449 | tai_unix(&t->sec,now.tv_sec); | 508 | tai_unix(&t->sec, now.tv_sec); |
450 | t->nano = 1000 * now.tv_usec + 500; | 509 | t->nano = 1000 * now.tv_usec + 500; |
451 | t->atto = 0; | 510 | t->atto = 0; |
452 | } | 511 | } |
@@ -454,11 +513,11 @@ void taia_now(struct taia *t) | |||
454 | 513 | ||
455 | /*** taia_pack.c ***/ | 514 | /*** taia_pack.c ***/ |
456 | 515 | ||
457 | void taia_pack(char *s,const struct taia *t) | 516 | void taia_pack(char *s, const struct taia *t) |
458 | { | 517 | { |
459 | unsigned long x; | 518 | unsigned long x; |
460 | 519 | ||
461 | tai_pack(s,&t->sec); | 520 | tai_pack(s, &t->sec); |
462 | s += 8; | 521 | s += 8; |
463 | 522 | ||
464 | x = t->atto; | 523 | x = t->atto; |
@@ -575,25 +634,25 @@ GEN_ALLOC_append(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus,stralloc_appe | |||
575 | 634 | ||
576 | void iopause(iopause_fd *x,unsigned len,struct taia *deadline,struct taia *stamp) | 635 | void iopause(iopause_fd *x,unsigned len,struct taia *deadline,struct taia *stamp) |
577 | { | 636 | { |
578 | struct taia t; | ||
579 | int millisecs; | 637 | int millisecs; |
580 | double d; | ||
581 | int i; | 638 | int i; |
582 | 639 | ||
583 | if (taia_less(deadline,stamp)) | 640 | if (taia_less(deadline,stamp)) |
584 | millisecs = 0; | 641 | millisecs = 0; |
585 | else { | 642 | else { |
643 | uint64_t m; | ||
644 | struct taia t; | ||
586 | t = *stamp; | 645 | t = *stamp; |
587 | taia_sub(&t,deadline,&t); | 646 | taia_sub(&t, deadline, &t); |
588 | d = taia_approx(&t); | 647 | millisecs = m = taia2millisec(&t); |
589 | if (d > 1000.0) d = 1000.0; | 648 | if (m > 1000) millisecs = 1000; |
590 | millisecs = d * 1000.0 + 20.0; | 649 | millisecs += 20; |
591 | } | 650 | } |
592 | 651 | ||
593 | for (i = 0;i < len;++i) | 652 | for (i = 0; i < len; ++i) |
594 | x[i].revents = 0; | 653 | x[i].revents = 0; |
595 | 654 | ||
596 | poll(x,len,millisecs); | 655 | poll(x, len, millisecs); |
597 | /* XXX: some kernels apparently need x[0] even if len is 0 */ | 656 | /* XXX: some kernels apparently need x[0] even if len is 0 */ |
598 | /* XXX: how to handle EAGAIN? are kernels really this dumb? */ | 657 | /* XXX: how to handle EAGAIN? are kernels really this dumb? */ |
599 | /* XXX: how to handle EINVAL? when exactly can this happen? */ | 658 | /* XXX: how to handle EINVAL? when exactly can this happen? */ |
@@ -867,26 +926,28 @@ unsigned scan_ulong(const char *s,unsigned long *u) | |||
867 | } | 926 | } |
868 | 927 | ||
869 | 928 | ||
929 | #ifdef UNUSED | ||
870 | /*** seek_set.c ***/ | 930 | /*** seek_set.c ***/ |
871 | 931 | ||
872 | int seek_set(int fd,seek_pos pos) | 932 | int seek_set(int fd,seek_pos pos) |
873 | { | 933 | { |
874 | if (lseek(fd,(off_t) pos,SEEK_SET) == -1) return -1; return 0; | 934 | if (lseek(fd,(off_t) pos,SEEK_SET) == -1) return -1; return 0; |
875 | } | 935 | } |
936 | #endif | ||
876 | 937 | ||
877 | 938 | ||
878 | /*** sig.c ***/ | 939 | /*** sig.c ***/ |
879 | 940 | ||
880 | int sig_alarm = SIGALRM; | 941 | //int sig_alarm = SIGALRM; |
881 | int sig_child = SIGCHLD; | 942 | //int sig_child = SIGCHLD; |
882 | int sig_cont = SIGCONT; | 943 | //int sig_cont = SIGCONT; |
883 | int sig_hangup = SIGHUP; | 944 | //int sig_hangup = SIGHUP; |
884 | int sig_int = SIGINT; | 945 | //int sig_int = SIGINT; |
885 | int sig_pipe = SIGPIPE; | 946 | //int sig_pipe = SIGPIPE; |
886 | int sig_term = SIGTERM; | 947 | //int sig_term = SIGTERM; |
887 | 948 | ||
888 | void (*sig_defaulthandler)(int) = SIG_DFL; | 949 | //void (*sig_defaulthandler)(int) = SIG_DFL; |
889 | void (*sig_ignorehandler)(int) = SIG_IGN; | 950 | //void (*sig_ignorehandler)(int) = SIG_IGN; |
890 | 951 | ||
891 | 952 | ||
892 | /*** sig_block.c ***/ | 953 | /*** sig_block.c ***/ |
@@ -947,10 +1008,9 @@ unsigned str_chr(const char *s,int c) | |||
947 | ch = c; | 1008 | ch = c; |
948 | t = s; | 1009 | t = s; |
949 | for (;;) { | 1010 | for (;;) { |
950 | if (!*t) break; if (*t == ch) break; ++t; | 1011 | if (!*t) break; |
951 | if (!*t) break; if (*t == ch) break; ++t; | 1012 | if (*t == ch) break; |
952 | if (!*t) break; if (*t == ch) break; ++t; | 1013 | ++t; |
953 | if (!*t) break; if (*t == ch) break; ++t; | ||
954 | } | 1014 | } |
955 | return t - s; | 1015 | return t - s; |
956 | } | 1016 | } |
@@ -960,7 +1020,7 @@ unsigned str_chr(const char *s,int c) | |||
960 | 1020 | ||
961 | int wait_nohang(int *wstat) | 1021 | int wait_nohang(int *wstat) |
962 | { | 1022 | { |
963 | return waitpid(-1,wstat,WNOHANG); | 1023 | return waitpid(-1, wstat, WNOHANG); |
964 | } | 1024 | } |
965 | 1025 | ||
966 | 1026 | ||
@@ -971,7 +1031,7 @@ int wait_pid(int *wstat, int pid) | |||
971 | int r; | 1031 | int r; |
972 | 1032 | ||
973 | do | 1033 | do |
974 | r = waitpid(pid,wstat,0); | 1034 | r = waitpid(pid, wstat, 0); |
975 | while ((r == -1) && (errno == EINTR)); | 1035 | while ((r == -1) && (errno == EINTR)); |
976 | return r; | 1036 | return r; |
977 | } | 1037 | } |
diff --git a/runit/runit_lib.h b/runit/runit_lib.h index f4beb560e..f594f8f69 100644 --- a/runit/runit_lib.h +++ b/runit/runit_lib.h | |||
@@ -107,46 +107,46 @@ extern int fifo_make(const char *,int); | |||
107 | 107 | ||
108 | /*** fmt.h ***/ | 108 | /*** fmt.h ***/ |
109 | 109 | ||
110 | #define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ | 110 | //#define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ |
111 | #define FMT_LEN ((char *) 0) /* convenient abbreviation */ | 111 | //#define FMT_LEN ((char *) 0) /* convenient abbreviation */ |
112 | 112 | ||
113 | extern unsigned fmt_uint(char *,unsigned); | 113 | //extern unsigned fmt_uint(char *,unsigned); |
114 | extern unsigned fmt_uint0(char *,unsigned,unsigned); | 114 | //extern unsigned fmt_uint0(char *,unsigned,unsigned); |
115 | extern unsigned fmt_xint(char *,unsigned); | 115 | //extern unsigned fmt_xint(char *,unsigned); |
116 | extern unsigned fmt_nbbint(char *,unsigned,unsigned,unsigned,unsigned); | 116 | //extern unsigned fmt_nbbint(char *,unsigned,unsigned,unsigned,unsigned); |
117 | extern unsigned fmt_ushort(char *,unsigned short); | 117 | //extern unsigned fmt_ushort(char *,unsigned short); |
118 | extern unsigned fmt_xshort(char *,unsigned short); | 118 | //extern unsigned fmt_xshort(char *,unsigned short); |
119 | extern unsigned fmt_nbbshort(char *,unsigned,unsigned,unsigned,unsigned short); | 119 | //extern unsigned fmt_nbbshort(char *,unsigned,unsigned,unsigned,unsigned short); |
120 | extern unsigned fmt_ulong(char *,unsigned long); | 120 | //extern unsigned fmt_ulong(char *,unsigned long); |
121 | extern unsigned fmt_xlong(char *,unsigned long); | 121 | //extern unsigned fmt_xlong(char *,unsigned long); |
122 | extern unsigned fmt_nbblong(char *,unsigned,unsigned,unsigned,unsigned long); | 122 | //extern unsigned fmt_nbblong(char *,unsigned,unsigned,unsigned,unsigned long); |
123 | 123 | ||
124 | extern unsigned fmt_plusminus(char *,int); | 124 | //extern unsigned fmt_plusminus(char *,int); |
125 | extern unsigned fmt_minus(char *,int); | 125 | //extern unsigned fmt_minus(char *,int); |
126 | extern unsigned fmt_0x(char *,int); | 126 | //extern unsigned fmt_0x(char *,int); |
127 | 127 | ||
128 | extern unsigned fmt_str(char *,const char *); | 128 | //extern unsigned fmt_str(char *,const char *); |
129 | extern unsigned fmt_strn(char *,const char *,unsigned); | 129 | //extern unsigned fmt_strn(char *,const char *,unsigned); |
130 | 130 | ||
131 | 131 | ||
132 | /*** tai.h ***/ | 132 | /*** tai.h ***/ |
133 | 133 | ||
134 | struct tai { | 134 | struct tai { |
135 | uint64_t x; | 135 | uint64_t x; |
136 | } ; | 136 | }; |
137 | 137 | ||
138 | #define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64_t) (u))) | 138 | #define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64_t) (u))) |
139 | 139 | ||
140 | extern void tai_now(struct tai *); | 140 | //extern void tai_now(struct tai *); |
141 | 141 | ||
142 | #define tai_approx(t) ((double) ((t)->x)) | 142 | //#define tai_approx(t) ((double) ((t)->x)) |
143 | 143 | ||
144 | extern void tai_add(struct tai *,const struct tai *,const struct tai *); | 144 | //extern void tai_add(struct tai *,const struct tai *,const struct tai *); |
145 | extern void tai_sub(struct tai *,const struct tai *,const struct tai *); | 145 | //extern void tai_sub(struct tai *,const struct tai *,const struct tai *); |
146 | #define tai_less(t,u) ((t)->x < (u)->x) | 146 | //#define tai_less(t,u) ((t)->x < (u)->x) |
147 | 147 | ||
148 | #define TAI_PACK 8 | 148 | #define TAI_PACK 8 |
149 | extern void tai_pack(char *,const struct tai *); | 149 | //extern void tai_pack(char *,const struct tai *); |
150 | extern void tai_unpack(const char *,struct tai *); | 150 | extern void tai_unpack(const char *,struct tai *); |
151 | 151 | ||
152 | extern void tai_uint(struct tai *,unsigned); | 152 | extern void tai_uint(struct tai *,unsigned); |
@@ -158,14 +158,14 @@ struct taia { | |||
158 | struct tai sec; | 158 | struct tai sec; |
159 | unsigned long nano; /* 0...999999999 */ | 159 | unsigned long nano; /* 0...999999999 */ |
160 | unsigned long atto; /* 0...999999999 */ | 160 | unsigned long atto; /* 0...999999999 */ |
161 | } ; | 161 | }; |
162 | 162 | ||
163 | extern void taia_tai(const struct taia *,struct tai *); | 163 | //extern void taia_tai(const struct taia *,struct tai *); |
164 | 164 | ||
165 | extern void taia_now(struct taia *); | 165 | extern void taia_now(struct taia *); |
166 | 166 | ||
167 | extern double taia_approx(const struct taia *); | 167 | //extern double taia_approx(const struct taia *); |
168 | extern double taia_frac(const struct taia *); | 168 | //extern double taia_frac(const struct taia *); |
169 | 169 | ||
170 | extern void taia_add(struct taia *,const struct taia *,const struct taia *); | 170 | extern void taia_add(struct taia *,const struct taia *,const struct taia *); |
171 | extern void taia_addsec(struct taia *,const struct taia *,int); | 171 | extern void taia_addsec(struct taia *,const struct taia *,int); |
@@ -175,10 +175,10 @@ extern int taia_less(const struct taia *,const struct taia *); | |||
175 | 175 | ||
176 | #define TAIA_PACK 16 | 176 | #define TAIA_PACK 16 |
177 | extern void taia_pack(char *,const struct taia *); | 177 | extern void taia_pack(char *,const struct taia *); |
178 | extern void taia_unpack(const char *,struct taia *); | 178 | //extern void taia_unpack(const char *,struct taia *); |
179 | 179 | ||
180 | #define TAIA_FMTFRAC 19 | 180 | //#define TAIA_FMTFRAC 19 |
181 | extern unsigned taia_fmtfrac(char *,const struct taia *); | 181 | //extern unsigned taia_fmtfrac(char *,const struct taia *); |
182 | 182 | ||
183 | extern void taia_uint(struct taia *,unsigned); | 183 | extern void taia_uint(struct taia *,unsigned); |
184 | 184 | ||
@@ -187,10 +187,13 @@ extern void taia_uint(struct taia *,unsigned); | |||
187 | 187 | ||
188 | #define FMT_PTIME 30 | 188 | #define FMT_PTIME 30 |
189 | 189 | ||
190 | extern unsigned fmt_ptime(char *, struct taia *); | 190 | /* NUL terminated */ |
191 | extern unsigned fmt_taia(char *, struct taia *); | 191 | extern void fmt_ptime30nul(char *, struct taia *); |
192 | /* NOT terminated! */ | ||
193 | extern unsigned fmt_taia25(char *, struct taia *); | ||
192 | 194 | ||
193 | 195 | ||
196 | #ifdef UNUSED | ||
194 | /*** gen_alloc.h ***/ | 197 | /*** gen_alloc.h ***/ |
195 | 198 | ||
196 | #define GEN_ALLOC_typedef(ta,type,field,len,a) \ | 199 | #define GEN_ALLOC_typedef(ta,type,field,len,a) \ |
@@ -233,7 +236,6 @@ int ta_append(ta *x,const type *i) \ | |||
233 | 236 | ||
234 | 237 | ||
235 | /*** stralloc.h ***/ | 238 | /*** stralloc.h ***/ |
236 | #if 0 | ||
237 | GEN_ALLOC_typedef(stralloc,char,s,len,a) | 239 | GEN_ALLOC_typedef(stralloc,char,s,len,a) |
238 | 240 | ||
239 | extern int stralloc_ready(stralloc *,unsigned); | 241 | extern int stralloc_ready(stralloc *,unsigned); |
@@ -314,6 +316,7 @@ extern int readclose(int,stralloc *,unsigned); | |||
314 | 316 | ||
315 | /*** scan.h ***/ | 317 | /*** scan.h ***/ |
316 | 318 | ||
319 | #if 0 | ||
317 | extern unsigned scan_uint(const char *,unsigned *); | 320 | extern unsigned scan_uint(const char *,unsigned *); |
318 | extern unsigned scan_xint(const char *,unsigned *); | 321 | extern unsigned scan_xint(const char *,unsigned *); |
319 | extern unsigned scan_nbbint(const char *,unsigned,unsigned,unsigned,unsigned *); | 322 | extern unsigned scan_nbbint(const char *,unsigned,unsigned,unsigned,unsigned *); |
@@ -337,6 +340,7 @@ extern unsigned scan_memcmp(const char *,const char *,unsigned); | |||
337 | 340 | ||
338 | extern unsigned scan_long(const char *,long *); | 341 | extern unsigned scan_long(const char *,long *); |
339 | extern unsigned scan_8long(const char *,unsigned long *); | 342 | extern unsigned scan_8long(const char *,unsigned long *); |
343 | #endif | ||
340 | 344 | ||
341 | 345 | ||
342 | /*** seek.h ***/ | 346 | /*** seek.h ***/ |
@@ -345,30 +349,27 @@ typedef unsigned long seek_pos; | |||
345 | 349 | ||
346 | extern seek_pos seek_cur(int); | 350 | extern seek_pos seek_cur(int); |
347 | 351 | ||
348 | extern int seek_set(int,seek_pos); | 352 | //extern int seek_set(int,seek_pos); |
349 | extern int seek_end(int); | 353 | extern int seek_end(int); |
350 | 354 | ||
351 | extern int seek_trunc(int,seek_pos); | 355 | extern int seek_trunc(int,seek_pos); |
352 | 356 | ||
353 | #define seek_begin(fd) (seek_set((fd),(seek_pos) 0)) | 357 | //#define seek_begin(fd) (seek_set((fd),(seek_pos) 0)) |
354 | 358 | ||
355 | 359 | ||
356 | /*** sig.h ***/ | 360 | /*** sig.h ***/ |
357 | 361 | ||
358 | extern int sig_alarm; | 362 | //extern int sig_alarm; |
359 | extern int sig_child; | 363 | //extern int sig_child; |
360 | extern int sig_cont; | 364 | //extern int sig_cont; |
361 | extern int sig_hangup; | 365 | //extern int sig_hangup; |
362 | extern int sig_int; | 366 | //extern int sig_int; |
363 | extern int sig_pipe; | 367 | //extern int sig_pipe; |
364 | extern int sig_term; | 368 | //extern int sig_term; |
365 | |||
366 | extern void (*sig_defaulthandler)(int); | ||
367 | extern void (*sig_ignorehandler)(int); | ||
368 | 369 | ||
369 | extern void sig_catch(int,void (*)(int)); | 370 | extern void sig_catch(int,void (*)(int)); |
370 | #define sig_ignore(s) (sig_catch((s),sig_ignorehandler)) | 371 | #define sig_ignore(s) (sig_catch((s),SIG_IGN)) |
371 | #define sig_uncatch(s) (sig_catch((s),sig_defaulthandler)) | 372 | #define sig_uncatch(s) (sig_catch((s),SIG_DFL)) |
372 | 373 | ||
373 | extern void sig_block(int); | 374 | extern void sig_block(int); |
374 | extern void sig_unblock(int); | 375 | extern void sig_unblock(int); |
diff --git a/runit/runsv.c b/runit/runsv.c index aace041a8..24a51f2b1 100644 --- a/runit/runsv.c +++ b/runit/runsv.c | |||
@@ -307,10 +307,10 @@ static void startservice(struct svdir *s) | |||
307 | close(logpipe[0]); | 307 | close(logpipe[0]); |
308 | } | 308 | } |
309 | } | 309 | } |
310 | sig_uncatch(sig_child); | 310 | sig_uncatch(SIGCHLD); |
311 | sig_unblock(sig_child); | 311 | sig_unblock(SIGCHLD); |
312 | sig_uncatch(sig_term); | 312 | sig_uncatch(SIGTERM); |
313 | sig_unblock(sig_term); | 313 | sig_unblock(SIGTERM); |
314 | execve(*run, run, environ); | 314 | execve(*run, run, environ); |
315 | if (s->islog) | 315 | if (s->islog) |
316 | fatal2_cannot("start log/", *run); | 316 | fatal2_cannot("start log/", *run); |
@@ -406,10 +406,10 @@ int runsv_main(int argc, char **argv) | |||
406 | ndelay_on(selfpipe[0]); | 406 | ndelay_on(selfpipe[0]); |
407 | ndelay_on(selfpipe[1]); | 407 | ndelay_on(selfpipe[1]); |
408 | 408 | ||
409 | sig_block(sig_child); | 409 | sig_block(SIGCHLD); |
410 | sig_catch(sig_child, s_child); | 410 | sig_catch(SIGCHLD, s_child); |
411 | sig_block(sig_term); | 411 | sig_block(SIGTERM); |
412 | sig_catch(sig_term, s_term); | 412 | sig_catch(SIGTERM, s_term); |
413 | 413 | ||
414 | xchdir(dir); | 414 | xchdir(dir); |
415 | svd[0].pid = 0; | 415 | svd[0].pid = 0; |
@@ -533,11 +533,11 @@ int runsv_main(int argc, char **argv) | |||
533 | taia_uint(&deadline, 3600); | 533 | taia_uint(&deadline, 3600); |
534 | taia_add(&deadline, &now, &deadline); | 534 | taia_add(&deadline, &now, &deadline); |
535 | 535 | ||
536 | sig_unblock(sig_term); | 536 | sig_unblock(SIGTERM); |
537 | sig_unblock(sig_child); | 537 | sig_unblock(SIGCHLD); |
538 | iopause(x, 2+haslog, &deadline, &now); | 538 | iopause(x, 2+haslog, &deadline, &now); |
539 | sig_block(sig_term); | 539 | sig_block(SIGTERM); |
540 | sig_block(sig_child); | 540 | sig_block(SIGCHLD); |
541 | 541 | ||
542 | while (read(selfpipe[0], &ch, 1) == 1) | 542 | while (read(selfpipe[0], &ch, 1) == 1) |
543 | ; | 543 | ; |
diff --git a/runit/runsvdir.c b/runit/runsvdir.c index 3290da5e6..41581a8c8 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c | |||
@@ -70,8 +70,8 @@ static void runsv(int no, char *name) | |||
70 | prog[0] = "runsv"; | 70 | prog[0] = "runsv"; |
71 | prog[1] = name; | 71 | prog[1] = name; |
72 | prog[2] = 0; | 72 | prog[2] = 0; |
73 | sig_uncatch(sig_hangup); | 73 | sig_uncatch(SIGHUP); |
74 | sig_uncatch(sig_term); | 74 | sig_uncatch(SIGTERM); |
75 | if (pgrp) setsid(); | 75 | if (pgrp) setsid(); |
76 | execvp(prog[0], prog); | 76 | execvp(prog[0], prog); |
77 | //pathexec_run(*prog, prog, (char* const*)environ); | 77 | //pathexec_run(*prog, prog, (char* const*)environ); |
@@ -197,8 +197,8 @@ int runsvdir_main(int argc, char **argv) | |||
197 | if (!argv || !*argv) usage(); | 197 | if (!argv || !*argv) usage(); |
198 | } | 198 | } |
199 | 199 | ||
200 | sig_catch(sig_term, s_term); | 200 | sig_catch(SIGTERM, s_term); |
201 | sig_catch(sig_hangup, s_hangup); | 201 | sig_catch(SIGHUP, s_hangup); |
202 | svdir = *argv++; | 202 | svdir = *argv++; |
203 | if (argv && *argv) { | 203 | if (argv && *argv) { |
204 | rplog = *argv; | 204 | rplog = *argv; |
@@ -276,12 +276,12 @@ int runsvdir_main(int argc, char **argv) | |||
276 | taia_uint(&deadline, check ? 1 : 5); | 276 | taia_uint(&deadline, check ? 1 : 5); |
277 | taia_add(&deadline, &now, &deadline); | 277 | taia_add(&deadline, &now, &deadline); |
278 | 278 | ||
279 | sig_block(sig_child); | 279 | sig_block(SIGCHLD); |
280 | if (rplog) | 280 | if (rplog) |
281 | iopause(io, 1, &deadline, &now); | 281 | iopause(io, 1, &deadline, &now); |
282 | else | 282 | else |
283 | iopause(0, 0, &deadline, &now); | 283 | iopause(0, 0, &deadline, &now); |
284 | sig_unblock(sig_child); | 284 | sig_unblock(SIGCHLD); |
285 | 285 | ||
286 | if (rplog && (io[0].revents | IOPAUSE_READ)) | 286 | if (rplog && (io[0].revents | IOPAUSE_READ)) |
287 | while (read(logpipe[0], &ch, 1) > 0) | 287 | while (read(logpipe[0], &ch, 1) > 0) |
diff --git a/runit/sv.c b/runit/sv.c index 054053619..6594e1451 100644 --- a/runit/sv.c +++ b/runit/sv.c | |||
@@ -326,28 +326,38 @@ int sv_main(int argc, char **argv) | |||
326 | service++; | 326 | service++; |
327 | } | 327 | } |
328 | 328 | ||
329 | if (*cbk) | 329 | if (*cbk) { |
330 | for (;;) { | 330 | for (;;) { |
331 | //TODO: tdiff resolution is way too high. seconds will be enough | ||
331 | taia_sub(&tdiff, &tnow, &tstart); | 332 | taia_sub(&tdiff, &tnow, &tstart); |
332 | service = servicex; want_exit = 1; | 333 | service = servicex; want_exit = 1; |
333 | for (i = 0; i < services; ++i, ++service) { | 334 | for (i = 0; i < services; ++i, ++service) { |
334 | if (!*service) continue; | 335 | if (!*service) |
336 | continue; | ||
335 | if ((**service != '/') && (**service != '.')) { | 337 | if ((**service != '/') && (**service != '.')) { |
336 | if ((chdir(varservice) == -1) || (chdir(*service) == -1)) { | 338 | if (chdir(varservice) == -1) |
337 | fail("cannot change to service directory"); | 339 | goto chdir_failed; |
338 | *service = 0; | 340 | } |
339 | } | 341 | if (chdir(*service) == -1) { |
340 | } else if (chdir(*service) == -1) { | 342 | chdir_failed: |
341 | fail("cannot change to service directory"); | 343 | fail("cannot change to service directory"); |
342 | *service = 0; | 344 | goto nullify_service; |
343 | } | 345 | } |
344 | if (*service) { if (cbk(acts) != 0) *service = 0; else want_exit = 0; } | 346 | if (cbk(acts) != 0) |
345 | if (*service && taia_approx(&tdiff) > waitsec) { | 347 | goto nullify_service; |
348 | want_exit = 0; | ||
349 | //if (taia_approx(&tdiff) > waitsec) | ||
350 | if (tdiff.sec.x >= waitsec) { | ||
346 | kll ? printf(KILL) : printf(TIMEOUT); | 351 | kll ? printf(KILL) : printf(TIMEOUT); |
347 | if (svstatus_get() > 0) { svstatus_print(*service); ++rc; } | 352 | if (svstatus_get() > 0) { |
353 | svstatus_print(*service); | ||
354 | ++rc; | ||
355 | } | ||
348 | puts(""); /* will also flush the output */ | 356 | puts(""); /* will also flush the output */ |
349 | if (kll) control("k"); | 357 | if (kll) |
350 | *service = 0; | 358 | control("k"); |
359 | nullify_service: | ||
360 | *service = NULL; | ||
351 | } | 361 | } |
352 | if (fchdir(curdir) == -1) | 362 | if (fchdir(curdir) == -1) |
353 | fatal_cannot("change to original directory"); | 363 | fatal_cannot("change to original directory"); |
@@ -356,5 +366,6 @@ int sv_main(int argc, char **argv) | |||
356 | usleep(420000); | 366 | usleep(420000); |
357 | taia_now(&tnow); | 367 | taia_now(&tnow); |
358 | } | 368 | } |
369 | } | ||
359 | return rc > 99 ? 99 : rc; | 370 | return rc > 99 ? 99 : rc; |
360 | } | 371 | } |
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 | } |
101 | static void pause_nomem(void) | 101 | static 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 | } |
105 | static void pause1cannot(char *m0) | 106 | static 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 | } |
109 | static void pause2cannot(char *m0, char *m1) | 111 | static void pause2cannot(char *m0, char *m1) |
110 | { | 112 | { |
@@ -115,7 +117,8 @@ static void pause2cannot(char *m0, char *m1) | |||
115 | static char* wstrdup(const char *str) | 117 | static 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); |