aboutsummaryrefslogtreecommitdiff
path: root/networking/zcip.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-03 12:28:32 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-03 12:28:32 +0000
commita9abecd85e5e6a9e1623d7edffd154e717f8a6d7 (patch)
treee12c71e3521b2b52dd70ccad0d71936393e2cd2b /networking/zcip.c
parent65dbd8752b4b183c11a631792ef2ad07a7f251e4 (diff)
downloadbusybox-w32-a9abecd85e5e6a9e1623d7edffd154e717f8a6d7.tar.gz
busybox-w32-a9abecd85e5e6a9e1623d7edffd154e717f8a6d7.tar.bz2
busybox-w32-a9abecd85e5e6a9e1623d7edffd154e717f8a6d7.zip
zcip: fix stdout/err versus syslog output.
Incomplete: xfunc() would not respect this. TODO.
Diffstat (limited to 'networking/zcip.c')
-rw-r--r--networking/zcip.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/networking/zcip.c b/networking/zcip.c
index 55d28e563..330ec7af4 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -76,6 +76,10 @@ enum {
76 do { } while (0) 76 do { } while (0)
77#define VDBG DBG 77#define VDBG DBG
78 78
79static unsigned long opts;
80#define FOREGROUND (opts & 1)
81#define QUIT (opts & 2)
82
79/** 83/**
80 * Pick a random link local IP address on 169.254/16, except that 84 * Pick a random link local IP address on 169.254/16, except that
81 * the first and last 256 addresses are reserved. 85 * the first and last 256 addresses are reserved.
@@ -119,7 +123,10 @@ static int arp(int fd, struct sockaddr *saddr, int op,
119 123
120 // send it 124 // send it
121 if (sendto(fd, &p, sizeof (p), 0, saddr, sizeof (*saddr)) < 0) { 125 if (sendto(fd, &p, sizeof (p), 0, saddr, sizeof (*saddr)) < 0) {
122 perror("sendto"); 126 if (FOREGROUND)
127 perror("sendto");
128 else
129 syslog(LOG_ERR, "sendto: %s", strerror(errno));
123 return -errno; 130 return -errno;
124 } 131 }
125 return 0; 132 return 0;
@@ -127,19 +134,20 @@ static int arp(int fd, struct sockaddr *saddr, int op,
127 134
128/** 135/**
129 * Run a script. 136 * Run a script.
130 * TODO: sort out stderr/syslog reporting. 137 * TODO: we need a flag to direct bb_[p]error_msg output to stderr.
131 */ 138 */
132static int run(char *script, char *arg, char *intf, struct in_addr *ip) 139static int run(char *script, char *arg, char *intf, struct in_addr *ip)
133{ 140{
134 int pid, status; 141 int pid, status;
135 char *why; 142 char *why;
136 143
137 if (script != NULL) { 144 if(1) { //always true: if (script != NULL)
138 VDBG("%s run %s %s\n", intf, script, arg); 145 VDBG("%s run %s %s\n", intf, script, arg);
139 if (ip != NULL) { 146 if (ip != NULL) {
140 char *addr = inet_ntoa(*ip); 147 char *addr = inet_ntoa(*ip);
141 setenv("ip", addr, 1); 148 setenv("ip", addr, 1);
142 syslog(LOG_INFO, "%s %s %s", arg, intf, addr); 149 if (!FOREGROUND)
150 syslog(LOG_INFO, "%s %s %s", arg, intf, addr);
143 } 151 }
144 152
145 pid = vfork(); 153 pid = vfork();
@@ -148,7 +156,10 @@ static int run(char *script, char *arg, char *intf, struct in_addr *ip)
148 goto bad; 156 goto bad;
149 } else if (pid == 0) { // child 157 } else if (pid == 0) { // child
150 execl(script, script, arg, NULL); 158 execl(script, script, arg, NULL);
151 perror("execl"); 159 if (FOREGROUND)
160 perror("execl");
161 else
162 syslog(LOG_ERR, "execl: %s", strerror(errno));
152 _exit(EXIT_FAILURE); 163 _exit(EXIT_FAILURE);
153 } 164 }
154 165
@@ -157,7 +168,11 @@ static int run(char *script, char *arg, char *intf, struct in_addr *ip)
157 goto bad; 168 goto bad;
158 } 169 }
159 if (WEXITSTATUS(status) != 0) { 170 if (WEXITSTATUS(status) != 0) {
160 bb_error_msg("script %s failed, exit=%d\n", 171 if (FOREGROUND)
172 bb_error_msg("script %s failed, exit=%d\n",
173 script, WEXITSTATUS(status));
174 else
175 syslog(LOG_ERR, "script %s failed, exit=%d",
161 script, WEXITSTATUS(status)); 176 script, WEXITSTATUS(status));
162 return -errno; 177 return -errno;
163 } 178 }
@@ -165,8 +180,12 @@ static int run(char *script, char *arg, char *intf, struct in_addr *ip)
165 return 0; 180 return 0;
166bad: 181bad:
167 status = -errno; 182 status = -errno;
168 syslog(LOG_ERR, "%s %s, %s error: %s", 183 if (FOREGROUND)
169 arg, intf, why, strerror(errno)); 184 bb_perror_msg("%s %s, %s",
185 arg, intf, why);
186 else
187 syslog(LOG_ERR, "%s %s, %s: %s",
188 arg, intf, why, strerror(errno));
170 return status; 189 return status;
171} 190}
172 191
@@ -211,11 +230,7 @@ int zcip_main(int argc, char *argv[])
211 int fd; 230 int fd;
212 231
213 // parse commandline: prog [options] ifname script 232 // parse commandline: prog [options] ifname script
214#define FOREGROUND (opts & 1)
215#define QUIT (opts & 2)
216 char *r_opt; 233 char *r_opt;
217 unsigned long opts;
218
219 bb_opt_complementally = "vv"; // -v options accumulate 234 bb_opt_complementally = "vv"; // -v options accumulate
220 opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose); 235 opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose);
221 if (opts & 4) { 236 if (opts & 4) {