diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-02-08 19:58:47 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-02-08 19:58:47 +0000 |
commit | e49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch) | |
tree | c90bda10731ad9333ce3b404f993354c9fc104b8 /sysklogd/logger.c | |
parent | c0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff) | |
download | busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2 busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip |
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'sysklogd/logger.c')
-rw-r--r-- | sysklogd/logger.c | 191 |
1 files changed, 95 insertions, 96 deletions
diff --git a/sysklogd/logger.c b/sysklogd/logger.c index aab95b984..a9e0afcc8 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * Mini logger implementation for busybox | 3 | * Mini logger implementation for busybox |
3 | * | 4 | * |
@@ -39,21 +40,22 @@ | |||
39 | */ | 40 | */ |
40 | #include <sys/syslog.h> | 41 | #include <sys/syslog.h> |
41 | typedef struct _code { | 42 | typedef struct _code { |
42 | char *c_name; | 43 | char *c_name; |
43 | int c_val; | 44 | int c_val; |
44 | } CODE; | 45 | } CODE; |
45 | extern CODE prioritynames[]; | 46 | extern CODE prioritynames[]; |
46 | extern CODE facilitynames[]; | 47 | extern CODE facilitynames[]; |
47 | #endif | 48 | #endif |
48 | 49 | ||
49 | static const char logger_usage[] = | 50 | static const char logger_usage[] = |
50 | "logger [OPTION]... [MESSAGE]\n\n" | 51 | "logger [OPTION]... [MESSAGE]\n\n" |
51 | "Write MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n" | 52 | "Write MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n" |
52 | "Options:\n" | 53 | "Options:\n" |
53 | "\t-s\tLog to stderr as well as the system log.\n" | 54 | "\t-s\tLog to stderr as well as the system log.\n" |
54 | "\t-t\tLog using the specified tag (defaults to user name).\n" | 55 | "\t-t\tLog using the specified tag (defaults to user name).\n" |
55 | "\t-p\tEnter the message with the specified priority.\n" | 56 | |
56 | "\t\tThis may be numerical or a ``facility.level'' pair.\n"; | 57 | "\t-p\tEnter the message with the specified priority.\n" |
58 | "\t\tThis may be numerical or a ``facility.level'' pair.\n"; | ||
57 | 59 | ||
58 | 60 | ||
59 | /* Decode a symbolic name to a numeric value | 61 | /* Decode a symbolic name to a numeric value |
@@ -61,20 +63,19 @@ static const char logger_usage[] = | |||
61 | * Copyright (c) 1983, 1993 | 63 | * Copyright (c) 1983, 1993 |
62 | * The Regents of the University of California. All rights reserved. | 64 | * The Regents of the University of California. All rights reserved. |
63 | */ | 65 | */ |
64 | static int | 66 | static int decode(char *name, CODE * codetab) |
65 | decode(char* name, CODE* codetab) | ||
66 | { | 67 | { |
67 | CODE *c; | 68 | CODE *c; |
68 | 69 | ||
69 | if (isdigit(*name)) | 70 | if (isdigit(*name)) |
70 | return (atoi(name)); | 71 | return (atoi(name)); |
71 | for (c = codetab; c->c_name; c++) { | 72 | for (c = codetab; c->c_name; c++) { |
72 | if (!strcasecmp(name, c->c_name)) { | 73 | if (!strcasecmp(name, c->c_name)) { |
73 | return (c->c_val); | 74 | return (c->c_val); |
75 | } | ||
74 | } | 76 | } |
75 | } | ||
76 | 77 | ||
77 | return (-1); | 78 | return (-1); |
78 | } | 79 | } |
79 | 80 | ||
80 | /* Decode a symbolic name to a numeric value | 81 | /* Decode a symbolic name to a numeric value |
@@ -82,96 +83,94 @@ decode(char* name, CODE* codetab) | |||
82 | * Copyright (c) 1983, 1993 | 83 | * Copyright (c) 1983, 1993 |
83 | * The Regents of the University of California. All rights reserved. | 84 | * The Regents of the University of California. All rights reserved. |
84 | */ | 85 | */ |
85 | static int | 86 | static int pencode(char *s) |
86 | pencode(char* s) | ||
87 | { | 87 | { |
88 | char *save; | 88 | char *save; |
89 | int lev, fac=LOG_USER; | 89 | int lev, fac = LOG_USER; |
90 | 90 | ||
91 | for (save = s; *s && *s != '.'; ++s); | 91 | for (save = s; *s && *s != '.'; ++s); |
92 | if (*s) { | 92 | if (*s) { |
93 | *s = '\0'; | 93 | *s = '\0'; |
94 | fac = decode(save, facilitynames); | 94 | fac = decode(save, facilitynames); |
95 | if (fac < 0) { | 95 | if (fac < 0) { |
96 | fprintf(stderr, "unknown facility name: %s\n", save); | 96 | fprintf(stderr, "unknown facility name: %s\n", save); |
97 | exit( FALSE); | 97 | exit(FALSE); |
98 | } | ||
99 | *s++ = '.'; | ||
100 | } else { | ||
101 | s = save; | ||
102 | } | ||
103 | lev = decode(s, prioritynames); | ||
104 | if (lev < 0) { | ||
105 | fprintf(stderr, "unknown priority name: %s\n", save); | ||
106 | exit(FALSE); | ||
98 | } | 107 | } |
99 | *s++ = '.'; | 108 | return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); |
100 | } | ||
101 | else { | ||
102 | s = save; | ||
103 | } | ||
104 | lev = decode(s, prioritynames); | ||
105 | if (lev < 0) { | ||
106 | fprintf(stderr, "unknown priority name: %s\n", save); | ||
107 | exit( FALSE); | ||
108 | } | ||
109 | return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); | ||
110 | } | 109 | } |
111 | 110 | ||
112 | 111 | ||
113 | extern int logger_main(int argc, char **argv) | 112 | extern int logger_main(int argc, char **argv) |
114 | { | 113 | { |
115 | int pri = LOG_USER|LOG_NOTICE; | 114 | int pri = LOG_USER | LOG_NOTICE; |
116 | int option = 0; | 115 | int option = 0; |
117 | int fromStdinFlag=FALSE; | 116 | int fromStdinFlag = FALSE; |
118 | int stopLookingAtMeLikeThat=FALSE; | 117 | int stopLookingAtMeLikeThat = FALSE; |
119 | char *message, buf[1024], name[128]; | 118 | char *message, buf[1024], name[128]; |
120 | 119 | ||
121 | /* Fill out the name string early (may be overwritten later */ | 120 | /* Fill out the name string early (may be overwritten later */ |
122 | my_getpwuid(name, geteuid()); | 121 | my_getpwuid(name, geteuid()); |
123 | 122 | ||
124 | /* Parse any options */ | 123 | /* Parse any options */ |
125 | while (--argc > 0 && **(++argv) == '-') { | 124 | while (--argc > 0 && **(++argv) == '-') { |
126 | if (*((*argv)+1) == '\0') { | 125 | if (*((*argv) + 1) == '\0') { |
127 | fromStdinFlag=TRUE; | 126 | fromStdinFlag = TRUE; |
128 | } | ||
129 | stopLookingAtMeLikeThat=FALSE; | ||
130 | while (*(++(*argv)) && stopLookingAtMeLikeThat==FALSE) { | ||
131 | switch (**argv) { | ||
132 | case 's': | ||
133 | option |= LOG_PERROR; | ||
134 | break; | ||
135 | case 'p': | ||
136 | if (--argc == 0) { | ||
137 | usage(logger_usage); | ||
138 | } | 127 | } |
139 | pri = pencode(*(++argv)); | 128 | stopLookingAtMeLikeThat = FALSE; |
140 | stopLookingAtMeLikeThat=TRUE; | 129 | while (*(++(*argv)) && stopLookingAtMeLikeThat == FALSE) { |
141 | break; | 130 | switch (**argv) { |
142 | case 't': | 131 | case 's': |
143 | if (--argc == 0) { | 132 | option |= LOG_PERROR; |
144 | usage(logger_usage); | 133 | break; |
134 | case 'p': | ||
135 | if (--argc == 0) { | ||
136 | usage(logger_usage); | ||
137 | } | ||
138 | pri = pencode(*(++argv)); | ||
139 | stopLookingAtMeLikeThat = TRUE; | ||
140 | break; | ||
141 | case 't': | ||
142 | if (--argc == 0) { | ||
143 | usage(logger_usage); | ||
144 | } | ||
145 | strncpy(name, *(++argv), sizeof(name)); | ||
146 | stopLookingAtMeLikeThat = TRUE; | ||
147 | break; | ||
148 | default: | ||
149 | usage(logger_usage); | ||
150 | } | ||
145 | } | 151 | } |
146 | strncpy(name, *(++argv), sizeof(name)); | ||
147 | stopLookingAtMeLikeThat=TRUE; | ||
148 | break; | ||
149 | default: | ||
150 | usage(logger_usage); | ||
151 | } | ||
152 | } | 152 | } |
153 | } | ||
154 | 153 | ||
155 | if (fromStdinFlag==TRUE) { | 154 | if (fromStdinFlag == TRUE) { |
156 | /* read from stdin */ | 155 | /* read from stdin */ |
157 | int c, i=0; | 156 | int c, i = 0; |
158 | while ((c = getc(stdin)) != EOF && i<sizeof(buf)) { | 157 | |
159 | buf[i++]=c; | 158 | while ((c = getc(stdin)) != EOF && i < sizeof(buf)) { |
160 | } | 159 | buf[i++] = c; |
161 | message=buf; | 160 | } |
162 | } else { | 161 | message = buf; |
163 | if (argc>=1) { | ||
164 | message = *argv; | ||
165 | } else { | 162 | } else { |
166 | fprintf(stderr, "No message\n"); | 163 | if (argc >= 1) { |
167 | exit( FALSE); | 164 | message = *argv; |
165 | } else { | ||
166 | fprintf(stderr, "No message\n"); | ||
167 | exit(FALSE); | ||
168 | } | ||
168 | } | 169 | } |
169 | } | ||
170 | 170 | ||
171 | openlog( name, option, (pri | LOG_FACMASK)); | 171 | openlog(name, option, (pri | LOG_FACMASK)); |
172 | syslog( pri, message); | 172 | syslog(pri, message); |
173 | closelog(); | 173 | closelog(); |
174 | 174 | ||
175 | exit( TRUE); | 175 | exit(TRUE); |
176 | } | 176 | } |
177 | |||