-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fisop/labs#13: "use isatty(3)"
- Loading branch information
Showing
2 changed files
with
26 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,49 @@ | ||
#include <unistd.h> | ||
|
||
#include "printstatus.h" | ||
|
||
// prints information of process' status | ||
void | ||
print_status_info(struct cmd *cmd) | ||
{ | ||
const char *action; | ||
|
||
if (strlen(cmd->scmd) == 0 || cmd->type == PIPE) | ||
return; | ||
|
||
if (WIFEXITED(status)) { | ||
#ifndef SHELL_NO_INTERACTIVE | ||
fprintf(stdout, | ||
"%s Program: [%s] exited, status: %d %s\n", | ||
COLOR_BLUE, | ||
cmd->scmd, | ||
WEXITSTATUS(status), | ||
COLOR_RESET); | ||
#endif | ||
action = "exited"; | ||
status = WEXITSTATUS(status); | ||
} else if (WIFSIGNALED(status)) { | ||
#ifndef SHELL_NO_INTERACTIVE | ||
fprintf(stdout, | ||
"%s Program: [%s] killed, status: %d %s\n", | ||
COLOR_BLUE, | ||
cmd->scmd, | ||
-WTERMSIG(status), | ||
COLOR_RESET); | ||
#endif | ||
action = "killed"; | ||
status = -WTERMSIG(status); | ||
} else if (WTERMSIG(status)) { | ||
action = "stopped"; | ||
status = -WSTOPSIG(status); | ||
} else { | ||
return; | ||
} | ||
|
||
#ifndef SHELL_NO_INTERACTIVE | ||
if (isatty(1)) { | ||
fprintf(stdout, | ||
"%s Program: [%s] stopped, status: %d %s\n", | ||
"%s Program: [%s] %s, status: %d %s\n", | ||
COLOR_BLUE, | ||
cmd->scmd, | ||
-WSTOPSIG(status), | ||
action, | ||
status, | ||
COLOR_RESET); | ||
#endif | ||
status = -WSTOPSIG(status); | ||
} | ||
#endif | ||
} | ||
|
||
// prints info when a background process is spawned | ||
void | ||
print_back_info(struct cmd *back) | ||
{ | ||
#ifndef SHELL_NO_INTERACTIVE | ||
fprintf(stdout, "%s [PID=%d] %s\n", COLOR_BLUE, back->pid, COLOR_RESET); | ||
if (isatty(1)) { | ||
fprintf(stdout, "%s [PID=%d] %s\n", COLOR_BLUE, back->pid, COLOR_RESET); | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters