LOG_SYS_ERROR

Table of Contents

LOG_SYS_ERROR

Description

Writes an error-level log message with errno explanation appended at the end of final string.

Info

Think of this as perror() with LOG

Success

Error message written to log output

Failure

Logging fails silently (output not guaranteed)

Usage example (Cross-references)

    can_rollback = true;
    } else {
    LOG_SYS_ERROR("Could not save file position for rollback");
    }
    }
    LOG_ERROR("Failed to get localtime : {}", syserr);
    });
    LOG_SYS_ERROR("Failed to get localtime");
    goto LOG_STREAM_FALLBACK;
    }
    if (e || !file) {
    free(buffer);
    LOG_SYS_ERROR("fopen() failed");
    return false;
    }
    if (fsize != (i64)fread(buffer, 1, fsize, file)) {
    fclose(file);
    LOG_SYS_ERROR("Failed to read complete file");
    return false;
    }
    DIR *dir = opendir(path);
    if (NULL == dir) {
    LOG_SYS_ERROR("opendir(\"{}\") failed", path);
    return (SysDirContents) {0};
    }
    HANDLE file = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    if (file == INVALID_HANDLE_VALUE) {
    LOG_SYS_ERROR("CreateFileA() failed");
    return -1;
    }
    LARGE_INTEGER file_size;
    if (!GetFileSizeEx(file, &file_size)) {
    LOG_SYS_ERROR("GetFileSizeEx() failed");
    CloseHandle(file);
    return -1;
    return (i64)file_stat.st_size;
    } else {
    LOG_SYS_ERROR("stat() failed");
    return -1;
    }
    
    if (pipe(stdin_pipe) == -1 || pipe(stdout_pipe) == -1 || pipe(stderr_pipe) == -1) {
    LOG_SYS_ERROR("pipe() failed");
    if (stdin_pipe[READ_END])
    close(stdin_pipe[READ_END]);
    pid_t pid = fork();
    if (pid < 0) {
    LOG_SYS_ERROR("fork");
    
    close(stdin_pipe[READ_END]);
    
    // if continues then this is bad, execve failed
    LOG_SYS_ERROR("execve() failed");
    
    close(stdin_pipe[READ_END]);
    if (!CreatePipe(&hStdinRead, &hStdinWrite, &sa, 0) || !CreatePipe(&hStdoutRead, &hStdoutWrite, &sa, 0) ||
    !CreatePipe(&hStderrRead, &hStderrWrite, &sa, 0)) {
    LOG_SYS_ERROR("CreatePipe failed");
    
    // Clean up only those handles that were successfully created
    
    if (!CreateProcessA(NULL, cmdline.data, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) {
    LOG_SYS_ERROR("CreateProcessA() failed");
    
    StrDeinit(&cmdline);
    #if defined(__APPLE__) || defined(__linux__)
    if (-1 == kill(proc->pid, SIGTERM)) {
    LOG_SYS_ERROR("kill(pid, SIGTERM) failed");
    }
    int status;
    if (-1 == waitpid(proc->pid, &status, 0)) {
    LOG_SYS_ERROR("waitpid after SIGTERM failed");
    return;
    }
    #else
    if (!TerminateProcess(proc->pi.hProcess, 1)) {
    LOG_SYS_ERROR("TerminateProcess failed");
    return;
    }
    // Wait for it to actually exit
    if (WAIT_FAILED == WaitForSingleObject(proc->pi.hProcess, INFINITE)) {
    LOG_SYS_ERROR("WaitForSingleObject after TerminateProcess failed");
    return;
    }
    if (errno == EINTR)
    continue; // retry on signal
    LOG_SYS_ERROR("read failed");
    total_read = -1;
    break;
    
    if (!PeekNamedPipe(rhandle, NULL, 0, NULL, &available, NULL)) {
    LOG_SYS_ERROR("PeekNamedPipe failed");
    return -1;
    }
    
    if (!ReadFile(rhandle, tmpbuf, 1023, &bytes_read, NULL)) {
    LOG_SYS_ERROR("ReadFile failed");
    return -1;
    }

Share :

Related Posts

JW_STR

JW_STR Description Append a string value (quoted) to the JSON.

Read More

JW_STR_KV

JW_STR_KV Description Write a key and string value into a JSON object.

Read More

LOG_FATAL

LOG_FATAL Description Writes a fatal log message and aborts the program. …[in] : Format string and arguments following printf-style syntax.

Read More