Daniel P. Berrange wrote:
On Sat, Feb 17, 2007 at 01:11:48PM +0000, Richard W.M. Jones wrote:
> oneMark McLoughlin wrote:
>> Add a qemudLog() function which uses syslog() if we're in
>> daemon mode, doesn't output INFO/DEBUG messages unless
>> the verbose flag is set and doesn't output DEBUG messages
>> unless compiled with --enable-debug.
> You're all gonna hate this I know, but libvirtd handles syslog by
> forking an external logger(1) process. Messages sent to stderr go to
> syslog. This is partly necessary because the SunRPC code within glibc
> is a bit too happy to send debug messages to stderr & nowhere else.
Is this just wrt to the server side of SunRPC, or does it apply to the
client side too ? If using libvirt from command line tools it won't
be nice if SunRPC is spewing crap to STDERR.
The external logger only applies server-side.
On the client side I am very careful to turn all RPC (and other) errors
into virterror errors. However it may still be the case that SunRPC
code prints additional messages to stderr, although no relevant debug
information should be lost (all pertinent information related to an RPC
will make it into the virterror mechanism).
[The complicated bit, unrelated to this, is virterrors generated on the
server side. What the latest version does is to serialise these errors
and pass them to the client side, where they are converted into
virterror errors on the client side. Thus things like user error
handling should work transparently over the remote connection.]
> #ifdef LOGGER
> /* Send stderr to syslog using logger. It's a lot simpler
> * to do this. Note that SunRPC in glibc prints lots of
> * gumf to stderr and it'd be a load of work to change that.
> */
> int fd[2];
> if (pipe (fd) == -1) {
> perror ("pipe");
> exit (2);
> }
> int pid = fork ();
> if (pid == -1) {
> perror ("fork");
> exit (2);
> }
> if (pid == 0) { /* Child - logger. */
> const char *args[] = {
> "logger", "-tlibvirtd", "-p",
"daemon.notice", NULL
> };
> close (fd[1]);
> dup2 (fd[0], 0);
> close (fd[0]);
> execv (LOGGER, (char *const *) args);
> perror ("execv");
> _exit (1);
> }
> close (fd[0]);
> dup2 (fd[1], 2);
> close (fd[1]);
> #endif
BTW, need to make sure all file descriptors are either explicitly closed,
or have close-on-exec set
Do you mean fds > 2 which might be passed across the fork in the code
above? Or the new stderr-to-pipe in the parent process?
Rich.
--
Emerging Technologies, Red Hat
http://et.redhat.com/~rjones/
64 Baker Street, London, W1U 7DF Mobile: +44 7866 314 421
"[Negative numbers] darken the very whole doctrines of the equations
and make dark of the things which are in their nature excessively
obvious and simple" (Francis Maseres FRS, mathematician, 1759)