/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2009-08-30 02:49:46 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090830024946-bfr985x8kmrep11j
* plugins.d/mandos-client.c (signal_received): New.
  (handle_sigterm): Save signal received.
  (main): Also set handler for SIGINT and SIGHUP.  If exiting due to
          signal, re-raise signal received instead of returning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
                                   argp_parse(), ARGP_KEY_ARG,
81
81
                                   ARGP_KEY_END, ARGP_ERR_UNKNOWN */
82
82
#include <signal.h>             /* sigemptyset(), sigaddset(),
83
 
                                   sigaction(), SIGTERM, sigaction,
84
 
                                   sig_atomic_t */
 
83
                                   sigaction(), SIGTERM, sig_atomic_t,
 
84
                                   raise() */
85
85
 
86
86
#ifdef __linux__
87
87
#include <sys/klog.h>           /* klogctl() */
514
514
static void empty_log(__attribute__((unused)) AvahiLogLevel level,
515
515
                      __attribute__((unused)) const char *txt){}
516
516
 
 
517
sig_atomic_t quit_now = 0;
 
518
int signal_received = 0;
 
519
 
517
520
/* Called when a Mandos server is found */
518
521
static int start_mandos_communication(const char *ip, uint16_t port,
519
522
                                      AvahiIfIndex if_index,
780
783
  return retval;
781
784
}
782
785
 
783
 
sig_atomic_t quit_now = 0;
784
 
 
785
786
static void resolve_callback(AvahiSServiceResolver *r,
786
787
                             AvahiIfIndex interface,
787
788
                             AvahiProtocol proto,
882
883
}
883
884
 
884
885
/* stop main loop after sigterm has been called */
885
 
static void handle_sigterm(__attribute__((unused)) int sig){
 
886
static void handle_sigterm(int sig){
886
887
  if(quit_now){
887
888
    return;
888
889
  }
889
890
  quit_now = 1;
 
891
  signal_received = sig;
890
892
  int old_errno = errno;
891
893
  if(mc.simple_poll != NULL){
892
894
    avahi_simple_poll_quit(mc.simple_poll);
1053
1055
    exitcode = EXIT_FAILURE;
1054
1056
    goto end;
1055
1057
  }
1056
 
  ret = sigaction(SIGTERM, &sigterm_action, &old_sigterm_action);
1057
 
  if(ret == -1){
1058
 
    perror("sigaction");
1059
 
    exitcode = EXIT_FAILURE;
1060
 
    goto end;
1061
 
  }  
 
1058
  ret = sigaction(SIGINT, &sigterm_action, &old_sigterm_action);
 
1059
  if(ret == -1){
 
1060
    perror("sigaction");
 
1061
    exitcode = EXIT_FAILURE;
 
1062
    goto end;
 
1063
  }
 
1064
  ret = sigaction(SIGHUP, &sigterm_action, NULL);
 
1065
  if(ret == -1){
 
1066
    perror("sigaction");
 
1067
    exitcode = EXIT_FAILURE;
 
1068
    goto end;
 
1069
  }
 
1070
  ret = sigaction(SIGTERM, &sigterm_action, NULL);
 
1071
  if(ret == -1){
 
1072
    perror("sigaction");
 
1073
    exitcode = EXIT_FAILURE;
 
1074
    goto end;
 
1075
  }
1062
1076
  
1063
1077
  /* If the interface is down, bring it up */
1064
1078
  if(interface[0] != '\0'){
1419
1433
    }
1420
1434
  }
1421
1435
  
 
1436
  if(quit_now){
 
1437
    ret = sigaction(signal_received, &old_sigterm_action, NULL);
 
1438
    if(ret == -1){
 
1439
      perror("sigaction");
 
1440
    }
 
1441
    raise(signal_received);
 
1442
  }
 
1443
  
1422
1444
  return exitcode;
1423
1445
}