- char *run[2];
-
- if (s->state == S_FINISH)
- run[0] = (char*)"./finish";
- else {
- run[0] = (char*)"./run";
+ const char *arg[4];
+ char exitcode[sizeof(int)*3 + 2];
+
+ if (s->state == S_FINISH) {
+/* Two arguments are given to ./finish. The first one is ./run exit code,
+ * or -1 if ./run didnt exit normally. The second one is
+ * the least significant byte of the exit status as determined by waitpid;
+ * for instance it is 0 if ./run exited normally, and the signal number
+ * if ./run was terminated by a signal. If runsv cannot start ./run
+ * for some reason, the exit code is 111 and the status is 0.
+ */
+ arg[0] = "./finish";
+ arg[1] = "-1";
+ if (WIFEXITED(s->wstat)) {
+ *utoa_to_buf(WEXITSTATUS(s->wstat), exitcode, sizeof(exitcode)) = '\0';
+ arg[1] = exitcode;
+ }
+ //arg[2] = "0";
+ //if (WIFSIGNALED(s->wstat)) {
+ arg[2] = utoa(WTERMSIG(s->wstat));
+ //}
+ arg[3] = NULL;
+ } else {
+ arg[0] = "./run";
+ arg[1] = NULL;