[Toybox] sh: run "command &" in background, showing "jobs" or "ps" will crash

Mingliang HU 胡明亮 mingliang.hu at nio.com
Mon May 29 19:33:53 PDT 2023


When running apps in the background by “xxx &” and try “jobs” or “ps” sometimes, it will crash.
It is caused by some TT.jobs arguments freed.

static void run_lines(void)
…
    // Three cases: 1) background & 2) pipeline | 3) last process in pipeline ;
    // If we ran a process and didn't pipe output, background or wait for exit
    if (pplist && TT.ff->blk->pout == -1) {
      if (ctl && !strcmp(ctl, "&")) {
        if (!TT.jobs.c) TT.jobcnt = 0;
        pplist->job = ++TT.jobcnt;
        arg_add(&TT.jobs, (void *)pplist);
-->  pplist is freed later...
        if (TT.options&FLAG_i) dprintf(2, "[%u] %u\n", pplist->job,pplist->pid);
      } else {
        toys.exitval = wait_pipeline(pplist);
        llist_traverse(pplist, (void *)free_process);
      }
      pplist = 0;
}

Then, in show_job(), it will use random points.


Mingliang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20230530/be0a355a/attachment.htm>


More information about the Toybox mailing list