beta-0.89.2
[luatex.git] / source / texk / web2c / lib / coredump.c
blobcf883bf716622ff0c07cae2292dd8d7957823237
1 /* coredump.c. Public domain.
3 This procedure is due to Chris Torek, chris@umd.edu. It makes a core
4 dump without any sort of error status (abort(2) does return an error
5 status, so we don't want to use that). It is used only when making a
6 preloaded TeX from virtex, and is triggered by a magic file name
7 requested as input (see `open_input', above). Finding a way to
8 reconstitute the core dump into a binary (i.e., with undump) is up to
9 you. Perl has some things to say about these days. */
11 #include <w2c/config.h>
13 /* Do not try to compile this Unix-y unportable stuff unless it's needed. */
15 #ifdef FUNNY_CORE_DUMP
16 #include <signal.h>
17 #include <sys/wait.h>
19 void
20 funny_core_dump (void)
22 #ifdef __EMX__
24 int handle = open ("core", O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
25 if (handle >= 0 && _core (handle) == 0)
26 exit (0);
27 (void) write (2, "attempt to dump core failed\n", 28);
28 exit (1);
30 #else /* !__EMX__ */
31 int pid, w;
32 union wait status;
34 switch (pid = fork ())
36 case -1: /* failed */
37 perror ("vfork");
38 exit (-1);
39 /*NOTREACHED*/
41 case 0: /* child */
42 (void) signal (SIGQUIT, SIG_DFL);
43 (void) kill (getpid (), SIGQUIT);
44 (void) write (2, "how did we get here?\n", 21);
45 _exit (1);
46 /*NOTREACHED*/
48 default: /* parent */
49 while ((w = wait (&status)) != pid && w != -1)
51 if (status.w_coredump)
52 exit (0);
53 (void) write (2, "attempt to dump core failed\n", 28);
54 exit (1);
56 #endif /* not __EMX__ */
58 #endif /* FUNNY_CORE_DUMP */