On Fri, Jul 05, 2013 at 07:16:03PM +0700, Alexey Dokuchaev wrote:
> On Thu, Jul 04, 2013 at 01:35:21PM +0100, Daniel P. Berrange wrote:
> > Hmm, I'd have a slight preference for use of GIO's GSocket +
> > GUnixSocketAddress APIs, rather than directly accessing the
> > POSIX sockets APIs, if you're willing to rewrite to them.
> 
> I've attempted to replace POSIX socket/connect stuff with corresponding
> g_* calls, but cannot figure out to properly handle devd(8) daemon
> restarts.  It's easy when dealing with raw file descriptors, because IO
> channel also works over them (not GSockets).  See my POSIX code below:
> 
> > > +    case G_IO_STATUS_EOF:
> > > +    case G_IO_STATUS_AGAIN:
> > > +        /*
> > > +         * Apparently, devd(8) was reinited (restarted?).  Allocate
> > > +         * new channel and teardown previous connection.
> > > +         */
> > > +        devd_init(manager);
> > > +        if (manager->priv->efd > 0) {
> > > +            int old_efd = g_io_channel_unix_get_fd(source);
> > > +            g_io_channel_shutdown(source, FALSE, NULL);
> > > +            close(old_efd);
> > > +            return FALSE;
> > > +        }
> > > +        break;
> 
> Now with GSocket, I'm no longer working with "int fd", but with GSocket*
> priv->ctx (I reused the same name as in Linux, since they both unrefed in
> the same way, just differ in type).
> 
> If I replace it with something like this (to avoid caching priv->ctx),
> once I issue "service devd restart", autodetection stops working. :-(
> 
>   if (manager->priv->ctx) {
>       g_io_channel_shutdown(source, FALSE, NULL);
>       g_object_unref(manager->priv->ctx);
>   }
>   devd_init(manager);
> 
> What I need to do, is first to reestablish new connection to newly run
> devd, and then g_io_channel_shutdown(...)/g_object_unref(oldsocket).

IMHO the order you have here ought to be ok.

> I'm not sure how to correctly emulate "old_efd = 
> g_io_channel_unix_get_fd(...)"
> to obtain underlying (old, stray) GSocket.  Any ideas how to correctly reopen
> new socket, and *then* teardown old channel/socket in GIO words?

Can you send the code you currently have, so I can see the bigger
picture of how you now have it written.

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 :|

_______________________________________________
Entangle-devel mailing list
Entangle-devel@gna.org
https://mail.gna.org/listinfo/entangle-devel

Reply via email to