[Libvir] [patch 9/9] Implement better error reporting
Daniel P. Berrange
berrange at redhat.com
Mon Feb 19 14:20:24 UTC 2007
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.
> #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
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
More information about the libvir-list
mailing list