From 37be2f44c685f1d51d8678854c93d91319907862 Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Sun, 16 May 2010 01:34:52 +0800 Subject: [PATCH] Better waitpid(2) --- src/syscalls/ffi-functions-unix.lisp | 7 ++++++- src/syscalls/ffi-types-unix.lisp | 28 ++++++++++++++++++++++++-- src/syscalls/ffi-wrappers-unix.lisp | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/syscalls/ffi-functions-unix.lisp b/src/syscalls/ffi-functions-unix.lisp index a931725..72a54e6 100644 --- a/src/syscalls/ffi-functions-unix.lisp +++ b/src/syscalls/ffi-functions-unix.lisp @@ -661,11 +661,16 @@ processes mapping the same region." (file :string) (argv :pointer)) -(defsyscall (waitpid "waitpid") pid-t +(defsyscall (%waitpid "waitpid") pid-t (pid pid-t) (status :pointer) (options :int)) +(defentrypoint waitpid (pid options) + (with-foreign-pointer (status size-of-int) + (let ((ret (%waitpid pid status options))) + (values ret (mem-ref status :int))))) + (defsyscall (getpid "getpid") pid-t "Returns the process id of the current process") diff --git a/src/syscalls/ffi-types-unix.lisp b/src/syscalls/ffi-types-unix.lisp index 567b763..b216b7e 100644 --- a/src/syscalls/ffi-types-unix.lisp +++ b/src/syscalls/ffi-types-unix.lisp @@ -19,7 +19,7 @@ (include "stdlib.h" "errno.h" "sys/types.h" "sys/stat.h" "sys/mman.h" "fcntl.h" "signal.h" "unistd.h" "limits.h" "time.h" "sys/select.h" "sys/poll.h" "sys/ioctl.h" "sys/resource.h" "pwd.h" "grp.h" - "dirent.h" "sys/utsname.h") + "dirent.h" "sys/utsname.h" "sys/wait.h") #+linux (include "sys/epoll.h" "sys/syscall.h") @@ -59,6 +59,9 @@ (constant (o-sync "O_SYNC")) (constant (o-nofollow "O_NOFOLLOW")) (constant (o-async "O_ASYNC")) +(constant (o-cloexec #+linux "O_CLOEXEC" + #-linux "0")) + ;;;------------------------------------------------------------------------- @@ -188,6 +191,7 @@ :documentation "stop signal generated from keyboard.") (constant (sigcont "SIGCONT") :documentation "continue after stop.") (constant (sigchld "SIGCHLD") :documentation "child status has changed.") +(constant (sigcld "SIGCLD") :documentation "child status has changed.") ; same as above (constant (sigttin "SIGTTIN") :documentation "background read attempted from control terminal.") (constant (sigttou "SIGTTOU") @@ -218,7 +222,19 @@ (constant (sig-dfl "SIG_DFL")) (cstruct sigaction "struct sigaction" - (handler "sa_handler" :type :long)) + (handler "sa_handler" :type :pointer) + (sigaction "sa_sigaction" :type :pointer) + (mask "sa_mask" :type :unsigned-long) ;; actual type can be structure or array... + (flags "sa_flags" :type :int)) + +(constant (sa-nocldstop "SA_NOCLDSTOP")) +(constant (sa-nocldwait "SA_NOCLDWAIT")) +(constant (sa-nodefer "SA_NODEFER")) +(constant (sa-onstack "SA_ONSTACK")) +(constant (sa-resethand "SA_RESETHAND")) +(constant (sa-restart "SA_RESTART")) +(constant (sa-siginfo "SA_SIGINFO")) + ;;;------------------------------------------------------------------------- @@ -680,3 +696,11 @@ ((:enobufs "ENOBUFS")) ((:enotsup "ENOTSUP")) ((:eopnotsupp "EOPNOTSUPP"))) + +;;;------------------------------------------------------------------------- +;;; sys/wait.h +;;;------------------------------------------------------------------------- + +(constant (wnohang "WNOHANG")) +(constant (wuntraced "WUNTRACED")) +(constant (wcontinued "WCONTINUED")) diff --git a/src/syscalls/ffi-wrappers-unix.lisp b/src/syscalls/ffi-wrappers-unix.lisp index af4b80b..7f7ac88 100644 --- a/src/syscalls/ffi-wrappers-unix.lisp +++ b/src/syscalls/ffi-wrappers-unix.lisp @@ -33,6 +33,44 @@ ;;;------------------------------------------------------------------------- +;;; waitpid status readers +;;;------------------------------------------------------------------------- +(include "sys/types.h" "sys/wait.h") + +(declaim (inline wifexited wexitstatus wtermsig wcoredump wifstopped + wstopsig wifcontinued)) + +(defwrapper ("WIFEXITED" wifexited) :int ;; boolean + (status :int)) + +(defwrapper ("WEXITSTATUS" wexitstatus) :int ;; unsigned-char + (status :int)) + +(defwrapper ("WTERMSIG" wtermsig) :int + (status :int)) + +(defwrapper* ("iolib_wcoredump" wcoredump) :int ;; boolean + ((status :int)) +" + #ifdef WCOREDUMP + return WCOREDUMP(status); + #else + return 0; + #endif +") + +(defwrapper ("WIFSTOPPED" wifstopped) :int ;; boolean + (status :int)) + +(defwrapper ("WSTOPSIG" wstopsig) :int + (status :int)) + +(defwrapper ("WIFCONTINUED" wifcontinued) :int ;; boolean + (status :int)) + + + +;;;------------------------------------------------------------------------- ;;; Socket message readers ;;;------------------------------------------------------------------------- -- 2.11.4.GIT