1 /* Repeatedly run a program with a given uid, gid and termination signal. */
4 * Copyright (C) 2003-2006 IBM
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include <sys/types.h>
33 static char *progname
;
34 static pid_t test_pgrp
;
37 static int the_signal
= SIGTERM
;
39 static void int_func(int signum
) {
40 pounder_fprintf(tty_fp
, "%s: Killed by interrupt. Last exit code = %d.\n",
42 kill(-test_pgrp
, the_signal
);
45 static void alarm_func(int signum
) {
46 pounder_fprintf(tty_fp
, "%s: Killed by timer. Last exit code = %d.\n",
48 kill(-test_pgrp
, the_signal
);
52 int main(int argc
, char *argv
[]) {
55 unsigned int revs
= 0;
61 printf("Usage: %s time_in_sec uid gid signal command [args]\n", argv
[0]);
65 tty_fp
= fdopen(3, "w+");
67 tty_fp
= fopen("/dev/tty", "w+");
74 progname
= rindex(argv
[5], '/');
75 if (progname
== NULL
) {
82 memset(&zig
, 0x00, sizeof(zig
));
83 zig
.sa_handler
= alarm_func
;
84 sigaction(SIGALRM
, &zig
, NULL
);
85 zig
.sa_handler
= int_func
;
86 sigaction(SIGINT
, &zig
, NULL
);
87 sigaction(SIGTERM
, &zig
, NULL
);
89 /* set up process groups so that we can kill the
90 * loop test and descendants easily */
95 the_signal
= atoi(argv
[4]);
99 pounder_fprintf(tty_fp
, "%s: uid = %d, gid = %d, sig = %d\n",
100 progname
, uid
, gid
, the_signal
);
103 pounder_fprintf(tty_fp
, "%s: %s loop #%d.\n", progname
,
112 // set group and user id
113 if (setregid(gid
, gid
) != 0) {
118 if (setreuid(uid
, uid
) != 0) {
125 stat
= execvp(argv
[5], &argv
[5]);
127 stat
= execvp(argv
[5], &argv
[5]);
135 /* save the pgrp of the spawned process */
138 // wait for it to be done
139 if (waitpid(pid
, &stat
, 0) != pid
) {
145 if (WIFSIGNALED(stat
)) {
146 pounder_fprintf(tty_fp
, "%s: %s on signal %d.\n",
147 progname
, fail_msg
, WTERMSIG(stat
));
150 res
= WEXITSTATUS(stat
);
152 pounder_fprintf(tty_fp
, "%s: %s.\n", progname
, pass_msg
);
153 } else if (res
< 0 || res
== 255) {
154 pounder_fprintf(tty_fp
, "%s: %s with code %d.\n",
155 progname
, abort_msg
, res
);
157 // FIXME: add test to blacklist
159 pounder_fprintf(tty_fp
, "%s: %s with code %d.\n",
160 progname
, fail_msg
, res
);