Debian Codegraph @

tests/k5start/sigchld-t

raw
1 #!/usr/bin/perl -w
2 #
3 # Test for proper SIGCHLD handling in k5start.
4 #
5 # Written by Russ Allbery <[email protected]>
6 # Copyright 2021 Russ Allbery <[email protected]>
7 # Copyright 2010, 2014
8 # The Board of Trustees of the Leland Stanford Junior University
9 #
10 # SPDX-License-Identifier: MIT
11
12 use POSIX qw(SIGCHLD SIGCONT SIGSTOP SIGTERM);
13 use Test::More;
14
15 # The full path to the newly-built k5start client.
16 our $K5START = "$ENV{C_TAP_BUILD}/../commands/k5start";
17
18 # The path to our data directory, which contains the keytab to use to test.
19 our $DATA = "$ENV{C_TAP_BUILD}/data";
20
21 # Load our test utility programs.
22 require "$ENV{C_TAP_SOURCE}/libtest.pl";
23
24 # Decide whether we have the configuration to run the tests.
25 if (-f "$DATA/test.keytab" and -f "$DATA/test.principal") {
26 plan tests => 2;
27 } else {
28 plan skip_all => 'no keytab configuration';
29 exit 0;
30 }
31
32 # Get the test principal.
33 my $principal = contents ("$DATA/test.principal");
34
35 # Don't overwrite the user's ticket cache.
36 $ENV{KRB5CCNAME} = 'krb5cc_test';
37
38 # We're going to test multiple receipt of SIGCHLD and see if k5start loses
39 # track of the signal handler and then keeps running until its timeout period.
40 my $pid = fork;
41 if (not defined $pid) {
42 BAIL_OUT ("cannot fork: $!\n");
43 } elsif ($pid == 0) {
44 exec ($K5START, '-qUf', "$DATA/test.keytab", '-K60', '-c', 'child-pid',
45 '--', 'sleep', '100');
46 } else {
47 my $tries = 0;
48 while (not -f 'child-pid' and $tries < 100) {
49 select (undef, undef, undef, 0.1);
50 $tries++;
51 }
52 }
53 kill (SIGCHLD, $pid) or BAIL_OUT ("cannot send SIGCHLD to child $pid\n");
54 my $start = time;
55 open (CHILD, '<', 'child-pid') or BAIL_OUT ("cannot open child-pid: $!\n");
56 my $child = <CHILD>;
57 close CHILD;
58 chomp $child;
59 unless (kill (0, $child)) {
60 BAIL_OUT ("cannot locate child process $child\n");
61 }
62 kill (SIGSTOP, $child) or BAIL_OUT ("cannot send SIGSTOP to child $child\n");
63 sleep 1;
64 kill (SIGCONT, $child) or BAIL_OUT ("cannot send SIGCONT to child $child\n");
65 sleep 1;
66 kill (SIGTERM, $child) or BAIL_OUT ("cannot send SIGTERM to child $child\n");
67 waitpid ($pid, 0);
68 is ($? >> 8, 128 + SIGTERM, 'command killed with SIGTERM');
69 ok (time < $start + 5, 'k5start got SIGCHLD and woke up properly');
70 unlink 'child-pid';