Build with musl libc
Subsystems (2)
cover Build with musl libc
I was trying to build util-linux with the musl libc (http://www.etalabs.net/musl/),
and found that a few patches were needed. These seem to just be some minor cleanups in most cases. I'm a bit dubious of the hwclock patch, though, as it seems at least a little bit hackish.
Josiah Worcester (6):
fdisk, display, hexdump.h: Use standard C types instead of u_int,
u_char, u_long, etc.
fsck, checktty, flock: Use more portable includes.
checktty: Use NGROUPS_MAX instead of NGROUPS
lib/tt.c: Fix mbs_width macro for systems without WIDECHAR
test_sysinfo: Use CHAR_BIT*sizeof(void*) instead of __WORDSIZE.
hwclock: Don't use asm/io.h if sys/io.h can't be found
fdisk/fdiskbsdlabel.c | 34 +++++++++++++++++----------------- fsck/fsck.c | 2 +- hwclock/cmos.c | 7 ++++++- lib/tt.c | 2 +- login-utils/checktty.c | 7 +++++-- sys-utils/flock.c | 2 ++ tests/helpers/test_sysinfo.c | 2 +- text-utils/display.c | 32 ++++++++++++++++---------------- text-utils/hexdump.h | 4 ++-- 9 files changed, 51 insertions(+), 41 deletions(-)
Signature · 1 line
1.7.5.3
PATCH 1/6 fdisk, display, hexdump.h: Use standard C types instead of u_int, u_char, u_long, etc.
--- fdisk/fdiskbsdlabel.c | 34 +++++++++++++++++----------------- text-utils/display.c | 32 ++++++++++++++++---------------- text-utils/hexdump.h | 4 ++-- 3 files changed, 35 insertions(+), 35 deletions(-)
fdisk/fdiskbsdlabel.c +17 -17
@@ -71,7 +71,7 @@ static void xbsd_change_fstype (void);static int xbsd_get_part_index (int max);static int xbsd_check_new_partition (int *i);static void xbsd_list_types (void ); -static u_short xbsd_dkcksum (struct xbsd_disklabel *lp); +static unsigned short xbsd_dkcksum (struct xbsd_disklabel *lp);static int xbsd_initlabel (struct partition *p,struct xbsd_disklabel *d,int pindex);static int xbsd_readlabel (struct partition *p,struct xbsd_disklabel *d);
@@ -463,28 +463,28 @@ xbsd_edit_disklabel (void) d = &xbsd_dlabel;#if defined (__alpha__) || defined (__ia64__) - d -> d_secsize = (u_long )edit_int ((u_long ) d -> d_secsize ,_ ("bytes/sector" )); - d -> d_nsectors = (u_long )edit_int ((u_long ) d -> d_nsectors ,_ ("sectors/track" )); - d -> d_ntracks = (u_long )edit_int ((u_long ) d -> d_ntracks ,_ ("tracks/cylinder" )); - d -> d_ncylinders = (u_long )edit_int ((u_long ) d -> d_ncylinders ,_ ("cylinders" )); + d -> d_secsize = (unsigned long )edit_int ((unsigned long ) d -> d_secsize ,_ ("bytes/sector" )); + d -> d_nsectors = (unsigned long )edit_int ((unsigned long ) d -> d_nsectors ,_ ("sectors/track" )); + d -> d_ntracks = (unsigned long )edit_int ((unsigned long ) d -> d_ntracks ,_ ("tracks/cylinder" )); + d -> d_ncylinders = (unsigned long )edit_int ((unsigned long ) d -> d_ncylinders ,_ ("cylinders" ));#endif /* d -> d_secpercyl can be != d -> d_nsectors * d -> d_ntracks */ while (1 ) { - d -> d_secpercyl = (u_long )edit_int ((u_long ) d -> d_nsectors * d -> d_ntracks, + d -> d_secpercyl = (unsigned long )edit_int ((unsigned long ) d -> d_nsectors * d -> d_ntracks,_ ("sectors/cylinder" ));if (d -> d_secpercyl <= d -> d_nsectors * d -> d_ntracks)break ;printf (_ ("Must be <= sectors/track * tracks/cylinder (default).\n" )); } - d -> d_rpm = (u_short )edit_int ((u_short ) d -> d_rpm ,_ ("rpm" )); - d -> d_interleave = (u_short )edit_int ((u_short ) d -> d_interleave,_ ("interleave" )); - d -> d_trackskew = (u_short )edit_int ((u_short ) d -> d_trackskew ,_ ("trackskew" )); - d -> d_cylskew = (u_short )edit_int ((u_short ) d -> d_cylskew ,_ ("cylinderskew" )); - d -> d_headswitch = (u_long )edit_int ((u_long ) d -> d_headswitch ,_ ("headswitch" )); - d -> d_trkseek = (u_long )edit_int ((u_long ) d -> d_trkseek ,_ ("track-to-track seek" )); + d -> d_rpm = (unsigned short )edit_int ((unsigned short ) d -> d_rpm ,_ ("rpm" )); + d -> d_interleave = (unsigned short )edit_int ((unsigned short ) d -> d_interleave,_ ("interleave" )); + d -> d_trackskew = (unsigned short )edit_int ((unsigned short ) d -> d_trackskew ,_ ("trackskew" )); + d -> d_cylskew = (unsigned short )edit_int ((unsigned short ) d -> d_cylskew ,_ ("cylinderskew" )); + d -> d_headswitch = (unsigned long )edit_int ((unsigned long ) d -> d_headswitch ,_ ("headswitch" )); + d -> d_trkseek = (unsigned long )edit_int ((unsigned long ) d -> d_trkseek ,_ ("track-to-track seek" )); d -> d_secperunit = d -> d_secpercyl * d -> d_ncylinders; }
@@ -638,13 +638,13 @@ xbsd_list_types (void) {list_types (xbsd_fstypes); } -static u_short +static unsigned short xbsd_dkcksum (struct xbsd_disklabel *lp) { -u_short *start, *end; -u_short sum =0 ; +unsigned short *start, *end; +unsigned short sum =0 ; - start = (u_short *) lp; - end = (u_short *) &lp->d_partitions[lp->d_npartitions]; + start = (unsigned short *) lp; + end = (unsigned short *) &lp->d_partitions[lp->d_npartitions];while (start < end) sum ^= *start++;return sum;
text-utils/display.c +16 -16
@@ -55,11 +55,11 @@ static off_t address; /* address/offset in stream */static off_t eaddress;/* end address */ static inline void -PR *pr,u_char *bp) { +PR *pr,unsigned char *bp) {switch (pr->flags) {case F_ADDRESS : - (void )printf (pr->fmt, (quad_t )address); + (void )printf (pr->fmt, (int64_t )address);break ;case F_BPAD : (void )printf (pr->fmt,"" );
@@ -90,23 +90,23 @@ print(PR *pr, u_char *bp) { {short sval;/* int16_t */ int ival;/* int32_t */ -long long Lval;/* int64_t, quad_t */ +long long Lval;/* int64_t, int64_t */ switch (pr->bcnt) {case 1 : - (void )printf (pr->fmt, (quad_t)*bp); + (void )printf (pr->fmt, (int64_t )*bp);break ;case 2 :memmove (&sval, bp,sizeof (sval)); - (void )printf (pr->fmt, (quad_t )sval); + (void )printf (pr->fmt, (int64_t )sval);break ;case 4 :memmove (&ival, bp,sizeof (ival)); - (void )printf (pr->fmt, (quad_t )ival); + (void )printf (pr->fmt, (int64_t )ival);break ;case 8 :memmove (&Lval, bp,sizeof (Lval)); - (void )printf (pr->fmt, (quad_t )Lval); + (void )printf (pr->fmt, (int64_t )Lval);break ; }break ;
@@ -127,23 +127,23 @@ print(PR *pr, u_char *bp) { {unsigned short sval;/* u_int16_t */ unsigned int ival;/* u_int32_t */ -unsigned long long Lval;/* u_int64_t, u_quad_t */ +unsigned long long Lval;/* u_int64_t, u_int64_t */ switch (pr->bcnt) {case 1 : - (void )printf (pr->fmt, (u_quad_t)*bp); + (void )printf (pr->fmt, (uint64_t )*bp);break ;case 2 :memmove (&sval, bp,sizeof (sval)); - (void )printf (pr->fmt, (u_quad_t )sval); + (void )printf (pr->fmt, (uint64_t )sval);break ;case 4 :memmove (&ival, bp,sizeof (ival)); - (void )printf (pr->fmt, (u_quad_t )ival); + (void )printf (pr->fmt, (uint64_t )ival);break ;case 8 :memmove (&Lval, bp,sizeof (Lval)); - (void )printf (pr->fmt, (u_quad_t )Lval); + (void )printf (pr->fmt, (uint64_t )Lval);break ; }break ;
@@ -174,9 +174,9 @@ void display(void) registerFU *fu; registerPR *pr; registerint cnt; - registeru_char *bp; + registerunsigned char *bp;off_t saveaddress; -u_char savech =0 , *savebp; +unsigned char savech =0 , *savebp; while ((bp = get()) != NULL) for (fs = fshead, savebp = bp, saveaddress = address; fs;
@@ -212,7 +212,7 @@ void display(void)for (pr = endfu->nextpr; pr; pr = pr->nextpr)switch (pr->flags) {case F_ADDRESS : - (void )printf (pr->fmt, (quad_t )eaddress); + (void )printf (pr->fmt, (int64_t )eaddress);break ;case F_TEXT : (void )printf ("%s" , pr->fmt);
@@ -261,7 +261,7 @@ get(void) eaddress = address + nread;return (curp); } - n =fread ((char *)curp + nread,sizeof (u_char), + n =fread ((char *)curp + nread,sizeof (unsigned char ), length ==-1 ? need :MIN (length, need), stdin);if (!n) {if (ferror (stdin))
text-utils/hexdump.h +2 -2
@@ -46,7 +46,7 @@ typedef struct _pr {#define F_U 0x100/* %_u */ #define F_UINT 0x200/* %[ouXx] */ #define F_TEXT 0x400/* no conversions */ -u_int flags;/* flag values */ +unsigned int flags;/* flag values */ int bcnt;/* byte count */ char *cchar;/* conversion character */ char *fmt;/* printf format */
@@ -58,7 +58,7 @@ typedef struct _fu {struct _pr *nextpr;/* next print unit */ #define F_IGNORE 0x01/* %_A */ #define F_SETREP 0x02/* rep count set, not default */ -u_int flags;/* flag values */ +unsigned int flags;/* flag values */ int reps;/* repetition count */ int bcnt;/* byte count */ char *fmt;/* format string */
Signature · 1 line
1.7.5.3
PATCH 2/6 fsck, checktty, flock: Use more portable includes.
In reply to Josiah Worcester--- fsck/fsck.c | 2 +- login-utils/checktty.c | 3 +++ sys-utils/flock.c | 2 ++ 3 files changed, 6 insertions(+), 1 deletions(-)
fsck/fsck.c +1 -1
@@ -29,7 +29,7 @@#include <sys/types.h> #include <sys/wait.h> -#include <sys/signal.h> +#include <signal.h> #include <sys/stat.h> #include <sys/file.h> #include <fcntl.h>
login-utils/checktty.c +3 -0
@@ -22,7 +22,10 @@#include <malloc.h> #include <netdb.h> #include <sys/syslog.h> +#include <sys/socket.h> #include <ctype.h> +#include <limits.h> +#include <netinet/in.h> #include "nls.h" #include <sys/sysmacros.h>
sys-utils/flock.c +2 -0
@@ -39,6 +39,8 @@#include <sys/file.h> #include <sys/time.h> #include <sys/wait.h> +#include <sys/stat.h> +#include <fcntl.h> #include "nls.h"
Signature · 1 line
1.7.5.3
PATCH 3/6 checktty: Use NGROUPS_MAX instead of NGROUPS
In reply to Josiah Worcester--- login-utils/checktty.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
login-utils/checktty.c +2 -2
@@ -42,7 +42,7 @@#define TTY_MAJOR 4#endif -static gid_t mygroups[NGROUPS ]; +static gid_t mygroups[NGROUPS_MAX ];static int num_groups;#define NAMELEN 128
@@ -83,7 +83,7 @@ am_in_group(char *group)static void find_groups (gid_t defgrp,const char *user) { - num_groups =getgroups (NGROUPS , mygroups); + num_groups =getgroups (NGROUPS_MAX , mygroups); } static struct ttyclass *
Signature · 1 line
1.7.5.3
Re: [PATCH 3/6] checktty: Use NGROUPS_MAX instead of NGROUPS
Review
Quoted 2 lines · Josiah Worcester
(quoted diff) +1
-1-static gid_t mygroups[NGROUPS]; +static gid_t mygroups[NGROUPS_MAX];
That might fix issue with musl libc, but is that truly an enhancement? How about using sysconf(_SC_NGROUPS_MAX), e.g. see attachment.
Signature · 2 lines
Sami Kerola http://www.iki.fi/kerolasa/
From bf4382f2f49c99f8cb3db360b54d8825525c153d Mon Sep 17 00:00:00 2001
From: Sami Kerola <[email protected]>
Date: Thu, 9 Jun 2011 21:23:13 +0200
Subject: [PATCH] checktty: NGROUP -> sysconf
Use sysconf return value instead of NGROUP definition to determine size of grouplist array.
http://pubs.opengroup.org/onlinepubs/009695399/functions/getgroups.html
--- login-utils/checktty.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
login-utils/checktty.c +4 -1
@@ -33,13 +33,14 @@#include "pathnames.h" #include "login.h" #include "strutils.h" +#include "xalloc.h" #include "c.h" #ifndef TTY_MAJOR #define TTY_MAJOR 4#endif -static gid_t mygroups[NGROUPS ]; +static gid_t *mygroups;static int num_groups;#define NAMELEN 128
@@ -311,6 +312,7 @@ main(int argc, char **argv) { NULL, NULL } }, *item; + mygroups =xmalloc (sizeof (gid_t) *sysconf (_SC_NGROUPS_MAX));memset (&hints,0 ,sizeof (hints)); hints.ai_family =AF_UNSPEC ; hints.ai_flags =AI_NUMERICHOST |AI_PASSIVE |AI_ADDRCONFIG ;
@@ -342,6 +344,7 @@ main(int argc, char **argv) printf("getaddrinfo() failed\n"); } +free (mygroups);return EXIT_SUCCESS ; }#endif /* MAIN_TEST_CHECKTTY */
Signature · 1 line
1.7.5.2
PATCH 4/6 lib/tt.c: Fix mbs_width macro for systems without WIDECHAR
In reply to Josiah Worcester--- lib/tt.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
lib/tt.c +1 -1
@@ -52,7 +52,7 @@ static const struct tt_symbols utf8_tt_symbols = { };#else /* !HAVE_WIDECHAR */ -# define mbs_width strlen(_s) +# define mbs_width (_s) strlen(_s)#endif /* !HAVE_WIDECHAR */ #define is_last_column (_tb, _cl) \
Signature · 1 line
1.7.5.3
PATCH 5/6 test_sysinfo: Use CHAR_BIT*sizeof(void*) instead of __WORDSIZE.
In reply to Josiah Worcester--- tests/helpers/test_sysinfo.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tests/helpers/test_sysinfo.c +1 -1
@@ -28,7 +28,7 @@ typedef struct {int hlp_wordsize (void ) { -printf ("%d\n" , __WORDSIZE); +printf ("%d\n" ,CHAR_BIT *sizeof (void *));return 0 ; }
Signature · 1 line
1.7.5.3
PATCH 6/6 hwclock: Don't use asm/io.h if sys/io.h can't be found
In reply to Josiah Worcester--- hwclock/cmos.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
hwclock/cmos.c +6 -1
@@ -53,7 +53,12 @@#ifdef HAVE_SYS_IO_H #include <sys/io.h> #else -#include <asm/io.h> /* for inb, outb */ +/* Disable cmos access; we can no longer use asm/io.h, since +* the kernel does not export that header. +*/ +#undef __i386__ +void outb (int a,int b){} +int inb (int c){return 0 ; }#endif #elif defined(__alpha__)/* <asm/io.h> fails to compile, probably because of u8 etc */
Signature · 1 line
1.7.5.3
Re: [PATCH 6/6] hwclock: Don't use asm/io.h if sys/io.h can't be found
hwclock/cmos.c line 61
Quoted 7 lines · On Wednesday, June 08, 2011 18:52:48 Josiah Worcester wrote:
hwclock/cmos.c +6
-1-#include <asm/io.h> /* for inb, outb */ +/* Disable cmos access; we can no longer use asm/io.h, since +* the kernel does not export that header. +*/ +#undef __i386__ +void outb (int a,int b){} +int inb (int c){return 0 ; }
probably should be turned into a header check in configure -mike
Karel Zak
maintainerRe: [PATCH 6/6] hwclock: Don't use asm/io.h if sys/io.h can't be found
Quoted 10 lines · Mike Frysinger
hwclock/cmos.c line 61
Quoted 7 lines · On Wednesday, June 08, 2011 18:52:48 Josiah Worcester wrote:
hwclock/cmos.c +6
-1-#include <asm/io.h> /* for inb, outb */ +/* Disable cmos access; we can no longer use asm/io.h, since +* the kernel does not export that header. +*/ +#undef __i386__ +void outb (int a,int b){} +int inb (int c){return 0 ; }probably should be turned into a header check in configure
I have added asm/io.h check to configure.ac to keep it backwardly compatible...
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 10 lines · Josiah Worcester
fdisk/fdiskbsdlabel.c | 34 +++++++++++++++++----------------- fsck/fsck.c | 2 +- hwclock/cmos.c | 7 ++++++- lib/tt.c | 2 +- login-utils/checktty.c | 7 +++++-- sys-utils/flock.c | 2 ++ tests/helpers/test_sysinfo.c | 2 +- text-utils/display.c | 32 ++++++++++++++++---------------- text-utils/hexdump.h | 4 ++-- 9 files changed, 51 insertions(+), 41 deletions(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com