unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
blob 6b2db10866206519cca50ce1a45fd9226a8ec5b0 1445 bytes (raw)
name: gnu/system/aux-files/shepherd-crash-handler.c 	 # note: path name is non-authoritative(*)

 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
#define _GNU_SOURCE

#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/syscall.h>   /* For SYS_xxx definitions */
#include <signal.h>

static void
handle_crash (int sig)
{
  static const char msg[] = "Shepherd crashed!\n";
  write (2, msg, sizeof msg);

#ifdef __sparc__
  /* See 'raw_clone' in systemd.  */
# error "SPARC uses a different 'clone' syscall convention"
#endif

  pid_t pid = syscall (SYS_clone, SIGCHLD, NULL);
  if (pid < 0)
    abort ();

  if (pid == 0)
    {
      /* Restore the default signal handler to get a core dump.  */
      signal (sig, SIG_DFL);

      const struct rlimit infinity = { RLIM_INFINITY, RLIM_INFINITY };
      setrlimit (RLIMIT_CORE, &infinity);
      chdir ("/");

      int pid = syscall (SYS_getpid);
      kill (pid, sig);

      /* As it turns out, 'kill' simply returns without doing anything, which
	 is consistent with the "Notes" section of kill(2).  Thus, force a
	 crash.  */
      * (int *) 0 = 42;

      _exit (254);
    }
  else
    {
      signal (sig, SIG_IGN);

      int status;
      waitpid (pid, &status, 0);

      sync ();

      _exit (255);
    }

  _exit (253);
}

static void initialize_crash_handler (void)
  __attribute__ ((constructor));

static void
initialize_crash_handler (void)
{
  signal (SIGSEGV, handle_crash);
  signal (SIGABRT, handle_crash);
}

debug log:

solving 6b2db10866 ...
found 6b2db10866 in https://yhetil.org/guix-bugs/87d0d6k4z4.fsf@gnu.org/

applying [1/1] https://yhetil.org/guix-bugs/87d0d6k4z4.fsf@gnu.org/
diff --git a/gnu/system/aux-files/shepherd-crash-handler.c b/gnu/system/aux-files/shepherd-crash-handler.c
new file mode 100644
index 0000000000..6b2db10866

Checking patch gnu/system/aux-files/shepherd-crash-handler.c...
Applied patch gnu/system/aux-files/shepherd-crash-handler.c cleanly.

index at:
100644 6b2db10866206519cca50ce1a45fd9226a8ec5b0	gnu/system/aux-files/shepherd-crash-handler.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).