Make job control work
This commit is contained in:
parent
34761f66d2
commit
fe9bfbf1a0
|
@ -48,32 +48,31 @@
|
||||||
(sync (job-status-rv job)))
|
(sync (job-status-rv job)))
|
||||||
|
|
||||||
(define (spawn-job-status-surveillant job)
|
(define (spawn-job-status-surveillant job)
|
||||||
(let ((channel (make-channel)))
|
(spawn
|
||||||
(spawn
|
(lambda ()
|
||||||
(lambda ()
|
(let ((status (wait (job-proc job) wait/stopped-children)))
|
||||||
(let ((status (wait (job-proc job) wait/stopped-children)))
|
(cond
|
||||||
(cond
|
((status:exit-val status)
|
||||||
((status:exit-val status)
|
=> (lambda (i)
|
||||||
=> (lambda (i)
|
(debug-message "spawn-job-status-surveillant exit-val")
|
||||||
(debug-message "spawn-job-status-surveillant exit-val")
|
(set-job-run-status! job 'ready)
|
||||||
(set-job-run-status! job 'ready)
|
(set-job-end-time! job (date))))
|
||||||
(set-job-end-time! job (date))))
|
((status:stop-sig status)
|
||||||
((status:stop-sig status)
|
=> (lambda (signal)
|
||||||
=> (lambda (signal)
|
(debug-message "spawn-job-status-surveillant stop-sig")
|
||||||
(debug-message "spawn-job-status-surveillant stop-sig")
|
(cond
|
||||||
(cond
|
((= signal signal/ttin)
|
||||||
((= signal signal/ttin)
|
(set-job-run-status! job 'waiting-for-input))
|
||||||
(set-job-run-status! job 'waiting-for-input))
|
((= signal signal/ttou)
|
||||||
((= signal signal/ttou)
|
(set-job-run-status! job 'new-output))
|
||||||
(set-job-run-status! job 'new-output))
|
(else
|
||||||
(else
|
(set-job-run-status! job 'stopped)))))
|
||||||
(set-job-run-status! job 'stopped)))))
|
((status:term-sig status)
|
||||||
((status:term-sig status)
|
=> (lambda (i)
|
||||||
=> (lambda (i)
|
(debug-message "spawn-job-status-surveillant term-sig")
|
||||||
(debug-message "spawn-job-status-surveillant term-sig")
|
(set-job-run-status! job 'stopped))))
|
||||||
(set-job-run-status! job 'stopped))))
|
(placeholder-set!
|
||||||
(placeholder-set!
|
(really-job-status job) status)))))
|
||||||
(really-job-status job) status))))))
|
|
||||||
|
|
||||||
(define (job-running? job)
|
(define (job-running? job)
|
||||||
(eq? (job-run-status job) 'running))
|
(eq? (job-run-status job) 'running))
|
||||||
|
@ -101,7 +100,8 @@
|
||||||
(set-job-run-status! job 'running)
|
(set-job-run-status! job 'running)
|
||||||
(signal-process-group
|
(signal-process-group
|
||||||
(proc:pid (job-proc job)) signal/cont)
|
(proc:pid (job-proc job)) signal/cont)
|
||||||
(spawn-job-status-surveillant job))
|
(spawn-job-status-surveillant job)
|
||||||
|
(send notify-continue/foreground-channel job))
|
||||||
|
|
||||||
(define (pause-job-output job)
|
(define (pause-job-output job)
|
||||||
(pause-console-output (job-console job)))
|
(pause-console-output (job-console job)))
|
||||||
|
@ -138,6 +138,9 @@
|
||||||
(define clear-ready-jobs-channel
|
(define clear-ready-jobs-channel
|
||||||
(make-channel))
|
(make-channel))
|
||||||
|
|
||||||
|
(define notify-continue/foreground-channel
|
||||||
|
(make-channel))
|
||||||
|
|
||||||
(define (add-job! job)
|
(define (add-job! job)
|
||||||
(send add-job-channel job))
|
(send add-job-channel job))
|
||||||
|
|
||||||
|
@ -196,6 +199,14 @@
|
||||||
(lp (cons new-job running)
|
(lp (cons new-job running)
|
||||||
ready stopped new-output waiting-for-input #t)))
|
ready stopped new-output waiting-for-input #t)))
|
||||||
|
|
||||||
|
(wrap (receive-rv notify-continue/foreground-channel)
|
||||||
|
(lambda (job)
|
||||||
|
(lp (cons job running)
|
||||||
|
ready
|
||||||
|
(delete job stopped)
|
||||||
|
(delete job new-output)
|
||||||
|
(delete job waiting-for-input) #t)))
|
||||||
|
|
||||||
(wrap (receive-rv clear-ready-jobs-channel)
|
(wrap (receive-rv clear-ready-jobs-channel)
|
||||||
(lambda (ignore)
|
(lambda (ignore)
|
||||||
(lp running '() stopped new-output waiting-for-input #t)))
|
(lp running '() stopped new-output waiting-for-input #t)))
|
||||||
|
@ -306,29 +317,17 @@
|
||||||
(define-syntax go/bg
|
(define-syntax go/bg
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
((_ epf)
|
((_ epf)
|
||||||
(let* ((orig (tty-info (current-output-port)))
|
(begin
|
||||||
(child (copy-tty-info orig)))
|
|
||||||
(obtain-lock paint-lock)
|
(obtain-lock paint-lock)
|
||||||
(endwin)
|
|
||||||
(drain-tty (current-output-port))
|
(drain-tty (current-output-port))
|
||||||
; (set-tty-process-group (current-output-port) (pid))
|
(set-tty-process-group (current-output-port) (pid))
|
||||||
(set-tty-info:local-flags
|
|
||||||
child
|
|
||||||
(bitwise-and (tty-info:local-flags child)
|
|
||||||
ttyl/ttou-signal))
|
|
||||||
(set-tty-info/now (current-output-port) child)
|
|
||||||
(let ((proc
|
(let ((proc
|
||||||
(fork
|
(fork
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(set-process-group (pid) (pid))
|
(set-process-group (pid) (pid))
|
||||||
(exec-epf epf)))))
|
(exec-epf epf)))))
|
||||||
(let ((job (make-job-sans-console (quote epf) proc)))
|
(let ((job (make-job-sans-console (quote epf) proc)))
|
||||||
(set-tty-info/now (current-output-port) orig)
|
|
||||||
(release-lock paint-lock)
|
(release-lock paint-lock)
|
||||||
job))))))
|
job))))))
|
||||||
|
|
||||||
|
;;; EOF
|
||||||
; (set-tty-info/now (current-input-port) info)))))))
|
|
||||||
|
|
||||||
;;; EOF
|
|
||||||
|
|
|
@ -257,7 +257,9 @@
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (signal)
|
(lambda (signal)
|
||||||
(set-interrupt-handler signal #f))
|
(set-interrupt-handler signal #f))
|
||||||
(list interrupt/int interrupt/quit interrupt/tstp))
|
(list interrupt/int
|
||||||
|
;interrupt/quit
|
||||||
|
interrupt/tstp))
|
||||||
(set-interrupt-handler signal/ttin terminal-input-handler)
|
(set-interrupt-handler signal/ttin terminal-input-handler)
|
||||||
(set-interrupt-handler signal/ttou terminal-output-handler))
|
(set-interrupt-handler signal/ttou terminal-output-handler))
|
||||||
|
|
||||||
|
@ -265,7 +267,7 @@
|
||||||
(let ((info (copy-tty-info (tty-info port))))
|
(let ((info (copy-tty-info (tty-info port))))
|
||||||
(set-tty-info:local-flags
|
(set-tty-info:local-flags
|
||||||
info
|
info
|
||||||
(bitwise-and (tty-info:local-flags info)
|
(bitwise-ior (tty-info:local-flags info)
|
||||||
ttyl/ttou-signal))
|
ttyl/ttou-signal))
|
||||||
(set-tty-info/now port info)))
|
(set-tty-info/now port info)))
|
||||||
|
|
||||||
|
@ -275,6 +277,9 @@
|
||||||
;; handle input
|
;; handle input
|
||||||
(define (run)
|
(define (run)
|
||||||
(save-initial-tty-info! (current-input-port))
|
(save-initial-tty-info! (current-input-port))
|
||||||
|
|
||||||
|
(autoreap-policy #f)
|
||||||
|
|
||||||
(init-screen)
|
(init-screen)
|
||||||
(init-windows!)
|
(init-windows!)
|
||||||
(clear)
|
(clear)
|
||||||
|
|
Loading…
Reference in New Issue