openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/tools/rsyslogd.c
static void prepareBackground(const int parentPipeFD)
{
    DBGPRINTF("rsyslogd: in child, finalizing initialization\n");

    dbgTimeoutToStderr = 0; /* we loose stderr when backgrounding! */
    int r = setsid();
    if (r == -1)
    {
        char err[1024];
        char em[2048];
        rs_strerror_r(errno, err, sizeof(err));
        snprintf(em, sizeof(em) - 1,
                 "rsyslog: error "
                 "auto-backgrounding: %s\n",
                 err);
        dbgprintf("%s\n", em);
        fprintf(stderr, "%s", em);
    }

    int beginClose = 3;

#ifdef HAVE_LIBSYSTEMD
    /* running under systemd? Then we must make sure we "forward" any
     * fds passed by it (adjust the pid).
     */
    if (sd_booted())
    {
        const char* lstnPid = getenv("LISTEN_PID");
        if (lstnPid != NULL)
        {
            char szBuf[64];
            const int lstnPidI = atoi(lstnPid);
            snprintf(szBuf, sizeof(szBuf), "%d", lstnPidI);
            if (!strcmp(szBuf, lstnPid) && lstnPidI == getppid())
            {
                snprintf(szBuf, sizeof(szBuf), "%d", (int)getpid());
                setenv("LISTEN_PID", szBuf, 1);
                /* ensure we do not close what systemd provided */
                const int nFds = sd_listen_fds(0);
                if (nFds > 0)
                {
                    beginClose = SD_LISTEN_FDS_START + nFds;
                }
            }
        }
    }
#endif

    /* close unnecessary open files */
    const int endClose = getdtablesize();
    close(0);
    for (int i = beginClose; i <= endClose; ++i)
    {
        if ((i != dbgGetDbglogFd()) && (i != parentPipeFD))
        {
            aix_close_it(i); /* AIXPORT */
        }
    }
}
/* prepares the background processes (if auto-backbrounding) for
 * operation.
 */
prepares the background processes (if auto-backbrounding) for
operation.
prepares the background processes ( if auto - backbrounding ) for operation .
static void prepareBackground(const int parentPipeFD)
{
    DBGPRINTF("rsyslogd: in child, finalizing initialization\n");
    dbgTimeoutToStderr = 0; 
    int r = setsid();
    if (r == -1)
    {
        char err[1024];
        char em[2048];
        rs_strerror_r(errno, err, sizeof(err));
        snprintf(em, sizeof(em) - 1,
                 "rsyslog: error "
                 "auto-backgrounding: %s\n",
                 err);
        dbgprintf("%s\n", em);
        fprintf(stderr, "%s", em);
    }
    int beginClose = 3;
#ifdef HAVE_LIBSYSTEMD
    if (sd_booted())
    {
        const char* lstnPid = getenv("LISTEN_PID");
        if (lstnPid != NULL)
        {
            char szBuf[64];
            const int lstnPidI = atoi(lstnPid);
            snprintf(szBuf, sizeof(szBuf), "%d", lstnPidI);
            if (!strcmp(szBuf, lstnPid) && lstnPidI == getppid())
            {
                snprintf(szBuf, sizeof(szBuf), "%d", (int)getpid());
                setenv("LISTEN_PID", szBuf, 1);
                const int nFds = sd_listen_fds(0);
                if (nFds > 0)
                {
                    beginClose = SD_LISTEN_FDS_START + nFds;
                }
            }
        }
    }
#endif
    const int endClose = getdtablesize();
    close(0);
    for (int i = beginClose; i <= endClose; ++i)
    {
        if ((i != dbgGetDbglogFd()) && (i != parentPipeFD))
        {
            aix_close_it(i); 
        }
    }
}
static void prepareBackground ( const int parentPipeFD ) { DBGPRINTF ( " \n " ) ; dbgTimeoutToStderr = 0 ; int r = setsid ( ) ; if ( r == -1 ) { char err [ 1024 ] ; char em [ 2048 ] ; rs_strerror_r ( errno , err , sizeof ( err ) ) ; snprintf ( em , sizeof ( em ) - 1 , " " " \n " , err ) ; dbgprintf ( " \n " , em ) ; fprintf ( stderr , " " , em ) ; } int beginClose = 3 ; #ifdef HAVE_LIBSYSTEMD if ( sd_booted ( ) ) { const char * lstnPid = getenv ( " " ) ; if ( lstnPid != NULL ) { char szBuf [ 64 ] ; const int lstnPidI = atoi ( lstnPid ) ; snprintf ( szBuf , sizeof ( szBuf ) , " " , lstnPidI ) ; if ( ! strcmp ( szBuf , lstnPid ) && lstnPidI == getppid ( ) ) { snprintf ( szBuf , sizeof ( szBuf ) , " " , ( int ) getpid ( ) ) ; setenv ( " " , szBuf , 1 ) ; const int nFds = sd_listen_fds ( 0 ) ; if ( nFds > 0 ) { beginClose = SD_LISTEN_FDS_START + nFds ; } } } } #endif const int endClose = getdtablesize ( ) ; close ( 0 ) ; for ( int i = beginClose ; i <= endClose ; ++ i ) { if ( ( i != dbgGetDbglogFd ( ) ) && ( i != parentPipeFD ) ) { aix_close_it ( i ) ; } } }
prepares the background processes (if auto-backbrounding) for
 operation.
prepares the background processes ( if auto - backbrounding ) for operation .
/* we loose stderr when backgrounding! */ /* running under systemd? Then we must make sure we "forward" any
     * fds passed by it (adjust the pid).
     */ /* ensure we do not close what systemd provided */ /* close unnecessary open files */ /* AIXPORT */