[cffi-devel] Using the exec() family of functions
Hi, I have tried to use execv() from glibc in SBCL, but it's either not compatible with SBCL for some reason or I'm not calling it correctly. Perhaps one of you guys can spot mistakes here: CL-USER(2): (use-package :cffi) T CL-USER(3): (define-foreign-library libc (:unix "libc.so.6")) LIBC CL-USER(4): (use-foreign-library libc) #<CFFI::FOREIGN-LIBRARY {B277599}> CL-USER(7): (defcfun "execv" :int (path :string) (args :pointer)) EXECV CL-USER(14): (execv "/bin/chmod" (null-pointer)) zsh: segmentation fault rlwrap sbcl Leslie -- LinkedIn Profile: http://www.linkedin.com/in/polzer Xing Profile: https://www.xing.com/profile/LeslieP_Polzer Blog: http://blog.viridian-project.de/
On Sun, Mar 29, 2009 at 11:11 AM, Leslie P. Polzer <sky@viridian-project.de> wrote:
Perhaps one of you guys can spot mistakes here: [...] CL-USER(14): (execv "/bin/chmod" (null-pointer))
That should be something like: (with-foreign-object (args :string 2) (setf (mem-aref args :string 0) "/bin/chmod") (setf (mem-aref args :pointer 1) (null-pointer)) (execv "/bin/chmod" args)) -- Luís Oliveira http://student.dei.uc.pt/~lmoliv/
On Sun, Mar 29, 2009 at 11:11 AM, Leslie P. Polzer That should be something like:
(with-foreign-object (args :string 2) (setf (mem-aref args :string 0) "/bin/chmod") (setf (mem-aref args :pointer 1) (null-pointer)) (execv "/bin/chmod" args))
I didn't know that the caller is supposed to setup argv[0] as well. Thanks!
On Sun, 2009-03-29 at 12:11 +0200, Leslie P. Polzer wrote:
Hi,
I have tried to use execv() from glibc in SBCL, but it's either not compatible with SBCL for some reason or I'm not calling it correctly.
Perhaps one of you guys can spot mistakes here:
you haven't read its man page carefully
CL-USER(2): (use-package :cffi)
T CL-USER(3): (define-foreign-library libc (:unix "libc.so.6"))
LIBC CL-USER(4): (use-foreign-library libc)
#<CFFI::FOREIGN-LIBRARY {B277599}> CL-USER(7): (defcfun "execv" :int (path :string) (args :pointer))
EXECV CL-USER(14): (execv "/bin/chmod" (null-pointer)) zsh: segmentation fault rlwrap sbcl
(defcfun (%execv "execv") :int (path :string) (args :pointer)) (defun execv/0 (binary) (check-type binary string) (with-foreign-string (cstring binary) (with-foreign-object (v :pointer 2) (setf (mem-aref v :pointer 0) cstring) (setf (mem-aref v :pointer 1) (null-pointer)) (%execv binary v)))) -- Stelian Ionescu a.k.a. fe[nl]ix Quidquid latine dictum sit, altum videtur.
participants (3)
-
Leslie P. Polzer
-
Luís Oliveira
-
Stelian Ionescu