From cecc4c3f7d79c480409e584e6b26aebedae8a758 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 13 Aug 2026 12:39:11 +0000 Subject: ok --- tsh.cc | 11 +++++++---- util.h | 27 +++++++++++++++++---------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/tsh.cc b/tsh.cc index bc550ab..198dde0 100644 --- a/tsh.cc +++ b/tsh.cc @@ -215,12 +215,12 @@ void eval(char *cmdline) if (pid == 0) // child { sigprocmask(SIG_UNBLOCK, &mask_sigchld, NULL); - pid = getpid(); - setpgid(pid, pid); + setpgid(0, 0); execve(argv[0], argv, NULL); - atomic_print("log: command not found\n"); + atomic_print(cmdline, true); + atomic_print(": Command not found\n"); exit(-1); // if no command is found } @@ -409,7 +409,10 @@ void waitfg(pid_t pid) LOG << "finished fg " << endl; if ((j->state == ST)) { - cout << "[" << j->jid << "] (" << pid << ") Stopped " << j->cmdline << endl; + cout << "Job [" << j->jid << "] (" << pid << ") stopped by signal 20" << endl; + } else if (getjobpid(jobs, pid) == nullptr) + { + cout << "Job [" << j->jid << "] (" << pid << ") terminated by signal 2" << endl; } return; } diff --git a/util.h b/util.h index 05eb118..26dab12 100644 --- a/util.h +++ b/util.h @@ -17,13 +17,13 @@ namespace ov4 { -void atomic_print(char *s); +void atomic_print(char*, bool); void atomic_print(int x); -void atomic_debug(char *s); -void atomic_debug(int x); -bool isnum(char *s); -void reverse(char str[], int length); -char* itoa(int num, char* str, int base); +void atomic_debug(char*, bool); +void atomic_debug(int); +bool isnum(char*); +void reverse(char[], int); +char *itoa(int, char*, int); constexpr bool GLOBAL_DEBUG = true; bool DEBUG = false; // verbose mode, can be enabled on demand using something like -v @@ -32,8 +32,15 @@ struct LogVoidify { void operator&(std::ostream&) const {} }; const int DECIMAL = 10; const int LENGTH = 25; -void atomic_print(char *s) +void atomic_print(char *s, bool ignore_wrap = false) { + if (ignore_wrap) + for (int i = 0; s[i] != 0; i++) + if (s[i] == '\n') + { + write(STDOUT_FILENO, s, i); + return; + } write(STDOUT_FILENO, s, strlen(s)); } @@ -57,9 +64,9 @@ void reverse(char str[], int length) } } -void atomic_debug(char *s) +void atomic_debug(char *s, bool ignore_wrap = false) { - if (DEBUG && GLOBAL_DEBUG) atomic_print(s); + if (DEBUG && GLOBAL_DEBUG) atomic_print(s, ignore_wrap); } void atomic_debug(int x) @@ -76,7 +83,7 @@ bool isnum(char *s) } -char* itoa(int num, char* str, int base) +char *itoa(int num, char* str, int base) { int i = 0; bool isNegative = false; -- cgit v1.3.1-4-g156e