diff options
author | Matt Kraai <kraai@debian.org> | 2001-01-02 18:13:58 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-01-02 18:13:58 +0000 |
commit | 1944f547bdb9bd2615acf284366c924fd180f53c (patch) | |
tree | 61d5452ccbc189ba430b4a15c4d91efe4ee5a152 | |
parent | 28b3c53f0de370b26aa5ec7ea35176fd4316f7e3 (diff) | |
download | busybox-w32-1944f547bdb9bd2615acf284366c924fd180f53c.tar.gz busybox-w32-1944f547bdb9bd2615acf284366c924fd180f53c.tar.bz2 busybox-w32-1944f547bdb9bd2615acf284366c924fd180f53c.zip |
Log stdin when no message given and use getopt.
-rw-r--r-- | applets/usage.c | 2 | ||||
-rw-r--r-- | logger.c | 55 | ||||
-rw-r--r-- | sysklogd/logger.c | 55 | ||||
-rw-r--r-- | usage.c | 2 |
4 files changed, 36 insertions, 78 deletions
diff --git a/applets/usage.c b/applets/usage.c index c7bc0e8a9..b904e0c7c 100644 --- a/applets/usage.c +++ b/applets/usage.c | |||
@@ -586,7 +586,7 @@ const char loadkmap_usage[] = | |||
586 | const char logger_usage[] = | 586 | const char logger_usage[] = |
587 | "logger [OPTION]... [MESSAGE]\n" | 587 | "logger [OPTION]... [MESSAGE]\n" |
588 | #ifndef BB_FEATURE_TRIVIAL_HELP | 588 | #ifndef BB_FEATURE_TRIVIAL_HELP |
589 | "\nWrite MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n" | 589 | "\nWrite MESSAGE to the system log. If MESSAGE is omitted, log stdin.\n\n" |
590 | "Options:\n" | 590 | "Options:\n" |
591 | "\t-s\tLog to stderr as well as the system log.\n" | 591 | "\t-s\tLog to stderr as well as the system log.\n" |
592 | "\t-t\tLog using the specified tag (defaults to user name).\n" | 592 | "\t-t\tLog using the specified tag (defaults to user name).\n" |
@@ -101,68 +101,47 @@ extern int logger_main(int argc, char **argv) | |||
101 | { | 101 | { |
102 | int pri = LOG_USER | LOG_NOTICE; | 102 | int pri = LOG_USER | LOG_NOTICE; |
103 | int option = 0; | 103 | int option = 0; |
104 | int fromStdinFlag = FALSE; | 104 | int c, i, len, opt; |
105 | int stopLookingAtMeLikeThat = FALSE; | ||
106 | char *message=NULL, buf[1024], name[128]; | 105 | char *message=NULL, buf[1024], name[128]; |
107 | 106 | ||
108 | /* Fill out the name string early (may be overwritten later */ | 107 | /* Fill out the name string early (may be overwritten later) */ |
109 | my_getpwuid(name, geteuid()); | 108 | my_getpwuid(name, geteuid()); |
110 | 109 | ||
111 | /* Parse any options */ | 110 | /* Parse any options */ |
112 | while (--argc > 0 && **(++argv) == '-') { | 111 | while ((opt = getopt(argc, argv, "p:st:")) > 0) { |
113 | if (*((*argv) + 1) == '\0') { | 112 | switch (opt) { |
114 | fromStdinFlag = TRUE; | ||
115 | } | ||
116 | stopLookingAtMeLikeThat = FALSE; | ||
117 | while (*(++(*argv)) && stopLookingAtMeLikeThat == FALSE) { | ||
118 | switch (**argv) { | ||
119 | case 's': | 113 | case 's': |
120 | option |= LOG_PERROR; | 114 | option |= LOG_PERROR; |
121 | break; | 115 | break; |
122 | case 'p': | 116 | case 'p': |
123 | if (--argc == 0) { | 117 | pri = pencode(optarg); |
124 | usage(logger_usage); | ||
125 | } | ||
126 | pri = pencode(*(++argv)); | ||
127 | stopLookingAtMeLikeThat = TRUE; | ||
128 | break; | 118 | break; |
129 | case 't': | 119 | case 't': |
130 | if (--argc == 0) { | 120 | strncpy(name, optarg, sizeof(name)); |
131 | usage(logger_usage); | ||
132 | } | ||
133 | strncpy(name, *(++argv), sizeof(name)); | ||
134 | stopLookingAtMeLikeThat = TRUE; | ||
135 | break; | 121 | break; |
136 | default: | 122 | default: |
137 | usage(logger_usage); | 123 | usage(logger_usage); |
138 | } | ||
139 | } | 124 | } |
140 | } | 125 | } |
141 | 126 | ||
142 | if (fromStdinFlag == TRUE) { | 127 | if (optind == argc) { |
143 | /* read from stdin */ | 128 | /* read from stdin */ |
144 | int c; | 129 | i = 0; |
145 | unsigned int i = 0; | ||
146 | |||
147 | while ((c = getc(stdin)) != EOF && i < sizeof(buf)) { | 130 | while ((c = getc(stdin)) != EOF && i < sizeof(buf)) { |
148 | buf[i++] = c; | 131 | buf[i++] = c; |
149 | } | 132 | } |
150 | message = buf; | 133 | message = buf; |
151 | } else { | 134 | } else { |
152 | if (argc >= 1) { | 135 | len = 1; /* for the '\0' */ |
153 | int len = 1; /* for the '\0' */ | 136 | message=xcalloc(1, 1); |
154 | message=xcalloc(1, 1); | 137 | for (i = optind; i < argc; i++) { |
155 | for (; *argv != NULL; argv++) { | 138 | len += strlen(argv[i]); |
156 | len += strlen(*argv); | 139 | len += 1; /* for the space between the args */ |
157 | len += 1; /* for the space between the args */ | 140 | message = xrealloc(message, len); |
158 | message = xrealloc(message, len); | 141 | strcat(message, argv[i]); |
159 | strcat(message, *argv); | 142 | strcat(message, " "); |
160 | strcat(message, " "); | ||
161 | } | ||
162 | message[strlen(message)-1] = '\0'; | ||
163 | } else { | ||
164 | error_msg_and_die("No message\n"); | ||
165 | } | 143 | } |
144 | message[strlen(message)-1] = '\0'; | ||
166 | } | 145 | } |
167 | 146 | ||
168 | openlog(name, option, (pri | LOG_FACMASK)); | 147 | openlog(name, option, (pri | LOG_FACMASK)); |
diff --git a/sysklogd/logger.c b/sysklogd/logger.c index f5c776ddf..21906401f 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c | |||
@@ -101,68 +101,47 @@ extern int logger_main(int argc, char **argv) | |||
101 | { | 101 | { |
102 | int pri = LOG_USER | LOG_NOTICE; | 102 | int pri = LOG_USER | LOG_NOTICE; |
103 | int option = 0; | 103 | int option = 0; |
104 | int fromStdinFlag = FALSE; | 104 | int c, i, len, opt; |
105 | int stopLookingAtMeLikeThat = FALSE; | ||
106 | char *message=NULL, buf[1024], name[128]; | 105 | char *message=NULL, buf[1024], name[128]; |
107 | 106 | ||
108 | /* Fill out the name string early (may be overwritten later */ | 107 | /* Fill out the name string early (may be overwritten later) */ |
109 | my_getpwuid(name, geteuid()); | 108 | my_getpwuid(name, geteuid()); |
110 | 109 | ||
111 | /* Parse any options */ | 110 | /* Parse any options */ |
112 | while (--argc > 0 && **(++argv) == '-') { | 111 | while ((opt = getopt(argc, argv, "p:st:")) > 0) { |
113 | if (*((*argv) + 1) == '\0') { | 112 | switch (opt) { |
114 | fromStdinFlag = TRUE; | ||
115 | } | ||
116 | stopLookingAtMeLikeThat = FALSE; | ||
117 | while (*(++(*argv)) && stopLookingAtMeLikeThat == FALSE) { | ||
118 | switch (**argv) { | ||
119 | case 's': | 113 | case 's': |
120 | option |= LOG_PERROR; | 114 | option |= LOG_PERROR; |
121 | break; | 115 | break; |
122 | case 'p': | 116 | case 'p': |
123 | if (--argc == 0) { | 117 | pri = pencode(optarg); |
124 | usage(logger_usage); | ||
125 | } | ||
126 | pri = pencode(*(++argv)); | ||
127 | stopLookingAtMeLikeThat = TRUE; | ||
128 | break; | 118 | break; |
129 | case 't': | 119 | case 't': |
130 | if (--argc == 0) { | 120 | strncpy(name, optarg, sizeof(name)); |
131 | usage(logger_usage); | ||
132 | } | ||
133 | strncpy(name, *(++argv), sizeof(name)); | ||
134 | stopLookingAtMeLikeThat = TRUE; | ||
135 | break; | 121 | break; |
136 | default: | 122 | default: |
137 | usage(logger_usage); | 123 | usage(logger_usage); |
138 | } | ||
139 | } | 124 | } |
140 | } | 125 | } |
141 | 126 | ||
142 | if (fromStdinFlag == TRUE) { | 127 | if (optind == argc) { |
143 | /* read from stdin */ | 128 | /* read from stdin */ |
144 | int c; | 129 | i = 0; |
145 | unsigned int i = 0; | ||
146 | |||
147 | while ((c = getc(stdin)) != EOF && i < sizeof(buf)) { | 130 | while ((c = getc(stdin)) != EOF && i < sizeof(buf)) { |
148 | buf[i++] = c; | 131 | buf[i++] = c; |
149 | } | 132 | } |
150 | message = buf; | 133 | message = buf; |
151 | } else { | 134 | } else { |
152 | if (argc >= 1) { | 135 | len = 1; /* for the '\0' */ |
153 | int len = 1; /* for the '\0' */ | 136 | message=xcalloc(1, 1); |
154 | message=xcalloc(1, 1); | 137 | for (i = optind; i < argc; i++) { |
155 | for (; *argv != NULL; argv++) { | 138 | len += strlen(argv[i]); |
156 | len += strlen(*argv); | 139 | len += 1; /* for the space between the args */ |
157 | len += 1; /* for the space between the args */ | 140 | message = xrealloc(message, len); |
158 | message = xrealloc(message, len); | 141 | strcat(message, argv[i]); |
159 | strcat(message, *argv); | 142 | strcat(message, " "); |
160 | strcat(message, " "); | ||
161 | } | ||
162 | message[strlen(message)-1] = '\0'; | ||
163 | } else { | ||
164 | error_msg_and_die("No message\n"); | ||
165 | } | 143 | } |
144 | message[strlen(message)-1] = '\0'; | ||
166 | } | 145 | } |
167 | 146 | ||
168 | openlog(name, option, (pri | LOG_FACMASK)); | 147 | openlog(name, option, (pri | LOG_FACMASK)); |
@@ -586,7 +586,7 @@ const char loadkmap_usage[] = | |||
586 | const char logger_usage[] = | 586 | const char logger_usage[] = |
587 | "logger [OPTION]... [MESSAGE]\n" | 587 | "logger [OPTION]... [MESSAGE]\n" |
588 | #ifndef BB_FEATURE_TRIVIAL_HELP | 588 | #ifndef BB_FEATURE_TRIVIAL_HELP |
589 | "\nWrite MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n" | 589 | "\nWrite MESSAGE to the system log. If MESSAGE is omitted, log stdin.\n\n" |
590 | "Options:\n" | 590 | "Options:\n" |
591 | "\t-s\tLog to stderr as well as the system log.\n" | 591 | "\t-s\tLog to stderr as well as the system log.\n" |
592 | "\t-t\tLog using the specified tag (defaults to user name).\n" | 592 | "\t-t\tLog using the specified tag (defaults to user name).\n" |