Index | Thread | Search

From:
Theo Buehler <tb@theobuehler.org>
Subject:
Re: x11/gentoo build fix for opaque FILE
To:
YASUOKA Masahiko <yasuoka@openbsd.org>
Cc:
ports@openbsd.org
Date:
Tue, 15 Jul 2025 08:54:15 +0200

Download raw body.

Thread
On Tue, Jul 15, 2025 at 03:44:57PM +0900, YASUOKA Masahiko wrote:
> On Sun, 13 Jul 2025 00:09:07 +0200
> Theo Buehler <tb@theobuehler.org> wrote:
> > I don't think this code is actually used. The static FILE themselves
> > are just placeholders as is explained in the nearby comments. Instead
> > of addresses to statics, we can just open the files normally use the
> > pointers for copmarison and close them again.
> 
> My diff below fixes the same problem by putting a dummy __sFILE.  The
> downside of this is the patch can only be applied after the stdio
> opaque patch.

I saw. The code seems to be compiled but unused, so I don't have a
real preference and am happy to go with yours since it's simpler.
If you want to commit now, I think you could guard the dummy with this:

#if defined(__OpenBSD__) && !defined(__sferror)
struct __sFILE { long dummy; };
#endif

Either way is ok with me.

> 
> (I've sent the diff for x11/gentoo for hackers@ with the diffs for
>  others)
> 
> Index: x11/gentoo/patches/patch-src_mntent_wrap_c
> ===================================================================
> RCS file: x11/gentoo/patches/patch-src_mntent_wrap_c
> diff -N x11/gentoo/patches/patch-src_mntent_wrap_c
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ x11/gentoo/patches/patch-src_mntent_wrap_c	15 Jul 2025 01:27:46 -0000
> @@ -0,0 +1,15 @@
> +Index: src/mntent_wrap.c
> +--- src/mntent_wrap.c.orig
> ++++ src/mntent_wrap.c
> +@@ -101,6 +101,11 @@ gint mne_endmntent(FILE *filep)
> + #include <sys/param.h>
> + #include <sys/ucred.h>
> + 
> ++#ifdef __OpenBSD__
> ++/* recent OpenBSD doesn't expose struct __sFILE anymore */
> ++struct __sFILE { long dummy; };
> ++#endif
> ++
> + /* A pointer to one of these is returned by mne_setmntent(), depending on which file
> + ** name is given as an input. Note that on BSD systems, the system calls themselves
> + ** deal with the reading of files, so gentoo will never in fact open any files. But
> 
> > mntent_wrap.c:112:13: error: tentative definition has type 'FILE' (aka
> > 'struct __sFILE') that is
> > never completed
> >   112 | static FILE     f_fstab, f_mtab;
> >       |                 ^
> > 
> > Index: patches/patch-src_mntent_wrap_c
> > ===================================================================
> > RCS file: patches/patch-src_mntent_wrap_c
> > diff -N patches/patch-src_mntent_wrap_c
> > --- /dev/null	1 Jan 1970 00:00:00 -0000
> > +++ patches/patch-src_mntent_wrap_c	12 Jul 2025 14:07:11 -0000
> > @@ -0,0 +1,80 @@
> > +Index: src/mntent_wrap.c
> > +--- src/mntent_wrap.c.orig
> > ++++ src/mntent_wrap.c
> > +@@ -109,7 +109,7 @@ gint mne_endmntent(FILE *filep)
> > + ** of what kind of mount entries we're supposed to deal with. Since gentoo will
> > + ** pass a FILE pointer to mne_getmntent() anyway, it seems natural to use it.
> > + */
> > +-static FILE	f_fstab, f_mtab;
> > ++static FILE	*f_fstab, *f_mtab;
> > + 
> > + /* These are used when we're accessing the currently mounted filesystems, using
> > + ** a call to getmntinfo(). The mtab_pos and mtab_num integers are then used to
> > +@@ -131,29 +131,34 @@ FILE * mne_setmntent(const gchar *filename)
> > + 
> > + 	if(strcmp(filename, "/etc/fstab") == 0)		/* Looking for available filesystems? */
> > + 	{
> > +-		if(setfsent() == 1)
> > +-			return &f_fstab;
> > ++		if(setfsent() == 1) {
> > ++			if (f_fstab == NULL)
> > ++				f_fstab = fopen(filename, "r");
> > ++			return f_fstab;
> > ++		}
> > + 	}
> > + 	else if(strcmp(filename, "/proc/mtab") == 0)	/* Looking for mounted filesystems? */
> > + 	{
> > + 		if((mtab_num = getmntinfo(&mtab, 0)) > 0)
> > + 		{
> > + 			mtab_pos = 0;
> > +-			return &f_mtab;
> > ++			if (f_mtab == NULL)
> > ++				f_mtab = fopen(filename, "r");
> > ++			return f_mtab;
> > + 		}
> > + 	}
> > + 	return NULL;
> > + }
> > + 
> > +-/* 1999-05-09 -	Get another entry of data, either about mounted (filep == &f_mtab) or available
> > +-**		(filep == &f_fstab) filesystems. Returns NULL when the respective data source
> > ++/* 1999-05-09 -	Get another entry of data, either about mounted (filep == f_mtab) or available
> > ++**		(filep == f_fstab) filesystems. Returns NULL when the respective data source
> > + **		is exhausted.
> > + */
> > + const MntEnt * mne_getmntent(FILE *filep)
> > + {
> > + 	static MntEnt	me;
> > + 
> > +-	if(filep == &f_fstab)
> > ++	if(filep == f_fstab)
> > + 	{
> > + 		struct fstab	*ment;
> > + 
> > +@@ -164,7 +169,7 @@ const MntEnt * mne_getmntent(FILE *filep)
> > + 			return &me;
> > + 		}
> > + 	}
> > +-	else if(filep == &f_mtab)
> > ++	else if(filep == f_mtab)
> > + 	{
> > + 		if(mtab_pos == mtab_num)		/* Array exhausted? */
> > + 			return NULL;
> > +@@ -182,8 +187,16 @@ const MntEnt * mne_getmntent(FILE *filep)
> > + /* 1999-05-09 -	Stop traversing mount/fs data. */
> > + gint mne_endmntent(FILE *filep)
> > + {
> > +-	if(filep == &f_fstab)
> > ++	if (filep == NULL)
> > ++		return 0;
> > ++	if(filep == f_fstab) {
> > ++		fclose(f_fstab);
> > ++		f_fstab = NULL;
> > + 		endfsent();
> > ++	} else if (filep == f_mtab) {
> > ++		fclose(f_mtab);
> > ++		f_mtab = NULL;
> > ++	}
> > + 
> > + 	return 0;
> > + }
> > 
> >