Quellcode durchsuchen

Shell: Print the name of each process whose exit status we're reporting.

Andreas Kling vor 6 Jahren
Ursprung
Commit
ecb72dd991
1 geänderte Dateien mit 11 neuen und 6 gelöschten Zeilen
  1. 11 6
      Shell/main.cpp

+ 11 - 6
Shell/main.cpp

@@ -359,7 +359,12 @@ static int run_command(const String& cmd)
     struct termios trm;
     struct termios trm;
     tcgetattr(0, &trm);
     tcgetattr(0, &trm);
 
 
-    Vector<pid_t> children;
+    struct SpawnedProcess {
+        String name;
+        pid_t pid;
+    };
+
+    Vector<SpawnedProcess> children;
 
 
     CommandTimer timer;
     CommandTimer timer;
 
 
@@ -408,7 +413,7 @@ static int run_command(const String& cmd)
             }
             }
             ASSERT_NOT_REACHED();
             ASSERT_NOT_REACHED();
         }
         }
-        children.append(child);
+        children.append({ argv[0], child });
     }
     }
 
 
 #ifdef SH_DEBUG
 #ifdef SH_DEBUG
@@ -429,7 +434,7 @@ static int run_command(const String& cmd)
     for (int i = 0; i < children.size(); ++i) {
     for (int i = 0; i < children.size(); ++i) {
         auto& child = children[i];
         auto& child = children[i];
         do {
         do {
-            int rc = waitpid(child, &wstatus, 0);
+            int rc = waitpid(child.pid, &wstatus, 0);
             if (rc < 0 && errno != EINTR) {
             if (rc < 0 && errno != EINTR) {
                 if (errno != ECHILD)
                 if (errno != ECHILD)
                     perror("waitpid");
                     perror("waitpid");
@@ -437,14 +442,14 @@ static int run_command(const String& cmd)
             }
             }
             if (WIFEXITED(wstatus)) {
             if (WIFEXITED(wstatus)) {
                 if (WEXITSTATUS(wstatus) != 0)
                 if (WEXITSTATUS(wstatus) != 0)
-                    printf("Shell: Child %d exited with status %d\n", child, WEXITSTATUS(wstatus));
+                    printf("Shell: %s(%d) exited with status %d\n", child.name.characters(), child.pid, WEXITSTATUS(wstatus));
                 if (i == 0)
                 if (i == 0)
                     return_value = WEXITSTATUS(wstatus);
                     return_value = WEXITSTATUS(wstatus);
             } else {
             } else {
                 if (WIFSIGNALED(wstatus)) {
                 if (WIFSIGNALED(wstatus)) {
-                    printf("Shell: Child %d exited due to signal '%s'\n", child, strsignal(WTERMSIG(wstatus)));
+                    printf("Shell: %s(%d) exited due to signal '%s'\n", child.name.characters(), child.pid, strsignal(WTERMSIG(wstatus)));
                 } else {
                 } else {
-                    printf("Shell: Child %d exited abnormally\n", child);
+                    printf("Shell: %s(%d) exited abnormally\n", child.name.characters(), child.pid);
                 }
                 }
             }
             }
         } while(errno == EINTR);
         } while(errno == EINTR);