LingYun Studio embeded system framwork software, such as thirdparty build shell and lingyun library
guowenxue
2024-08-19 b78fa65e73b7e1ebc668fb70dc532e85dc47e312
booster/util_proc.c
@@ -13,12 +13,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include "util_proc.h"
#include "logger.h"
@@ -64,7 +66,7 @@
{
    struct sigaction sigact, sigign;
    log_nrml("Install default signal handler.\n");
    log_info("Install default signal handler.\n");
    /*  Initialize the catch signal structure. */
    sigemptyset(&sigact.sa_mask);
@@ -159,7 +161,7 @@
    if( check_daemon_running(pidfile) )
    {
        log_err("Program already running, process exit now");
        log_error("Program already running, process exit now");
        return -1;
    }
@@ -167,7 +169,7 @@
    {
        if( set_daemon_running(pidfile) < 0 )
        {
            log_err("set program running as daemon failure\n");
            log_error("set program running as daemon failure\n");
            return -2;
        }
    }
@@ -175,7 +177,7 @@
    {
        if( record_daemon_pid(pidfile) < 0 )
        {
            log_err("record program running PID failure\n");
            log_error("record program running PID failure\n");
            return -3;
        }
    }
@@ -209,7 +211,7 @@
    {
        if (mkdir(ipc_dir, mode) < 0)
        {
            log_err("cannot create %s: %s\n", ipc_dir, strerror(errno));
            log_error("cannot create %s: %s\n", ipc_dir, strerror(errno));
            return -1;
        }
@@ -225,11 +227,11 @@
        write(fd, pid, strlen(pid));
        close(fd);
        log_dbg("Record PID<%u> to file %s.\n", getpid(), pid_file);
        log_debug("Record PID<%u> to file %s.\n", getpid(), pid_file);
    }
    else
    {
        log_err("cannot create %s: %s\n", pid_file, strerror(errno));
        log_error("cannot create %s: %s\n", pid_file, strerror(errno));
        return -1;
    }
@@ -257,7 +259,7 @@
    }
    else
    {
        log_err("Can't open PID record file %s: %s\n", pid_file, strerror(errno));
        log_error("Can't open PID record file %s: %s\n", pid_file, strerror(errno));
        return -1;
    }
    return pid;
@@ -356,11 +358,11 @@
int set_daemon_running(const char *pid_file)
{
    daemonize(0, 1);
    log_nrml("Program running as daemon [PID:%d].\n", getpid());
    log_info("Program running as daemon [PID:%d].\n", getpid());
    if (record_daemon_pid(pid_file) < 0)
    {
        log_err("Record PID to file \"%s\" failure.\n", pid_file);
        log_error("Record PID to file \"%s\" failure.\n", pid_file);
        return -2;
    }