! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
diskperf-plugin: missing <sys/sysmacros.h> include (fails to build w/ glibc-2...
Status:
RESOLVED: FIXED
Product:
Xfce4-diskperf-plugin
Component:
General

Comments

Description Michał Górny 2017-10-21 00:16:54 CEST
Created attachment 7377 
0001-Add-sys-sysmacros.h-include-required-for-glibc-2.25.patch

When building against glibc-2.25+:

devperf.c: In function ‘DevGetPerfData1’:
devperf.c:65:32: warning: implicit declaration of function ‘major’ [-Wimplicit-function-declaration]
     const int       iMajorNo = major(p_iDevice),
                                ^
devperf.c:66:13: warning: implicit declaration of function ‘minor’ [-Wimplicit-function-declaration]
  iMinorNo = minor(p_iDevice);
             ^
devperf.c:69:21: error: ‘major’ redeclared as different kind of symbol
     unsigned int    major, minor, rsect, wsect, ruse, wuse, use;
                     ^
devperf.c:65:32: note: previous implicit declaration of ‘major’ was here
     const int       iMajorNo = major(p_iDevice),
                                ^
devperf.c:69:28: error: ‘minor’ redeclared as different kind of symbol
     unsigned int    major, minor, rsect, wsect, ruse, wuse, use;
                            ^
devperf.c:66:13: note: previous implicit declaration of ‘minor’ was here
  iMinorNo = minor(p_iDevice);
             ^
devperf.c:87:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
  fscanf (pF, "%*s"); /* Skip device name */
  ^


This version of glibc no longer implicitly includes major/minor macros via other headers. It requires using <sys/sysmacros.h> for that explicitly (it also works on BSD). I'm attaching a patch fixing the issue.
Comment 1 Skunnyk editbugs 2017-10-21 22:02:59 CEST
With glibc 2.26:

devperf.c: In function ‘DevGetPerfData1’:
devperf.c:65:13: warning: In the GNU C Library, "major" is defined
 by <sys/sysmacros.h>. For historical compatibility, it is
 currently defined by <sys/types.h> as well, but we plan to
 remove this soon. To use "major", include <sys/sysmacros.h>
 directly. If you did not intend to use a system-defined macro
 "major", you should undefine it after including <sys/types.h>.
     const int       iMajorNo = major(p_iDevice),
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   





I can confirm that the patch fix the problem
Comment 2 Landry Breuil editbugs 2017-10-21 22:05:30 CEST
OpenBSD doesn't have sysmacros.h :)
Comment 3 Landry Breuil editbugs 2017-10-21 22:06:59 CEST
I'd rather have this within a #ifdef _SOMETHING_GLIBC but the patch is fine otherwise
Comment 4 Landry Breuil editbugs 2017-10-21 22:08:02 CEST
Only freebsd has one in its source tree (cf http://bxr.su/search?q=&defs=&refs=&path=sysmacros.h) and it's not even installed, so yeah only for GLIBC that is.
Comment 5 Michał Górny 2017-10-22 00:07:36 CEST
Created attachment 7382 
0001-Support-sys-sysmacros.h-include-required-for-glibc-2.patch

How about this one? It adds a configure check, so I guess it's the safest option.
Comment 6 Landry Breuil editbugs 2017-10-22 08:14:14 CEST
Right, that's a valid option... but if we know that only glibc has this behaviour (what about musl libc ?) i'd have thought about #if defined(__GLIBC__), but i dont even know if that's the canonical way to detect glibc..
Comment 7 Landry Breuil editbugs 2017-10-22 08:27:02 CEST
My point being if sysmacros.h is needed only for glibc > 2.25, it should be included only in this case :) otherwise it's context pollution... but that's not a huge deal.
Comment 8 Landry Breuil editbugs 2017-10-22 08:29:43 CEST
So maybe #if defined(__GLIBC__) && __GLIBC__ > 2 && __GLIBC_MINOR__ > 25, if that works for you.. assuming that if __GLIBC__ is defined, then __GLIBC_MINOR__ is defined too.
Comment 9 Michał Górny 2017-10-22 09:41:18 CEST
I think Gentoo has been backporting this patch to older versions, so I'd rather not rely on specific versions. The autoconf variant is relatively safe, and should not require any further work once other libcs follow suit. After all, the rationale makes sense -- major() and minor() names are very collision-prone, so they should not be included along with commonly used stuff.
Comment 10 Landry Breuil editbugs 2017-10-23 18:16:58 CEST
Oh, but you mean sys/sysmacros.h is a *new* header that appeared with this glib version ?
Comment 11 Michał Górny 2017-10-24 07:49:38 CEST
No, it was always there. Previously it was included implicitly, though.
Comment 12 Landry Breuil editbugs 2017-11-19 21:03:38 CET
Sorry i had completely forgotten this - your last patch is applied in 0787a89, thanks !

Bug #13940

Reported by:
Michał Górny
Reported on: 2017-10-21
Last modified on: 2017-11-19

People

Assignee:
Xfce-Goodies Maintainers
CC List:
2 users

Version

Attachments

Additional information