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).

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?

> configure is actually an auto-generated file. The master
> source is in  configure.ac You'll want to conditionalize
> the call to PKG_CHECK_MODULES([GUDEV], [gudev-1.0 >= $GUDEV_REQUIRED])
> in that file instead.

OK, simple patch attached.  It also fixes one apparent typo.

./danfe
--- configure.ac.orig   2013-03-13 05:23:34.000000000 +0800
+++ configure.ac        2013-07-05 18:45:32.000000000 +0800
@@ -30,8 +30,6 @@
 AC_SUBST(GTK_REQUIRED)
 GPHOTO2_REQUIRED=2.4.11
 AC_SUBST(GPHOTO2_REQUIRED)
-GUDEV_REQUIRED=145
-AC_SUBST(GUDEV_REQUIRED)
 DBUS_GLIB_REQUIRED=0.60
 AC_SUBST(DBUS_GLIB_REQUIRED)
 GOBJECT_INTROSPECTION_REQUIRED=0.9.3
@@ -61,7 +59,7 @@
 AC_SUBST(GLIB_CFLAGS)
 AC_SUBST(GLIB_LIBS)
 
-PKG_CHECK_MODULES([GIO], [glib-2.0 >= $GIO_REQUIRED])
+PKG_CHECK_MODULES([GIO], [gio-2.0 >= $GIO_REQUIRED])
 AC_SUBST(GIO_CFLAGS)
 AC_SUBST(GIO_LIBS)
 
@@ -102,9 +100,13 @@
   AC_DEFINE_UNQUOTED([HAVE_GPHOTO25], 1, [whether we're building libgphoto >= 
2.5])
 fi
 
-PKG_CHECK_MODULES([GUDEV], [gudev-1.0 >= $GUDEV_REQUIRED])
-AC_SUBST(GUDEV_CFLAGS)
-AC_SUBST(GUDEV_LIBS)
+if test `uname -s` = "Linux"; then
+  GUDEV_REQUIRED=145
+  AC_SUBST(GUDEV_REQUIRED)
+  PKG_CHECK_MODULES([GUDEV], [gudev-1.0 >= $GUDEV_REQUIRED])
+  AC_SUBST(GUDEV_CFLAGS)
+  AC_SUBST(GUDEV_LIBS)
+fi
 
 PKG_CHECK_MODULES([DBUS_GLIB], [dbus-glib-1 >= $DBUS_GLIB_REQUIRED])
 AC_SUBST(DBUS_GLIB_CFLAGS)
_______________________________________________
Entangle-devel mailing list
Entangle-devel@gna.org
https://mail.gna.org/listinfo/entangle-devel

Reply via email to