openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/nss-pam-ldapd/0.9.8-r0/nss-pam-ldapd-0.9.8/nslcd/nslcd.c
static void create_pidfile(const char* filename)
{
    int fd;
    char buffer[20];
    if (filename != NULL)
    {
        mkdirname(filename);
        if ((fd = open(filename, O_RDWR | O_CREAT, 0644)) < 0)
        {
            log_log(LOG_ERR, "cannot create pid file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        if (lockf(fd, F_TLOCK, 0) < 0)
        {
            log_log(LOG_ERR, "cannot lock pid file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        if (ftruncate(fd, 0) < 0)
        {
            log_log(LOG_ERR, "cannot truncate pid file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        mysnprintf(buffer, sizeof(buffer), "%lu\n",
                   (unsigned long int)getpid());
        if (write(fd, buffer, strlen(buffer)) != (int)strlen(buffer))
        {
            log_log(LOG_ERR, "error writing pid file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        /* we keep the pidfile open so the lock remains valid */
    }
}
/* write the current process id to the specified file */
write the current process id to the specified file
write the current process id to the specified file
static void create_pidfile(const char* filename)
{
    int fd;
    char buffer[20];
    if (filename != NULL)
    {
        mkdirname(filename);
        if ((fd = open(filename, O_RDWR | O_CREAT, 0644)) < 0)
        {
            log_log(LOG_ERR, "cannot create pid file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        if (lockf(fd, F_TLOCK, 0) < 0)
        {
            log_log(LOG_ERR, "cannot lock pid file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        if (ftruncate(fd, 0) < 0)
        {
            log_log(LOG_ERR, "cannot truncate pid file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
        mysnprintf(buffer, sizeof(buffer), "%lu\n",
                   (unsigned long int)getpid());
        if (write(fd, buffer, strlen(buffer)) != (int)strlen(buffer))
        {
            log_log(LOG_ERR, "error writing pid file (%s): %s", filename,
                    strerror(errno));
            exit(EXIT_FAILURE);
        }
    }
}
static void create_pidfile ( const char * filename ) { int fd ; char buffer [ 20 ] ; if ( filename != NULL ) { mkdirname ( filename ) ; if ( ( fd = open ( filename , O_RDWR | O_CREAT , 0644 ) ) < 0 ) { log_log ( LOG_ERR , " " , filename , strerror ( errno ) ) ; exit ( EXIT_FAILURE ) ; } if ( lockf ( fd , F_TLOCK , 0 ) < 0 ) { log_log ( LOG_ERR , " " , filename , strerror ( errno ) ) ; exit ( EXIT_FAILURE ) ; } if ( ftruncate ( fd , 0 ) < 0 ) { log_log ( LOG_ERR , " " , filename , strerror ( errno ) ) ; exit ( EXIT_FAILURE ) ; } mysnprintf ( buffer , sizeof ( buffer ) , " \n " , ( unsigned long int ) getpid ( ) ) ; if ( write ( fd , buffer , strlen ( buffer ) ) != ( int ) strlen ( buffer ) ) { log_log ( LOG_ERR , " " , filename , strerror ( errno ) ) ; exit ( EXIT_FAILURE ) ; } } }
write the current process id to the specified file
write the current process id to the specified file
/* we keep the pidfile open so the lock remains valid */