GNUnet 0.22.2
gnunet-timeout.c File Reference
#include "platform.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Include dependency graph for gnunet-timeout.c:

Go to the source code of this file.

Functions

static void sigchld_handler (int val)
 
static void sigint_handler (int val)
 
int main (int argc, char *argv[])
 

Variables

static pid_t child
 

Function Documentation

◆ sigchld_handler()

static void sigchld_handler ( int  val)
static

Definition at line 39 of file gnunet-timeout.c.

40{
41 int status = 0;
42 int ret = 0;
43
44 (void) val;
45 waitpid (child, &status, 0);
46 if (WIFEXITED (status) != 0)
47 {
48 ret = WEXITSTATUS (status);
49 _exit (ret); /* return same status code */
50 }
51 if (WIFSIGNALED (status) != 0)
52 {
53 ret = WTERMSIG (status);
54 kill (getpid (), ret); /* kill self with the same signal */
55 }
56 _exit (-1);
57}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static int status
The program status; 0 for success.
Definition: gnunet-nse.c:39
static pid_t child

References child, ret, and status.

Referenced by main().

Here is the caller graph for this function:

◆ sigint_handler()

static void sigint_handler ( int  val)
static

Definition at line 61 of file gnunet-timeout.c.

62{
63 kill (0, val);
64 _exit (val);
65}

Referenced by main().

Here is the caller graph for this function:

◆ main()

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

Definition at line 69 of file gnunet-timeout.c.

70{
71 int timeout = 0;
72 pid_t gpid = 0;
73
74 if (argc < 3)
75 {
76 fprintf (stderr,
77 "arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n");
78 exit (-1);
79 }
80
81 timeout = atoi (argv[1]);
82
83 if (timeout == 0)
84 timeout = 600;
85
86 /* with getpgid() it does not compile, but getpgrp is the BSD version and working */
87 gpid = getpgrp ();
88
89 signal (SIGCHLD, sigchld_handler);
90 signal (SIGABRT, sigint_handler);
91 signal (SIGFPE, sigint_handler);
92 signal (SIGILL, sigint_handler);
93 signal (SIGINT, sigint_handler);
94 signal (SIGSEGV, sigint_handler);
95 signal (SIGTERM, sigint_handler);
96
97 child = fork ();
98 if (child == 0)
99 {
100 /* int setpgrp(pid_t pid, pid_t pgid); is not working on this machine */
101 // setpgrp (0, pid_t gpid);
102 if (-1 != gpid)
103 setpgid (0, gpid);
104 execvp (argv[2], &argv[2]);
105 exit (-1);
106 }
107 if (child > 0)
108 {
109 sleep (timeout);
110 printf ("Child processes were killed after timeout of %u seconds\n",
111 timeout);
112 kill (0, SIGTERM);
113 exit (3);
114 }
115 exit (-1);
116}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:118
static void sigint_handler(int val)
static void sigchld_handler(int val)

References child, sigchld_handler(), sigint_handler(), and timeout.

Here is the call graph for this function:

Variable Documentation

◆ child

pid_t child
static

Definition at line 35 of file gnunet-timeout.c.

Referenced by get_file_information(), main(), mark_as_reachable(), and sigchld_handler().