Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/sysklogd/logger.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/sysklogd/logger.c
r821 r1770 8 8 */ 9 9 10 #include "busybox.h" 11 #include <stdio.h> 12 #include <unistd.h> 13 #include <sys/types.h> 14 #include <fcntl.h> 15 #include <ctype.h> 16 #include <string.h> 17 #include <stdlib.h> 10 #include "libbb.h" 18 11 19 12 #if !defined CONFIG_SYSLOGD … … 49 42 50 43 if (isdigit(*name)) 51 return (atoi(name));44 return atoi(name); 52 45 for (c = codetab; c->c_name; c++) { 53 46 if (!strcasecmp(name, c->c_name)) { 54 return (c->c_val);47 return c->c_val; 55 48 } 56 49 } 57 50 58 return (-1);51 return -1; 59 52 } 60 53 … … 71 64 int lev, fac = LOG_USER; 72 65 73 for (save = s; *s && *s != '.'; ++s); 66 for (save = s; *s && *s != '.'; ++s) 67 ; 74 68 if (*s) { 75 69 *s = '\0'; 76 70 fac = decode(save, facilitynames); 77 71 if (fac < 0) 78 bb_error_msg_and_die("unknown facility name: %s", save);72 bb_error_msg_and_die("unknown %s name: %s", "facility", save); 79 73 *s++ = '.'; 80 74 } else { … … 83 77 lev = decode(s, prioritynames); 84 78 if (lev < 0) 85 bb_error_msg_and_die("unknown priority name: %s", save);79 bb_error_msg_and_die("unknown %s name: %s", "priority", save); 86 80 return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); 87 81 } 88 82 89 83 84 int logger_main(int argc, char **argv); 90 85 int logger_main(int argc, char **argv) 91 86 { 92 int pri = LOG_USER | LOG_NOTICE; 93 int option = 0; 94 int c, i, opt; 95 char buf[1024], name[128]; 87 char *str_p, *str_t; 88 int i = 0; 89 char name[80]; 96 90 97 91 /* Fill out the name string early (may be overwritten later) */ 98 bb_getpwuid(name, geteuid(), sizeof(name)); 92 bb_getpwuid(name, sizeof(name), geteuid()); 93 str_t = name; 99 94 100 95 /* Parse any options */ 101 while ((opt = getopt(argc, argv, "p:st:")) > 0) { 102 switch (opt) { 103 case 's': 104 option |= LOG_PERROR; 105 break; 106 case 'p': 107 pri = pencode(optarg); 108 break; 109 case 't': 110 safe_strncpy(name, optarg, sizeof(name)); 111 break; 112 default: 113 bb_show_usage(); 96 getopt32(argv, "p:st:", &str_p, &str_t); 97 98 if (option_mask32 & 0x2) /* -s */ 99 i |= LOG_PERROR; 100 //if (option_mask32 & 0x4) /* -t */ 101 openlog(str_t, i, 0); 102 i = LOG_USER | LOG_NOTICE; 103 if (option_mask32 & 0x1) /* -p */ 104 i = pencode(str_p); 105 106 argc -= optind; 107 argv += optind; 108 if (!argc) { 109 #define strbuf bb_common_bufsiz1 110 while (fgets(strbuf, BUFSIZ, stdin)) { 111 if (strbuf[0] 112 && NOT_LONE_CHAR(strbuf, '\n') 113 ) { 114 /* Neither "" nor "\n" */ 115 syslog(i, "%s", strbuf); 116 } 114 117 } 115 }116 117 openlog(name, option, 0);118 if (optind == argc) {119 do {120 /* read from stdin */121 i = 0;122 while ((c = getc(stdin)) != EOF && c != '\n' &&123 i < (sizeof(buf)-1)) {124 buf[i++] = c;125 }126 if (i > 0) {127 buf[i++] = '\0';128 syslog(pri, "%s", buf);129 }130 } while (c != EOF);131 118 } else { 132 119 char *message = NULL; 133 int len = argc - optind; /* for the space between the args 134 and '\0' */ 135 opt = len; 136 argv += optind; 137 for (i = 0; i < opt; i++) { 138 len += strlen(*argv); 120 int len = 1; /* for NUL */ 121 int pos = 0; 122 do { 123 len += strlen(*argv) + 1; 139 124 message = xrealloc(message, len); 140 if(!i) 141 message[0] = 0; 142 else 143 strcat(message, " "); 144 strcat(message, *argv); 145 argv++; 146 } 147 syslog(pri, "%s", message); 125 sprintf(message + pos, " %s", *argv), 126 pos = len; 127 } while (*++argv); 128 syslog(i, "%s", message + 1); /* skip leading " " */ 148 129 } 149 130 … … 187 168 * SUCH DAMAGE. 188 169 */ 189 190 191
Note:
See TracChangeset
for help on using the changeset viewer.