File: dmtcp5.c

package info (click to toggle)
dmtcp 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,496 kB
  • sloc: cpp: 33,592; ansic: 28,099; sh: 6,735; makefile: 1,950; perl: 1,690; python: 1,241; asm: 138; java: 13
file content (53 lines) | stat: -rw-r--r-- 1,439 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//Setting _POSIX_C_SOURCE to 200112 changes the semantics of this program.  Why?
//#define _POSIX_C_SOURCE 200112
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

#define BT_SIZE 1024
// #define ENABLE_BACKTRACE
#ifdef ENABLE_BACKTRACE
# include <execinfo.h>
#endif

// See comment in autotest.py; This can trigger bug in 32-bit Linux
// because original app places vdso and libs in low memory when kernel uses
// legacy_va_layout (which is forced when stacksize is small), and the new
// vdso collides with the old libs in mtcp_restart.  So, it gets unmapped.

void myHandler(int i){
#ifdef ENABLE_BACKTRACE
  int nptrs;
  void * buffer[BT_SIZE];
#endif

  printf("signal %d received.\n", i);
#ifdef ENABLE_BACKTRACE
  nptrs = backtrace (buffer, BT_SIZE);
  backtrace_symbols_fd ( buffer, nptrs, STDOUT_FILENO );
  printf("\n");
#endif
}

int main(int argc, char* argv[]){
  char cmd_file[256];
  int cmd_len = readlink("/proc/self/exe", cmd_file, 255);
  if (cmd_len == -1)
    printf("WARNING:  Couldn't find /proc/self/exe."
	   "  Trying to continue anyway.\n");
  else {
    cmd_file[cmd_len] = '\0';
    signal(SIGUSR1, &myHandler);
    signal(SIGUSR2, &myHandler); // DMTCP should not enable this.
    if ( !getenv("IS_CHILD") && 0 != fork() ) { /* if child, do exec */
      setenv("IS_CHILD", "true", 1);
      execv(cmd_file, argv);
    }
  }

  while (1){
    sleep(1);
    raise(SIGUSR1);
  }
}