Blame src/pm/util/newsession.c

Packit Service c5cf8c
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit Service c5cf8c
/*
Packit Service c5cf8c
 *  (C) 2003 by Argonne National Laboratory.
Packit Service c5cf8c
 *      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
 */
Packit Service c5cf8c
#include "mpichconf.h"
Packit Service c5cf8c
#include <sys/types.h>
Packit Service c5cf8c
#ifdef HAVE_UNISTD_H
Packit Service c5cf8c
/* To get the prototype for getsid in gcc environments,
Packit Service c5cf8c
   define both _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED  or
Packit Service c5cf8c
   define _XOPEN_SOURCE n for n >= 500 */
Packit Service c5cf8c
#include <unistd.h>
Packit Service c5cf8c
#endif
Packit Service c5cf8c
#include <errno.h>
Packit Service c5cf8c
#include "pmutil.h"
Packit Service c5cf8c
Packit Service c5cf8c
/* ------------------------------------------------------------------------ */
Packit Service c5cf8c
/* On some systems (SGI IRIX 6), process exit sometimes kills all processes
Packit Service c5cf8c
 * in the process GROUP.  This code attempts to fix that.
Packit Service c5cf8c
 * We DON'T do it if stdin (0) is connected to a terminal, because that
Packit Service c5cf8c
 * disconnects the process from the terminal.
Packit Service c5cf8c
 * ------------------------------------------------------------------------ */
Packit Service c5cf8c
void MPIE_CreateNewSession(void)
Packit Service c5cf8c
{
Packit Service c5cf8c
#if defined(HAVE_SETSID) && defined(HAVE_ISATTY) && \
Packit Service c5cf8c
    defined(USE_NEW_SESSION) && defined(HAVE_GETSID)
Packit Service c5cf8c
#ifdef NEEDS_GETSID_DECL
Packit Service c5cf8c
    pid_t getsid(pid_t);
Packit Service c5cf8c
#endif
Packit Service c5cf8c
    if (!isatty(0) && !isatty(1) && !isatty(2) && getsid(0) != getpid()) {
Packit Service c5cf8c
        pid_t rc;
Packit Service c5cf8c
        /* printf("Creating a new session\n"); */
Packit Service c5cf8c
/*    printf("Session id = %d and process id = %d\n", getsid(0), getpid());*/
Packit Service c5cf8c
        MPIE_SYSCALL(rc, setsid, ());
Packit Service c5cf8c
        if (rc < 0) {
Packit Service c5cf8c
            MPL_internal_sys_error_printf("setsid", errno, "Could not create new process group\n");
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
}