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 rsRetVal checkStartupOK(void)
{
    FILE* fp = NULL;
    DEFiRet;

    DBGPRINTF("rsyslogd: checking if startup is ok, pidfile '%s'.\n", PidFile);

    if (!strcmp(PidFile, NO_PIDFILE))
    {
        dbgprintf("no pid file shall be written, skipping check\n");
        FINALIZE;
    }

    if ((fp = fopen((char*)PidFile, "r")) == NULL)
        FINALIZE; /* all well, no pid file yet */

    int pf_pid;
    if (fscanf(fp, "%d", &pf_pid) != 1)
    {
        fprintf(stderr, "rsyslogd: error reading pid file, cannot start up\n");
        ABORT_FINALIZE(RS_RET_ERR);
    }

    /* ok, we got a pid, let's check if the process is running */
    const pid_t pid = (pid_t)pf_pid;
    if (kill(pid, 0) == 0 || errno != ESRCH)
    {
        fprintf(stderr,
                "rsyslogd: pidfile '%s' and pid %d already exist.\n"
                "If you want to run multiple instances of rsyslog, you need "
                "to specify\n"
                "different pid files for them (-i option).\n",
                PidFile, (int)getpid());
        ABORT_FINALIZE(RS_RET_ERR);
    }

finalize_it:
    if (fp != NULL)
        fclose(fp);
    RETiRet;
}
/* duplicate startup protection: check, based on pid file, if our instance
 * is already running. This MUST be called before we write our own pid file.
 */
duplicate startup protection: check, based on pid file, if our instance
is already running. This MUST be called before we write our own pid file.
duplicate startup protection : check based on pid file if our instance is already running . This MUST be called before we write our own pid file .
static rsRetVal checkStartupOK(void)
{
    FILE* fp = NULL;
    DEFiRet;
    DBGPRINTF("rsyslogd: checking if startup is ok, pidfile '%s'.\n", PidFile);
    if (!strcmp(PidFile, NO_PIDFILE))
    {
        dbgprintf("no pid file shall be written, skipping check\n");
        FINALIZE;
    }
    if ((fp = fopen((char*)PidFile, "r")) == NULL)
        FINALIZE; 
    int pf_pid;
    if (fscanf(fp, "%d", &pf_pid) != 1)
    {
        fprintf(stderr, "rsyslogd: error reading pid file, cannot start up\n");
        ABORT_FINALIZE(RS_RET_ERR);
    }
    const pid_t pid = (pid_t)pf_pid;
    if (kill(pid, 0) == 0 || errno != ESRCH)
    {
        fprintf(stderr,
                "rsyslogd: pidfile '%s' and pid %d already exist.\n"
                "If you want to run multiple instances of rsyslog, you need "
                "to specify\n"
                "different pid files for them (-i option).\n",
                PidFile, (int)getpid());
        ABORT_FINALIZE(RS_RET_ERR);
    }
finalize_it:
    if (fp != NULL)
        fclose(fp);
    RETiRet;
}
static rsRetVal checkStartupOK ( void ) { FILE * fp = NULL ; DEFiRet ; DBGPRINTF ( " \n " , PidFile ) ; if ( ! strcmp ( PidFile , NO_PIDFILE ) ) { dbgprintf ( " \n " ) ; FINALIZE ; } if ( ( fp = fopen ( ( char * ) PidFile , " " ) ) == NULL ) FINALIZE ; int pf_pid ; if ( fscanf ( fp , " " , & pf_pid ) != 1 ) { fprintf ( stderr , " \n " ) ; ABORT_FINALIZE ( RS_RET_ERR ) ; } const pid_t pid = ( pid_t ) pf_pid ; if ( kill ( pid , 0 ) == 0 || errno != ESRCH ) { fprintf ( stderr , " \n " " " " \n " " \n " , PidFile , ( int ) getpid ( ) ) ; ABORT_FINALIZE ( RS_RET_ERR ) ; } finalize_it : if ( fp != NULL ) fclose ( fp ) ; RETiRet ; }
duplicate startup protection: check, based on pid file, if our instance
 is already running.
duplicate startup protection : check based on pid file if our instance is already running .
/* all well, no pid file yet */ /* ok, we got a pid, let's check if the process is running */