Back to index

tetex-bin  3.0
coredump.c
Go to the documentation of this file.
00001 /* coredump.c.  Public domain.
00002 
00003    This procedure is due to Chris Torek, chris@umd.edu.  It makes a core
00004    dump without any sort of error status (abort(2) does return an error
00005    status, so we don't want to use that).  It is used only when making a
00006    preloaded TeX from virtex, and is triggered by a magic file name
00007    requested as input (see `open_input', above).  Finding a way to
00008    reconstitute the core dump into a binary (i.e., with undump) is up to
00009    you.  Perl has some things to say about these days.  */
00010 
00011 #include "config.h"
00012 
00013 /* Do not try to compile this Unix-y unportable stuff unless it's needed.  */
00014 
00015 #ifdef FUNNY_CORE_DUMP
00016 #include <signal.h>
00017 #include <sys/wait.h>
00018 
00019 void
00020 funny_core_dump P1H(void)
00021 {
00022 #ifdef __EMX__
00023   {
00024     int handle = open ("core", O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
00025     if (handle >= 0 && _core (handle) == 0)
00026       exit (0);
00027     (void) write (2, "attempt to dump core failed\n", 28);
00028     exit (1);
00029   }
00030 #else /* !__EMX__ */
00031   int pid, w;
00032   union wait status;
00033 
00034   switch (pid = fork ())
00035     {
00036     case -1:         /* failed */
00037       perror ("vfork");
00038       exit (-1);
00039       /*NOTREACHED*/
00040 
00041     case 0:             /* child */
00042        (void) signal (SIGQUIT, SIG_DFL);
00043        (void) kill (getpid (), SIGQUIT);
00044        (void) write (2, "how did we get here?\n", 21);
00045        _exit (1);
00046        /*NOTREACHED*/
00047 
00048     default:         /* parent */
00049       while ((w = wait (&status)) != pid && w != -1)
00050        ;
00051       if (status.w_coredump)
00052        exit (0);
00053       (void) write (2, "attempt to dump core failed\n", 28);
00054       exit (1);
00055     }
00056 #endif /* not __EMX__ */
00057 }
00058 #endif /* FUNNY_CORE_DUMP */