diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-06 18:36:50 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-06 18:36:50 +0000 |
commit | 3538b9a8822421b7c8596a33a917dcf2f99c92b7 (patch) | |
tree | 768c23fe79bb81583de7376a4d744632d888d303 /networking/udhcp/dhcpc.c | |
parent | 5d725462d44268f9a86030daaa6f6396d32f796c (diff) | |
download | busybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.tar.gz busybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.tar.bz2 busybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.zip |
Implement optional syslog logging using ordinary
bb_xx_msg calls, and convert networking/* to it.
The rest of bbox will be converted gradually.
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 989759ab8..5b2612e56 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -65,7 +65,7 @@ struct client_config_t client_config = { | |||
65 | /* just a little helper */ | 65 | /* just a little helper */ |
66 | static void change_mode(int new_mode) | 66 | static void change_mode(int new_mode) |
67 | { | 67 | { |
68 | DEBUG(LOG_INFO, "entering %s listen mode", | 68 | DEBUG("entering %s listen mode", |
69 | new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none"); | 69 | new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none"); |
70 | if (fd >= 0) close(fd); | 70 | if (fd >= 0) close(fd); |
71 | fd = -1; | 71 | fd = -1; |
@@ -76,7 +76,7 @@ static void change_mode(int new_mode) | |||
76 | /* perform a renew */ | 76 | /* perform a renew */ |
77 | static void perform_renew(void) | 77 | static void perform_renew(void) |
78 | { | 78 | { |
79 | LOG(LOG_INFO, "Performing a DHCP renew"); | 79 | bb_info_msg("Performing a DHCP renew"); |
80 | switch (state) { | 80 | switch (state) { |
81 | case BOUND: | 81 | case BOUND: |
82 | change_mode(LISTEN_KERNEL); | 82 | change_mode(LISTEN_KERNEL); |
@@ -114,12 +114,12 @@ static void perform_release(void) | |||
114 | temp_addr.s_addr = server_addr; | 114 | temp_addr.s_addr = server_addr; |
115 | sprintf(buffer, "%s", inet_ntoa(temp_addr)); | 115 | sprintf(buffer, "%s", inet_ntoa(temp_addr)); |
116 | temp_addr.s_addr = requested_ip; | 116 | temp_addr.s_addr = requested_ip; |
117 | LOG(LOG_INFO, "Unicasting a release of %s to %s", | 117 | bb_info_msg("Unicasting a release of %s to %s", |
118 | inet_ntoa(temp_addr), buffer); | 118 | inet_ntoa(temp_addr), buffer); |
119 | send_release(server_addr, requested_ip); /* unicast */ | 119 | send_release(server_addr, requested_ip); /* unicast */ |
120 | udhcp_run_script(NULL, "deconfig"); | 120 | udhcp_run_script(NULL, "deconfig"); |
121 | } | 121 | } |
122 | LOG(LOG_INFO, "Entering released state"); | 122 | bb_info_msg("Entering released state"); |
123 | 123 | ||
124 | change_mode(LISTEN_NONE); | 124 | change_mode(LISTEN_NONE); |
125 | state = RELEASED; | 125 | state = RELEASED; |
@@ -310,14 +310,14 @@ int udhcpc_main(int argc, char *argv[]) | |||
310 | else | 310 | else |
311 | fd = raw_socket(client_config.ifindex); | 311 | fd = raw_socket(client_config.ifindex); |
312 | if (fd < 0) { | 312 | if (fd < 0) { |
313 | LOG(LOG_ERR, "FATAL: couldn't listen on socket, %m"); | 313 | bb_perror_msg("FATAL: couldn't listen on socket"); |
314 | return 0; | 314 | return 0; |
315 | } | 315 | } |
316 | } | 316 | } |
317 | max_fd = udhcp_sp_fd_set(&rfds, fd); | 317 | max_fd = udhcp_sp_fd_set(&rfds, fd); |
318 | 318 | ||
319 | if (tv.tv_sec > 0) { | 319 | if (tv.tv_sec > 0) { |
320 | DEBUG(LOG_INFO, "Waiting on select..."); | 320 | DEBUG("Waiting on select..."); |
321 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); | 321 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); |
322 | } else retval = 0; /* If we already timed out, fall through */ | 322 | } else retval = 0; /* If we already timed out, fall through */ |
323 | 323 | ||
@@ -338,10 +338,10 @@ int udhcpc_main(int argc, char *argv[]) | |||
338 | } else { | 338 | } else { |
339 | udhcp_run_script(NULL, "leasefail"); | 339 | udhcp_run_script(NULL, "leasefail"); |
340 | if (client_config.background_if_no_lease) { | 340 | if (client_config.background_if_no_lease) { |
341 | LOG(LOG_INFO, "No lease, forking to background."); | 341 | bb_info_msg("No lease, forking to background"); |
342 | client_background(); | 342 | client_background(); |
343 | } else if (client_config.abort_if_no_lease) { | 343 | } else if (client_config.abort_if_no_lease) { |
344 | LOG(LOG_INFO, "No lease, failing."); | 344 | bb_info_msg("No lease, failing"); |
345 | return 1; | 345 | return 1; |
346 | } | 346 | } |
347 | /* wait to try again */ | 347 | /* wait to try again */ |
@@ -372,7 +372,7 @@ int udhcpc_main(int argc, char *argv[]) | |||
372 | /* Lease is starting to run out, time to enter renewing state */ | 372 | /* Lease is starting to run out, time to enter renewing state */ |
373 | state = RENEWING; | 373 | state = RENEWING; |
374 | change_mode(LISTEN_KERNEL); | 374 | change_mode(LISTEN_KERNEL); |
375 | DEBUG(LOG_INFO, "Entering renew state"); | 375 | DEBUG("Entering renew state"); |
376 | /* fall right through */ | 376 | /* fall right through */ |
377 | case RENEWING: | 377 | case RENEWING: |
378 | /* Either set a new T1, or enter REBINDING state */ | 378 | /* Either set a new T1, or enter REBINDING state */ |
@@ -380,7 +380,7 @@ int udhcpc_main(int argc, char *argv[]) | |||
380 | /* timed out, enter rebinding state */ | 380 | /* timed out, enter rebinding state */ |
381 | state = REBINDING; | 381 | state = REBINDING; |
382 | timeout = now + (t2 - t1); | 382 | timeout = now + (t2 - t1); |
383 | DEBUG(LOG_INFO, "Entering rebinding state"); | 383 | DEBUG("Entering rebinding state"); |
384 | } else { | 384 | } else { |
385 | /* send a request packet */ | 385 | /* send a request packet */ |
386 | send_renew(xid, server_addr, requested_ip); /* unicast */ | 386 | send_renew(xid, server_addr, requested_ip); /* unicast */ |
@@ -394,7 +394,7 @@ int udhcpc_main(int argc, char *argv[]) | |||
394 | if ((lease - t2) <= (lease / 14400 + 1)) { | 394 | if ((lease - t2) <= (lease / 14400 + 1)) { |
395 | /* timed out, enter init state */ | 395 | /* timed out, enter init state */ |
396 | state = INIT_SELECTING; | 396 | state = INIT_SELECTING; |
397 | LOG(LOG_INFO, "Lease lost, entering init state"); | 397 | bb_info_msg("Lease lost, entering init state"); |
398 | udhcp_run_script(NULL, "deconfig"); | 398 | udhcp_run_script(NULL, "deconfig"); |
399 | timeout = now; | 399 | timeout = now; |
400 | packet_num = 0; | 400 | packet_num = 0; |
@@ -420,25 +420,25 @@ int udhcpc_main(int argc, char *argv[]) | |||
420 | else len = get_raw_packet(&packet, fd); | 420 | else len = get_raw_packet(&packet, fd); |
421 | 421 | ||
422 | if (len == -1 && errno != EINTR) { | 422 | if (len == -1 && errno != EINTR) { |
423 | DEBUG(LOG_INFO, "error on read, %m, reopening socket"); | 423 | DEBUG("error on read, %s, reopening socket", strerror(errno)); |
424 | change_mode(listen_mode); /* just close and reopen */ | 424 | change_mode(listen_mode); /* just close and reopen */ |
425 | } | 425 | } |
426 | if (len < 0) continue; | 426 | if (len < 0) continue; |
427 | 427 | ||
428 | if (packet.xid != xid) { | 428 | if (packet.xid != xid) { |
429 | DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)", | 429 | DEBUG("Ignoring XID %lx (our xid is %lx)", |
430 | (unsigned long) packet.xid, xid); | 430 | (unsigned long) packet.xid, xid); |
431 | continue; | 431 | continue; |
432 | } | 432 | } |
433 | 433 | ||
434 | /* Ignore packets that aren't for us */ | 434 | /* Ignore packets that aren't for us */ |
435 | if (memcmp(packet.chaddr, client_config.arp, 6)) { | 435 | if (memcmp(packet.chaddr, client_config.arp, 6)) { |
436 | DEBUG(LOG_INFO, "packet does not have our chaddr -- ignoring"); | 436 | DEBUG("Packet does not have our chaddr - ignoring"); |
437 | continue; | 437 | continue; |
438 | } | 438 | } |
439 | 439 | ||
440 | if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { | 440 | if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { |
441 | DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); | 441 | bb_error_msg("Couldnt get option from packet - ignoring"); |
442 | continue; | 442 | continue; |
443 | } | 443 | } |
444 | 444 | ||
@@ -456,7 +456,7 @@ int udhcpc_main(int argc, char *argv[]) | |||
456 | timeout = now; | 456 | timeout = now; |
457 | packet_num = 0; | 457 | packet_num = 0; |
458 | } else { | 458 | } else { |
459 | DEBUG(LOG_ERR, "No server ID in message"); | 459 | bb_error_msg("No server ID in message"); |
460 | } | 460 | } |
461 | } | 461 | } |
462 | break; | 462 | break; |
@@ -466,7 +466,7 @@ int udhcpc_main(int argc, char *argv[]) | |||
466 | case REBINDING: | 466 | case REBINDING: |
467 | if (*message == DHCPACK) { | 467 | if (*message == DHCPACK) { |
468 | if (!(temp = get_option(&packet, DHCP_LEASE_TIME))) { | 468 | if (!(temp = get_option(&packet, DHCP_LEASE_TIME))) { |
469 | LOG(LOG_ERR, "No lease time with ACK, using 1 hour lease"); | 469 | bb_error_msg("No lease time with ACK, using 1 hour lease"); |
470 | lease = 60 * 60; | 470 | lease = 60 * 60; |
471 | } else { | 471 | } else { |
472 | memcpy(&lease, temp, 4); | 472 | memcpy(&lease, temp, 4); |
@@ -479,7 +479,7 @@ int udhcpc_main(int argc, char *argv[]) | |||
479 | /* little fixed point for n * .875 */ | 479 | /* little fixed point for n * .875 */ |
480 | t2 = (lease * 0x7) >> 3; | 480 | t2 = (lease * 0x7) >> 3; |
481 | temp_addr.s_addr = packet.yiaddr; | 481 | temp_addr.s_addr = packet.yiaddr; |
482 | LOG(LOG_INFO, "Lease of %s obtained, lease time %ld", | 482 | bb_info_msg("Lease of %s obtained, lease time %ld", |
483 | inet_ntoa(temp_addr), lease); | 483 | inet_ntoa(temp_addr), lease); |
484 | start = now; | 484 | start = now; |
485 | timeout = t1 + start; | 485 | timeout = t1 + start; |
@@ -496,7 +496,7 @@ int udhcpc_main(int argc, char *argv[]) | |||
496 | 496 | ||
497 | } else if (*message == DHCPNAK) { | 497 | } else if (*message == DHCPNAK) { |
498 | /* return to init state */ | 498 | /* return to init state */ |
499 | LOG(LOG_INFO, "Received DHCP NAK"); | 499 | bb_info_msg("Received DHCP NAK"); |
500 | udhcp_run_script(&packet, "nak"); | 500 | udhcp_run_script(&packet, "nak"); |
501 | if (state != REQUESTING) | 501 | if (state != REQUESTING) |
502 | udhcp_run_script(NULL, "deconfig"); | 502 | udhcp_run_script(NULL, "deconfig"); |
@@ -519,14 +519,14 @@ int udhcpc_main(int argc, char *argv[]) | |||
519 | perform_release(); | 519 | perform_release(); |
520 | break; | 520 | break; |
521 | case SIGTERM: | 521 | case SIGTERM: |
522 | LOG(LOG_INFO, "Received SIGTERM"); | 522 | bb_info_msg("Received SIGTERM"); |
523 | return 0; | 523 | return 0; |
524 | } | 524 | } |
525 | } else if (retval == -1 && errno == EINTR) { | 525 | } else if (retval == -1 && errno == EINTR) { |
526 | /* a signal was caught */ | 526 | /* a signal was caught */ |
527 | } else { | 527 | } else { |
528 | /* An error occured */ | 528 | /* An error occured */ |
529 | DEBUG(LOG_ERR, "Error on select"); | 529 | bb_perror_msg("select"); |
530 | } | 530 | } |
531 | 531 | ||
532 | } | 532 | } |