/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-27 23:12:09 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090827231209-ry9loqws0gr7ze4g
* 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:
44
44
#include <stdint.h>             /* uint16_t, uint32_t */
45
45
#include <stddef.h>             /* NULL, size_t, ssize_t */
46
46
#include <stdlib.h>             /* free(), EXIT_SUCCESS, EXIT_FAILURE,
47
 
                                   srand(), strtof(), abort() */
 
47
                                   srand(), strtof() */
48
48
#include <stdbool.h>            /* bool, false, true */
49
49
#include <string.h>             /* memset(), strcmp(), strlen(),
50
50
                                   strerror(), asprintf(), strcpy() */
71
71
                                   INET_ADDRSTRLEN, INET6_ADDRSTRLEN
72
72
                                */
73
73
#include <unistd.h>             /* close(), SEEK_SET, off_t, write(),
74
 
                                   getuid(), getgid(), seteuid(),
75
 
                                   setgid(), pause() */
 
74
                                   getuid(), getgid(), setuid(),
 
75
                                   setgid() */
76
76
#include <arpa/inet.h>          /* inet_pton(), htons */
77
77
#include <iso646.h>             /* not, or, and */
78
78
#include <argp.h>               /* struct argp_option, error_t, struct
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() */
142
142
                      .dh_bits = 1024, .priority = "SECURE256"
143
143
                      ":!CTYPE-X.509:+CTYPE-OPENPGP" };
144
144
 
145
 
sig_atomic_t quit_now = 0;
146
 
int signal_received = 0;
147
 
 
148
145
/*
149
146
 * Make additional room in "buffer" for at least BUFFER_SIZE more
150
147
 * bytes. "buffer_capacity" is how much is currently allocated,
167
164
 */
168
165
static bool init_gpgme(const char *seckey,
169
166
                       const char *pubkey, const char *tempdir){
 
167
  int ret;
170
168
  gpgme_error_t rc;
171
169
  gpgme_engine_info_t engine_info;
172
170
  
175
173
   * Helper function to insert pub and seckey to the engine keyring.
176
174
   */
177
175
  bool import_key(const char *filename){
178
 
    int ret;
179
176
    int fd;
180
177
    gpgme_data_t pgp_data;
181
178
    
252
249
    return false;
253
250
  }
254
251
  
255
 
  return true;
 
252
  return true; 
256
253
}
257
254
 
258
255
/* 
477
474
static int init_gnutls_session(gnutls_session_t *session){
478
475
  int ret;
479
476
  /* GnuTLS session creation */
480
 
  do {
481
 
    ret = gnutls_init(session, GNUTLS_SERVER);
482
 
    if(quit_now){
483
 
      return -1;
484
 
    }
485
 
  } while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
 
477
  ret = gnutls_init(session, GNUTLS_SERVER);
486
478
  if(ret != GNUTLS_E_SUCCESS){
487
479
    fprintf(stderr, "Error in GnuTLS session initialization: %s\n",
488
480
            safer_gnutls_strerror(ret));
490
482
  
491
483
  {
492
484
    const char *err;
493
 
    do {
494
 
      ret = gnutls_priority_set_direct(*session, mc.priority, &err);
495
 
      if(quit_now){
496
 
        gnutls_deinit(*session);
497
 
        return -1;
498
 
      }
499
 
    } while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
 
485
    ret = gnutls_priority_set_direct(*session, mc.priority, &err);
500
486
    if(ret != GNUTLS_E_SUCCESS){
501
487
      fprintf(stderr, "Syntax error at: %s\n", err);
502
488
      fprintf(stderr, "GnuTLS error: %s\n",
506
492
    }
507
493
  }
508
494
  
509
 
  do {
510
 
    ret = gnutls_credentials_set(*session, GNUTLS_CRD_CERTIFICATE,
511
 
                                 mc.cred);
512
 
    if(quit_now){
513
 
      gnutls_deinit(*session);
514
 
      return -1;
515
 
    }
516
 
  } while(ret == GNUTLS_E_INTERRUPTED or ret == GNUTLS_E_AGAIN);
 
495
  ret = gnutls_credentials_set(*session, GNUTLS_CRD_CERTIFICATE,
 
496
                               mc.cred);
517
497
  if(ret != GNUTLS_E_SUCCESS){
518
498
    fprintf(stderr, "Error setting GnuTLS credentials: %s\n",
519
499
            safer_gnutls_strerror(ret));
522
502
  }
523
503
  
524
504
  /* ignore client certificate if any. */
525
 
  gnutls_certificate_server_set_request(*session, GNUTLS_CERT_IGNORE);
 
505
  gnutls_certificate_server_set_request(*session,
 
506
                                        GNUTLS_CERT_IGNORE);
526
507
  
527
508
  gnutls_dh_set_prime_bits(*session, mc.dh_bits);
528
509
  
537
518
static int start_mandos_communication(const char *ip, uint16_t port,
538
519
                                      AvahiIfIndex if_index,
539
520
                                      int af){
540
 
  int ret, tcp_sd = -1;
 
521
  int ret, tcp_sd;
541
522
  ssize_t sret;
542
523
  union {
543
524
    struct sockaddr_in in;
544
525
    struct sockaddr_in6 in6;
545
526
  } to;
546
527
  char *buffer = NULL;
547
 
  char *decrypted_buffer = NULL;
 
528
  char *decrypted_buffer;
548
529
  size_t buffer_length = 0;
549
530
  size_t buffer_capacity = 0;
 
531
  ssize_t decrypted_buffer_size;
550
532
  size_t written;
551
 
  int retval = -1;
 
533
  int retval = 0;
552
534
  gnutls_session_t session;
553
535
  int pf;                       /* Protocol family */
554
536
  
555
 
  if(quit_now){
556
 
    return -1;
557
 
  }
558
 
  
559
537
  switch(af){
560
538
  case AF_INET6:
561
539
    pf = PF_INET6;
581
559
  tcp_sd = socket(pf, SOCK_STREAM, 0);
582
560
  if(tcp_sd < 0){
583
561
    perror("socket");
584
 
    goto mandos_end;
585
 
  }
586
 
  
587
 
  if(quit_now){
588
 
    goto mandos_end;
 
562
    return -1;
589
563
  }
590
564
  
591
565
  memset(&to, 0, sizeof(to));
598
572
  }
599
573
  if(ret < 0 ){
600
574
    perror("inet_pton");
601
 
    goto mandos_end;
 
575
    return -1;
602
576
  }
603
577
  if(ret == 0){
604
578
    fprintf(stderr, "Bad address: %s\n", ip);
605
 
    goto mandos_end;
 
579
    return -1;
606
580
  }
607
581
  if(af == AF_INET6){
608
582
    to.in6.sin6_port = htons(port); /* Spurious warnings from
615
589
      if(if_index == AVAHI_IF_UNSPEC){
616
590
        fprintf(stderr, "An IPv6 link-local address is incomplete"
617
591
                " without a network interface\n");
618
 
        goto mandos_end;
 
592
        return -1;
619
593
      }
620
594
      /* Set the network interface number as scope */
621
595
      to.in6.sin6_scope_id = (uint32_t)if_index;
626
600
                                     -Wunreachable-code */
627
601
  }
628
602
  
629
 
  if(quit_now){
630
 
    goto mandos_end;
631
 
  }
632
 
  
633
603
  if(debug){
634
604
    if(af == AF_INET6 and if_index != AVAHI_IF_UNSPEC){
635
605
      char interface[IF_NAMESIZE];
662
632
    }
663
633
  }
664
634
  
665
 
  if(quit_now){
666
 
    goto mandos_end;
667
 
  }
668
 
  
669
635
  if(af == AF_INET6){
670
636
    ret = connect(tcp_sd, &to.in6, sizeof(to));
671
637
  } else {
673
639
  }
674
640
  if(ret < 0){
675
641
    perror("connect");
676
 
    goto mandos_end;
677
 
  }
678
 
  
679
 
  if(quit_now){
680
 
    goto mandos_end;
 
642
    return -1;
681
643
  }
682
644
  
683
645
  const char *out = mandos_protocol_version;
688
650
                                   out_size - written));
689
651
    if(ret == -1){
690
652
      perror("write");
 
653
      retval = -1;
691
654
      goto mandos_end;
692
655
    }
693
656
    written += (size_t)ret;
701
664
        break;
702
665
      }
703
666
    }
704
 
  
705
 
    if(quit_now){
706
 
      goto mandos_end;
707
 
    }
708
667
  }
709
668
  
710
669
  if(debug){
711
670
    fprintf(stderr, "Establishing TLS session with %s\n", ip);
712
671
  }
713
672
  
714
 
  if(quit_now){
715
 
    goto mandos_end;
716
 
  }
717
 
  
718
673
  gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) tcp_sd);
719
674
  
720
 
  if(quit_now){
721
 
    goto mandos_end;
722
 
  }
723
 
  
724
 
  do {
 
675
  do{
725
676
    ret = gnutls_handshake(session);
726
 
    if(quit_now){
727
 
      goto mandos_end;
728
 
    }
729
677
  } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
730
678
  
731
679
  if(ret != GNUTLS_E_SUCCESS){
733
681
      fprintf(stderr, "*** GnuTLS Handshake failed ***\n");
734
682
      gnutls_perror(ret);
735
683
    }
 
684
    retval = -1;
736
685
    goto mandos_end;
737
686
  }
738
687
  
744
693
  }
745
694
  
746
695
  while(true){
747
 
    
748
 
    if(quit_now){
749
 
      goto mandos_end;
750
 
    }
751
 
    
752
696
    buffer_capacity = incbuffer(&buffer, buffer_length,
753
697
                                   buffer_capacity);
754
698
    if(buffer_capacity == 0){
755
699
      perror("incbuffer");
756
 
      goto mandos_end;
757
 
    }
758
 
    
759
 
    if(quit_now){
 
700
      retval = -1;
760
701
      goto mandos_end;
761
702
    }
762
703
    
771
712
      case GNUTLS_E_AGAIN:
772
713
        break;
773
714
      case GNUTLS_E_REHANDSHAKE:
774
 
        do {
 
715
        do{
775
716
          ret = gnutls_handshake(session);
776
 
          
777
 
          if(quit_now){
778
 
            goto mandos_end;
779
 
          }
780
717
        } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
781
718
        if(ret < 0){
782
719
          fprintf(stderr, "*** GnuTLS Re-handshake failed ***\n");
783
720
          gnutls_perror(ret);
 
721
          retval = -1;
784
722
          goto mandos_end;
785
723
        }
786
724
        break;
787
725
      default:
788
726
        fprintf(stderr, "Unknown error while reading data from"
789
727
                " encrypted session with Mandos server\n");
 
728
        retval = -1;
790
729
        gnutls_bye(session, GNUTLS_SHUT_RDWR);
791
730
        goto mandos_end;
792
731
      }
799
738
    fprintf(stderr, "Closing TLS session\n");
800
739
  }
801
740
  
802
 
  if(quit_now){
803
 
    goto mandos_end;
804
 
  }
805
 
  
806
 
  do {
807
 
    ret = gnutls_bye(session, GNUTLS_SHUT_RDWR);
808
 
    if(quit_now){
809
 
      goto mandos_end;
810
 
    }
811
 
  } while(ret == GNUTLS_E_AGAIN or ret == GNUTLS_E_INTERRUPTED);
 
741
  gnutls_bye(session, GNUTLS_SHUT_RDWR);
812
742
  
813
743
  if(buffer_length > 0){
814
 
    ssize_t decrypted_buffer_size;
815
744
    decrypted_buffer_size = pgp_packet_decrypt(buffer,
816
745
                                               buffer_length,
817
746
                                               &decrypted_buffer);
818
747
    if(decrypted_buffer_size >= 0){
819
 
      
820
748
      written = 0;
821
749
      while(written < (size_t) decrypted_buffer_size){
822
 
        if(quit_now){
823
 
          goto mandos_end;
824
 
        }
825
 
        
826
750
        ret = (int)fwrite(decrypted_buffer + written, 1,
827
751
                          (size_t)decrypted_buffer_size - written,
828
752
                          stdout);
831
755
            fprintf(stderr, "Error writing encrypted data: %s\n",
832
756
                    strerror(errno));
833
757
          }
834
 
          goto mandos_end;
 
758
          retval = -1;
 
759
          break;
835
760
        }
836
761
        written += (size_t)ret;
837
762
      }
838
 
      retval = 0;
 
763
      free(decrypted_buffer);
 
764
    } else {
 
765
      retval = -1;
839
766
    }
 
767
  } else {
 
768
    retval = -1;
840
769
  }
841
770
  
842
771
  /* Shutdown procedure */
843
772
  
844
773
 mandos_end:
845
 
  free(decrypted_buffer);
846
774
  free(buffer);
847
 
  if(tcp_sd >= 0){
848
 
    ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
849
 
  }
 
775
  ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
850
776
  if(ret == -1){
851
777
    perror("close");
852
778
  }
853
779
  gnutls_deinit(session);
854
 
  if(quit_now){
855
 
    retval = -1;
856
 
  }
857
780
  return retval;
858
781
}
859
782
 
 
783
sig_atomic_t quit_now = 0;
 
784
 
860
785
static void resolve_callback(AvahiSServiceResolver *r,
861
786
                             AvahiIfIndex interface,
862
787
                             AvahiProtocol proto,
922
847
  /* Called whenever a new services becomes available on the LAN or
923
848
     is removed from the LAN */
924
849
  
925
 
  if(quit_now){
926
 
    return;
927
 
  }
928
 
  
929
850
  switch(event){
930
851
  default:
931
852
  case AVAHI_BROWSER_FAILURE:
961
882
}
962
883
 
963
884
/* stop main loop after sigterm has been called */
964
 
static void handle_sigterm(int sig){
 
885
static void handle_sigterm(__attribute__((unused)) int sig){
965
886
  if(quit_now){
966
887
    return;
967
888
  }
968
889
  quit_now = 1;
969
 
  signal_received = sig;
970
890
  int old_errno = errno;
971
891
  if(mc.simple_poll != NULL){
972
892
    avahi_simple_poll_quit(mc.simple_poll);
998
918
  bool gpgme_initialized = false;
999
919
  float delay = 2.5f;
1000
920
  
1001
 
  struct sigaction old_sigterm_action = { .sa_handler = SIG_DFL };
 
921
  struct sigaction old_sigterm_action;
1002
922
  struct sigaction sigterm_action = { .sa_handler = handle_sigterm };
1003
923
  
1004
 
  uid = getuid();
1005
 
  gid = getgid();
1006
 
  
1007
 
  /* Lower any group privileges we might have, just to be safe */
1008
 
  errno = 0;
1009
 
  ret = setgid(gid);
1010
 
  if(ret == -1){
1011
 
    perror("setgid");
1012
 
  }
1013
 
  
1014
 
  /* Lower user privileges (temporarily) */
1015
 
  errno = 0;
1016
 
  ret = seteuid(uid);
1017
 
  if(ret == -1){
1018
 
    perror("seteuid");
1019
 
  }
1020
 
  
1021
 
  if(quit_now){
1022
 
    goto end;
1023
 
  }
1024
 
  
1025
924
  {
1026
925
    struct argp_option options[] = {
1027
926
      { .name = "debug", .key = 128,
1154
1053
    exitcode = EXIT_FAILURE;
1155
1054
    goto end;
1156
1055
  }
1157
 
  /* Need to check if the handler is SIG_IGN before handling:
1158
 
     | [[info:libc:Initial Signal Actions]] |
1159
 
     | [[info:libc:Basic Signal Handling]]  |
1160
 
  */
1161
 
  ret = sigaction(SIGINT, NULL, &old_sigterm_action);
1162
 
  if(ret == -1){
1163
 
    perror("sigaction");
1164
 
    return EXIT_FAILURE;
1165
 
  }
1166
 
  if(old_sigterm_action.sa_handler != SIG_IGN){
1167
 
    ret = sigaction(SIGINT, &sigterm_action, NULL);
1168
 
    if(ret == -1){
1169
 
      perror("sigaction");
1170
 
      exitcode = EXIT_FAILURE;
1171
 
      goto end;
1172
 
    }
1173
 
  }
1174
 
  ret = sigaction(SIGHUP, NULL, &old_sigterm_action);
1175
 
  if(ret == -1){
1176
 
    perror("sigaction");
1177
 
    return EXIT_FAILURE;
1178
 
  }
1179
 
  if(old_sigterm_action.sa_handler != SIG_IGN){
1180
 
    ret = sigaction(SIGHUP, &sigterm_action, NULL);
1181
 
    if(ret == -1){
1182
 
      perror("sigaction");
1183
 
      exitcode = EXIT_FAILURE;
1184
 
      goto end;
1185
 
    }
1186
 
  }
1187
 
  ret = sigaction(SIGTERM, NULL, &old_sigterm_action);
1188
 
  if(ret == -1){
1189
 
    perror("sigaction");
1190
 
    return EXIT_FAILURE;
1191
 
  }
1192
 
  if(old_sigterm_action.sa_handler != SIG_IGN){
1193
 
    ret = sigaction(SIGTERM, &sigterm_action, NULL);
1194
 
    if(ret == -1){
1195
 
      perror("sigaction");
1196
 
      exitcode = EXIT_FAILURE;
1197
 
      goto end;
1198
 
    }
1199
 
  }
 
1056
  ret = sigaction(SIGTERM, &sigterm_action, &old_sigterm_action);
 
1057
  if(ret == -1){
 
1058
    perror("sigaction");
 
1059
    exitcode = EXIT_FAILURE;
 
1060
    goto end;
 
1061
  }  
1200
1062
  
1201
1063
  /* If the interface is down, bring it up */
1202
1064
  if(interface[0] != '\0'){
1211
1073
      goto end;
1212
1074
    }
1213
1075
    
1214
 
    /* Re-raise priviliges */
1215
 
    errno = 0;
1216
 
    ret = seteuid(0);
1217
 
    if(ret == -1){
1218
 
      perror("seteuid");
1219
 
    }
1220
 
    
1221
1076
#ifdef __linux__
1222
1077
    /* Lower kernel loglevel to KERN_NOTICE to avoid KERN_INFO
1223
1078
       messages to mess up the prompt */
1241
1096
        }
1242
1097
      }
1243
1098
#endif  /* __linux__ */
1244
 
      /* Lower privileges */
1245
 
      errno = 0;
1246
 
      ret = seteuid(uid);
1247
 
      if(ret == -1){
1248
 
        perror("seteuid");
1249
 
      }
1250
1099
      goto end;
1251
1100
    }
1252
1101
    strcpy(network.ifr_name, interface);
1262
1111
      }
1263
1112
#endif  /* __linux__ */
1264
1113
      exitcode = EXIT_FAILURE;
1265
 
      /* Lower privileges */
1266
 
      errno = 0;
1267
 
      ret = seteuid(uid);
1268
 
      if(ret == -1){
1269
 
        perror("seteuid");
1270
 
      }
1271
1114
      goto end;
1272
1115
    }
1273
1116
    if((network.ifr_flags & IFF_UP) == 0){
1286
1129
          }
1287
1130
        }
1288
1131
#endif  /* __linux__ */
1289
 
        /* Lower privileges */
1290
 
        errno = 0;
1291
 
        ret = seteuid(uid);
1292
 
        if(ret == -1){
1293
 
          perror("seteuid");
1294
 
        }
1295
1132
        goto end;
1296
1133
      }
1297
1134
    }
1325
1162
      }
1326
1163
    }
1327
1164
#endif  /* __linux__ */
1328
 
    /* Lower privileges */
1329
 
    errno = 0;
1330
 
    if(take_down_interface){
1331
 
      /* Lower privileges */
1332
 
      ret = seteuid(uid);
1333
 
      if(ret == -1){
1334
 
        perror("seteuid");
1335
 
      }
1336
 
    } else {
1337
 
      /* Lower privileges permanently */
1338
 
      ret = setuid(uid);
1339
 
      if(ret == -1){
1340
 
        perror("setuid");
1341
 
      }
1342
 
    }
 
1165
  }
 
1166
  
 
1167
  if(quit_now){
 
1168
    goto end;
 
1169
  }
 
1170
  
 
1171
  uid = getuid();
 
1172
  gid = getgid();
 
1173
  
 
1174
  errno = 0;
 
1175
  setgid(gid);
 
1176
  if(ret == -1){
 
1177
    perror("setgid");
 
1178
  }
 
1179
  
 
1180
  ret = setuid(uid);
 
1181
  if(ret == -1){
 
1182
    perror("setuid");
1343
1183
  }
1344
1184
  
1345
1185
  if(quit_now){
1519
1359
  
1520
1360
  /* Take down the network interface */
1521
1361
  if(take_down_interface){
1522
 
    /* Re-raise priviliges */
1523
 
    errno = 0;
1524
 
    ret = seteuid(0);
 
1362
    ret = ioctl(sd, SIOCGIFFLAGS, &network);
1525
1363
    if(ret == -1){
1526
 
      perror("seteuid");
 
1364
      perror("ioctl SIOCGIFFLAGS");
 
1365
    } else if(network.ifr_flags & IFF_UP) {
 
1366
      network.ifr_flags &= ~IFF_UP; /* clear flag */
 
1367
      ret = ioctl(sd, SIOCSIFFLAGS, &network);
 
1368
      if(ret == -1){
 
1369
        perror("ioctl SIOCSIFFLAGS");
 
1370
      }
1527
1371
    }
1528
 
    if(geteuid() == 0){
1529
 
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
1530
 
      if(ret == -1){
1531
 
        perror("ioctl SIOCGIFFLAGS");
1532
 
      } else if(network.ifr_flags & IFF_UP) {
1533
 
        network.ifr_flags &= ~IFF_UP; /* clear flag */
1534
 
        ret = ioctl(sd, SIOCSIFFLAGS, &network);
1535
 
        if(ret == -1){
1536
 
          perror("ioctl SIOCSIFFLAGS");
1537
 
        }
1538
 
      }
1539
 
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
1540
 
      if(ret == -1){
1541
 
        perror("close");
1542
 
      }
1543
 
      /* Lower privileges permanently */
1544
 
      errno = 0;
1545
 
      ret = setuid(uid);
1546
 
      if(ret == -1){
1547
 
        perror("setuid");
1548
 
      }
 
1372
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
1373
    if(ret == -1){
 
1374
      perror("close");
1549
1375
    }
1550
1376
  }
1551
1377
  
1593
1419
    }
1594
1420
  }
1595
1421
  
1596
 
  if(quit_now){
1597
 
    sigemptyset(&old_sigterm_action.sa_mask);
1598
 
    old_sigterm_action.sa_handler = SIG_DFL;
1599
 
    ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
1600
 
                                            &old_sigterm_action,
1601
 
                                            NULL));
1602
 
    if(ret == -1){
1603
 
      perror("sigaction");
1604
 
    }
1605
 
    do {
1606
 
      ret = raise(signal_received);
1607
 
    } while(ret != 0 and errno == EINTR);
1608
 
    if(ret != 0){
1609
 
      perror("raise");
1610
 
      abort();
1611
 
    }
1612
 
    TEMP_FAILURE_RETRY(pause());
1613
 
  }
1614
 
  
1615
1422
  return exitcode;
1616
1423
}