boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

42-clone-wait.scm (587B)


      1 ; sys-clone forks; the child exits with 17. The parent calls sys-waitid
      2 ; (idtype=P_PID=1, id=pid, infop=128-byte buffer, options=WEXITED=4) and
      3 ; reads the child's exit code from siginfo_t.si_status (offset 24 on
      4 ; 64-bit Linux). Final exit reflects the child's status.
      5 (define r (sys-clone))
      6 (if (not (car r))
      7     (sys-exit 1)
      8     (if (zero? (cdr r))
      9         (sys-exit 17)
     10         (let ((info (make-bytevector 128 0)))
     11           (let ((wr (sys-waitid 1 (cdr r) info 4)))
     12             (if (car wr)
     13                 (sys-exit (bytevector-u8-ref info 24))
     14                 (sys-exit 2))))))