1 /*-
2   timeout.c - execute a command with one minute timeout
3 
4   Copyright (C) 2011 Mikolaj Izdebski
5 
6   This program is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10 
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15 
16   You should have received a copy of the GNU General Public License
17   along with lbzip2.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /*
21   This program basically does the same thing as the following one-liner:
22 
23      perl -e'alarm 60; exec @ARGV or die $!'
24 
25   It's written in C because we don't want to depend on perl.
26 */
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 #include <unistd.h>             /* execv() */
33 #include <stdio.h>              /* perror() */
34 
35 int
main(int argc,char ** argv)36 main(int argc, char **argv)
37 {
38   alarm(60);
39 
40   argv++;
41   execv(*argv, argv);
42 
43   perror("execv");
44   return 1;
45 }
46