*: rename ATTRIBUTE_XXX to just XXX.
[platform/upstream/busybox.git] / networking / udhcp / dhcpc.c
1 /* vi: set sw=4 ts=4: */
2 /* dhcpc.c
3  *
4  * udhcp DHCP client
5  *
6  * Russ Dill <Russ.Dill@asu.edu> July 2001
7  *
8  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9  */
10
11 #include <syslog.h>
12
13 /* Override ENABLE_FEATURE_PIDFILE - ifupdown needs our pidfile to always exist */
14 #define WANT_PIDFILE 1
15 #include "common.h"
16 #include "dhcpd.h"
17 #include "dhcpc.h"
18 #include "options.h"
19
20
21 static int sockfd = -1;
22
23 #define LISTEN_NONE 0
24 #define LISTEN_KERNEL 1
25 #define LISTEN_RAW 2
26 static smallint listen_mode;
27
28 #define INIT_SELECTING  0
29 #define REQUESTING      1
30 #define BOUND           2
31 #define RENEWING        3
32 #define REBINDING       4
33 #define INIT_REBOOT     5
34 #define RENEW_REQUESTED 6
35 #define RELEASED        7
36 static smallint state;
37
38 /* struct client_config_t client_config is in bb_common_bufsiz1 */
39
40
41 /* just a little helper */
42 static void change_listen_mode(int new_mode)
43 {
44         DEBUG("entering %s listen mode",
45                 new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none");
46         if (sockfd >= 0) {
47                 close(sockfd);
48                 sockfd = -1;
49         }
50         listen_mode = new_mode;
51 }
52
53
54 /* perform a renew */
55 static void perform_renew(void)
56 {
57         bb_info_msg("Performing a DHCP renew");
58         switch (state) {
59         case BOUND:
60                 change_listen_mode(LISTEN_KERNEL);
61         case RENEWING:
62         case REBINDING:
63                 state = RENEW_REQUESTED;
64                 break;
65         case RENEW_REQUESTED: /* impatient are we? fine, square 1 */
66                 udhcp_run_script(NULL, "deconfig");
67         case REQUESTING:
68         case RELEASED:
69                 change_listen_mode(LISTEN_RAW);
70                 state = INIT_SELECTING;
71                 break;
72         case INIT_SELECTING:
73                 break;
74         }
75 }
76
77
78 /* perform a release */
79 static void perform_release(uint32_t requested_ip, uint32_t server_addr)
80 {
81         char buffer[sizeof("255.255.255.255")];
82         struct in_addr temp_addr;
83
84         /* send release packet */
85         if (state == BOUND || state == RENEWING || state == REBINDING) {
86                 temp_addr.s_addr = server_addr;
87                 strcpy(buffer, inet_ntoa(temp_addr));
88                 temp_addr.s_addr = requested_ip;
89                 bb_info_msg("Unicasting a release of %s to %s",
90                                 inet_ntoa(temp_addr), buffer);
91                 send_release(server_addr, requested_ip); /* unicast */
92                 udhcp_run_script(NULL, "deconfig");
93         }
94         bb_info_msg("Entering released state");
95
96         change_listen_mode(LISTEN_NONE);
97         state = RELEASED;
98 }
99
100
101 #if BB_MMU
102 static void client_background(void)
103 {
104         bb_daemonize(0);
105         logmode &= ~LOGMODE_STDIO;
106         /* rewrite pidfile, as our pid is different now */
107         write_pidfile(client_config.pidfile);
108 }
109 #endif
110
111
112 static uint8_t* alloc_dhcp_option(int code, const char *str, int extra)
113 {
114         uint8_t *storage;
115         int len = strlen(str);
116         if (len > 255) len = 255;
117         storage = xzalloc(len + extra + OPT_DATA);
118         storage[OPT_CODE] = code;
119         storage[OPT_LEN] = len + extra;
120         memcpy(storage + extra + OPT_DATA, str, len);
121         return storage;
122 }
123
124
125 int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
126 int udhcpc_main(int argc UNUSED_PARAM, char **argv)
127 {
128         uint8_t *temp, *message;
129         char *str_c, *str_V, *str_h, *str_F, *str_r;
130         USE_FEATURE_UDHCP_PORT(char *str_P;)
131         llist_t *list_O = NULL;
132         int tryagain_timeout = 20;
133         int discover_timeout = 3;
134         int discover_retries = 3;
135         uint32_t server_addr = server_addr; /* for compiler */
136         uint32_t requested_ip = 0;
137         uint32_t xid = 0;
138         uint32_t lease_seconds = 0; /* can be given as 32-bit quantity */
139         int packet_num;
140         int timeout; /* must be signed */
141         unsigned already_waited_sec;
142         unsigned opt;
143         int max_fd;
144         int retval;
145         struct timeval tv;
146         struct dhcpMessage packet;
147         fd_set rfds;
148
149 #if ENABLE_GETOPT_LONG
150         static const char udhcpc_longopts[] ALIGN1 =
151                 "clientid\0"       Required_argument "c"
152                 "clientid-none\0"  No_argument       "C"
153                 "vendorclass\0"    Required_argument "V"
154                 "hostname\0"       Required_argument "H"
155                 "fqdn\0"           Required_argument "F"
156                 "interface\0"      Required_argument "i"
157                 "now\0"            No_argument       "n"
158                 "pidfile\0"        Required_argument "p"
159                 "quit\0"           No_argument       "q"
160                 "release\0"        No_argument       "R"
161                 "request\0"        Required_argument "r"
162                 "script\0"         Required_argument "s"
163                 "timeout\0"        Required_argument "T"
164                 "version\0"        No_argument       "v"
165                 "retries\0"        Required_argument "t"
166                 "tryagain\0"       Required_argument "A"
167                 "syslog\0"         No_argument       "S"
168                 "request-option\0" Required_argument "O"
169                 "no-default-options\0" No_argument   "o"
170                 "foreground\0"     No_argument       "f"
171                 "background\0"     No_argument       "b"
172                 USE_FEATURE_UDHCPC_ARPING("arping\0"    No_argument       "a")
173                 USE_FEATURE_UDHCP_PORT("client-port\0"  Required_argument "P")
174                 ;
175 #endif
176         enum {
177                 OPT_c = 1 << 0,
178                 OPT_C = 1 << 1,
179                 OPT_V = 1 << 2,
180                 OPT_H = 1 << 3,
181                 OPT_h = 1 << 4,
182                 OPT_F = 1 << 5,
183                 OPT_i = 1 << 6,
184                 OPT_n = 1 << 7,
185                 OPT_p = 1 << 8,
186                 OPT_q = 1 << 9,
187                 OPT_R = 1 << 10,
188                 OPT_r = 1 << 11,
189                 OPT_s = 1 << 12,
190                 OPT_T = 1 << 13,
191                 OPT_t = 1 << 14,
192                 OPT_v = 1 << 15,
193                 OPT_S = 1 << 16,
194                 OPT_A = 1 << 17,
195                 OPT_O = 1 << 18,
196                 OPT_o = 1 << 19,
197                 OPT_f = 1 << 20,
198 /* The rest has variable bit positions, need to be clever */
199                 OPTBIT_f = 20,
200                 USE_FOR_MMU(              OPTBIT_b,)
201                 USE_FEATURE_UDHCPC_ARPING(OPTBIT_a,)
202                 USE_FEATURE_UDHCP_PORT(   OPTBIT_P,)
203                 USE_FOR_MMU(              OPT_b = 1 << OPTBIT_b,)
204                 USE_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,)
205                 USE_FEATURE_UDHCP_PORT(   OPT_P = 1 << OPTBIT_P,)
206         };
207
208         /* Default options. */
209         USE_FEATURE_UDHCP_PORT(SERVER_PORT = 67;)
210         USE_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;)
211         client_config.interface = "eth0";
212         client_config.script = DEFAULT_SCRIPT;
213
214         /* Parse command line */
215         /* Cc: mutually exclusive; O: list; -T,-t,-A take numeric param */
216         opt_complementary = "c--C:C--c:O::T+:t+:A+";
217         USE_GETOPT_LONG(applet_long_options = udhcpc_longopts;)
218         opt = getopt32(argv, "c:CV:H:h:F:i:np:qRr:s:T:t:vSA:O:of"
219                 USE_FOR_MMU("b")
220                 USE_FEATURE_UDHCPC_ARPING("a")
221                 USE_FEATURE_UDHCP_PORT("P:")
222                 , &str_c, &str_V, &str_h, &str_h, &str_F
223                 , &client_config.interface, &client_config.pidfile, &str_r /* i,p */
224                 , &client_config.script /* s */
225                 , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */
226                 , &list_O
227                 USE_FEATURE_UDHCP_PORT(, &str_P)
228                 );
229         if (opt & OPT_c)
230                 client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, str_c, 0);
231         if (opt & OPT_V)
232                 client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0);
233         if (opt & (OPT_h|OPT_H))
234                 client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
235         if (opt & OPT_F) {
236                 client_config.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3);
237                 /* Flags: 0000NEOS
238                 S: 1 => Client requests Server to update A RR in DNS as well as PTR
239                 O: 1 => Server indicates to client that DNS has been updated regardless
240                 E: 1 => Name data is DNS format, i.e. <4>host<6>domain<3>com<0> not "host.domain.com"
241                 N: 1 => Client requests Server to not update DNS
242                 */
243                 client_config.fqdn[OPT_DATA + 0] = 0x1;
244                 /* client_config.fqdn[OPT_DATA + 1] = 0; - redundant */
245                 /* client_config.fqdn[OPT_DATA + 2] = 0; - redundant */
246         }
247         if (opt & OPT_r)
248                 requested_ip = inet_addr(str_r);
249         if (opt & OPT_v) {
250                 puts("version "BB_VER);
251                 return 0;
252         }
253 #if ENABLE_FEATURE_UDHCP_PORT
254         if (opt & OPT_P) {
255                 CLIENT_PORT = xatou16(str_P);
256                 SERVER_PORT = CLIENT_PORT - 1;
257         }
258 #endif
259         if (opt & OPT_o)
260                 client_config.no_default_options = 1;
261         while (list_O) {
262                 int n = index_in_strings(dhcp_option_strings, llist_pop(&list_O));
263                 if (n < 0)
264                         bb_error_msg_and_die("unknown option '%s'", list_O->data);
265                 n = dhcp_options[n].code;
266                 client_config.opt_mask[n >> 3] |= 1 << (n & 7);
267         }
268
269         if (read_interface(client_config.interface, &client_config.ifindex,
270                            NULL, client_config.arp))
271                 return 1;
272 #if !BB_MMU
273         /* on NOMMU reexec (i.e., background) early */
274         if (!(opt & OPT_f)) {
275                 bb_daemonize_or_rexec(0 /* flags */, argv);
276                 logmode = 0;
277         }
278 #endif
279         if (opt & OPT_S) {
280                 openlog(applet_name, LOG_PID, LOG_LOCAL0);
281                 logmode |= LOGMODE_SYSLOG;
282         }
283
284         /* Make sure fd 0,1,2 are open */
285         bb_sanitize_stdio();
286         /* Equivalent of doing a fflush after every \n */
287         setlinebuf(stdout);
288
289         /* Create pidfile */
290         write_pidfile(client_config.pidfile);
291
292         /* Goes to stdout (unless NOMMU) and possibly syslog */
293         bb_info_msg("%s (v"BB_VER") started", applet_name);
294
295         /* if not set, and not suppressed, setup the default client ID */
296         if (!client_config.clientid && !(opt & OPT_C)) {
297                 client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7);
298                 client_config.clientid[OPT_DATA] = 1;
299                 memcpy(client_config.clientid + OPT_DATA+1, client_config.arp, 6);
300         }
301
302         if (!client_config.vendorclass)
303                 client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, "udhcp "BB_VER, 0);
304
305         /* setup the signal pipe */
306         udhcp_sp_setup();
307
308         state = INIT_SELECTING;
309         udhcp_run_script(NULL, "deconfig");
310         change_listen_mode(LISTEN_RAW);
311         packet_num = 0;
312         timeout = 0;
313         already_waited_sec = 0;
314
315         /* Main event loop. select() waits on signal pipe and possibly
316          * on sockfd.
317          * "continue" statements in code below jump to the top of the loop.
318          */
319         for (;;) {
320                 unsigned timestamp_before_wait;
321
322                 if (listen_mode != LISTEN_NONE && sockfd < 0) {
323                         if (listen_mode == LISTEN_KERNEL)
324                                 sockfd = listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface);
325                         else
326                                 sockfd = raw_socket(client_config.ifindex);
327                 }
328                 max_fd = udhcp_sp_fd_set(&rfds, sockfd);
329
330                 tv.tv_sec = timeout - already_waited_sec;
331                 tv.tv_usec = 0;
332                 retval = 0; /* If we already timed out, fall through, else... */
333                 if (tv.tv_sec > 0) {
334                         timestamp_before_wait = (unsigned)monotonic_sec();
335                         DEBUG("Waiting on select...");
336                         retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
337                         if (retval < 0) {
338                                 /* EINTR? A signal was caught, don't panic */
339                                 if (errno == EINTR)
340                                         continue;
341                                 /* Else: an error occured, panic! */
342                                 bb_perror_msg_and_die("select");
343                         }
344                 }
345
346                 /* If timeout dropped to zero, time to become active:
347                  * resend discover/renew/whatever
348                  */
349                 if (retval == 0) {
350                         /* We will restart wait afresh in any case */
351                         already_waited_sec = 0;
352
353                         switch (state) {
354                         case INIT_SELECTING:
355                                 if (packet_num < discover_retries) {
356                                         if (packet_num == 0)
357                                                 xid = random_xid();
358
359                                         send_discover(xid, requested_ip); /* broadcast */
360
361                                         timeout = discover_timeout;
362                                         packet_num++;
363                                         continue;
364                                 }
365                                 udhcp_run_script(NULL, "leasefail");
366 #if BB_MMU /* -b is not supported on NOMMU */
367                                 if (opt & OPT_b) { /* background if no lease */
368                                         bb_info_msg("No lease, forking to background");
369                                         client_background();
370                                         /* do not background again! */
371                                         opt = ((opt & ~OPT_b) | OPT_f);
372                                 } else
373 #endif
374                                 if (opt & OPT_n) { /* abort if no lease */
375                                         bb_info_msg("No lease, failing");
376                                         retval = 1;
377                                         goto ret;
378                                 }
379                                 /* wait before trying again */
380                                 timeout = tryagain_timeout;
381                                 packet_num = 0;
382                                 continue;
383                         case RENEW_REQUESTED:
384                         case REQUESTING:
385                                 if (packet_num < discover_retries) {
386                                         /* send request packet */
387                                         if (state == RENEW_REQUESTED) /* unicast */
388                                                 send_renew(xid, server_addr, requested_ip);
389                                         else /* broadcast */
390                                                 send_selecting(xid, server_addr, requested_ip);
391
392                                         timeout = discover_timeout;
393                                         packet_num++;
394                                         continue;
395                                 }
396                                 /* timed out, go back to init state */
397                                 if (state == RENEW_REQUESTED)
398                                         udhcp_run_script(NULL, "deconfig");
399                                 change_listen_mode(LISTEN_RAW);
400                                 state = INIT_SELECTING;
401                                 timeout = 0;
402                                 packet_num = 0;
403                                 continue;
404                         case BOUND:
405                                 /* Half of the lease passed, time to enter renewing state */
406                                 change_listen_mode(LISTEN_KERNEL);
407                                 DEBUG("Entering renew state");
408                                 state = RENEWING;
409                                 /* fall right through */
410                         case RENEWING:
411                                 if (timeout > 60) {
412                                         /* send a request packet */
413                                         send_renew(xid, server_addr, requested_ip); /* unicast */
414                                         timeout >>= 1;
415                                         continue;
416                                 }
417                                 /* Timed out, enter rebinding state */
418                                 DEBUG("Entering rebinding state");
419                                 state = REBINDING;
420                                 /* fall right through */
421                         case REBINDING:
422                                 /* Lease is *really* about to run out,
423                                  * try to find DHCP server using broadcast */
424                                 if (timeout > 0) {
425                                         /* send a request packet */
426                                         send_renew(xid, 0, requested_ip); /* broadcast */
427                                         timeout >>= 1;
428                                         continue;
429                                 }
430                                 /* Timed out, enter init state */
431                                 bb_info_msg("Lease lost, entering init state");
432                                 udhcp_run_script(NULL, "deconfig");
433                                 change_listen_mode(LISTEN_RAW);
434                                 state = INIT_SELECTING;
435                                 /*timeout = 0; - already is */
436                                 packet_num = 0;
437                                 continue;
438                         /* case RELEASED: */
439                         }
440                         /* yah, I know, *you* say it would never happen */
441                         timeout = INT_MAX;
442                         continue; /* back to main loop */
443                 }
444
445                 /* select() didn't timeout, something did happen. */
446                 /* Is is a packet? */
447                 if (listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) {
448                         int len;
449                         /* A packet is ready, read it */
450
451                         if (listen_mode == LISTEN_KERNEL)
452                                 len = udhcp_recv_kernel_packet(&packet, sockfd);
453                         else
454                                 len = udhcp_recv_raw_packet(&packet, sockfd);
455                         if (len == -1) { /* error is severe, reopen socket */
456                                 DEBUG("error on read, %s, reopening socket", strerror(errno));
457                                 sleep(discover_timeout); /* 3 seconds by default */
458                                 change_listen_mode(listen_mode); /* just close and reopen */
459                         }
460                         /* If this packet will turn out to be unrelated/bogus,
461                          * we will go back and wait for next one.
462                          * Be sure timeout is properly decreased. */
463                         already_waited_sec += (unsigned)monotonic_sec() - timestamp_before_wait;
464                         if (len < 0)
465                                 continue;
466
467                         if (packet.xid != xid) {
468                                 DEBUG("Ignoring XID %x (our xid is %x)",
469                                         (unsigned)packet.xid, (unsigned)xid);
470                                 continue;
471                         }
472
473                         /* Ignore packets that aren't for us */
474                         if (memcmp(packet.chaddr, client_config.arp, 6)) {
475                                 DEBUG("Packet does not have our chaddr - ignoring");
476                                 continue;
477                         }
478
479                         message = get_option(&packet, DHCP_MESSAGE_TYPE);
480                         if (message == NULL) {
481                                 bb_error_msg("cannot get message type from packet - ignoring");
482                                 continue;
483                         }
484
485                         switch (state) {
486                         case INIT_SELECTING:
487                                 /* Must be a DHCPOFFER to one of our xid's */
488                                 if (*message == DHCPOFFER) {
489                         /* TODO: why we don't just fetch server's IP from IP header? */
490                                         temp = get_option(&packet, DHCP_SERVER_ID);
491                                         if (!temp) {
492                                                 bb_error_msg("no server ID in message");
493                                                 continue;
494                                                 /* still selecting - this server looks bad */
495                                         }
496                                         /* it IS unaligned sometimes, don't "optimize" */
497                                         server_addr = get_unaligned_u32p((uint32_t*)temp);
498                                         xid = packet.xid;
499                                         requested_ip = packet.yiaddr;
500
501                                         /* enter requesting state */
502                                         state = REQUESTING;
503                                         timeout = 0;
504                                         packet_num = 0;
505                                         already_waited_sec = 0;
506                                 }
507                                 continue;
508                         case RENEW_REQUESTED:
509                         case REQUESTING:
510                         case RENEWING:
511                         case REBINDING:
512                                 if (*message == DHCPACK) {
513                                         temp = get_option(&packet, DHCP_LEASE_TIME);
514                                         if (!temp) {
515                                                 bb_error_msg("no lease time with ACK, using 1 hour lease");
516                                                 lease_seconds = 60 * 60;
517                                         } else {
518                                                 /* can be misaligned, thus memcpy */
519                                                 memcpy(&lease_seconds, temp, 4);
520                                                 lease_seconds = ntohl(lease_seconds);
521                                                 lease_seconds &= 0x0fffffff; /* paranoia: must not be prone to overflows */
522                                                 if (lease_seconds < 10) /* and not too small */
523                                                         lease_seconds = 10;
524                                         }
525 #if ENABLE_FEATURE_UDHCPC_ARPING
526                                         if (opt & OPT_a) {
527                                                 if (!arpping(packet.yiaddr,
528                                                             (uint32_t) 0,
529                                                             client_config.arp,
530                                                             client_config.interface)
531                                                 ) {
532                                                         bb_info_msg("offered address is in use "
533                                                                 "(got ARP reply), declining");
534                                                         send_decline(xid, server_addr, packet.yiaddr);
535
536                                                         if (state != REQUESTING)
537                                                                 udhcp_run_script(NULL, "deconfig");
538                                                         change_listen_mode(LISTEN_RAW);
539                                                         state = INIT_SELECTING;
540                                                         requested_ip = 0;
541                                                         timeout = tryagain_timeout;
542                                                         packet_num = 0;
543                                                         already_waited_sec = 0;
544                                                         continue; /* back to main loop */
545                                                 }
546                                         }
547 #endif
548                                         /* enter bound state */
549                                         timeout = lease_seconds / 2;
550                                         {
551                                                 struct in_addr temp_addr;
552                                                 temp_addr.s_addr = packet.yiaddr;
553                                                 bb_info_msg("Lease of %s obtained, lease time %u",
554                                                         inet_ntoa(temp_addr), (unsigned)lease_seconds);
555                                         }
556                                         requested_ip = packet.yiaddr;
557                                         udhcp_run_script(&packet,
558                                                    ((state == RENEWING || state == REBINDING) ? "renew" : "bound"));
559
560                                         state = BOUND;
561                                         change_listen_mode(LISTEN_NONE);
562                                         if (opt & OPT_q) { /* quit after lease */
563                                                 if (opt & OPT_R) /* release on quit */
564                                                         perform_release(requested_ip, server_addr);
565                                                 goto ret0;
566                                         }
567 #if BB_MMU /* NOMMU case backgrounded earlier */
568                                         if (!(opt & OPT_f)) {
569                                                 client_background();
570                                                 /* do not background again! */
571                                                 opt = ((opt & ~OPT_b) | OPT_f);
572                                         }
573 #endif
574                                         already_waited_sec = 0;
575                                         continue; /* back to main loop */
576                                 }
577                                 if (*message == DHCPNAK) {
578                                         /* return to init state */
579                                         bb_info_msg("Received DHCP NAK");
580                                         udhcp_run_script(&packet, "nak");
581                                         if (state != REQUESTING)
582                                                 udhcp_run_script(NULL, "deconfig");
583                                         change_listen_mode(LISTEN_RAW);
584                                         sleep(3); /* avoid excessive network traffic */
585                                         state = INIT_SELECTING;
586                                         requested_ip = 0;
587                                         timeout = 0;
588                                         packet_num = 0;
589                                         already_waited_sec = 0;
590                                 }
591                                 continue;
592                         /* case BOUND, RELEASED: - ignore all packets */
593                         }
594                         continue; /* back to main loop */
595                 }
596
597                 /* select() didn't timeout, something did happen.
598                  * But it wasn't a packet. It's a signal pipe then. */
599                 {
600                         int signo = udhcp_sp_read(&rfds);
601                         switch (signo) {
602                         case SIGUSR1:
603                                 perform_renew();
604                                 /* start things over */
605                                 packet_num = 0;
606                                 /* Kill any timeouts because the user wants this to hurry along */
607                                 timeout = 0;
608                                 break;
609                         case SIGUSR2:
610                                 perform_release(requested_ip, server_addr);
611                                 timeout = INT_MAX;
612                                 break;
613                         case SIGTERM:
614                                 bb_info_msg("Received SIGTERM");
615                                 if (opt & OPT_R) /* release on quit */
616                                         perform_release(requested_ip, server_addr);
617                                 goto ret0;
618                         }
619                 }
620         } /* for (;;) - main loop ends */
621
622  ret0:
623         retval = 0;
624  ret:
625         /*if (client_config.pidfile) - remove_pidfile has its own check */
626                 remove_pidfile(client_config.pidfile);
627         return retval;
628 }