aa39c968907abec9bb030521854dcb448d340cbd
[freeradius.git] / src / main / radiusd.c
1 /*
2  * radiusd.c    Main loop of the radius server.
3  *
4  * Version:     $Id$
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2000,2001,2002,2003,2004  The FreeRADIUS server project
21  * Copyright 1999,2000  Miquel van Smoorenburg <miquels@cistron.nl>
22  * Copyright 2000  Alan DeKok <aland@ox.org>
23  * Copyright 2000  Alan Curry <pacman-radius@cqc.com>
24  * Copyright 2000  Jeff Carneal <jeff@apex.net>
25  * Copyright 2000  Chad Miller <cmiller@surfsouth.com>
26  */
27
28 /* don't look here for the version, run radiusd -v or look in version.c */
29 static const char rcsid[] =
30 "$Id$";
31
32 #include <freeradius-devel/autoconf.h>
33
34 #include <sys/file.h>
35
36 #ifdef HAVE_NETINET_IN_H
37 #       include <netinet/in.h>
38 #endif
39
40 #include <stdlib.h>
41 #include <string.h>
42 #include <fcntl.h>
43 #include <ctype.h>
44
45 #ifdef HAVE_UNISTD_H
46 #       include <unistd.h>
47 #endif
48
49 #include <signal.h>
50
51 #ifdef HAVE_GETOPT_H
52 #       include <getopt.h>
53 #endif
54
55 #ifdef HAVE_SYS_SELECT_H
56 #       include <sys/select.h>
57 #endif
58
59 #ifdef HAVE_SYS_WAIT_H
60 #       include <sys/wait.h>
61 #endif
62 #ifndef WEXITSTATUS
63 #       define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
64 #endif
65 #ifndef WIFEXITED
66 #       define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
67 #endif
68
69 #include <freeradius-devel/radiusd.h>
70 #include <freeradius-devel/rad_assert.h>
71 #include <freeradius-devel/conffile.h>
72 #include <freeradius-devel/modules.h>
73 #include <freeradius-devel/request_list.h>
74 #include <freeradius-devel/radius_snmp.h>
75
76 #define SLEEP_FOREVER (65536)
77
78 /*
79  *  Global variables.
80  */
81 const char *progname = NULL;
82 const char *radius_dir = NULL;
83 const char *radacct_dir = NULL;
84 const char *radlog_dir = NULL;
85 const char *radlib_dir = NULL;
86 int log_stripped_names;
87 int debug_flag = 0;
88 int log_auth_detail = FALSE;
89 int need_reload = FALSE;
90
91 const char *radiusd_version = "FreeRADIUS Version " RADIUSD_VERSION ", for host " HOSTINFO ", built on " __DATE__ " at " __TIME__;
92
93 time_t time_now;
94 static pid_t radius_pid;
95
96 /*
97  *  Configuration items.
98  */
99 static int do_exit = 0;
100
101 /*
102  *      Static functions.
103  */
104 static void usage(int);
105
106 static void sig_fatal (int);
107 static void sig_hup (int);
108
109 /*
110  *      The main guy.
111  */
112 int main(int argc, char *argv[])
113 {
114         REQUEST *request;
115         unsigned char buffer[4096];
116         fd_set readfds;
117         int argval;
118         int pid;
119         int max_fd;
120         int status;
121         int sleep_time = SLEEP_FOREVER;
122         int spawn_flag = TRUE;
123         int dont_fork = FALSE;
124         int sig_hup_block = FALSE;
125         time_t last_cleaned_lists = 0;
126
127 #ifdef HAVE_SIGACTION
128         struct sigaction act;
129 #endif
130         rad_listen_t *listener;
131
132 #ifdef OSFC2
133         set_auth_parameters(argc,argv);
134 #endif
135
136         if ((progname = strrchr(argv[0], '/')) == NULL)
137                 progname = argv[0];
138         else
139                 progname++;
140
141         debug_flag = 0;
142         spawn_flag = TRUE;
143         radius_dir = strdup(RADIUS_DIR);
144
145         /*
146          *      Ensure that the configuration is initialized.
147          */
148         memset(&mainconfig, 0, sizeof(mainconfig));
149         mainconfig.myip.af = AF_UNSPEC;
150         mainconfig.port = -1;
151         mainconfig.radiusd_conf = strdup("radiusd.conf");
152
153 #ifdef HAVE_SIGACTION
154         memset(&act, 0, sizeof(act));
155         act.sa_flags = 0 ;
156         sigemptyset( &act.sa_mask ) ;
157 #endif
158
159         /*  Process the options.  */
160         while ((argval = getopt(argc, argv, "Aa:bcd:fg:hi:l:n:p:sSvxXyz")) != EOF) {
161
162                 switch(argval) {
163
164                         case 'A':
165                                 log_auth_detail = TRUE;
166                                 break;
167
168                         case 'a':
169                                 if (radacct_dir) free(radacct_dir);
170                                 radacct_dir = strdup(optarg);
171                                 break;
172
173                         case 'c':
174                                 /* ignore for backwards compatibility with Cistron */
175                                 break;
176
177                         case 'd':
178                                 if (radius_dir) free(radius_dir);
179                                 radius_dir = strdup(optarg);
180                                 break;
181
182                         case 'f':
183                                 dont_fork = TRUE;
184                                 break;
185
186                         case 'h':
187                                 usage(0);
188                                 break;
189
190                         case 'i':
191                                 if (ip_hton(optarg, AF_UNSPEC, &mainconfig.myip) < 0) {
192                                         fprintf(stderr, "radiusd: Invalid IP Address or hostname \"%s\"\n", optarg);
193                                         exit(1);
194                                 }
195                                 break;
196
197                         case 'l':
198                                 if ((strcmp(optarg, "stdout") == 0) ||
199                                     (strcmp(optarg, "stderr") == 0) ||
200                                     (strcmp(optarg, "syslog") == 0)) {
201                                         fprintf(stderr, "radiusd: -l %s is unsupported.  Use log_destination in radiusd.conf\n", optarg);
202                                         exit(1);
203                                 }
204                                 if (radlog_dir) free(radlog_dir);
205                                 radlog_dir = strdup(optarg);
206                                 break;
207
208                         case 'g':
209                                 fprintf(stderr, "radiusd: -g is unsupported.  Use log_destination in radiusd.conf.\n");
210                                 exit(1);
211                                 break;
212
213                         case 'n':
214                                 if ((strchr(optarg, '/') != NULL) ||
215                                     (strchr(optarg, '.') != NULL) ||
216                                     (strlen(optarg) > 45)) usage(1);
217
218                                 snprintf(buffer, sizeof(buffer), "%s.conf",
219                                          optarg);
220                                 if (mainconfig.radiusd_conf)
221                                         free(mainconfig.radiusd_conf);
222                                 mainconfig.radiusd_conf = strdup(buffer);
223                                 break;
224
225                         case 'S':
226                                 log_stripped_names++;
227                                 break;
228
229                         case 'p':
230                                 mainconfig.port = atoi(optarg);
231                                 if ((mainconfig.port <= 0) ||
232                                     (mainconfig.port >= 65536)) {
233                                         fprintf(stderr, "radiusd: Invalid port number %s\n", optarg);
234                                         exit(1);
235                                 }
236                                 break;
237
238                         case 's':       /* Single process mode */
239                                 spawn_flag = FALSE;
240                                 dont_fork = TRUE;
241                                 break;
242
243                         case 'v':
244                                 version();
245                                 break;
246
247                                 /*
248                                  *  BIG debugging mode for users who are
249                                  *  TOO LAZY to type '-sfxxyz -l stdout' themselves.
250                                  */
251                         case 'X':
252                                 spawn_flag = FALSE;
253                                 dont_fork = TRUE;
254                                 debug_flag += 2;
255                                 mainconfig.log_auth = TRUE;
256                                 mainconfig.log_auth_badpass = TRUE;
257                                 mainconfig.log_auth_goodpass = TRUE;
258                                 mainconfig.radlog_dest = RADLOG_STDOUT;
259                                 break;
260
261                         case 'x':
262                                 debug_flag++;
263                                 break;
264
265                         case 'y':
266                                 mainconfig.log_auth = TRUE;
267                                 mainconfig.log_auth_badpass = TRUE;
268                                 break;
269
270                         case 'z':
271                                 mainconfig.log_auth_badpass = TRUE;
272                                 mainconfig.log_auth_goodpass = TRUE;
273                                 break;
274
275                         default:
276                                 usage(1);
277                                 break;
278                 }
279         }
280
281         /*  Read the configuration files, BEFORE doing anything else.  */
282         if (read_mainconfig(0) < 0) {
283                 exit(1);
284         }
285
286         /*
287          *  Disconnect from session
288          */
289         if (debug_flag == 0 && dont_fork == FALSE) {
290                 pid = fork();
291                 if(pid < 0) {
292                         radlog(L_ERR|L_CONS, "Couldn't fork");
293                         exit(1);
294                 }
295
296                 /*
297                  *  The parent exits, so the child can run in the background.
298                  */
299                 if (pid > 0) {
300                         exit(0);
301                 }
302 #ifdef HAVE_SETSID
303                 setsid();
304 #endif
305         }
306
307         /*
308          *      If we're NOT debugging, trap fatal signals, so we can
309          *      easily clean up after ourselves.
310          *
311          *      If we ARE debugging, don't trap them, so we can
312          *      dump core.
313          */
314         if ((mainconfig.allow_core_dumps == FALSE) && (debug_flag == 0)) {
315 #ifdef SIGSEGV
316 #ifdef HAVE_SIGACTION
317                 act.sa_handler = sig_fatal;
318                 sigaction(SIGSEGV, &act, NULL);
319 #else
320                 signal(SIGSEGV, sig_fatal);
321 #endif
322 #endif
323         }
324
325 #ifdef WITH_SNMP
326         if (mainconfig.do_snmp) radius_snmp_init();
327 #endif
328
329         /*
330          *  Ensure that we're using the CORRECT pid after forking,
331          *  NOT the one we started with.
332          */
333         radius_pid = getpid();
334
335
336         /*
337          *  Only write the PID file if we're running as a daemon.
338          *
339          *  And write it AFTER we've forked, so that we write the
340          *  correct PID.
341          */
342         if (dont_fork == FALSE) {
343                 FILE *fp;
344
345                 fp = fopen(mainconfig.pid_file, "w");
346                 if (fp != NULL) {
347                         /*
348                          *      FIXME: What about following symlinks,
349                          *      and having it over-write a normal file?
350                          */
351                         fprintf(fp, "%d\n", (int) radius_pid);
352                         fclose(fp);
353                 } else {
354                         radlog(L_ERR|L_CONS, "Failed creating PID file %s: %s\n",
355                                mainconfig.pid_file, strerror(errno));
356                         exit(1);
357                 }
358         }
359
360         /*
361          *      If we're running as a daemon, close the default file
362          *      descriptors, AFTER forking.
363          */
364         mainconfig.radlog_fd = -1;
365         if (debug_flag) {
366                 mainconfig.radlog_fd = STDOUT_FILENO;
367         } else {
368                 int devnull;
369
370                 devnull = open("/dev/null", O_RDWR);
371                 if (devnull < 0) {
372                         radlog(L_ERR|L_CONS, "Failed opening /dev/null: %s\n",
373                                strerror(errno));
374                         exit(1);
375                 }
376                 dup2(devnull, STDIN_FILENO);
377                 if (mainconfig.radlog_dest == RADLOG_STDOUT) {
378                         mainconfig.radlog_fd = dup(STDOUT_FILENO);
379                 }
380                 dup2(devnull, STDOUT_FILENO);
381                 if (mainconfig.radlog_dest == RADLOG_STDERR) {
382                         mainconfig.radlog_fd = dup(STDERR_FILENO);
383                 }
384                 dup2(devnull, STDERR_FILENO);
385                 close(devnull);
386         }
387
388         /*
389          *      It's called the thread pool, but it does a little
390          *      more than that.
391          */
392         thread_pool_init(spawn_flag);
393
394         /*
395          *  Use linebuffered or unbuffered stdout if
396          *  the debug flag is on.
397          */
398         if (debug_flag == TRUE)
399                 setlinebuf(stdout);
400
401         /*
402          *      Print out which ports we're listening on.
403          */
404         for (listener = mainconfig.listen;
405              listener != NULL;
406              listener = listener->next) {
407                 listener->print(listener, buffer, sizeof(buffer));
408                 switch (listener->type) {
409                 case RAD_LISTEN_AUTH:
410                         DEBUG("Listening on authentication address %s", buffer);
411                         break;
412
413                 case RAD_LISTEN_ACCT:
414                         DEBUG("Listening on accounting address %s", buffer);
415                         break;
416
417                 case RAD_LISTEN_PROXY:
418                         DEBUG("Listening on proxy address %s", buffer);
419                         break;
420
421                 case RAD_LISTEN_DETAIL:
422                         DEBUG("Listening on detail file %s", buffer);
423                         break;
424
425                 default:
426                         break;
427                 }
428         }
429
430         /*
431          *      Now that we've set everything up, we can install the signal
432          *      handlers.  Before this, if we get any signal, we don't know
433          *      what to do, so we might as well do the default, and die.
434          */
435         signal(SIGPIPE, SIG_IGN);
436 #ifdef HAVE_SIGACTION
437         act.sa_handler = sig_hup;
438         sigaction(SIGHUP, &act, NULL);
439         act.sa_handler = sig_fatal;
440         sigaction(SIGTERM, &act, NULL);
441 #else
442         signal(SIGHUP, sig_hup);
443         signal(SIGTERM, sig_fatal);
444 #endif
445         /*
446          *      If we're debugging, then a CTRL-C will cause the
447          *      server to die immediately.  Use SIGTERM to shut down
448          *      the server cleanly in that case.
449          */
450         if (debug_flag == 0) {
451 #ifdef HAVE_SIGACTION
452                 act.sa_handler = sig_fatal;
453                 sigaction(SIGINT, &act, NULL);
454                 sigaction(SIGQUIT, &act, NULL);
455 #else
456                 signal(SIGINT, sig_fatal);
457                 signal(SIGQUIT, sig_fatal);
458 #endif
459         }
460
461         radlog(L_INFO, "Ready to process requests.");
462
463         /*
464          *  Receive user requests
465          */
466         for (;;) {
467                 /*
468                  *      If we've been told to exit, then do so,
469                  *      even if we have data waiting.
470                  */
471                 if (do_exit) {
472                         DEBUG("Exiting...");
473
474                         /*
475                          *      Ignore the TERM signal: we're about
476                          *      to die.
477                          */
478                         signal(SIGTERM, SIG_IGN);
479
480                         /*
481                          *      Send a TERM signal to all associated
482                          *      processes (including us, which gets
483                          *      ignored.)
484                          */
485                         kill(-radius_pid, SIGTERM);
486
487                         /*
488                          *      FIXME: Kill child threads, and
489                          *      clean up?
490                          */
491
492                         /*
493                          *      Detach any modules.
494                          */
495                         detach_modules();
496
497                         /*
498                          *      FIXME: clean up any active REQUEST
499                          *      handles.
500                          */
501
502                         /*
503                          *      We're exiting, so we can delete the PID
504                          *      file.  (If it doesn't exist, we can ignore
505                          *      the error returned by unlink)
506                          */
507                         if (dont_fork == FALSE) {
508                                 unlink(mainconfig.pid_file);
509                         }
510
511                         /*
512                          *      Free the configuration items.
513                          */
514                         free_mainconfig();
515
516                         /*
517                          *      SIGTERM gets do_exit=0,
518                          *      and we want to exit cleanly.
519                          *
520                          *      Other signals make us exit
521                          *      with an error status.
522                          */
523                         exit(do_exit - 1);
524                 }
525
526                 if (need_reload) {
527 #ifdef HAVE_PTHREAD_H
528                         /*
529                          *      Threads: wait for all threads to stop
530                          *      processing before re-loading the
531                          *      config, so we don't pull the rug out
532                          *      from under them.
533                          */
534                         int max_wait = 0;
535                         if (spawn_flag) for(;;) {
536                                 /*
537                                  * Block until there are '0' threads
538                                  * with a REQUEST handle.
539                                  */
540                                 sig_hup_block = TRUE;
541                                 if( (total_active_threads() == 0) ||
542                                     (max_wait >= 5) ) {
543                                         sig_hup_block = FALSE;
544                                         break;
545                                 }
546                                 sleep(1);
547                                 max_wait++;
548                         }
549 #endif
550                         if (read_mainconfig(TRUE) < 0) {
551                                 exit(1);
552                         }
553
554                         need_reload = FALSE;
555                         radlog(L_INFO, "Ready to process requests.");
556                 }
557
558                 FD_ZERO(&readfds);
559                 max_fd = 0;
560
561                 /*
562                  *      Loop over all the listening FD's.
563                  */
564                 for (listener = mainconfig.listen;
565                      listener != NULL;
566                      listener = listener->next) {
567                         if (listener->fd < 0) continue;
568
569                         FD_SET(listener->fd, &readfds);
570                         if (listener->fd > max_fd) max_fd = listener->fd;
571                 }
572
573 #ifdef WITH_SNMP
574                 if (mainconfig.do_snmp &&
575                     (rad_snmp.smux_fd >= 0)) {
576                         FD_SET(rad_snmp.smux_fd, &readfds);
577                         if (rad_snmp.smux_fd > max_fd) max_fd = rad_snmp.smux_fd;
578                 }
579 #endif
580
581                 if (sleep_time == SLEEP_FOREVER) {
582                         DEBUG2("Nothing to do.  Sleeping until we see a request.");
583                         status = select(max_fd + 1, &readfds, NULL, NULL, NULL);
584                 } else {
585                         struct timeval tv;
586
587                         DEBUG2("Waking up in %d seconds...", sleep_time);
588
589                         tv.tv_sec = sleep_time;
590                         tv.tv_usec = 0;
591                         status = select(max_fd + 1, &readfds, NULL, NULL, &tv);
592                 }
593                 if (status == -1) {
594                         /*
595                          *      On interrupts, we clean up the request
596                          *      list.  We then continue with the loop,
597                          *      so that if we're supposed to exit,
598                          *      then the code at the start of the loop
599                          *      catches that, and exits.
600                          */
601                         if (errno == EINTR) {
602 #ifdef MEMORY_USE_DEBUGGING
603                                 /*
604                                  *      Run the server in debugging mode,
605                                  *      without threads, and give it a
606                                  *      SIGHUP.  It will clean up after
607                                  *      itself, and any memory left over
608                                  *      should be allocated by C libraries,
609                                  *      and the like.
610                                  */
611                                 detach_modules();
612                                 free_mainconfig();
613                                 xlat_free();
614                                 dict_free();
615                                 exit(1);
616 #endif
617                                 continue;
618                         }
619                         radlog(L_ERR, "Unexpected error in select(): %s",
620                                         strerror(errno));
621                         exit(1);
622                 }
623
624                 time_now = time(NULL);
625 #ifndef HAVE_PTHREAD_H
626                 /*
627                  *      If there are no child threads, then there may
628                  *      be child processes.  In that case, wait for
629                  *      their exit status, and throw that exit status
630                  *      away.  This helps get rid of zxombie children.
631                  */
632                 while (waitpid(-1, &argval, WNOHANG) > 0) {
633                         /* do nothing */
634                 }
635 #endif
636
637                 /*
638                  *      Loop over the open socket FD's, reading any data.
639                  */
640                 for (listener = mainconfig.listen;
641                      listener != NULL;
642                      listener = listener->next) {
643                         RAD_REQUEST_FUNP fun;
644
645                         if ((listener->fd >= 0) &&
646                             !FD_ISSET(listener->fd, &readfds))
647                                 continue;
648
649                         /*
650                          *  Receive the packet.
651                          */
652                         if (sig_hup_block != FALSE) {
653                                 continue;
654                         }
655
656                         /*
657                          *      Do per-socket receive processing of the
658                          *      packet.
659                          */
660                         if (!listener->recv(listener, &fun, &request)) {
661                                 continue;
662                         }
663                         
664                         /*
665                          *      Drop the request into the thread pool,
666                          *      and let the thread pool take care of
667                          *      doing something with it.
668                          */
669                         if (!thread_pool_addrequest(request, fun)) {
670                                 /*
671                                  *      FIXME: Maybe just drop
672                                  *      the packet on the floor?
673                                  */
674                                 request_reject(request, REQUEST_FAIL_NO_THREADS);
675                                 request->finished = TRUE;
676                         }
677                 } /* loop over listening sockets*/
678
679 #ifdef WITH_SNMP
680                 if (mainconfig.do_snmp) {
681                         /*
682                          *  After handling all authentication/accounting
683                          *  requests, THEN process any pending SMUX/SNMP
684                          *  queries.
685                          *
686                          *  Note that the handling is done in the main server,
687                          *  which probably isn't a Good Thing.  It really
688                          *  should be wrapped, and handled in a thread pool.
689                          */
690                         if ((rad_snmp.smux_fd >= 0) &&
691                             FD_ISSET(rad_snmp.smux_fd, &readfds) &&
692                             (rad_snmp.smux_event == SMUX_READ)) {
693                                 smux_read();
694                         }
695
696                         /*
697                          *  If we've got to re-connect, then do so now,
698                          *  before calling select again.
699                          */
700                         if (rad_snmp.smux_event == SMUX_CONNECT) {
701                                 smux_connect();
702                         }
703                 }
704 #endif
705
706                 /*
707                  *      Loop through the request lists once per
708                  *      second, to clean up old requests.
709                  */
710                 if (last_cleaned_lists != time_now) {
711                         last_cleaned_lists = time_now;
712
713                         DEBUG2("--- Walking the entire request list ---");
714                         sleep_time = SLEEP_FOREVER;
715                         for (listener = mainconfig.listen;
716                              listener != NULL;
717                              listener = listener->next) {
718                                 int next;
719                                 
720                                 next = listener->update(listener, time_now);
721                                 if (next < sleep_time) {
722                                         sleep_time = next;
723                                 }
724                         }
725                 }
726
727 #ifdef HAVE_PTHREAD_H
728
729                 /*
730                  *      Only clean the thread pool if we're spawning
731                  *      child threads. 
732                  */
733                 if (spawn_flag) {
734                         thread_pool_clean(time_now);
735                 }
736 #endif
737         } /* loop forever */
738 }
739
740
741 /*
742  *  Display the syntax for starting this program.
743  */
744 static void NEVER_RETURNS usage(int status)
745 {
746         FILE *output = status?stderr:stdout;
747
748         fprintf(output,
749                         "Usage: %s [-a acct_dir] [-d db_dir] [-l log_dir] [-i address] [-AcfnsSvXxyz]\n", progname);
750         fprintf(output, "Options:\n\n");
751         fprintf(output, "  -a acct_dir     use accounting directory 'acct_dir'.\n");
752         fprintf(output, "  -A              Log auth detail.\n");
753         fprintf(output, "  -d raddb_dir    Configuration files are in \"raddbdir/*\".\n");
754         fprintf(output, "  -f              Run as a foreground process, not a daemon.\n");
755         fprintf(output, "  -h              Print this help message.\n");
756         fprintf(output, "  -i ipaddr       Listen on ipaddr ONLY\n");
757         fprintf(output, "  -l log_dir      Log file is \"log_dir/radius.log\" (not used in debug mode)\n");
758         fprintf(output, "  -p port         Listen on port ONLY\n");
759         fprintf(output, "  -s              Do not spawn child processes to handle requests.\n");
760         fprintf(output, "  -S              Log stripped names.\n");
761         fprintf(output, "  -v              Print server version information.\n");
762         fprintf(output, "  -X              Turn on full debugging.\n");
763         fprintf(output, "  -x              Turn on additional debugging. (-xx gives more debugging).\n");
764         fprintf(output, "  -y              Log authentication failures, with password.\n");
765         fprintf(output, "  -z              Log authentication successes, with password.\n");
766         exit(status);
767 }
768
769
770 /*
771  *      We got a fatal signal.
772  */
773 static void sig_fatal(int sig)
774 {
775         switch(sig) {
776                 case SIGSEGV:
777                         /* We can't really do anything intelligent here so just die */
778                         _exit(1);
779                 case SIGTERM:
780                         do_exit = 1;
781                         break;
782                 default:
783                         do_exit = 2;
784                         break;
785         }
786 }
787
788
789 /*
790  *  We got the hangup signal.
791  *  Re-read the configuration files.
792  */
793 /*ARGSUSED*/
794 static void sig_hup(int sig)
795 {
796         sig = sig; /* -Wunused */
797
798         reset_signal(SIGHUP, sig_hup);
799
800         /*
801          *  Only do the reload if we're the main server, both
802          *  for processes, and for threads.
803          */
804         if (getpid() == radius_pid) {
805                 need_reload = TRUE;
806         }
807 #ifdef WITH_SNMP
808         if (mainconfig.do_snmp) {
809                 rad_snmp.smux_failures = 0;
810                 rad_snmp.smux_event = SMUX_CONNECT;
811         }
812 #endif
813 }