Skip to content

Commit

Permalink
Use openpty() for run-program on FreeBSD.
Browse files Browse the repository at this point in the history
Opening /dev/ptmx doesn't work for me on the default installation.
  • Loading branch information
stassats committed Mar 22, 2014
1 parent b2ce611 commit 6e0340a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/code/run-program.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ status slot."
;;; Find an unused pty. Return three values: the file descriptor for
;;; the master side of the pty, the file descriptor for the slave side
;;; of the pty, and the name of the tty device for the slave side.
#-(or win32 openbsd)
#-(or win32 openbsd freebsd)
(progn
(define-alien-routine ptsname c-string (fd int))
(define-alien-routine grantpt boolean (fd int))
Expand Down Expand Up @@ -456,12 +456,13 @@ status slot."
slave-name)))
(sb-unix:unix-close master-fd))))))
(error "could not find a pty")))
#+openbsd

#+(or openbsd freebsd)
(progn
(define-alien-routine openpty int (amaster int :out) (aslave int :out)
(name (* char)) (termp (* t)) (winp (* t)))
(defun find-a-pty ()
(with-alien ((name-buf (array char 16)))
(with-alien ((name-buf (array char #.path-max)))
(multiple-value-bind (return-val master-fd slave-fd)
(openpty (cast name-buf (* char)) nil nil)
(if (zerop return-val)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/Config.x86-64-freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ASSEM_SRC += ldso-stubs.S
# worked fine for most things, but LOAD-FOREIGN & friends require
# dlopen() etc., which in turn depend on dynamic linking of the
# runtime.
LINKFLAGS += -dynamic -export-dynamic
OS_LIBS += -lutil

# use libthr (1:1 threading). libpthread (m:n threading) does not work.
ifdef LISP_FEATURE_SB_THREAD
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/Config.x86-freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ ASSEM_SRC += ldso-stubs.S
# worked fine for most things, but LOAD-FOREIGN & friends require
# dlopen() etc., which in turn depend on dynamic linking of the
# runtime.
LINKFLAGS += -dynamic -export-dynamic
LINKFLAGS += -dynamic -Wl,--export-dynamic

OS_LIBS += -lutil

# use libthr (1:1 threading). libpthread (m:n threading) does not work.
ifdef LISP_FEATURE_SB_THREAD
Expand Down
19 changes: 11 additions & 8 deletions tests/run-program.impure.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,17 @@

(with-test (:name (:run-program :pty-stream) :fails-on :win32)
(assert (equal "OK"
(subseq
(with-output-to-string (s)
(assert (= 42 (process-exit-code
(run-program "/bin/sh" '("-c" "echo OK; exit 42") :wait t
:pty s))))
s)
0
2))))
(handler-case
(with-timeout 1
(subseq
(with-output-to-string (s)
(assert (= 42 (process-exit-code
(run-program "/bin/sh" '("-c" "echo OK; exit 42") :wait t
:pty s))))
s)
0
2))
(timeout () "timeout")))))

;; Check whether RUN-PROGRAM puts its child process into the foreground
;; when stdin is inherited. If it fails to do so we will receive a SIGTTIN.
Expand Down
2 changes: 2 additions & 0 deletions tools-for-build/grovel-headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ main(int argc, char *argv[])
defconstant("kern-osrelease", KERN_OSRELEASE);
defconstant("hw-model", HW_MODEL);
defconstant("hw-pagesize", HW_PAGESIZE);

defconstant("path-max", PATH_MAX);
printf("\n");
#endif

Expand Down
2 changes: 1 addition & 1 deletion tools-for-build/ldso-stubs.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ ldso_stub__ ## fct: ; \\
'("ptsname"
"grantpt"
"unlockpt")
#!+openbsd
#!+(or openbsd freebsd)
'("openpty")
'("dlclose"
"dlerror"
Expand Down

0 comments on commit 6e0340a

Please sign in to comment.