From: "Wolfgang Jährling" <pro-linux@gmx.de>
Subject: Handling POSIX signals (Guile 1.6)
Date: Sun, 6 Oct 2002 19:10:32 +0200 (MEST) [thread overview]
Message-ID: <7512.1033924232@www52.gmx.net> (raw)
Hi!
I have a very interesting problem with signals (I'm using Guile 1.6 on
GNU/Linux): I want to handle SIGCHLD so that I can respawn several
programs as soon as they terminate, but I also want to execute shell
commands on other places.
I used Guile's (system ...), but the result was that my SIGCHLD
handler got called, but there was no process for (waitpid WAIT_ANY)
anymore, which in my understanding makes sense as Guile runs signal
handlers only in "safe" situations and (system ...) already collects
(i.e. waits for) the child process before the handler gets called.
Here is what I tried so far:
I came up with the idea of using (throw ...) in the SIGCHLD handler
and catching it in my own procedure that otherwise acts like (system
...). It looks like this:
(define (my-system command)
(catch 'process-terminated
(lambda ()
(let ((pid (primitive-fork)))
(if (zero? pid)
(execl "/bin/sh" "sh" "-c" command)
;; Wait for the SIGCHLD handler to (throw ...).
(let loop ()
(sleep 1)
(loop)))))
(lambda (key status)
status)))
The SIGCHLD handler does the following (I snipped a few unimportant
parts and replaced them with (...) here):
(define (respawn-service signum)
(call/ec (lambda (return)
(let* ((wait-result (waitpid WAIT_ANY))
(pid (car wait-result))
(status (cdr wait-result)))
;; Try to find what we want to respawn.
(for-each-service
(lambda (serv)
(and (respawn? serv)
(running? serv)
(...)
;; We found it.
(begin
(...)
(return #t)))))
;; Nothing to respawn, pass it to `dmd-system'.
(throw 'process-terminated status)))))
This works for the first time, but the handler will not be entered a
second time. I think the reason for this is obvious: The signal
handler has never actually returned, it has just thrown
'process-terminated to a place outside of the handler.
Any suggestions?
Cheers,
GNU/Wolfgang
--
+++ GMX - Mail, Messaging & more http://www.gmx.net +++
NEU: Mit GMX ins Internet. Günstige DSL- & Modem/ISDN-Tarife!
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
next reply other threads:[~2002-10-06 17:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-06 17:10 Wolfgang Jährling [this message]
2002-10-08 4:23 ` Handling POSIX signals (Guile 1.6) Wolfgang Jaehrling
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7512.1033924232@www52.gmx.net \
--to=pro-linux@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).