Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/runit/svlogd.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/runit/svlogd.c
r1765 r2725 26 26 */ 27 27 28 /* Busyboxed by Den is Vlasenko <vda.linux@googlemail.com> */28 /* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */ 29 29 /* TODO: depends on runit_lib.c - review and reduce/eliminate */ 30 31 /* 32 Config files 33 34 On startup, and after receiving a HUP signal, svlogd checks for each 35 log directory log if the configuration file log/config exists, 36 and if so, reads the file line by line and adjusts configuration 37 for log as follows: 38 39 If the line is empty, or starts with a #, it is ignored. A line 40 of the form 41 42 ssize 43 sets the maximum file size of current when svlogd should rotate 44 the current log file to size bytes. Default is 1000000. 45 If size is zero, svlogd doesnt rotate log files 46 You should set size to at least (2 * len). 47 nnum 48 sets the number of old log files svlogd should maintain to num. 49 If svlogd sees more that num old log files in log after log file 50 rotation, it deletes the oldest one. Default is 10. 51 If num is zero, svlogd doesnt remove old log files. 52 Nmin 53 sets the minimum number of old log files svlogd should maintain 54 to min. min must be less than num. If min is set, and svlogd 55 cannot write to current because the filesystem is full, 56 and it sees more than min old log files, it deletes the oldest one. 57 ttimeout 58 sets the maximum age of the current log file when svlogd should 59 rotate the current log file to timeout seconds. If current 60 is timeout seconds old, and is not empty, svlogd forces log file rotation. 61 !processor 62 tells svlogd to feed each recent log file through processor 63 (see above) on log file rotation. By default log files are not processed. 64 ua.b.c.d[:port] 65 tells svlogd to transmit the first len characters of selected 66 log messages to the IP address a.b.c.d, port number port. 67 If port isnt set, the default port for syslog is used (514). 68 len can be set through the -l option, see below. If svlogd 69 has trouble sending udp packets, it writes error messages 70 to the log directory. Attention: logging through udp is unreliable, 71 and should be used in private networks only. 72 Ua.b.c.d[:port] 73 is the same as the u line above, but the log messages are no longer 74 written to the log directory, but transmitted through udp only. 75 Error messages from svlogd concerning sending udp packages still go 76 to the log directory. 77 pprefix 78 tells svlogd to prefix each line to be written to the log directory, 79 to standard error, or through UDP, with prefix. 80 81 If a line starts with a -, +, e, or E, svlogd matches the first len characters 82 of each log message against pattern and acts accordingly: 83 84 -pattern 85 the log message is deselected. 86 +pattern 87 the log message is selected. 88 epattern 89 the log message is selected to be printed to standard error. 90 Epattern 91 the log message is deselected to be printed to standard error. 92 93 Initially each line is selected to be written to log/current. Deselected 94 log messages are discarded from log. Initially each line is deselected 95 to be written to standard err. Log messages selected for standard error 96 are written to standard error. 97 98 Pattern Matching 99 100 svlogd matches a log message against the string pattern as follows: 101 102 pattern is applied to the log message one character by one, starting 103 with the first. A character not a star (*) and not a plus (+) matches itself. 104 A plus matches the next character in pattern in the log message one 105 or more times. A star before the end of pattern matches any string 106 in the log message that does not include the next character in pattern. 107 A star at the end of pattern matches any string. 108 109 Timestamps optionally added by svlogd are not considered part 110 of the log message. 111 112 An svlogd pattern is not a regular expression. For example consider 113 a log message like this 114 115 2005-12-18_09:13:50.97618 tcpsvd: info: pid 1977 from 10.4.1.14 116 117 The following pattern doesnt match 118 119 -*pid* 120 121 because the first star matches up to the first p in tcpsvd, 122 and then the match fails because i is not s. To match this 123 log message, you can use a pattern like this instead 124 125 -*: *: pid * 126 */ 30 127 31 128 #include <sys/poll.h> … … 38 135 #define FMT_PTIME 30 39 136 40 static unsigned verbose; 41 static int linemax = 1000; 42 ////static int buflen = 1024; 43 static int linelen; 44 45 static char **fndir; 46 static int fdwdir; 47 static int wstat; 48 static unsigned nearest_rotate; 49 50 static char *line; 51 static smallint exitasap; 52 static smallint rotateasap; 53 static smallint reopenasap; 54 static smallint linecomplete = 1; 55 56 static smallint tmaxflag; 57 58 static char repl; 59 static const char *replace = ""; 60 61 static sigset_t *blocked_sigset; 62 static int fl_flag_0; 63 64 static struct logdir { 137 struct logdir { 65 138 ////char *btmp; 66 139 /* pattern list to match, in "aa\0bb\0\cc\0\0" form */ … … 82 155 char match; 83 156 char matcherr; 84 } *dir; 85 static unsigned dirn; 157 }; 158 159 160 struct globals { 161 struct logdir *dir; 162 unsigned verbose; 163 int linemax; 164 ////int buflen; 165 int linelen; 166 167 int fdwdir; 168 char **fndir; 169 int wstat; 170 unsigned nearest_rotate; 171 172 void* (*memRchr)(const void *, int, size_t); 173 174 smallint exitasap; 175 smallint rotateasap; 176 smallint reopenasap; 177 smallint linecomplete; 178 smallint tmaxflag; 179 180 char repl; 181 const char *replace; 182 int fl_flag_0; 183 unsigned dirn; 184 185 sigset_t blocked_sigset; 186 }; 187 #define G (*ptr_to_globals) 188 #define dir (G.dir ) 189 #define verbose (G.verbose ) 190 #define linemax (G.linemax ) 191 #define buflen (G.buflen ) 192 #define linelen (G.linelen ) 193 #define fndir (G.fndir ) 194 #define fdwdir (G.fdwdir ) 195 #define wstat (G.wstat ) 196 #define memRchr (G.memRchr ) 197 #define nearest_rotate (G.nearest_rotate) 198 #define exitasap (G.exitasap ) 199 #define rotateasap (G.rotateasap ) 200 #define reopenasap (G.reopenasap ) 201 #define linecomplete (G.linecomplete ) 202 #define tmaxflag (G.tmaxflag ) 203 #define repl (G.repl ) 204 #define replace (G.replace ) 205 #define blocked_sigset (G.blocked_sigset) 206 #define fl_flag_0 (G.fl_flag_0 ) 207 #define dirn (G.dirn ) 208 #define INIT_G() do { \ 209 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 210 linemax = 1000; \ 211 /*buflen = 1024;*/ \ 212 linecomplete = 1; \ 213 replace = ""; \ 214 } while (0) 215 216 #define line bb_common_bufsiz1 217 86 218 87 219 #define FATAL "fatal: " … … 90 222 #define INFO "info: " 91 223 92 #define usage() bb_show_usage()93 224 static void fatalx(const char *m0) 94 225 { … … 114 245 static void pause1cannot(const char *m0) 115 246 { 116 bb_perror_msg(PAUSE"can not %s", m0);247 bb_perror_msg(PAUSE"can't %s", m0); 117 248 sleep(3); 118 249 } 119 250 static void pause2cannot(const char *m0, const char *m1) 120 251 { 121 bb_perror_msg(PAUSE"can not %s %s", m0, m1);252 bb_perror_msg(PAUSE"can't %s %s", m0, m1); 122 253 sleep(3); 123 254 } … … 131 262 } 132 263 264 static unsigned pmatch(const char *p, const char *s, unsigned len) 265 { 266 for (;;) { 267 char c = *p++; 268 if (!c) return !len; 269 switch (c) { 270 case '*': 271 c = *p; 272 if (!c) return 1; 273 for (;;) { 274 if (!len) return 0; 275 if (*s == c) break; 276 ++s; 277 --len; 278 } 279 continue; 280 case '+': 281 c = *p++; 282 if (c != *s) return 0; 283 for (;;) { 284 if (!len) return 1; 285 if (*s != c) break; 286 ++s; 287 --len; 288 } 289 continue; 290 /* 291 case '?': 292 if (*p == '?') { 293 if (*s != '?') return 0; 294 ++p; 295 } 296 ++s; --len; 297 continue; 298 */ 299 default: 300 if (!len) return 0; 301 if (*s != c) return 0; 302 ++s; 303 --len; 304 continue; 305 } 306 } 307 return 0; 308 } 309 133 310 /*** ex fmt_ptime.[ch] ***/ 134 311 … … 136 313 static void fmt_time_human_30nul(char *s) 137 314 { 138 struct tm * t;315 struct tm *ptm; 139 316 struct timeval tv; 140 317 141 318 gettimeofday(&tv, NULL); 142 t = gmtime(&(tv.tv_sec));319 ptm = gmtime(&tv.tv_sec); 143 320 sprintf(s, "%04u-%02u-%02u_%02u:%02u:%02u.%06u000", 144 (unsigned)(1900 + t->tm_year),145 (unsigned)( t->tm_mon + 1),146 (unsigned)( t->tm_mday),147 (unsigned)( t->tm_hour),148 (unsigned)( t->tm_min),149 (unsigned)( t->tm_sec),321 (unsigned)(1900 + ptm->tm_year), 322 (unsigned)(ptm->tm_mon + 1), 323 (unsigned)(ptm->tm_mday), 324 (unsigned)(ptm->tm_hour), 325 (unsigned)(ptm->tm_min), 326 (unsigned)(ptm->tm_sec), 150 327 (unsigned)(tv.tv_usec) 151 328 ); … … 175 352 } 176 353 177 static unsigned processorstart(struct logdir *ld) 178 { 354 static void processorstart(struct logdir *ld) 355 { 356 char sv_ch; 179 357 int pid; 180 358 181 if (!ld->processor) return 0;359 if (!ld->processor) return; 182 360 if (ld->ppid) { 183 361 warnx("processor already running", ld->name); 184 return 0; 185 } 186 while ((pid = fork()) == -1) 187 pause2cannot("fork for processor", ld->name); 362 return; 363 } 364 365 /* vfork'ed child trashes this byte, save... */ 366 sv_ch = ld->fnsave[26]; 367 368 while ((pid = vfork()) == -1) 369 pause2cannot("vfork for processor", ld->name); 188 370 if (!pid) { 189 char *prog[4];190 371 int fd; 191 372 192 373 /* child */ 193 signal(SIGTERM, SIG_DFL); 194 signal(SIGALRM, SIG_DFL); 195 signal(SIGHUP, SIG_DFL); 374 /* Non-ignored signals revert to SIG_DFL on exec anyway */ 375 /*bb_signals(0 376 + (1 << SIGTERM) 377 + (1 << SIGALRM) 378 + (1 << SIGHUP) 379 , SIG_DFL);*/ 196 380 sig_unblock(SIGTERM); 197 381 sig_unblock(SIGALRM); … … 202 386 fd = xopen(ld->fnsave, O_RDONLY|O_NDELAY); 203 387 xmove_fd(fd, 0); 204 ld->fnsave[26] = 't'; 388 ld->fnsave[26] = 't'; /* <- that's why we need sv_ch! */ 205 389 fd = xopen(ld->fnsave, O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT); 206 390 xmove_fd(fd, 1); 207 fd = open _read("state");391 fd = open("state", O_RDONLY|O_NDELAY); 208 392 if (fd == -1) { 209 393 if (errno != ENOENT) 210 bb_perror_msg_and_die(FATAL"can not %s processor %s", "open state for", ld->name);394 bb_perror_msg_and_die(FATAL"can't %s processor %s", "open state for", ld->name); 211 395 close(xopen("state", O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT)); 212 396 fd = xopen("state", O_RDONLY|O_NDELAY); … … 217 401 218 402 // getenv("SHELL")? 219 prog[0] = (char*)"sh"; 220 prog[1] = (char*)"-c"; 221 prog[2] = ld->processor; 222 prog[3] = NULL; 223 execve("/bin/sh", prog, environ); 224 bb_perror_msg_and_die(FATAL"cannot %s processor %s", "run", ld->name); 225 } 403 execl(DEFAULT_SHELL, DEFAULT_SHELL_SHORT_NAME, "-c", ld->processor, (char*) NULL); 404 bb_perror_msg_and_die(FATAL"can't %s processor %s", "run", ld->name); 405 } 406 ld->fnsave[26] = sv_ch; /* ...restore */ 226 407 ld->ppid = pid; 227 return 1;228 408 } 229 409 … … 234 414 if (ld->ppid) { 235 415 sig_unblock(SIGHUP); 236 while ( wait_pid(&wstat, ld->ppid) == -1)416 while (safe_waitpid(ld->ppid, &wstat, 0) == -1) 237 417 pause2cannot("wait for processor", ld->name); 238 418 sig_block(SIGHUP); 239 419 ld->ppid = 0; 240 420 } 241 if (ld->fddir == -1) return 1; 421 if (ld->fddir == -1) 422 return 1; 242 423 while (fchdir(ld->fddir) == -1) 243 424 pause2cannot("change directory, want processor", ld->name); 244 if ( wait_exitcode(wstat) != 0) {425 if (WEXITSTATUS(wstat) != 0) { 245 426 warnx("processor failed, restart", ld->name); 246 427 ld->fnsave[26] = 't'; … … 262 443 ld->fnsave[26] = 'u'; 263 444 if (unlink(ld->fnsave) == -1) 264 bb_error_msg(WARNING"can not unlink: %s/%s", ld->name, ld->fnsave);445 bb_error_msg(WARNING"can't unlink: %s/%s", ld->name, ld->fnsave); 265 446 while (rename("newstate", "state") == -1) 266 447 pause2cannot("rename state", ld->name); … … 287 468 if (f->d_name[26] == 't') { 288 469 if (unlink(f->d_name) == -1) 289 warn2("can not unlink processor leftover", f->d_name);470 warn2("can't unlink processor leftover", f->d_name); 290 471 } else { 291 472 ++n; … … 297 478 } 298 479 if (errno) 299 warn2("can not read directory", ld->name);480 warn2("can't read directory", ld->name); 300 481 closedir(d); 301 482 … … 304 485 bb_error_msg(INFO"delete: %s/%s", ld->name, oldest); 305 486 if ((*oldest == '@') && (unlink(oldest) == -1)) 306 warn2("can not unlink oldest logfile", ld->name);487 warn2("can't unlink oldest logfile", ld->name); 307 488 } 308 489 } … … 359 540 while ((ld->fdcur = open("current", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600)) == -1) 360 541 pause2cannot("create new current", ld->name); 361 /* we presume this cannot fail */362 ld->filecur = fdopen(ld->fdcur, "a"); ////542 while ((ld->filecur = fdopen(ld->fdcur, "a")) == NULL) //// 543 pause2cannot("create new current", ld->name); /* very unlikely */ 363 544 setvbuf(ld->filecur, NULL, _IOFBF, linelen); //// 364 c oe(ld->fdcur);545 close_on_exec_on(ld->fdcur); 365 546 ld->size = 0; 366 547 while (fchmod(ld->fdcur, 0644) == -1) 367 548 pause2cannot("set mode of current", ld->name); 549 368 550 rmoldest(ld); 369 551 processorstart(ld); … … 413 595 memcpy(oldest, f->d_name, 27); 414 596 } 415 if (errno) warn2("can not read directory, want remove old logfile",597 if (errno) warn2("can't read directory, want remove old logfile", 416 598 ld->name); 417 599 closedir(d); … … 423 605 errno = 0; 424 606 if (unlink(oldest) == -1) { 425 warn2("can not unlink oldest logfile", ld->name);607 warn2("can't unlink oldest logfile", ld->name); 426 608 errno = ENOSPC; 427 609 } … … 468 650 } 469 651 470 static unsigned logdir_open(struct logdir *ld, const char *fn)652 static NOINLINE unsigned logdir_open(struct logdir *ld, const char *fn) 471 653 { 472 654 char buf[128]; … … 480 662 ld->fddir = open(fn, O_RDONLY|O_NDELAY); 481 663 if (ld->fddir == -1) { 482 warn2("can not open log directory", (char*)fn);664 warn2("can't open log directory", (char*)fn); 483 665 return 0; 484 666 } 485 c oe(ld->fddir);667 close_on_exec_on(ld->fddir); 486 668 if (fchdir(ld->fddir) == -1) { 487 669 logdir_close(ld); 488 warn2("can not change directory", (char*)fn);670 warn2("can't change directory", (char*)fn); 489 671 return 0; 490 672 } 491 673 ld->fdlock = open("lock", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600); 492 674 if ((ld->fdlock == -1) 493 || ( lock_exnb(ld->fdlock) == -1)675 || (flock(ld->fdlock, LOCK_EX | LOCK_NB) == -1) 494 676 ) { 495 677 logdir_close(ld); 496 warn2("can not lock directory", (char*)fn);678 warn2("can't lock directory", (char*)fn); 497 679 while (fchdir(fdwdir) == -1) 498 680 pause1cannot("change to initial working directory"); 499 681 return 0; 500 682 } 501 c oe(ld->fdlock);683 close_on_exec_on(ld->fdlock); 502 684 503 685 ld->size = 0; … … 512 694 513 695 /* read config */ 514 i = open_read_close("config", buf, sizeof(buf) );696 i = open_read_close("config", buf, sizeof(buf) - 1); 515 697 if (i < 0 && errno != ENOENT) 516 698 bb_perror_msg(WARNING"%s/config", ld->name); 517 699 if (i > 0) { 700 buf[i] = '\0'; 518 701 if (verbose) 519 702 bb_error_msg(INFO"read: %s/config", ld->name); … … 528 711 case 'e': 529 712 case 'E': 713 /* Filtering requires one-line buffering, 714 * resetting the "find newline" function 715 * accordingly */ 716 memRchr = memchr; 530 717 /* Add '\n'-terminated line to ld->inst */ 531 718 while (1) { 532 int l = asprintf(&new, "%s%s\n", ld->inst ? : "", s);719 int l = asprintf(&new, "%s%s\n", ld->inst ? ld->inst : "", s); 533 720 if (l >= 0 && new) 534 721 break; … … 542 729 { "k", 1024 }, 543 730 { "m", 1024*1024 }, 544 { }731 { "", 0 } 545 732 }; 546 733 ld->sizemax = xatou_sfx(&s[1], km_suffixes); … … 548 735 } 549 736 case 'n': 550 ld->nmax = xatoi_ u(&s[1]);737 ld->nmax = xatoi_positive(&s[1]); 551 738 break; 552 739 case 'N': 553 ld->nmin = xatoi_ u(&s[1]);740 ld->nmin = xatoi_positive(&s[1]); 554 741 break; 555 742 case 't': { … … 558 745 { "h", 60*60 }, 559 746 /*{ "d", 24*60*60 },*/ 560 { }747 { "", 0 } 561 748 }; 562 749 ld->rotate_period = xatou_sfx(&s[1], mh_suffixes); … … 613 800 if (errno != ENOENT) { 614 801 logdir_close(ld); 615 warn2("can not stat current", ld->name);802 warn2("can't stat current", ld->name); 616 803 while (fchdir(fdwdir) == -1) 617 804 pause1cannot("change to initial working directory"); … … 621 808 while ((ld->fdcur = open("current", O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600)) == -1) 622 809 pause2cannot("open current", ld->name); 623 /* we presume this cannot fail */624 ld->filecur = fdopen(ld->fdcur, "a"); ////810 while ((ld->filecur = fdopen(ld->fdcur, "a")) == NULL) 811 pause2cannot("open current", ld->name); //// 625 812 setvbuf(ld->filecur, NULL, _IOFBF, linelen); //// 626 813 627 c oe(ld->fdcur);814 close_on_exec_on(ld->fdcur); 628 815 while (fchmod(ld->fdcur, 0644) == -1) 629 816 pause2cannot("set mode of current", ld->name); … … 666 853 667 854 /* Used for reading stdin */ 668 static int buffer_pread( int fd,char *s, unsigned len)855 static int buffer_pread(/*int fd, */char *s, unsigned len) 669 856 { 670 857 unsigned now; … … 672 859 int i; 673 860 674 input.fd = 0;861 input.fd = STDIN_FILENO; 675 862 input.events = POLLIN; 676 863 … … 701 888 } 702 889 703 sigprocmask(SIG_UNBLOCK, blocked_sigset, NULL);890 sigprocmask(SIG_UNBLOCK, &blocked_sigset, NULL); 704 891 i = nearest_rotate - now; 705 892 if (i > 1000000) … … 708 895 i = 1; 709 896 poll(&input, 1, i * 1000); 710 sigprocmask(SIG_BLOCK, blocked_sigset, NULL);711 712 i = ndelay_read( fd, s, len);897 sigprocmask(SIG_BLOCK, &blocked_sigset, NULL); 898 899 i = ndelay_read(STDIN_FILENO, s, len); 713 900 if (i >= 0) 714 901 break; … … 716 903 continue; 717 904 if (errno != EAGAIN) { 718 warn("can not read standard input");905 warn("can't read standard input"); 719 906 break; 720 907 } … … 750 937 } 751 938 752 static void sig_term_handler(int sig_no )939 static void sig_term_handler(int sig_no UNUSED_PARAM) 753 940 { 754 941 if (verbose) … … 757 944 } 758 945 759 static void sig_child_handler(int sig_no) 760 { 761 int pid, l; 946 static void sig_child_handler(int sig_no UNUSED_PARAM) 947 { 948 pid_t pid; 949 int l; 762 950 763 951 if (verbose) 764 952 bb_error_msg(INFO"sig%s received", "child"); 765 while ((pid = wait_ nohang(&wstat)) > 0) {953 while ((pid = wait_any_nohang(&wstat)) > 0) { 766 954 for (l = 0; l < dirn; ++l) { 767 955 if (dir[l].ppid == pid) { … … 774 962 } 775 963 776 static void sig_alarm_handler(int sig_no )964 static void sig_alarm_handler(int sig_no UNUSED_PARAM) 777 965 { 778 966 if (verbose) … … 781 969 } 782 970 783 static void sig_hangup_handler(int sig_no )971 static void sig_hangup_handler(int sig_no UNUSED_PARAM) 784 972 { 785 973 if (verbose) … … 812 1000 } 813 1001 814 int svlogd_main(int argc, char **argv) ;1002 int svlogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 815 1003 int svlogd_main(int argc, char **argv) 816 1004 { 817 sigset_t ss; 818 char *r,*l,*b; 1005 char *r, *l, *b; 819 1006 ssize_t stdin_cnt = 0; 820 1007 int i; 821 1008 unsigned opt; 822 1009 unsigned timestamp = 0; 823 void* (*memRchr)(const void *, int, size_t) = memchr; 824 825 #define line bb_common_bufsiz1 1010 1011 INIT_G(); 826 1012 827 1013 opt_complementary = "tt:vv"; … … 830 1016 if (opt & 1) { // -r 831 1017 repl = r[0]; 832 if (!repl || r[1]) usage(); 1018 if (!repl || r[1]) 1019 bb_show_usage(); 833 1020 } 834 1021 if (opt & 2) if (!repl) repl = '_'; // -R 835 1022 if (opt & 4) { // -l 836 1023 linemax = xatou_range(l, 0, BUFSIZ-26); 837 if (linemax == 0) linemax = BUFSIZ-26; 838 if (linemax < 256) linemax = 256; 1024 if (linemax == 0) 1025 linemax = BUFSIZ-26; 1026 if (linemax < 256) 1027 linemax = 256; 839 1028 } 840 1029 ////if (opt & 8) { // -b 841 //// buflen = xatoi_ u(b);1030 //// buflen = xatoi_positive(b); 842 1031 //// if (buflen == 0) buflen = 1024; 843 1032 ////} … … 849 1038 850 1039 dirn = argc; 851 if (dirn <= 0) usage(); 852 ////if (buflen <= linemax) usage(); 1040 if (dirn <= 0) 1041 bb_show_usage(); 1042 ////if (buflen <= linemax) bb_show_usage(); 853 1043 fdwdir = xopen(".", O_RDONLY|O_NDELAY); 854 c oe(fdwdir);855 dir = xzalloc(dirn * sizeof( struct logdir));1044 close_on_exec_on(fdwdir); 1045 dir = xzalloc(dirn * sizeof(dir[0])); 856 1046 for (i = 0; i < dirn; ++i) { 857 1047 dir[i].fddir = -1; … … 867 1057 fl_flag_0 = fcntl(0, F_GETFL); 868 1058 869 blocked_sigset = &ss; 870 sigemptyset(&ss); 871 sigaddset(&ss, SIGTERM); 872 sigaddset(&ss, SIGCHLD); 873 sigaddset(&ss, SIGALRM); 874 sigaddset(&ss, SIGHUP); 875 sigprocmask(SIG_BLOCK, &ss, NULL); 876 sig_catch(SIGTERM, sig_term_handler); 877 sig_catch(SIGCHLD, sig_child_handler); 878 sig_catch(SIGALRM, sig_alarm_handler); 879 sig_catch(SIGHUP, sig_hangup_handler); 880 881 logdirs_reopen(); 1059 sigemptyset(&blocked_sigset); 1060 sigaddset(&blocked_sigset, SIGTERM); 1061 sigaddset(&blocked_sigset, SIGCHLD); 1062 sigaddset(&blocked_sigset, SIGALRM); 1063 sigaddset(&blocked_sigset, SIGHUP); 1064 sigprocmask(SIG_BLOCK, &blocked_sigset, NULL); 1065 bb_signals_recursive_norestart(1 << SIGTERM, sig_term_handler); 1066 bb_signals_recursive_norestart(1 << SIGCHLD, sig_child_handler); 1067 bb_signals_recursive_norestart(1 << SIGALRM, sig_alarm_handler); 1068 bb_signals_recursive_norestart(1 << SIGHUP, sig_hangup_handler); 882 1069 883 1070 /* Without timestamps, we don't have to print each line 884 1071 * separately, so we can look for _last_ newline, not first, 885 * thus batching writes */ 886 if (!timestamp) 887 memRchr = memrchr; 1072 * thus batching writes. If filtering is enabled in config, 1073 * logdirs_reopen resets it to memchr. 1074 */ 1075 memRchr = (timestamp ? memchr : memrchr); 1076 1077 logdirs_reopen(); 888 1078 889 1079 setvbuf(stderr, NULL, _IOFBF, linelen); … … 910 1100 i = linemax - stdin_cnt; /* avail. bytes at tail */ 911 1101 if (i >= 128) { 912 i = buffer_pread( 0,lineptr + stdin_cnt, i);1102 i = buffer_pread(/*0, */lineptr + stdin_cnt, i); 913 1103 if (i <= 0) /* EOF or error on stdin */ 914 1104 exitasap = 1; … … 925 1115 linelen = stdin_cnt; 926 1116 if (np) { 927 print_to_nl: /* NB: starting from here lineptr may point 1117 print_to_nl: 1118 /* NB: starting from here lineptr may point 928 1119 * farther out into line[] */ 929 1120 linelen = np - lineptr + 1; … … 953 1144 for (i = 0; i < dirn; ++i) { 954 1145 struct logdir *ld = &dir[i]; 955 if (ld->fddir == -1) continue; 1146 if (ld->fddir == -1) 1147 continue; 956 1148 if (ld->inst) 957 1149 logmatch(ld); 958 if (ld->matcherr == 'e') 959 ////full_write(2, printptr, printlen); 960 fwrite(lineptr, 1, linelen, stderr); 961 if (ld->match != '+') continue; 1150 if (ld->matcherr == 'e') { 1151 /* runit-1.8.0 compat: if timestamping, do it on stderr too */ 1152 ////full_write(STDERR_FILENO, printptr, printlen); 1153 fwrite(printptr, 1, printlen, stderr); 1154 } 1155 if (ld->match != '+') 1156 continue; 962 1157 buffer_pwrite(i, printptr, printlen); 963 1158 } … … 967 1162 while (ch != '\n') { 968 1163 /* lineptr is emptied now, safe to use as buffer */ 969 stdin_cnt = exitasap ? -1 : buffer_pread( 0,lineptr, linemax);1164 stdin_cnt = exitasap ? -1 : buffer_pread(/*0, */lineptr, linemax); 970 1165 if (stdin_cnt <= 0) { /* EOF or error on stdin */ 971 1166 exitasap = 1; … … 982 1177 /* linelen == no of chars incl. '\n' (or == stdin_cnt) */ 983 1178 for (i = 0; i < dirn; ++i) { 984 if (dir[i].fddir == -1) continue; 985 if (dir[i].matcherr == 'e') 986 ////full_write(2, lineptr, linelen); 1179 if (dir[i].fddir == -1) 1180 continue; 1181 if (dir[i].matcherr == 'e') { 1182 ////full_write(STDERR_FILENO, lineptr, linelen); 987 1183 fwrite(lineptr, 1, linelen, stderr); 988 if (dir[i].match != '+') continue; 1184 } 1185 if (dir[i].match != '+') 1186 continue; 989 1187 buffer_pwrite(i, lineptr, linelen); 990 1188 } … … 1002 1200 memmove((timestamp ? line+26 : line), lineptr, stdin_cnt); 1003 1201 } 1004 fflush (NULL);////1202 fflush_all();//// 1005 1203 } 1006 1204 … … 1008 1206 if (dir[i].ppid) 1009 1207 while (!processorstop(&dir[i])) 1010 /* repeat */;1208 continue; 1011 1209 logdir_close(&dir[i]); 1012 1210 }
Note:
See TracChangeset
for help on using the changeset viewer.