8be67f96f9a14b22700643c81b2ba002324d417c — Simon Ser 2 months ago 39c573e
Fix executing multiple commands at once in an interactive shell
2 files changed, 10 insertions(+), 3 deletions(-)

M shell/job.c
M shell/task/task.c
M shell/job.c => shell/job.c +8 -0
@@ 245,4 245,12 @@   void update_job(struct mrsh_state *state, pid_t pid, int stat) {
  	update_process(state, pid, stat);
+ 
+ 	// Put stopped and terminated jobs in the background
+ 	for (size_t i = 0; i < state->jobs.len; ++i) {
+ 		struct mrsh_job *job = state->jobs.data[i];
+ 		if (job_poll(job) != TASK_STATUS_WAIT) {
+ 			job_set_foreground(job, false, false);
+ 		}
+ 	}
  }

M shell/task/task.c => shell/task/task.c +2 -3
@@ 59,9 59,8 @@ }
  			}
  
- 			if (ctx->state->foreground_job != NULL) {
- 				job_set_foreground(ctx->state->foreground_job, false, false);
- 			}
+ 			// Either the job has terminated, either it's been stopped
+ 			assert(ctx->state->foreground_job == NULL);
  
  			destroy_finished_jobs(ctx->state);