g_open seems to require 3 arguments on some platforms/versions

Bug #999718 reported by reed on 2012-05-15
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Light Display Manager
Medium
Matt Fischer

Bug Description

I have the following (but untested). I am using glib2-2.32.2.

--- src/vt.c.orig 2012-05-14 20:12:26.000000000 -0500
+++ src/vt.c 2012-05-14 20:12:41.000000000 -0500
@@ -30,7 +30,7 @@
 {
     int fd;

- fd = g_open ("/dev/console", O_RDONLY | O_NOCTTY);
+ fd = g_open ("/dev/console", O_RDONLY | O_NOCTTY, 0);
     if (fd < 0)
         g_warning ("Error opening /dev/console: %s", strerror (errno));
     return fd;

Related branches

Matt Fischer (mfisch) wrote :

g_open doesn't seem to require the 3rd argument, perhaps it follows the manpage for open, where mode is only required when O_CREAT is specified? Is this causing a problem on your platform?

Changed in lightdm:
status: New → Incomplete
reed (reed-reedmedia) wrote :

  CC lightdm-vt.o
vt.c: In function 'open_console':
vt.c:33: error: too few arguments to function 'g_open'
gmake[3]: *** [lightdm-vt.o] Error 1

See
http://developer.gnome.org/glib/stable/glib-File-Utilities.html#g-open

As for the mode, I don't know what it used for. Maybe 600 would be better.

Matt Fischer (mfisch) wrote :

This builds fine on Ubuntu, and so does this simple test code:

#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <glib/gstdio.h>
#include <glib.h>

int main(void)
{
    int fd;
    fd = g_open ("./foo.c", O_RDONLY);
    if (fd >= 0) {
        close(fd);
    }
    fd = g_open ("./foo.c", O_RDONLY, 0);
    if (fd >= 0) {
        close(fd);
    }
    return 0;
}

mfisch@caprica:~/tmp$ gcc foo.c `pkg-config glib-2.0 --cflags --libs` -Wall
mfisch@caprica:~/tmp$

g_open is backed by open, and if you look at the open manpage it says "mode specifies the permissions to use in case a new file is created. This argument must be supplied when O_CREAT is specified in flags; if O_CREAT is not specified, then mode is ignored."

It seems that glib for me anyway is respecting this ignore option, although I cannot make it fail even if I switch the call above to O_CREAT and don't set a 3rd argument.

Are we using the same glib? I am using 2.32.1-0ubuntu2.

Of course we can still specify a mode here so that it doesn't break your build, but I'd like to know why it works fine for me.

Changed in lightdm:
assignee: nobody → Matt Fischer (mfisch)
summary: - what g_open version?
+ g_open seems to require 3 arguments on some platforms/versions
reed (reed-reedmedia) wrote :

I am using glib2-2.32.2 (as mentioned in original problem report). This was installed using the pkgsrc package system. This was tested on NetBSD not Ubuntu.

(Ignore my previous comment on non-0 mode -- I didn't pay attention to that it was read-only so mode is ignored.)

Now I see the pkgsrc package has a patch for this:

date: 2012/02/16 15:09:54; author: drochner; state: Exp;
open(2) is variadic (at least in Posix and NetBSD), g_open is not,
don't mix them, the ABIs are incompatible at least on amd64
bump PKGREV

The NetBSD problem report related to it was:
http://gnats.netbsd.org/45942

So maybe some glib2 issue.

Matt Fischer (mfisch) wrote :

Reed:

I'm not familiar with pkgsrc, but does that mean that glib2 was modified to fix this issue or that the issue is that glib doesn't complain when the 3rd argument is missing?

Matt Fischer (mfisch) wrote :

Also, I poked through the glib-2.0 source code and it looks like they use 2 args sometimes (well at least in one place) and they pass in 0 when the mode isn't needed.

gio/glocalfileoutputstream.c: fd = g_open (filename, open_flags, mode);
gio/glocalfile.c: fd = g_open (local->filename, O_RDONLY|O_BINARY, 0);
glib/gfileutils.c: * fd = g_open (filename, O_WRONLY);
glib/gkeyfile.c: fd = g_open (path, O_RDONLY, 0);
glib/gkeyfile.c: fd = g_open (file, O_RDONLY, 0);

reed (reed-reedmedia) wrote :

Pkgsrc is a packaging system. It provides build recipes and patches (if needed) for building and installing and bundling software.

Note that the glib/gfileutils.c line is commented out (and that file has other example that does use three arguments). So the documentation and the used examples all use the third argument.
I may need to ask about this upstream at glib.

Please consider just using 0 for a mode even if not needed.

Matt Fischer (mfisch) on 2012-06-05
Changed in lightdm:
status: Incomplete → New
Matt Fischer (mfisch) on 2012-06-05
Changed in lightdm:
status: New → In Progress
Matt Fischer (mfisch) wrote :

Well I don't see a harm in changing it, it would match the docs, examples, headers, etc. Working on it now.

Changed in lightdm:
status: In Progress → Fix Committed
importance: Undecided → Medium
Robert Ancell (robert-ancell) wrote :

Fixed in 1.3.1

Changed in lightdm:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers