GLib vs. libgeom: g_close()

Konstantin Belousov kostikbel at gmail.com
Tue Mar 18 15:23:09 UTC 2014


On Mon, Mar 17, 2014 at 10:37:14PM -0400, Ryan Lortie wrote:
> hi,
> 
> I'm part of a team that's trying to get the latest versions of GNOME
> (out of git) building on FreeBSD with the eventual goal of getting a
> "continuous integration" sort of setup so that we can flag FreeBSD
> portability issues in GNOME at an earlier stage.
> 
> We've made some pretty good progress so far:
> 
>   https://wiki.gnome.org/Projects/Jhbuild/FreeBSD
> 
> We hit an issue a bit over a month ago when attempting to get libgtop
> working with the latest GLib on FreeBSD.  Specifically: GLib added a
> g_close() function during the 2.36 cycle which conflicts with the
> g_close() function that is exported by libgeom.
> 
>   https://developer.gnome.org/glib/stable/glib-File-Utilities.html#g-close
>   http://www.unix.com/man-page/FreeBSD/3/g_close/
> 
> I tried to write to pjd@ to ask for advice but I didn't receive any
> reply.
> 
> In tthe short term is that we have had to remove support for reporting
> disk usage statistics on FreeBSD from libgtop in order to avoid the
> conflict.
> 
> In the medium-long term (maybe FreeBSD 11 timeframe) I was wondering if
> it would be possible to change libgeom so that it only uses one
> namespace (eg: geom_) instead of three (geom_, gctl_, g_).  This would
> allow us to re-enable support for disk statistics and would avoid future
> problems that will surely come up in other situations due to this
> conflict.
> 
> I understand that GLib was the second library to use the name 'g_close'
> but there are some factors that I think weigh in favour of GLib's
> continued use of the name:
> 
>  - GLib has a very strong and publicly-stated policy of API/ABI
>    stability
> 
>  - GLib is extremely widely used on essentially every platform in
>    existence
> 
>  - GLib's use of the g_ namespace is long-established, predating the
>    existence of libgeom.  It currently has approximately 4000 symbols
>    starting with g_ in this namespace.
> 
>  - I don't personally believe that it's a good idea to have multiple
>    libraries sharing a namespace, and libgeom is also using three
>    separate namespaces...
> 
> I appreciate any input on this issue.  I particularly hope to be able to
> find a solution that would allow us to re-enable the filesystem
> statistics reporting on FreeBSD.

You really cannot avoid conflict globally. The solution is to start use
versioning for both glib and libgeom, but this is something which cannot
help immediately. BTW, does Linux build of glib provides versioning ?

As an interim solution, something like the following code fragment should
provide stop-gap measure:

void
my_g_close_hack(int fd)
{
	void *libgeom;
	int (*g_close_f)(int);

	libgeom = dlopen("libgeom.so.5", RTLD_LAZY);
	if (libgeom == NULL) {
		fprintf(stderr, "Cannot open libgeom.so.5: %s\n", dlerror());
		return;
	}
	g_close_f = (int (*)(int))dlfunc(libgeom, "g_close");
	if (g_close_f == NULL) {
		fprintf(stderr, "libgeom.so does not resolve g_close: %s\n",
		    dlerror());
		dlclose(libgeom);
		return;
	}
	g_close_f(fd);
	dlclose(libgeom);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-geom/attachments/20140318/71bc1fc1/attachment.sig>


More information about the freebsd-geom mailing list