From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Wolfgang =?ISO-8859-1?Q?J=E4hrling?= Newsgroups: gmane.lisp.guile.user Subject: Handling POSIX signals (Guile 1.6) Date: Sun, 6 Oct 2002 19:10:32 +0200 (MEST) Sender: guile-user-admin@gnu.org Message-ID: <7512.1033924232@www52.gmx.net> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Trace: main.gmane.org 1033924548 31847 127.0.0.1 (6 Oct 2002 17:15:48 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 6 Oct 2002 17:15:48 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17yF0N-0008HO-00 for ; Sun, 06 Oct 2002 19:15:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17yEyB-00013J-00; Sun, 06 Oct 2002 13:13:31 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17yEwr-0005c9-00 for guile-user@gnu.org; Sun, 06 Oct 2002 13:12:09 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17yEw1-0003Np-00 for guile-user@gnu.org; Sun, 06 Oct 2002 13:11:21 -0400 Original-Received: from mx0.gmx.net ([213.165.64.100]) by monty-python.gnu.org with smtp (Exim 4.10) id 17yEvK-0001Vh-00 for guile-user@gnu.org; Sun, 06 Oct 2002 13:10:34 -0400 Original-Received: (qmail 21696 invoked by uid 0); 6 Oct 2002 17:10:32 -0000 Original-To: guile-user@gnu.org X-Priority: 3 (Normal) X-Authenticated-Sender: #0000897519@gmx.net X-Authenticated-IP: [145.254.224.18] X-Mailer: WWW-Mail 1.5 (Global Message Exchange) X-Flags: 0001 Errors-To: guile-user-admin@gnu.org X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.lisp.guile.user:1152 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:1152 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