Nikodemus Siivola | 2 Nov 2011 19:59
Gravatar

sb-texinfo

I'm planning on making SB-TEXINFO a proper contrib -- I already had
too many slightly divergent copies of it in various projects...

This:

  https://github.com/nikodemus/sb-texinfo

represents my best effort to get all those bits and pieces into one
place. ...haven't yet tested it for SBCL manual or all of those
projects, but for the one I did it looks OK.

If you are guilty of the same sin and have silently extended
docstrings.lisp somewhere, I would much appreciate getting a copy of
you version, along with notes of what it does differently.

Cheers,

 -- Nikodemus

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Sbcl-help mailing list
Sbcl-help <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-help
nicolas edel | 9 Nov 2011 12:09
Picon

sb-ext:run-program that can't be started

Hi,

I want to run an external program from within my Lisp program and then
interact with it using streams. And sb-ext:run-program match this
purpose. On traditional unix, this is done using fork/exec syscalls.
Now the question: is there a way to know wether the exec has failed or
not (and why in the latter case) ?

Eg:
;;; first case: the program doesn't even exist
CL-USER> (run-program "foo" nil :pty t :search t :wait nil :input
:stream :output :stream)
#<SB-IMPL::PROCESS 15214 :RUNNING>
CL-USER> *
#<SB-IMPL::PROCESS :EXITED 1>

;;; second case, the program exists
CL-USER> (run-program "/bin/sleep" '("2") :pty t :search t :wait nil
:input :stream :output :stream)
#<SB-IMPL::PROCESS 15258 :RUNNING>
CL-USER> *
#<SB-IMPL::PROCESS :EXITED 0>

;;; third case, the program exists, is started but return a failure exist status
CL-USER> (run-program "/bin/sh" '("-c" "exit 1") :pty t :search t
:wait nil :input :stream :output :stream)
#<SB-IMPL::PROCESS 15301 :RUNNING>
CL-USER> *
#<SB-IMPL::PROCESS :EXITED 1>
CL-USER>
(Continue reading)

Nikodemus Siivola | 9 Nov 2011 12:50
Gravatar

Re: sb-ext:run-program that can't be started

On 9 November 2011 13:09, nicolas edel <nicolas.edel <at> gmail.com> wrote:

> interact with it using streams. And sb-ext:run-program match this
> purpose. On traditional unix, this is done using fork/exec syscalls.
> Now the question: is there a way to know wether the exec has failed or
> not (and why in the latter case) ?

Not currently, unfortunately.

> ;;; first case: the program doesn't even exist
> CL-USER> (run-program "foo" nil :pty t :search t :wait nil :input
> :stream :output :stream)
> #<SB-IMPL::PROCESS 15214 :RUNNING>
> CL-USER> *
> #<SB-IMPL::PROCESS :EXITED 1>

> 2. In case the requested program doesn't even exist, why does the
> run-program function return a valid object with a :running status ?

Because we create the process object initially with status :RUNNING,
and it takes a tiny moment exec() to happen after the fork, and then
still a bit more for the SIGCHLD handler to get the exit notification
and update the process status.

Cheers,

 -- Nikodemus

------------------------------------------------------------------------------
RSA(R) Conference 2012
(Continue reading)

nicolas edel | 9 Nov 2011 14:14
Picon

Re: sb-ext:run-program that can't be started

On Wed, Nov 9, 2011 at 12:50 PM, Nikodemus Siivola
<nikodemus <at> random-state.net> wrote:
> On 9 November 2011 13:09, nicolas edel <nicolas.edel <at> gmail.com> wrote:
>
>> interact with it using streams. And sb-ext:run-program match this
>> purpose. On traditional unix, this is done using fork/exec syscalls.
>> Now the question: is there a way to know wether the exec has failed or
>> not (and why in the latter case) ?
>
> Not currently, unfortunately.
>
>> ;;; first case: the program doesn't even exist
>> CL-USER> (run-program "foo" nil :pty t :search t :wait nil :input
>> :stream :output :stream)
>> #<SB-IMPL::PROCESS 15214 :RUNNING>
>> CL-USER> *
>> #<SB-IMPL::PROCESS :EXITED 1>
>
>> 2. In case the requested program doesn't even exist, why does the
>> run-program function return a valid object with a :running status ?
>
> Because we create the process object initially with status :RUNNING,
> and it takes a tiny moment exec() to happen after the fork, and then
> still a bit more for the SIGCHLD handler to get the exit notification
> and update the process status.

Ok, I had a look at the source code; This is due to C code where only
the fork syscall is checked but not the exec. Also checking the latter
would avoid calling the make-process function by returning -1 if fork
*or* exec have failed and signal an error with an appropriate
(Continue reading)

Anton Kovalenko | 9 Nov 2011 14:25
Favicon

Re: sb-ext:run-program that can't be started

nicolas edel <nicolas.edel <at> gmail.com> writes:

> Ok, I had a look at the source code; This is due to C code where only
> the fork syscall is checked but not the exec. Also checking the latter
> would avoid calling the make-process function by returning -1 if fork
> *or* exec have failed and signal an error with an appropriate
> description .

It's not that easy: when exec fails, it fails in a child process that
was already created, and we can't return /anything/ to parent (or signal
an error in parent) at that point.

One possible solution is to create a pipe before fork(), set FD_CLOEXEC
on its write side, and wait in parent while its read side is closed.
If exec*() succeeds, there would be no data; if it fails, our child
process can write something to his end of pipe, indicating the failure
(and probably a reason for it). 

--

-- 
Regards, Anton Kovalenko <http://github.com/akovalenko/sbcl-win32-threads/wiki>
+7(916)345-34-02 | Elektrostal' MO, Russia

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
nicolas edel | 9 Nov 2011 14:34
Picon

Re: sb-ext:run-program that can't be started

On Wed, Nov 9, 2011 at 2:25 PM, Anton Kovalenko <anton <at> sw4me.com> wrote:
> nicolas edel <nicolas.edel <at> gmail.com> writes:
>
>> Ok, I had a look at the source code; This is due to C code where only
>> the fork syscall is checked but not the exec. Also checking the latter
>> would avoid calling the make-process function by returning -1 if fork
>> *or* exec have failed and signal an error with an appropriate
>> description .
>
> It's not that easy: when exec fails, it fails in a child process that
> was already created, and we can't return /anything/ to parent (or signal
> an error in parent) at that point.
>
> One possible solution is to create a pipe before fork(), set FD_CLOEXEC
> on its write side, and wait in parent while its read side is closed.
> If exec*() succeeds, there would be no data; if it fails, our child
> process can write something to his end of pipe, indicating the failure
> (and probably a reason for it).

That's indeed the usual way to implement it, and this is what I would
do if such a patch could be integrated. I did some tests using a
simple C program and it works. But as far as I can't test it (and even
compile it) on other OS than Linux/FreeBSD, I would like to know if
there is a way to compile/test before any patch proposal.

:Nicolas

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
(Continue reading)

Nikodemus Siivola | 9 Nov 2011 14:46
Gravatar

Re: sb-ext:run-program that can't be started

On 9 November 2011 15:34, nicolas edel <nicolas.edel <at> gmail.com> wrote:
> That's indeed the usual way to implement it, and this is what I would
> do if such a patch could be integrated. I did some tests using a
> simple C program and it works. But as far as I can't test it (and even
> compile it) on other OS than Linux/FreeBSD, I would like to know if
> there is a way to compile/test before any patch proposal.

Such a patch could definitely be integrated.

There is http://gcc.gnu.org/wiki/CompileFarm which has also NetBSD and
OpenBSD, but if you can tests your changes on Linux/FreeBSD that's
already plenty.

Drop by on #sbcl if you need help building, etc, and don't want to
wait for the mailing list turnaround. :)

Cheers,

 -- Nikodemus

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Sbcl-help mailing list
Sbcl-help <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-help
(Continue reading)

nicolas edel | 9 Nov 2011 14:55
Picon

Re: sb-ext:run-program that can't be started

On Wed, Nov 9, 2011 at 2:46 PM, Nikodemus Siivola
<nikodemus <at> random-state.net> wrote:
> On 9 November 2011 15:34, nicolas edel <nicolas.edel <at> gmail.com> wrote:
>> That's indeed the usual way to implement it, and this is what I would
>> do if such a patch could be integrated. I did some tests using a
>> simple C program and it works. But as far as I can't test it (and even
>> compile it) on other OS than Linux/FreeBSD, I would like to know if
>> there is a way to compile/test before any patch proposal.
>
> Such a patch could definitely be integrated.
>
> There is http://gcc.gnu.org/wiki/CompileFarm which has also NetBSD and
> OpenBSD, but if you can tests your changes on Linux/FreeBSD that's
> already plenty.
>
> Drop by on #sbcl if you need help building, etc, and don't want to
> wait for the mailing list turnaround. :)

Ok, I'll try to make something usable soon and let you know.
Thanks.

:Nicolas

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
Nikodemus Siivola | 9 Nov 2011 15:00
Gravatar

Re: sb-ext:run-program that can't be started

On 9 November 2011 15:55, nicolas edel <nicolas.edel <at> gmail.com> wrote:
> On Wed, Nov 9, 2011 at 2:46 PM, Nikodemus Siivola
> <nikodemus <at> random-state.net> wrote:
>> On 9 November 2011 15:34, nicolas edel <nicolas.edel <at> gmail.com> wrote:
>>> That's indeed the usual way to implement it, and this is what I would
>>> do if such a patch could be integrated. I did some tests using a
>>> simple C program and it works. But as far as I can't test it (and even
>>> compile it) on other OS than Linux/FreeBSD, I would like to know if
>>> there is a way to compile/test before any patch proposal.
>>
>> Such a patch could definitely be integrated.
>>
>> There is http://gcc.gnu.org/wiki/CompileFarm which has also NetBSD and
>> OpenBSD, but if you can tests your changes on Linux/FreeBSD that's
>> already plenty.
>>
>> Drop by on #sbcl if you need help building, etc, and don't want to
>> wait for the mailing list turnaround. :)
>
> Ok, I'll try to make something usable soon and let you know.

Apropos, HACKING file in the sources contains patch submission guidelines, etc.

Cheers,

 -- nikodemus

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
(Continue reading)

Nikodemus Siivola | 16 Nov 2011 13:38
Gravatar

SBCL numeric performance variation

Assuming not everyone here reads Planet Lisp, this could be of
interest for those of you trying to sort out numeric bottlenecks in
your code:

  http://random-state.net/log/3530433886.html

In other words, if you're doing FP and it isn't inlined most of the
way, you're losing big.

Cheers,

 -- Nikodemus

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Sbcl-help mailing list
Sbcl-help <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-help

Gmane