/mandos/release

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

« back to all changes in this revision

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

* plugins.d/mandos-client.c (quit_now): Move up declaration before
                                        first use.
  (resolve_callback, ): Check "quit_now" flag.
  (main): Renamed "interface_taken_up" to "take_down_interface" for
          clarity.  Check existence of interface before taking it up.
          Set "take_down_interface" and "tempdir_created" flags before
          any action is taken, to make sure cleanup is never missed.
          Check "quit_now" flag throughout.

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, sig_atomic_t,
84
 
                                   raise() */
 
83
                                   sigaction(), SIGTERM, sigaction,
 
84
                                   sig_atomic_t */
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
 
 
520
517
/* Called when a Mandos server is found */
521
518
static int start_mandos_communication(const char *ip, uint16_t port,
522
519
                                      AvahiIfIndex if_index,
783
780
  return retval;
784
781
}
785
782
 
 
783
sig_atomic_t quit_now = 0;
 
784
 
786
785
static void resolve_callback(AvahiSServiceResolver *r,
787
786
                             AvahiIfIndex interface,
788
787
                             AvahiProtocol proto,
883
882
}
884
883
 
885
884
/* stop main loop after sigterm has been called */
886
 
static void handle_sigterm(int sig){
 
885
static void handle_sigterm(__attribute__((unused)) int sig){
887
886
  if(quit_now){
888
887
    return;
889
888
  }
890
889
  quit_now = 1;
891
 
  signal_received = sig;
892
890
  int old_errno = errno;
893
891
  if(mc.simple_poll != NULL){
894
892
    avahi_simple_poll_quit(mc.simple_poll);
1055
1053
    exitcode = EXIT_FAILURE;
1056
1054
    goto end;
1057
1055
  }
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
 
  }
 
1056
  ret = sigaction(SIGTERM, &sigterm_action, &old_sigterm_action);
 
1057
  if(ret == -1){
 
1058
    perror("sigaction");
 
1059
    exitcode = EXIT_FAILURE;
 
1060
    goto end;
 
1061
  }  
1076
1062
  
1077
1063
  /* If the interface is down, bring it up */
1078
1064
  if(interface[0] != '\0'){
1433
1419
    }
1434
1420
  }
1435
1421
  
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
 
  
1444
1422
  return exitcode;
1445
1423
}