~aritra1911/mc_server

146d048d48160b1c3112b3888ad5a53ec41ef89a — Aritra Sarkar 1 year, 8 months ago b04c399
Exit ungracefully on Minix
1 files changed, 28 insertions(+), 0 deletions(-)

M main.c
M main.c => main.c +28 -0
@@ 47,7 47,11 @@ typedef struct {
    char    port[8];
} prefs_t;

#ifdef __minix
static void signal_handler(int) __attribute__((noreturn));
#else
static void signal_handler(int);
#endif
static int  get_listener(prefs_t *);
static void set_defaults(prefs_t *);
static void print_usage(const char *program);


@@ 57,6 61,30 @@ static void
signal_handler(int signum)
{
    printf("\nINFO : Received signal %i.\n", signum);
#ifdef __minix
    /*
     * HACK: Minix 3.3.0's libc has a broken implementation of the
     * `poll()` syscall.  We rely on `poll()`'s ability to error out
     * with an EINTR everytime it is interrupted with this signal
     * handler (like for example when the user presses ^C) to cleanup
     * heap before exiting.  Minix 3.3.0 just doesn't wanna error out,
     * rather it continues operating from where it left off.  Hence we
     * might just not care about the whole cleaning up heap thing and
     * just exit just in case of Minix since Linux and FreeBSD do not
     * misbehave in such a manner.  Also whoever builds this on Minix
     * and expects it to work flawlessly is probably a psychopath
     * anyway.
     *
     * WARN: We could declare `session` and `tpool` (defined in
     * `main()`) globally and call destroy on them right in this
     * subroutine, but I've been through that experiment and the pthread
     * calls segfault on Minix for some reason so that doesn't help
     * either.  Also I'm not a fan of global variables.
     */
    printf("WARN : Cannot exit gracefully on Minix.\n"
	   "     : Watch out for those memory leaks.\n");
    exit(EXIT_SUCCESS);
#endif	/* __minix */
}

static int