static bool ga_open_pidfile(const char *pidfile)

{

    int pidfd;

    char pidstr[32];



    pidfd = open(pidfile, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);

    if (pidfd == -1 || lockf(pidfd, F_TLOCK, 0)) {

        g_critical("Cannot lock pid file, %s", strerror(errno));

        if (pidfd != -1) {

            close(pidfd);

        }

        return false;

    }



    if (ftruncate(pidfd, 0) || lseek(pidfd, 0, SEEK_SET)) {

        g_critical("Failed to truncate pid file");

        goto fail;

    }

    snprintf(pidstr, sizeof(pidstr), "%d\n", getpid());

    if (write(pidfd, pidstr, strlen(pidstr)) != strlen(pidstr)) {

        g_critical("Failed to write pid file");

        goto fail;

    }



    return true;



fail:

    unlink(pidfile);

    return false;

}

static bool ga_open_pidfile(const char *pidfile)

{

    int pidfd;

    char pidstr[32];



    pidfd = open(pidfile, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);

    if (pidfd == -1 || lockf(pidfd, F_TLOCK, 0)) {

        g_critical("Cannot lock pid file, %s", strerror(errno));

        if (pidfd != -1) {

            close(pidfd);

        }

        return false;

    }



    if (ftruncate(pidfd, 0) || lseek(pidfd, 0, SEEK_SET)) {

        g_critical("Failed to truncate pid file");

        goto fail;

    }

    snprintf(pidstr, sizeof(pidstr), "%d\n", getpid());

    if (write(pidfd, pidstr, strlen(pidstr)) != strlen(pidstr)) {

        g_critical("Failed to write pid file");

        goto fail;

    }



    return true;



fail:

    unlink(pidfile);

    return false;

}

    pidfd = open(pidfile, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);
static bool FUNC_0(const char *pidfile)

{

    int VAR_0;

    char VAR_1[32];



    VAR_0 = open(pidfile, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);

    if (VAR_0 == -1 || lockf(VAR_0, F_TLOCK, 0)) {

        g_critical("Cannot lock pid file, %s", strerror(errno));

        if (VAR_0 != -1) {

            close(VAR_0);

        }

        return false;

    }



    if (ftruncate(VAR_0, 0) || lseek(VAR_0, 0, SEEK_SET)) {

        g_critical("Failed to truncate pid file");

        goto fail;

    }

    snprintf(VAR_1, sizeof(VAR_1), "%d\n", getpid());

    if (write(VAR_0, VAR_1, strlen(VAR_1)) != strlen(VAR_1)) {

        g_critical("Failed to write pid file");

        goto fail;

    }



    return true;



fail:

    unlink(pidfile);

    return false;

}

static bool FUNC_0(const char *pidfile)
{ int VAR_0; char VAR_1[32]; VAR_0 = open(pidfile, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR); if (VAR_0 == -1 || lockf(VAR_0, F_TLOCK, 0)) { g_critical("Cannot lock pid file, %s", strerror(errno)); if (VAR_0 != -1) { close(VAR_0); } return false; } if (ftruncate(VAR_0, 0) || lseek(VAR_0, 0, SEEK_SET)) { g_critical("Failed to truncate pid file"); goto fail; } snprintf(VAR_1, sizeof(VAR_1), "%d\n", getpid()); if (write(VAR_0, VAR_1, strlen(VAR_1)) != strlen(VAR_1)) { g_critical("Failed to write pid file"); goto fail; } return true; fail:
unlink(pidfile); return false; }