tests-autotest/timeout.c File Reference

Run a test for a given amount of runtime until either it quits naturally or we are forced to kill it. More...

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>

Include dependency graph for timeout.c:

Go to the source code of this file.

Functions

void family_assassination (int ignored)
 When triggered, kills the process at _pid.
int main (int argc, char *argv[])
 Main function: set up the alarm and run the child process until it quits or the alarm fires.

Variables

int _pid = -1
 global for the money-shot: the pid that is killed when the alarm goes off


Detailed Description

Run a test for a given amount of runtime until either it quits naturally or we are forced to kill it.

This file was written for the regression-testing of the nagios/ldap and the fsc-fs work which I was doing on my own inspired by the needs of a company I worked for in 2007. The function fork/execs a child process, and sets an alarm. If the child quits, all is fine; if the alarm goes off, it kills the child in a relatively impolite manner: SIGTERM, wait 1 sec, SIGKILL. There's a bit of tongue-in-cheek here, but that's the basics.

family_assassination() is the function tied to the SIGALRM; the wait for a normal termination is done with a wait() or pause().

This file is permitted use as GPL2 or Attribution + ShareAlike (by-sa) Creative-Commons. Whichever works for you.

Definition in file timeout.c.


Function Documentation

void family_assassination ( int  ignored  ) 

When triggered, kills the process at _pid.

Parameters:
ignored (ignored)

Definition at line 30 of file timeout.c.

References _pid.

Referenced by main().

int main ( int  argc,
char *  argv[] 
)

Main function: set up the alarm and run the child process until it quits or the alarm fires.

This function reads the parameters, set up a SIGALRM to call family_assassination() (kill your child, get it? dark humour, I'm sorry), then lauunch the child process an wait for it to finish. If the alarm goes off before the child finishes, this program kills the child and itself like a gruesome story in the newspaper; if the child finishes, then we terminate normally, which is nearly as gruesome (again, sorry).

Returns:
1 if there's a parameter problem or exec() problem, or if the child was killed by alarm

0 if there are no problems and child completed normally

Definition at line 52 of file timeout.c.

References _pid, family_assassination(), and opt.

Here is the call graph for this function:


Variable Documentation

int _pid = -1

global for the money-shot: the pid that is killed when the alarm goes off

Definition at line 24 of file timeout.c.

Referenced by family_assassination(), and main().


Generated on Sun Jul 12 20:25:33 2009 for mysqlfs by  doxygen 1.4.7