Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/sysklogd
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (11 years ago)
- Location:
- branches/3.2/mindi-busybox/sysklogd
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/sysklogd/Config.src
r2725 r3232 52 52 Option -D instructs syslogd to drop consecutive messages 53 53 which are totally the same. 54 55 config FEATURE_SYSLOGD_CFG 56 bool "Support syslog.conf" 57 default y 58 depends on SYSLOGD 59 help 60 Supports restricted syslogd config. See docs/syslog.conf.txt 54 61 55 62 config FEATURE_SYSLOGD_READ_BUFFER_SIZE … … 107 114 contention at some minor memory expense. 108 115 116 config FEATURE_KMSG_SYSLOG 117 bool "Linux kernel printk buffer support" 118 default y 119 depends on SYSLOGD 120 select PLATFORM_LINUX 121 help 122 When you enable this feature, the syslogd utility will 123 write system log message to the Linux kernel's printk buffer. 124 This can be used as a smaller alternative to the syslogd IPC 125 support, as klogd and logread aren't needed. 126 127 NOTICE: Syslog facilities in log entries needs kernel 3.5+. 128 109 129 config KLOGD 110 130 bool "klogd" … … 117 137 you should enable this option. 118 138 139 comment "klogd should not be used together with syslog to kernel printk buffer" 140 depends on KLOGD && FEATURE_KMSG_SYSLOG 141 119 142 config FEATURE_KLOGD_KLOGCTL 120 143 bool "Use the klogctl() interface" 121 144 default y 122 depends on KLOGD && PLATFORM_LINUX 145 depends on KLOGD 146 select PLATFORM_LINUX 123 147 help 124 148 The klogd applet supports two interfaces for reading -
branches/3.2/mindi-busybox/sysklogd/klogd.c
r2859 r3232 17 17 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 18 18 */ 19 20 //usage:#define klogd_trivial_usage 21 //usage: "[-c N] [-n]" 22 //usage:#define klogd_full_usage "\n\n" 23 //usage: "Kernel logger\n" 24 //usage: "\n -c N Print to console messages more urgent than prio N (1-8)" 25 //usage: "\n -n Run in foreground" 19 26 20 27 #include "libbb.h" … … 189 196 syslog(LOG_NOTICE, "klogd started: %s", bb_banner); 190 197 198 write_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); 199 191 200 used = 0; 192 201 while (!bb_got_signal) { … … 232 241 if (*start == '<') { 233 242 start++; 234 if (*start) { 235 /* kernel never generates multi-digit prios */ 236 priority = (*start - '0'); 237 start++; 238 } 243 if (*start) 244 priority = strtoul(start, &start, 10); 239 245 if (*start == '>') 240 246 start++; … … 252 258 klogd_close(); 253 259 syslog(LOG_NOTICE, "klogd: exiting"); 260 remove_pidfile(CONFIG_PID_FILE_PATH "/klogd.pid"); 254 261 if (bb_got_signal) 255 262 kill_myself_with_sig(bb_got_signal); -
branches/3.2/mindi-busybox/sysklogd/logger.c
r2725 r3232 7 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 10 //usage:#define logger_trivial_usage 11 //usage: "[OPTIONS] [MESSAGE]" 12 //usage:#define logger_full_usage "\n\n" 13 //usage: "Write MESSAGE (or stdin) to syslog\n" 14 //usage: "\n -s Log to stderr as well as the system log" 15 //usage: "\n -t TAG Log using the specified tag (defaults to user name)" 16 //usage: "\n -p PRIO Priority (numeric or facility.level pair)" 17 //usage: 18 //usage:#define logger_example_usage 19 //usage: "$ logger \"hello\"\n" 9 20 10 21 /* -
branches/3.2/mindi-busybox/sysklogd/logread.c
r2725 r3232 9 9 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 10 10 */ 11 12 //usage:#define logread_trivial_usage 13 //usage: "[-f]" 14 //usage:#define logread_full_usage "\n\n" 15 //usage: "Show messages in syslogd's circular buffer\n" 16 //usage: "\n -f Output data as log grows" 11 17 12 18 #include "libbb.h" -
branches/3.2/mindi-busybox/sysklogd/syslogd.c
r2725 r3232 14 14 */ 15 15 16 //usage:#define syslogd_trivial_usage 17 //usage: "[OPTIONS]" 18 //usage:#define syslogd_full_usage "\n\n" 19 //usage: "System logging utility\n" 20 //usage: IF_NOT_FEATURE_SYSLOGD_CFG( 21 //usage: "(this version of syslogd ignores /etc/syslog.conf)\n" 22 //usage: ) 23 //usage: "\n -n Run in foreground" 24 //usage: "\n -O FILE Log to FILE (default:/var/log/messages)" 25 //usage: "\n -l N Log only messages more urgent than prio N (1-8)" 26 //usage: "\n -S Smaller output" 27 //usage: IF_FEATURE_ROTATE_LOGFILE( 28 //usage: "\n -s SIZE Max size (KB) before rotation (default:200KB, 0=off)" 29 //usage: "\n -b N N rotated logs to keep (default:1, max=99, 0=purge)" 30 //usage: ) 31 //usage: IF_FEATURE_REMOTE_LOG( 32 //usage: "\n -R HOST[:PORT] Log to IP or hostname on PORT (default PORT=514/UDP)" 33 //usage: "\n -L Log locally and via network (default is network only if -R)" 34 //usage: ) 35 //usage: IF_FEATURE_SYSLOGD_DUP( 36 //usage: "\n -D Drop duplicates" 37 //usage: ) 38 //usage: IF_FEATURE_IPC_SYSLOG( 39 /* NB: -Csize shouldn't have space (because size is optional) */ 40 //usage: "\n -C[size_kb] Log to shared mem buffer (use logread to read it)" 41 //usage: ) 42 //usage: IF_FEATURE_SYSLOGD_CFG( 43 //usage: "\n -f FILE Use FILE as config (default:/etc/syslog.conf)" 44 //usage: ) 45 /* //usage: "\n -m MIN Minutes between MARK lines (default:20, 0=off)" */ 46 //usage: IF_FEATURE_KMSG_SYSLOG( 47 //usage: "\n -K Log to kernel printk buffer (use dmesg to read it)" 48 //usage: ) 49 //usage: 50 //usage:#define syslogd_example_usage 51 //usage: "$ syslogd -R masterlog:514\n" 52 //usage: "$ syslogd -R 192.168.1.1:601\n" 53 16 54 /* 17 55 * Done in syslogd_and_logger.c: … … 67 105 #endif 68 106 107 typedef struct logFile_t { 108 const char *path; 109 int fd; 110 #if ENABLE_FEATURE_ROTATE_LOGFILE 111 unsigned size; 112 uint8_t isRegular; 113 #endif 114 } logFile_t; 115 116 #if ENABLE_FEATURE_SYSLOGD_CFG 117 typedef struct logRule_t { 118 uint8_t enabled_facility_priomap[LOG_NFACILITIES]; 119 struct logFile_t *file; 120 struct logRule_t *next; 121 } logRule_t; 122 #endif 123 69 124 /* Allows us to have smaller initializer. Ugly. */ 70 125 #define GLOBALS \ 71 const char *logFilePath; \ 72 int logFD; \ 126 logFile_t logFile; \ 73 127 /* interval between marks in seconds */ \ 74 128 /*int markInterval;*/ \ … … 80 134 /* number of rotated message files */ \ 81 135 unsigned logFileRotate; \ 82 unsigned curFileSize; \83 smallint isRegular; \84 136 ) \ 85 137 IF_FEATURE_IPC_SYSLOG( \ … … 89 141 struct sembuf SMwup[1]; \ 90 142 struct sembuf SMwdn[3]; \ 143 ) \ 144 IF_FEATURE_SYSLOGD_CFG( \ 145 logRule_t *log_rules; \ 146 ) \ 147 IF_FEATURE_KMSG_SYSLOG( \ 148 int kmsgfd; \ 149 int primask; \ 91 150 ) 92 151 … … 120 179 121 180 static const struct init_globals init_data = { 122 .logFilePath = "/var/log/messages", 123 .logFD = -1, 181 .logFile = { 182 .path = "/var/log/messages", 183 .fd = -1, 184 }, 124 185 #ifdef SYSLOGD_MARK 125 186 .markInterval = 20 * 60, … … 133 194 .shmid = -1, 134 195 .s_semid = -1, 135 .shm_size = ((CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE)*1024), / / default shm size196 .shm_size = ((CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE)*1024), /* default shm size */ 136 197 .SMwup = { {1, -1, IPC_NOWAIT} }, 137 198 .SMwdn = { {0, 0}, {1, 0}, {1, +1} }, … … 158 219 IF_FEATURE_IPC_SYSLOG( OPTBIT_circularlog,) // -C 159 220 IF_FEATURE_SYSLOGD_DUP( OPTBIT_dup ,) // -D 221 IF_FEATURE_SYSLOGD_CFG( OPTBIT_cfg ,) // -f 222 IF_FEATURE_KMSG_SYSLOG( OPTBIT_kmsg ,) // -K 160 223 161 224 OPT_mark = 1 << OPTBIT_mark , … … 170 233 OPT_circularlog = IF_FEATURE_IPC_SYSLOG( (1 << OPTBIT_circularlog)) + 0, 171 234 OPT_dup = IF_FEATURE_SYSLOGD_DUP( (1 << OPTBIT_dup )) + 0, 235 OPT_cfg = IF_FEATURE_SYSLOGD_CFG( (1 << OPTBIT_cfg )) + 0, 236 OPT_kmsg = IF_FEATURE_KMSG_SYSLOG( (1 << OPTBIT_kmsg )) + 0, 237 172 238 }; 173 239 #define OPTION_STR "m:nO:l:S" \ … … 177 243 IF_FEATURE_REMOTE_LOG( "L" ) \ 178 244 IF_FEATURE_IPC_SYSLOG( "C::") \ 179 IF_FEATURE_SYSLOGD_DUP( "D" ) 245 IF_FEATURE_SYSLOGD_DUP( "D" ) \ 246 IF_FEATURE_SYSLOGD_CFG( "f:" ) \ 247 IF_FEATURE_KMSG_SYSLOG( "K" ) 180 248 #define OPTION_DECL *opt_m, *opt_l \ 181 249 IF_FEATURE_ROTATE_LOGFILE(,*opt_s) \ 182 250 IF_FEATURE_ROTATE_LOGFILE(,*opt_b) \ 183 IF_FEATURE_IPC_SYSLOG( ,*opt_C = NULL) 184 #define OPTION_PARAM &opt_m, &G.logFilePath, &opt_l \ 251 IF_FEATURE_IPC_SYSLOG( ,*opt_C = NULL) \ 252 IF_FEATURE_SYSLOGD_CFG( ,*opt_f = NULL) 253 #define OPTION_PARAM &opt_m, &(G.logFile.path), &opt_l \ 185 254 IF_FEATURE_ROTATE_LOGFILE(,&opt_s) \ 186 255 IF_FEATURE_ROTATE_LOGFILE(,&opt_b) \ 187 IF_FEATURE_REMOTE_LOG( ,&remoteAddrList) \ 188 IF_FEATURE_IPC_SYSLOG( ,&opt_C) 189 256 IF_FEATURE_REMOTE_LOG( ,&remoteAddrList) \ 257 IF_FEATURE_IPC_SYSLOG( ,&opt_C) \ 258 IF_FEATURE_SYSLOGD_CFG( ,&opt_f) 259 260 261 #if ENABLE_FEATURE_SYSLOGD_CFG 262 static const CODE* find_by_name(char *name, const CODE* c_set) 263 { 264 for (; c_set->c_name; c_set++) { 265 if (strcmp(name, c_set->c_name) == 0) 266 return c_set; 267 } 268 return NULL; 269 } 270 #endif 271 static const CODE* find_by_val(int val, const CODE* c_set) 272 { 273 for (; c_set->c_name; c_set++) { 274 if (c_set->c_val == val) 275 return c_set; 276 } 277 return NULL; 278 } 279 280 #if ENABLE_FEATURE_SYSLOGD_CFG 281 static void parse_syslogdcfg(const char *file) 282 { 283 char *t; 284 logRule_t **pp_rule; 285 /* tok[0] set of selectors */ 286 /* tok[1] file name */ 287 /* tok[2] has to be NULL */ 288 char *tok[3]; 289 parser_t *parser; 290 291 parser = config_open2(file ? file : "/etc/syslog.conf", 292 file ? xfopen_for_read : fopen_for_read); 293 if (!parser) 294 /* didn't find default /etc/syslog.conf */ 295 /* proceed as if we built busybox without config support */ 296 return; 297 298 /* use ptr to ptr to avoid checking whether head was initialized */ 299 pp_rule = &G.log_rules; 300 /* iterate through lines of config, skipping comments */ 301 while (config_read(parser, tok, 3, 2, "# \t", PARSE_NORMAL | PARSE_MIN_DIE)) { 302 char *cur_selector; 303 logRule_t *cur_rule; 304 305 /* unexpected trailing token? */ 306 if (tok[2]) 307 goto cfgerr; 308 309 cur_rule = *pp_rule = xzalloc(sizeof(*cur_rule)); 310 311 cur_selector = tok[0]; 312 /* iterate through selectors: "kern.info;kern.!err;..." */ 313 do { 314 const CODE *code; 315 char *next_selector; 316 uint8_t negated_prio; /* "kern.!err" */ 317 uint8_t single_prio; /* "kern.=err" */ 318 uint32_t facmap; /* bitmap of enabled facilities */ 319 uint8_t primap; /* bitmap of enabled priorities */ 320 unsigned i; 321 322 next_selector = strchr(cur_selector, ';'); 323 if (next_selector) 324 *next_selector++ = '\0'; 325 326 t = strchr(cur_selector, '.'); 327 if (!t) 328 goto cfgerr; 329 *t++ = '\0'; /* separate facility from priority */ 330 331 negated_prio = 0; 332 single_prio = 0; 333 if (*t == '!') { 334 negated_prio = 1; 335 ++t; 336 } 337 if (*t == '=') { 338 single_prio = 1; 339 ++t; 340 } 341 342 /* parse priority */ 343 if (*t == '*') 344 primap = 0xff; /* all 8 log levels enabled */ 345 else { 346 uint8_t priority; 347 code = find_by_name(t, prioritynames); 348 if (!code) 349 goto cfgerr; 350 primap = 0; 351 priority = code->c_val; 352 if (priority == INTERNAL_NOPRI) { 353 /* ensure we take "enabled_facility_priomap[fac] &= 0" branch below */ 354 negated_prio = 1; 355 } else { 356 priority = 1 << priority; 357 do { 358 primap |= priority; 359 if (single_prio) 360 break; 361 priority >>= 1; 362 } while (priority); 363 if (negated_prio) 364 primap = ~primap; 365 } 366 } 367 368 /* parse facility */ 369 if (*cur_selector == '*') 370 facmap = (1<<LOG_NFACILITIES) - 1; 371 else { 372 char *next_facility; 373 facmap = 0; 374 t = cur_selector; 375 /* iterate through facilities: "kern,daemon.<priospec>" */ 376 do { 377 next_facility = strchr(t, ','); 378 if (next_facility) 379 *next_facility++ = '\0'; 380 code = find_by_name(t, facilitynames); 381 if (!code) 382 goto cfgerr; 383 /* "mark" is not a real facility, skip it */ 384 if (code->c_val != INTERNAL_MARK) 385 facmap |= 1<<(LOG_FAC(code->c_val)); 386 t = next_facility; 387 } while (t); 388 } 389 390 /* merge result with previous selectors */ 391 for (i = 0; i < LOG_NFACILITIES; ++i) { 392 if (!(facmap & (1<<i))) 393 continue; 394 if (negated_prio) 395 cur_rule->enabled_facility_priomap[i] &= primap; 396 else 397 cur_rule->enabled_facility_priomap[i] |= primap; 398 } 399 400 cur_selector = next_selector; 401 } while (cur_selector); 402 403 /* check whether current file name was mentioned in previous rules or 404 * as global logfile (G.logFile). 405 */ 406 if (strcmp(G.logFile.path, tok[1]) == 0) { 407 cur_rule->file = &G.logFile; 408 goto found; 409 } 410 /* temporarily use cur_rule as iterator, but *pp_rule still points 411 * to currently processing rule entry. 412 * NOTE: *pp_rule points to the current (and last in the list) rule. 413 */ 414 for (cur_rule = G.log_rules; cur_rule != *pp_rule; cur_rule = cur_rule->next) { 415 if (strcmp(cur_rule->file->path, tok[1]) == 0) { 416 /* found - reuse the same file structure */ 417 (*pp_rule)->file = cur_rule->file; 418 cur_rule = *pp_rule; 419 goto found; 420 } 421 } 422 cur_rule->file = xzalloc(sizeof(*cur_rule->file)); 423 cur_rule->file->fd = -1; 424 cur_rule->file->path = xstrdup(tok[1]); 425 found: 426 pp_rule = &cur_rule->next; 427 } 428 config_close(parser); 429 return; 430 431 cfgerr: 432 bb_error_msg_and_die("error in '%s' at line %d", 433 file ? file : "/etc/syslog.conf", 434 parser->lineno); 435 } 436 #endif 190 437 191 438 /* circular buffer variables/structures */ … … 232 479 /*G.shbuf->tail = 0;*/ 233 480 234 / / we'll trust the OS to set initial semval to 0 (let's hope)481 /* we'll trust the OS to set initial semval to 0 (let's hope) */ 235 482 G.s_semid = semget(KEY_ID, 2, IPC_CREAT | IPC_EXCL | 1023); 236 483 if (G.s_semid == -1) { … … 245 492 246 493 /* Write message to shared mem buffer */ 247 static void log_to_shmem(const char *msg , int len)494 static void log_to_shmem(const char *msg) 248 495 { 249 496 int old_tail, new_tail; 497 int len; 250 498 251 499 if (semop(G.s_semid, G.SMwdn, 3) == -1) { … … 259 507 * Last byte of buffer is never used and remains NUL. 260 508 */ 261 len ++; /* length with NUL included */509 len = strlen(msg) + 1; /* length with NUL included */ 262 510 again: 263 511 old_tail = G.shbuf->tail; … … 284 532 } 285 533 #else 286 void ipcsyslog_cleanup(void); 287 void ipcsyslog_init(void); 534 static void ipcsyslog_cleanup(void) {} 535 static void ipcsyslog_init(void) {} 288 536 void log_to_shmem(const char *msg); 289 537 #endif /* FEATURE_IPC_SYSLOG */ 290 538 539 #if ENABLE_FEATURE_KMSG_SYSLOG 540 static void kmsg_init(void) 541 { 542 G.kmsgfd = xopen("/dev/kmsg", O_WRONLY); 543 544 /* 545 * kernel < 3.5 expects single char printk KERN_* priority prefix, 546 * from 3.5 onwards the full syslog facility/priority format is supported 547 */ 548 if (get_linux_version_code() < KERNEL_VERSION(3,5,0)) 549 G.primask = LOG_PRIMASK; 550 else 551 G.primask = -1; 552 } 553 554 static void kmsg_cleanup(void) 555 { 556 if (ENABLE_FEATURE_CLEAN_UP) 557 close(G.kmsgfd); 558 } 559 560 /* Write message to /dev/kmsg */ 561 static void log_to_kmsg(int pri, const char *msg) 562 { 563 /* 564 * kernel < 3.5 expects single char printk KERN_* priority prefix, 565 * from 3.5 onwards the full syslog facility/priority format is supported 566 */ 567 pri &= G.primask; 568 569 write(G.kmsgfd, G.printbuf, sprintf(G.printbuf, "<%d>%s\n", pri, msg)); 570 } 571 #else 572 static void kmsg_init(void) {} 573 static void kmsg_cleanup(void) {} 574 static void log_to_kmsg(int pri UNUSED_PARAM, const char *msg UNUSED_PARAM) {} 575 #endif /* FEATURE_KMSG_SYSLOG */ 291 576 292 577 /* Print a message to the log file. */ 293 static void log_locally(time_t now, char *msg )578 static void log_locally(time_t now, char *msg, logFile_t *log_file) 294 579 { 295 580 #ifdef SYSLOGD_WRLOCK … … 298 583 int len = strlen(msg); 299 584 300 #if ENABLE_FEATURE_IPC_SYSLOG 301 if ((option_mask32 & OPT_circularlog) && G.shbuf) { 302 log_to_shmem(msg, len); 303 return; 304 } 305 #endif 306 if (G.logFD >= 0) { 585 if (log_file->fd >= 0) { 307 586 /* Reopen log file every second. This allows admin 308 587 * to delete the file and not worry about restarting us. … … 314 593 if (G.last_log_time != now) { 315 594 G.last_log_time = now; 316 close( G.logFD);595 close(log_file->fd); 317 596 goto reopen; 318 597 } 319 598 } else { 320 599 reopen: 321 G.logFD = open(G.logFilePath, O_WRONLY | O_CREAT600 log_file->fd = open(log_file->path, O_WRONLY | O_CREAT 322 601 | O_NOCTTY | O_APPEND | O_NONBLOCK, 323 602 0666); 324 if ( G.logFD< 0) {603 if (log_file->fd < 0) { 325 604 /* cannot open logfile? - print to /dev/console then */ 326 605 int fd = device_open(DEV_CONSOLE, O_WRONLY | O_NOCTTY | O_NONBLOCK); … … 335 614 { 336 615 struct stat statf; 337 G.isRegular = (fstat(G.logFD, &statf) == 0 && S_ISREG(statf.st_mode));616 log_file->isRegular = (fstat(log_file->fd, &statf) == 0 && S_ISREG(statf.st_mode)); 338 617 /* bug (mostly harmless): can wrap around if file > 4gb */ 339 G.curFileSize = statf.st_size;618 log_file->size = statf.st_size; 340 619 } 341 620 #endif … … 347 626 fl.l_len = 1; 348 627 fl.l_type = F_WRLCK; 349 fcntl( G.logFD, F_SETLKW, &fl);628 fcntl(log_file->fd, F_SETLKW, &fl); 350 629 #endif 351 630 352 631 #if ENABLE_FEATURE_ROTATE_LOGFILE 353 if (G.logFileSize && G.isRegular && G.curFileSize > G.logFileSize) {632 if (G.logFileSize && log_file->isRegular && log_file->size > G.logFileSize) { 354 633 if (G.logFileRotate) { /* always 0..99 */ 355 int i = strlen( G.logFilePath) + 3 + 1;634 int i = strlen(log_file->path) + 3 + 1; 356 635 char oldFile[i]; 357 636 char newFile[i]; … … 359 638 /* rename: f.8 -> f.9; f.7 -> f.8; ... */ 360 639 while (1) { 361 sprintf(newFile, "%s.%d", G.logFilePath, i);640 sprintf(newFile, "%s.%d", log_file->path, i); 362 641 if (i == 0) break; 363 sprintf(oldFile, "%s.%d", G.logFilePath, --i);642 sprintf(oldFile, "%s.%d", log_file->path, --i); 364 643 /* ignore errors - file might be missing */ 365 644 rename(oldFile, newFile); 366 645 } 367 646 /* newFile == "f.0" now */ 368 rename(G.logFilePath, newFile); 647 rename(log_file->path, newFile); 648 /* Incredibly, if F and F.0 are hardlinks, POSIX 649 * _demands_ that rename returns 0 but does not 650 * remove F!!! 651 * (hardlinked F/F.0 pair was observed after 652 * power failure during rename()). 653 * Ensure old file is gone: 654 */ 655 unlink(log_file->path); 369 656 #ifdef SYSLOGD_WRLOCK 370 657 fl.l_type = F_UNLCK; 371 fcntl( G.logFD, F_SETLKW, &fl);372 #endif 373 close( G.logFD);658 fcntl(log_file->fd, F_SETLKW, &fl); 659 #endif 660 close(log_file->fd); 374 661 goto reopen; 375 662 } 376 ftruncate( G.logFD, 0);377 } 378 G.curFileSize +=379 #endif 380 full_write( G.logFD, msg, len);663 ftruncate(log_file->fd, 0); 664 } 665 log_file->size += 666 #endif 667 full_write(log_file->fd, msg, len); 381 668 #ifdef SYSLOGD_WRLOCK 382 669 fl.l_type = F_UNLCK; 383 fcntl( G.logFD, F_SETLKW, &fl);670 fcntl(log_file->fd, F_SETLKW, &fl); 384 671 #endif 385 672 } … … 389 676 const CODE *c_pri, *c_fac; 390 677 391 if (pri != 0) { 392 c_fac = facilitynames; 393 while (c_fac->c_name) { 394 if (c_fac->c_val != (LOG_FAC(pri) << 3)) { 395 c_fac++; 396 continue; 397 } 398 /* facility is found, look for prio */ 399 c_pri = prioritynames; 400 while (c_pri->c_name) { 401 if (c_pri->c_val != LOG_PRI(pri)) { 402 c_pri++; 403 continue; 404 } 405 snprintf(res20, 20, "%s.%s", 406 c_fac->c_name, c_pri->c_name); 407 return; 408 } 409 /* prio not found, bail out */ 410 break; 411 } 412 snprintf(res20, 20, "<%d>", pri); 413 } 678 c_fac = find_by_val(LOG_FAC(pri) << 3, facilitynames); 679 if (c_fac) { 680 c_pri = find_by_val(LOG_PRI(pri), prioritynames); 681 if (c_pri) { 682 snprintf(res20, 20, "%s.%s", c_fac->c_name, c_pri->c_name); 683 return; 684 } 685 } 686 snprintf(res20, 20, "<%d>", pri); 414 687 } 415 688 … … 436 709 timestamp[15] = '\0'; 437 710 711 if (option_mask32 & OPT_kmsg) { 712 log_to_kmsg(pri, msg); 713 return; 714 } 715 438 716 if (option_mask32 & OPT_small) 439 717 sprintf(G.printbuf, "%s %s\n", timestamp, msg); … … 445 723 446 724 /* Log message locally (to file or shared mem) */ 447 log_locally(now, G.printbuf); 725 #if ENABLE_FEATURE_SYSLOGD_CFG 726 { 727 bool match = 0; 728 logRule_t *rule; 729 uint8_t facility = LOG_FAC(pri); 730 uint8_t prio_bit = 1 << LOG_PRI(pri); 731 732 for (rule = G.log_rules; rule; rule = rule->next) { 733 if (rule->enabled_facility_priomap[facility] & prio_bit) { 734 log_locally(now, G.printbuf, rule->file); 735 match = 1; 736 } 737 } 738 if (match) 739 return; 740 } 741 #endif 742 if (LOG_PRI(pri) < G.logLevel) { 743 #if ENABLE_FEATURE_IPC_SYSLOG 744 if ((option_mask32 & OPT_circularlog) && G.shbuf) { 745 log_to_shmem(G.printbuf); 746 return; 747 } 748 #endif 749 log_locally(now, G.printbuf, &G.logFile); 750 } 448 751 } 449 752 … … 490 793 491 794 /* Now log it */ 492 if (LOG_PRI(pri) < G.logLevel) 493 timestamp_and_log(pri, G.parsebuf, q - G.parsebuf); 795 timestamp_and_log(pri, G.parsebuf, q - G.parsebuf); 494 796 } 495 797 } … … 512 814 int sock_fd; 513 815 char *dev_log_name; 816 817 #if ENABLE_FEATURE_SYSTEMD 818 if (sd_listen_fds() == 1) 819 return SD_LISTEN_FDS_START; 820 #endif 514 821 515 822 memset(&sunx, 0, sizeof(sunx)); … … 577 884 sock_fd = create_socket(); 578 885 579 if ( ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) {886 if (option_mask32 & OPT_circularlog) 580 887 ipcsyslog_init(); 581 } 888 889 if (option_mask32 & OPT_kmsg) 890 kmsg_init(); 582 891 583 892 timestamp_and_log_internal("syslogd started: BusyBox v" BB_VER); … … 666 975 timestamp_and_log_internal("syslogd exiting"); 667 976 puts("syslogd exiting"); 668 if (ENABLE_FEATURE_IPC_SYSLOG) 669 ipcsyslog_cleanup(); 977 remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); 978 ipcsyslog_cleanup(); 979 if (option_mask32 & OPT_kmsg) 980 kmsg_cleanup(); 670 981 kill_myself_with_sig(bb_got_signal); 671 982 #undef recvbuf … … 715 1026 G.shm_size = xatoul_range(opt_C, 4, INT_MAX/1024) * 1024; 716 1027 #endif 717 718 1028 /* If they have not specified remote logging, then log locally */ 719 1029 if (ENABLE_FEATURE_REMOTE_LOG && !(opts & OPT_remotelog)) // -R 720 1030 option_mask32 |= OPT_locallog; 1031 #if ENABLE_FEATURE_SYSLOGD_CFG 1032 parse_syslogdcfg(opt_f); 1033 #endif 721 1034 722 1035 /* Store away localhost's name before the fork */ … … 727 1040 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); 728 1041 } 1042 729 1043 //umask(0); - why?? 730 write_pidfile("/var/run/syslogd.pid"); 1044 write_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); 1045 731 1046 do_syslogd(); 732 1047 /* return EXIT_SUCCESS; */
Note:
See TracChangeset
for help on using the changeset viewer.