/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/password-prompt.c

  • Committer: Teddy Hogeborn
  • Date: 2009-09-04 16:32:22 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090904163222-l9wp25ng1e5ym0yq
* plugin-runner.c (main): When a plugin is killed by a signal, show
                          the signal name, not just the number, in the
                          debug log message.

* plugins.d/password-prompt.c (termination_handler): Store received
                                                     signal in
                                                     "signal_received".
  (main): If exiting due to signal, re-raise signal received instead
          of returning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- coding: utf-8 -*- */
 
1
/*  -*- coding: utf-8; mode: c; mode: orgtbl -*- */
2
2
/*
3
3
 * Password-prompt - Read a password from the terminal and print it
4
4
 * 
33
33
#include <signal.h>             /* sig_atomic_t, raise(), struct
34
34
                                   sigaction, sigemptyset(),
35
35
                                   sigaction(), sigaddset(), SIGINT,
36
 
                                   SIGQUIT, SIGHUP, SIGTERM */
 
36
                                   SIGQUIT, SIGHUP, SIGTERM,
 
37
                                   raise() */
37
38
#include <stddef.h>             /* NULL, size_t, ssize_t */
38
39
#include <sys/types.h>          /* ssize_t */
39
40
#include <stdlib.h>             /* EXIT_SUCCESS, EXIT_FAILURE,
52
53
                                   ARGP_ERR_UNKNOWN */
53
54
 
54
55
volatile sig_atomic_t quit_now = 0;
 
56
int signal_received;
55
57
bool debug = false;
56
58
const char *argp_program_version = "password-prompt " VERSION;
57
59
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
58
60
 
59
 
static void termination_handler(__attribute__((unused))int signum){
 
61
static void termination_handler(int signum){
 
62
  if(quit_now){
 
63
    return;
 
64
  }
60
65
  quit_now = 1;
 
66
  signal_received = signum;
61
67
}
62
68
 
63
69
int main(int argc, char **argv){
131
137
    perror("sigaction");
132
138
    return EXIT_FAILURE;
133
139
  }
 
140
  /* Need to check if the handler is SIG_IGN before handling:
 
141
     | [[info:libc:Initial Signal Actions]] |
 
142
     | [[info:libc:Basic Signal Handling]]  |
 
143
  */
134
144
  if(old_action.sa_handler != SIG_IGN){
135
145
    ret = sigaction(SIGINT, &new_action, NULL);
136
146
    if(ret == -1){
194
204
      const char *cryptsource = getenv("cryptsource");
195
205
      const char *crypttarget = getenv("crypttarget");
196
206
      const char *const prompt
197
 
        = "Enter passphrase to unlock the disk";      
 
207
        = "Enter passphrase to unlock the disk";
198
208
      if(cryptsource == NULL){
199
209
        if(crypttarget == NULL){
200
210
          fprintf(stderr, "%s: ", prompt);
242
252
    /* if(ret == 0), then the only sensible thing to do is to retry to
243
253
       read from stdin */
244
254
    fputc('\n', stderr);
245
 
    if(debug and quit_now == 0){
 
255
    if(debug and not quit_now){
246
256
      /* If quit_now is nonzero, we were interrupted by a signal, and
247
257
         will print that later, so no need to show this too. */
248
258
      fprintf(stderr, "getline() returned 0, retrying.\n");
258
268
    perror("tcsetattr+echo");
259
269
  }
260
270
  
 
271
  if(quit_now){
 
272
    sigemptyset(&old_action.sa_mask);
 
273
    old_action.sa_handler = SIG_DFL;
 
274
    ret = sigaction(signal_received, &old_action, NULL);
 
275
    if(ret == -1){
 
276
      perror("sigaction");
 
277
    }
 
278
    raise(signal_received);
 
279
  }
 
280
  
261
281
  if(debug){
262
282
    fprintf(stderr, "%s is exiting with status %d\n", argv[0],
263
283
            status);