chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] daemonize egg: redirect I/O?


From: Thomas Christian Chust
Subject: Re: [Chicken-users] daemonize egg: redirect I/O?
Date: Fri, 26 Oct 2007 11:34:51 +0200
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

Ozzi wrote:

> I am working on for creating unix daemons. Can anyone tell me how to
> redirect stdout and stderr? I want to redirect them to /dev/null by
> default.

Hello,

such an egg would indeed be a useful addition :-)

To redirect the standard file descriptors I would suggest to use the
same technique as if one wanted to achieve this from C:

  (require-extension posix)
  (let ((null-device (file-open
                       "/dev/null"
                       (bitwise-ior open/read open/write))))
    (duplicate-fileno null-device fileno/stdin)
    (duplicate-fileno null-device fileno/stdout)
    (duplicate-fileno null-device fileno/stderr)
    (file-close null-device))

> I would also be interested in comments on my plans for the egg in
> general. Presently, the interface is as follows:
> 
> daemonize is a function that takes a "daemon" proc of one argument, that
> argument being a "cleanup" proc which the "daemon" proc should call
> before it exits.

I wonder why one would want to pass this cleanup argument to the daemon
procedure -- why should the spawned process simply perform cleanup once
the daemon procedure returns?

> [...]
> Let me know what you think, and if you have any other ideas or suggestions.

Apart from redirecting I/O, don't forget to also place your daemon
process into its own process group so it doesn't get terminated when the
parent process' group leader dies (see setsid(2) and daemon(3) in your
system's manpages).

> [...]

cu,
Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]