/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-02-09 19:33:46 UTC
  • mfrom: (24.1.135 mandos)
  • Revision ID: teddy@fukt.bsnet.se-20090209193346-5insyr1rsisor8dj
Merge from Björn:

* plugins.d/mandos-client.c (mc): Initialize globally.
  (main): Better handling of signals.

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
} mandos_context;
135
135
 
136
136
/* global context so signal handler can reach it*/
137
 
mandos_context mc;
 
137
mandos_context mc = { .simple_poll = NULL, .server = NULL,
 
138
                      .dh_bits = 1024, .priority = "SECURE256"
 
139
                      ":!CTYPE-X.509:+CTYPE-OPENPGP" };
138
140
 
139
141
/*
140
142
 * Make additional room in "buffer" for at least BUFFER_SIZE more
874
876
 
875
877
sig_atomic_t quit_now = 0;
876
878
 
 
879
/* stop main loop after sigterm has been called */
877
880
static void handle_sigterm(__attribute__((unused)) int sig){
878
881
  if(quit_now){
879
882
    return;
1012
1015
    }
1013
1016
  }
1014
1017
  
 
1018
  if(not debug){
 
1019
    avahi_set_log_function(empty_log);
 
1020
  }
 
1021
  
 
1022
  /* Initialize Avahi early so avahi_simple_poll_quit() can be called
 
1023
     from the signal handler */
 
1024
  /* Initialize the pseudo-RNG for Avahi */
 
1025
  srand((unsigned int) time(NULL));
 
1026
  mc.simple_poll = avahi_simple_poll_new();
 
1027
  if(mc.simple_poll == NULL){
 
1028
    fprintf(stderr, "Avahi: Failed to create simple poll object.\n");
 
1029
    exitcode = EXIT_FAILURE;
 
1030
    goto end;
 
1031
  }
 
1032
  
 
1033
  sigemptyset(&sigterm_action.sa_mask);
 
1034
  ret = sigaddset(&sigterm_action.sa_mask, SIGINT);
 
1035
  if(ret == -1){
 
1036
    perror("sigaddset");
 
1037
    exitcode = EXIT_FAILURE;
 
1038
    goto end;
 
1039
  }
 
1040
  ret = sigaddset(&sigterm_action.sa_mask, SIGHUP);
 
1041
  if(ret == -1){
 
1042
    perror("sigaddset");
 
1043
    exitcode = EXIT_FAILURE;
 
1044
    goto end;
 
1045
  }
 
1046
  ret = sigaddset(&sigterm_action.sa_mask, SIGTERM);
 
1047
  if(ret == -1){
 
1048
    perror("sigaddset");
 
1049
    exitcode = EXIT_FAILURE;
 
1050
    goto end;
 
1051
  }
 
1052
  ret = sigaction(SIGTERM, &sigterm_action, &old_sigterm_action);
 
1053
  if(ret == -1){
 
1054
    perror("sigaction");
 
1055
    exitcode = EXIT_FAILURE;
 
1056
    goto end;
 
1057
  }  
 
1058
  
1015
1059
  /* If the interface is down, bring it up */
1016
1060
  if(interface[0] != '\0'){
1017
1061
#ifdef __linux__
1181
1225
    }
1182
1226
    goto end;
1183
1227
  }
1184
 
  
1185
 
  if(not debug){
1186
 
    avahi_set_log_function(empty_log);
1187
 
  }
1188
 
  
1189
 
  /* Initialize the pseudo-RNG for Avahi */
1190
 
  srand((unsigned int) time(NULL));
1191
 
  
1192
 
  /* Allocate main Avahi loop object */
1193
 
  mc.simple_poll = avahi_simple_poll_new();
1194
 
  if(mc.simple_poll == NULL){
1195
 
    fprintf(stderr, "Avahi: Failed to create simple poll object.\n");
1196
 
    exitcode = EXIT_FAILURE;
1197
 
    goto end;
1198
 
  }
1199
 
  
 
1228
    
1200
1229
  {
1201
1230
    AvahiServerConfig config;
1202
1231
    /* Do not publish any local Zeroconf records */
1234
1263
    goto end;
1235
1264
  }
1236
1265
  
1237
 
  sigemptyset(&sigterm_action.sa_mask);
1238
 
  ret = sigaddset(&sigterm_action.sa_mask, SIGINT);
1239
 
  if(ret == -1){
1240
 
    perror("sigaddset");
1241
 
    exitcode = EXIT_FAILURE;
1242
 
    goto end;
1243
 
  }
1244
 
  ret = sigaddset(&sigterm_action.sa_mask, SIGHUP);
1245
 
  if(ret == -1){
1246
 
    perror("sigaddset");
1247
 
    exitcode = EXIT_FAILURE;
1248
 
    goto end;
1249
 
  }
1250
 
  ret = sigaddset(&sigterm_action.sa_mask, SIGTERM);
1251
 
  if(ret == -1){
1252
 
    perror("sigaddset");
1253
 
    exitcode = EXIT_FAILURE;
1254
 
    goto end;
1255
 
  }
1256
 
  ret = sigaction(SIGTERM, &sigterm_action, &old_sigterm_action);
1257
 
  if(ret == -1){
1258
 
    perror("sigaction");
1259
 
    exitcode = EXIT_FAILURE;
1260
 
    goto end;
1261
 
  }  
1262
 
  
1263
1266
  /* Run the main loop */
1264
1267
  
1265
1268
  if(debug){