aboutsummaryrefslogtreecommitdiff
path: root/networking/zcip.c
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-06 18:36:50 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-06 18:36:50 +0000
commit601d93b47b8ac41f1fd763db15f05b6419c0b398 (patch)
tree768c23fe79bb81583de7376a4d744632d888d303 /networking/zcip.c
parent05fa38a6084b2f829750451d934f18c4dad62776 (diff)
downloadbusybox-w32-601d93b47b8ac41f1fd763db15f05b6419c0b398.tar.gz
busybox-w32-601d93b47b8ac41f1fd763db15f05b6419c0b398.tar.bz2
busybox-w32-601d93b47b8ac41f1fd763db15f05b6419c0b398.zip
Implement optional syslog logging using ordinary
bb_xx_msg calls, and convert networking/* to it. The rest of bbox will be converted gradually. git-svn-id: svn://busybox.net/trunk/busybox@16058 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to '')
-rw-r--r--networking/zcip.c45
1 files changed, 15 insertions, 30 deletions
diff --git a/networking/zcip.c b/networking/zcip.c
index 3a08382c2..5d2a5f786 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -124,10 +124,7 @@ static void arp(int fd, struct sockaddr *saddr, int op,
124 124
125 // send it 125 // send it
126 if (sendto(fd, &p, sizeof (p), 0, saddr, sizeof (*saddr)) < 0) { 126 if (sendto(fd, &p, sizeof (p), 0, saddr, sizeof (*saddr)) < 0) {
127 if (FOREGROUND) 127 bb_perror_msg("sendto");
128 perror("sendto");
129 else
130 syslog(LOG_ERR, "sendto: %s", strerror(errno));
131 //return -errno; 128 //return -errno;
132 } 129 }
133 // Currently all callers ignore errors, that's why returns are 130 // Currently all callers ignore errors, that's why returns are
@@ -148,8 +145,7 @@ static int run(char *script, char *arg, char *intf, struct in_addr *ip)
148 if (ip != NULL) { 145 if (ip != NULL) {
149 char *addr = inet_ntoa(*ip); 146 char *addr = inet_ntoa(*ip);
150 setenv("ip", addr, 1); 147 setenv("ip", addr, 1);
151 if (!FOREGROUND) 148 bb_info_msg("%s %s %s", arg, intf, addr);
152 syslog(LOG_INFO, "%s %s %s", arg, intf, addr);
153 } 149 }
154 150
155 pid = vfork(); 151 pid = vfork();
@@ -158,10 +154,7 @@ static int run(char *script, char *arg, char *intf, struct in_addr *ip)
158 goto bad; 154 goto bad;
159 } else if (pid == 0) { // child 155 } else if (pid == 0) { // child
160 execl(script, script, arg, NULL); 156 execl(script, script, arg, NULL);
161 if (FOREGROUND) 157 bb_perror_msg("execl");
162 perror("execl");
163 else
164 syslog(LOG_ERR, "execl: %s", strerror(errno));
165 _exit(EXIT_FAILURE); 158 _exit(EXIT_FAILURE);
166 } 159 }
167 160
@@ -170,24 +163,15 @@ static int run(char *script, char *arg, char *intf, struct in_addr *ip)
170 goto bad; 163 goto bad;
171 } 164 }
172 if (WEXITSTATUS(status) != 0) { 165 if (WEXITSTATUS(status) != 0) {
173 if (FOREGROUND) 166 bb_error_msg("script %s failed, exit=%d",
174 bb_error_msg("script %s failed, exit=%d", 167 script, WEXITSTATUS(status));
175 script, WEXITSTATUS(status));
176 else
177 syslog(LOG_ERR, "script %s failed, exit=%d",
178 script, WEXITSTATUS(status));
179 return -errno; 168 return -errno;
180 } 169 }
181 } 170 }
182 return 0; 171 return 0;
183bad: 172bad:
184 status = -errno; 173 status = -errno;
185 if (FOREGROUND) 174 bb_perror_msg("%s %s, %s", arg, intf, why);
186 bb_perror_msg("%s %s, %s",
187 arg, intf, why);
188 else
189 syslog(LOG_ERR, "%s %s, %s: %s",
190 arg, intf, why, strerror(errno));
191 return status; 175 return status;
192} 176}
193 177
@@ -235,6 +219,11 @@ int zcip_main(int argc, char *argv[])
235 char *r_opt; 219 char *r_opt;
236 bb_opt_complementally = "vv:vf"; // -v accumulates and implies -f 220 bb_opt_complementally = "vv:vf"; // -v accumulates and implies -f
237 opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose); 221 opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose);
222 if (!FOREGROUND) {
223 /* Do it early, before all bb_xx_msg calls */
224 logmode = LOGMODE_SYSLOG;
225 openlog(bb_applet_name, 0, LOG_DAEMON);
226 }
238 if (opts & 4) { // -r n.n.n.n 227 if (opts & 4) { // -r n.n.n.n
239 if (inet_aton(r_opt, &ip) == 0 228 if (inet_aton(r_opt, &ip) == 0
240 || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) { 229 || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
@@ -285,9 +274,9 @@ int zcip_main(int argc, char *argv[])
285 274
286 // daemonize now; don't delay system startup 275 // daemonize now; don't delay system startup
287 if (!FOREGROUND) { 276 if (!FOREGROUND) {
288 xdaemon(0, verbose); 277 setsid();
289 openlog(bb_applet_name, 0, LOG_DAEMON); 278 xdaemon(0, 0);
290 syslog(LOG_INFO, "start, interface %s", intf); 279 bb_info_msg("start, interface %s", intf);
291 } 280 }
292 281
293 // run the dynamic address negotiation protocol, 282 // run the dynamic address negotiation protocol,
@@ -557,10 +546,6 @@ int zcip_main(int argc, char *argv[])
557 } // switch poll 546 } // switch poll
558 } 547 }
559bad: 548bad:
560 if (FOREGROUND) 549 bb_perror_msg("%s, %s", intf, why);
561 perror(why);
562 else
563 syslog(LOG_ERR, "%s %s, %s error: %s",
564 bb_applet_name, intf, why, strerror(errno));
565 return EXIT_FAILURE; 550 return EXIT_FAILURE;
566} 551}