| 1 |
/* coredump.c. Public domain. |
| 2 |
|
| 3 |
This procedure is due to Chris Torek, [email protected]. 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. */ |
| 10 |
|
| 11 |
#include <w2c/config.h> |
| 12 |
|
| 13 |
/* Do not try to compile this Unix-y unportable stuff unless it's needed. */ |
| 14 |
|
| 15 |
#ifdef FUNNY_CORE_DUMP |
| 16 |
#include <signal.h> |
| 17 |
#include <sys/wait.h> |
| 18 |
|
| 19 |
void |
| 20 |
funny_core_dump (void) |
| 21 |
{ |
| 22 |
#ifdef __EMX__ |
| 23 |
{ |
| 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); |
| 29 |
} |
| 30 |
#else /* !__EMX__ */ |
| 31 |
int pid, w; |
| 32 |
union wait status; |
| 33 |
|
| 34 |
switch (pid = fork ()) |
| 35 |
{ |
| 36 |
case -1: /* failed */ |
| 37 |
perror ("vfork"); |
| 38 |
exit (-1); |
| 39 |
/*NOTREACHED*/ |
| 40 |
|
| 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*/ |
| 47 |
|
| 48 |
default: /* parent */ |
| 49 |
while ((w = wait (&status)) != pid && w != -1) |
| 50 |
; |
| 51 |
if (status.w_coredump) |
| 52 |
exit (0); |
| 53 |
(void) write (2, "attempt to dump core failed\n", 28); |
| 54 |
exit (1); |
| 55 |
} |
| 56 |
#endif /* not __EMX__ */ |
| 57 |
} |
| 58 |
#endif /* FUNNY_CORE_DUMP */ |