/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:26:19 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090209192619-7rse82x9pypq4ihk
* plugin-runner.c: Comment change.

* plugins.d/mandos-client.c: Comment changes.
  (quit_now): New global flag.
  (handle_sigterm): Only call avahi_simple_poll_quit once.
  (main): Also handle SIGINT and SIGHUP.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
                                   argp_parse(), ARGP_KEY_ARG,
77
77
                                   ARGP_KEY_END, ARGP_ERR_UNKNOWN */
78
78
#include <signal.h>             /* sigemptyset(), sigaddset(),
79
 
                                   sigaction(), SIGTERM, sigaction */
 
79
                                   sigaction(), SIGTERM, sigaction,
 
80
                                   sig_atomic_t */
80
81
 
81
82
#ifdef __linux__
82
83
#include <sys/klog.h>           /* klogctl() */
83
 
#endif
 
84
#endif  /* __linux__ */
84
85
 
85
86
/* Avahi */
86
87
/* All Avahi types, constants and functions
136
137
mandos_context mc;
137
138
 
138
139
/*
139
 
 * Make additional room in "buffer" for at least BUFFER_SIZE
140
 
 * additional bytes. "buffer_capacity" is how much is currently
141
 
 * allocated, "buffer_length" is how much is already used.
 
140
 * Make additional room in "buffer" for at least BUFFER_SIZE more
 
141
 * bytes. "buffer_capacity" is how much is currently allocated,
 
142
 * "buffer_length" is how much is already used.
142
143
 */
143
144
size_t incbuffer(char **buffer, size_t buffer_length,
144
145
                  size_t buffer_capacity){
871
872
  }
872
873
}
873
874
 
 
875
sig_atomic_t quit_now = 0;
 
876
 
874
877
static void handle_sigterm(__attribute__((unused)) int sig){
 
878
  if(quit_now){
 
879
    return;
 
880
  }
 
881
  quit_now = 1;
875
882
  int old_errno = errno;
876
 
  avahi_simple_poll_quit(mc.simple_poll);
 
883
  if(mc.simple_poll != NULL){
 
884
    avahi_simple_poll_quit(mc.simple_poll);
 
885
  }
877
886
  errno = old_errno;
878
887
}
879
888
 
1014
1023
      restore_loglevel = false;
1015
1024
      perror("klogctl");
1016
1025
    }
1017
 
#endif
 
1026
#endif  /* __linux__ */
1018
1027
    
1019
1028
    sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
1020
1029
    if(sd < 0){
1027
1036
          perror("klogctl");
1028
1037
        }
1029
1038
      }
1030
 
#endif
 
1039
#endif  /* __linux__ */
1031
1040
      goto end;
1032
1041
    }
1033
1042
    strcpy(network.ifr_name, interface);
1041
1050
          perror("klogctl");
1042
1051
        }
1043
1052
      }
1044
 
#endif
 
1053
#endif  /* __linux__ */
1045
1054
      exitcode = EXIT_FAILURE;
1046
1055
      goto end;
1047
1056
    }
1058
1067
            perror("klogctl");
1059
1068
          }
1060
1069
        }
1061
 
#endif
 
1070
#endif  /* __linux__ */
1062
1071
        goto end;
1063
1072
      }
1064
1073
    }
1088
1097
        perror("klogctl");
1089
1098
      }
1090
1099
    }
1091
 
#endif
 
1100
#endif  /* __linux__ */
1092
1101
  }
1093
1102
  
1094
1103
  uid = getuid();
1226
1235
  }
1227
1236
  
1228
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
  }
1229
1250
  ret = sigaddset(&sigterm_action.sa_mask, SIGTERM);
1230
1251
  if(ret == -1){
1231
1252
    perror("sigaddset");