[libvirt] [PATCH] virt-login-shell joins users into lxc container.

Daniel P. Berrange berrange at redhat.com
Tue Jul 30 15:18:29 UTC 2013


On Fri, Jul 26, 2013 at 12:26:36PM -0400, Daniel J Walsh wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 07/26/2013 07:40 AM, Daniel P. Berrange wrote:
> > On Fri, Jul 26, 2013 at 07:38:31AM -0400, Daniel J Walsh wrote:
> >> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
> >> 
> >> I can't seem to get the error reporting to turn on, what am I doing
> >> wrong.,
> >> 
> >> if (virInitialize() < 0) { fprintf(stderr, _("Failed to initialize
> >> libvirt")); return EXIT_FAILURE; }
> >> 
> >> if (virErrorInitialize() < 0) { fprintf(stderr, _("Failed to initialize
> >> libvirt Error Handling")); return EXIT_FAILURE; }
> >> 
> >> virSetErrorFunc(NULL, NULL);
> >> 
> >> 
> >> virReportSystemError(EINVAL, "%s", _("Test"));
> >> 
> >> And I get no output, I thought I would get error on stderr?
> > 
> > You would, except that you just turned off printing to stderr by calling
> > virSetErrorFunc in that way.
> > 
> > 
> > Daniel
> > 
> Am I misreading this?
> * virSetErrorFunc:
> * @userData: pointer to the user data provided in the handler callback
> * @handler: the function to get called in case of error or NULL
> *
> * Set a library global error handling function, if @handler is NULL,
> * it will reset to default printing on stderr. The error raised there
> * are those for which no handler at the connection level could caught.
> */
> Looks like setting handler to Null reset default printing on stderr?
> But I am getting no output whether or not I set this.

Oh, whoops, I'm back to front.

The actual reason you're having trouble is that you're using
virReportError from outside the context of any public API
calls.

virReportError does not actually print any errors, it just
records them. It requires a seprate call to virDispatchError
to trigger the print to stderr.  This is usually taken care
of by the public API methods.

You'll have to take care of it yourself though. If you
have a centralized error handling return point eg

    ...success...
     return 0;

   error:
      return -1;
   }

Then you'd put a virDispatchError call just after the
'error:' label

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list