Skip to content

LOG_SYS_ERROR

Description

Writes an error-level log message with the caller-supplied system error code explained. See LOG_SYS_FATAL for the errno-passing rationale.

Parameters

Name Direction Description
eno in System error code.

Success

Message + decoded error description written to fd 2.

Failure

Formatter / FileWrite errors are dropped silently.

Usage example (Cross-references)

Usage examples (Cross-references)
        long ret = direct_sys3(MISRA_SYS_mprotect, (long)(u64)ptr, (long)bytes, (long)posix_prot);
        if (ret != 0) {
            LOG_SYS_ERROR(ErrnoOf((i32)ret), "PageProtect: mprotect failed");
            return false;
        }
            // off): mprotect returns -1 and the system error is recovered
            // through ErrnoOf below.
            LOG_SYS_ERROR(ErrnoOf(-1), "PageProtect: mprotect failed");
            return false;
        }
    // syscall it carries -errno directly; on libSystem (macOS) the value
    // is -1 and errno is set. ErrnoOf papers over the difference.
    #    define LOG_SOCK_ERROR(ret, msg) LOG_SYS_ERROR(ErrnoOf(ret), msg)
    #endif // PLATFORM_WINDOWS
            pipe_ret = proc_pipe(stderr_pipe);
        if (pipe_ret < 0) {
            LOG_SYS_ERROR(ErrnoOf(pipe_ret), "proc_pipe() failed");
            if (stdin_pipe[READ_END] >= 0)
                direct_sys1(MISRA_SYS_close, (long)(stdin_pipe[READ_END]));
        pid_t pid = proc_fork();
        if (pid < 0) {
            LOG_SYS_ERROR(ErrnoOf(pid), "fork");
            direct_sys1(MISRA_SYS_close, (long)(stdin_pipe[READ_END]));
            direct_sys1(MISRA_SYS_close, (long)(stdout_pipe[READ_END]));
            // immediately via SYS_exit_group (127 is the conventional shell
            // "command not found" / exec-failed status).
            LOG_SYS_ERROR(ErrnoOf(exec_ret), "execve() failed");
            (void)direct_sys1(MISRA_SYS_exit_group, 127);
            // exit_group does not return; the unreachable proc return is
        long wait_ret = direct_sys4(MISRA_SYS_wait4, (long)(proc->_pid), (long)(u64)(&status), (long)(0), 0);
        if (wait_ret < 0) {
            LOG_SYS_ERROR(ErrnoOf(wait_ret), "Failed to wait for child process");
            return PROC_STATUS_ERROR;
        }
        long kill_ret = direct_sys2(MISRA_SYS_kill, (long)(proc->_pid), (long)(SIGTERM));
        if (kill_ret < 0) {
            LOG_SYS_ERROR(ErrnoOf(kill_ret), "direct_sys2(MISRA_SYS_kill, (long)(pid), (long)(SIGTERM)) failed");
        }
        long wait_ret = direct_sys4(MISRA_SYS_wait4, (long)(proc->_pid), (long)(u64)(&status), (long)(0), 0);
        if (wait_ret < 0) {
            LOG_SYS_ERROR(ErrnoOf(wait_ret), "waitpid after SIGTERM failed");
            return;
        }
                        continue;
    #    endif
                    LOG_SYS_ERROR(ErrnoOf(n), "read failed");
                    total_read = -1;
                    break;
    #    endif
        if (fd < 0) {
            LOG_SYS_ERROR(ErrnoOf(fd), "DirGetContents: open(\"{}\")", path);
            return dc;
        }
            }
            if (n < 0) {
                LOG_SYS_ERROR(ErrnoOf(n), "DirGetContents: getdents64");
                break;
            }
    #    endif
        if (fd < 0) {
            LOG_SYS_ERROR(ErrnoOf(fd), "FileGetSize: open(\"{}\")", filename);
            return -1;
        }
        (void)direct_sys1(MISRA_SYS_close, fd);
        if (sz < 0) {
            LOG_SYS_ERROR(ErrnoOf(sz), "FileGetSize: lseek on \"{}\"", filename);
            return -1;
        }
    #    endif
        if (ret < 0) {
            LOG_SYS_ERROR(ErrnoOf(ret), "FileRemove(\"{}\")", path);
            return 0;
        }
    #    endif
        if (ret < 0) {
            LOG_SYS_ERROR(ErrnoOf(ret), "DirRemove(\"{}\")", path);
            return 0;
        }
    #    endif
        if (ret < 0) {
            LOG_SYS_ERROR(ErrnoOf(ret), "DirCreate(\"{}\")", path);
            return 0;
        }
Last updated on