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: Elf
Subject: Re: [Chicken-users] daemonize egg: redirect I/O?
Date: Fri, 26 Oct 2007 03:11:51 -0700 (PDT)


um, why not just use (duplicate-fileno (portfileno <port>)) ? or if its only stdin/stdout/stderr that youre worried about, calling
(current-[input|output|error]-port) with an argument should change the value.
the above three procs are parameters....

(re: the daemon question, i would just use
     (foreign-lambda int "daemon" int int) ,
 but thats just me.)


-elf



On Fri, 26 Oct 2007, Thomas Christian Chust wrote:

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


_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users





reply via email to

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