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