diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-10-28 09:46:09 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-29 11:53:01 +0100 |
commit | a46318d414a30c3f30517795b8737600bed91486 (patch) | |
tree | 736925d37f5c2f53c18e9c9aef3853f3847c79ba /Shell/Job.cpp | |
parent | a935a31ecf5e443b12ee0422101fab11863c084a (diff) | |
download | serenity-a46318d414a30c3f30517795b8737600bed91486.zip |
Shell: Do not bail early when printing jobs if waitpid() fails
This fixes running `jobs` in a child process.
Also makes sure that stdout is flushed when writing jobs out.
Diffstat (limited to 'Shell/Job.cpp')
-rw-r--r-- | Shell/Job.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Shell/Job.cpp b/Shell/Job.cpp index 6402a3d5f9..de662033fb 100644 --- a/Shell/Job.cpp +++ b/Shell/Job.cpp @@ -37,13 +37,9 @@ bool Job::print_status(PrintStatusMode mode) { int wstatus; auto rc = waitpid(m_pid, &wstatus, WNOHANG); - if (rc == -1) { - perror("waitpid"); - return false; - } auto status = "running"; - if (rc != 0) { + if (rc > 0) { if (WIFEXITED(wstatus)) status = "exited"; @@ -52,6 +48,15 @@ bool Job::print_status(PrintStatusMode mode) if (WIFSIGNALED(wstatus)) status = "signaled"; + } else if (rc < 0) { + // We couldn't waitpid() it, probably because we're not the parent shell. + // just use the old information. + if (exited()) + status = "exited"; + else if (m_is_suspended) + status = "stopped"; + else if (signaled()) + status = "signaled"; } char background_indicator = '-'; @@ -72,6 +77,7 @@ bool Job::print_status(PrintStatusMode mode) outln("[{}] {} {} {} {} {}", m_job_id, background_indicator, m_pid, m_pgid, status, command); break; } + fflush(stdout); return true; } |