mailing list of musl libc
 help / color / mirror / code / Atom feed
* additional patches for musl
@ 2018-12-16  0:01 сергей волковичь
  2018-12-16  1:34 ` A. Wilcox
  2018-12-16  1:57 ` Rich Felker
  0 siblings, 2 replies; 4+ messages in thread
From: сергей волковичь @ 2018-12-16  0:01 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 360 bytes --]

cabulertion.
i finded additional patches for implementing some missing musl features.


-- реклама -----------------------------------------------------------
Поторопись зарегистрировать самый короткий почтовый адрес @i.ua
https://mail.i.ua/reg - и получи 1Gb для хранения писем

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: canonicalize_file_name.patch --]
[-- Type: text/x-patch; name="canonicalize_file_name.patch", Size: 617 bytes --]

--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -120,6 +120,9 @@
 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  || defined(_BSD_SOURCE)
 char *realpath (const char *__restrict, char *__restrict);
+#ifdef _GNU_SOURCE
+char *canonicalize_file_name (const char *__restrict);
+#endif
 long int random (void);
 void srandom (unsigned int);
 char *initstate (unsigned int, char *, size_t);
--- a/src/misc/realpath.c
+++ b/src/misc/realpath.c
@@ -42,4 +42,9 @@
 err:
 	__syscall(SYS_close, fd);
 	return 0;
 }
+
+char *canonicalize_file_name(const char *restrict filename)
+{
+	return realpath(filename, NULL);
+}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: netdb.patch --]
[-- Type: text/x-patch; name="netdb.patch", Size: 261 bytes --]

--- a/include/netdb.h
+++ b/include/netdb.h
@@ -124,6 +124,8 @@
 #define NO_RECOVERY    3
 #define NO_DATA        4
 #define NO_ADDRESS     NO_DATA
+#define NETDB_INTERNAL -1
+#define NETDB_SUCCESS  0
 #endif
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: nftw.patch --]
[-- Type: text/x-patch; name="nftw.patch", Size: 1746 bytes --]

--- a/include/ftw.h
+++ b/include/ftw.h
@@ -20,6 +20,14 @@
 #define FTW_MOUNT 2
 #define FTW_CHDIR 4
 #define FTW_DEPTH 8
+
+#ifdef _GNU_SOURCE
+#define FTW_ACTIONRETVAL 16
+#define FTW_CONTINUE 0
+#define FTW_STOP 1
+#define FTW_SKIP_SUBTREE 2
+#define FTW_SKIP_SIBLINGS 3
+#endif
 
 struct FTW {
 	int base;
--- a/src/misc/nftw.c
+++ b/src/misc/nftw.c
@@ -1,3 +1,8 @@
+#define FTW_ACTIONRETVAL 16
+#define FTW_CONTINUE 0
+#define FTW_STOP 1
+#define FTW_SKIP_SUBTREE 2
+#define FTW_SKIP_SIBLINGS 3
 #include <ftw.h>
 #include <dirent.h>
 #include <sys/stat.h>
@@ -58,8 +58,20 @@
 	lev.level = new.level;
 	lev.base = h ? h->base : (name=strrchr(path, '/')) ? name-path : 0;
 
-	if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
-		return r;
+	if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
+		if (flags & FTW_ACTIONRETVAL)
+			switch (r) {
+				case FTW_SKIP_SUBTREE:
+					h = NULL;
+				case FTW_CONTINUE:
+					break;
+				case FTW_SKIP_SIBLINGS:
+				case FTW_STOP:
+					return r;
+			}
+		else
+			return r;
+	}
 
 	for (; h; h = h->chain)
 		if (h->dev == st.st_dev && h->ino == st.st_ino)
@@ -82,7 +94,10 @@
 				strcpy(path+j+1, de->d_name);
 				if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) {
 					closedir(d);
-					return r;
+					if ((flags & FTW_ACTIONRETVAL) && r == FTW_SKIP_SIBLINGS)
+						break;
+					else
+						return r;
 				}
 			}
 			closedir(d);
@@ -93,8 +108,16 @@
 	}
 
 	path[l] = 0;
-	if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
-		return r;
+	if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
+		if (flags & FTW_ACTIONRETVAL)
+			switch (r) {
+				case FTW_SKIP_SIBLINGS:
+				case FTW_STOP:
+					return r;
+			}
+		else
+			return r;
+	}
 
 	return 0;
 }

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: printf.h.patch --]
[-- Type: text/x-patch; name="printf.h.patch", Size: 10293 bytes --]

--- /dev/null
+++ b/src/misc/parse-printf-format.c
@@ -0,0 +1,265 @@
+/***
+  Copyright 2014 Emil Renner Berthing
+  With parts from the musl C library
+  Copyright 2005-2014 Rich Felker, et al.
+
+  This file is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  This file is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+***/
+
+#include <stddef.h>
+#include <string.h>
+
+#include "printf.h"
+
+static const char *consume_nonarg(const char *fmt)
+{
+        do {
+                if (*fmt == '\0')
+                        return fmt;
+        } while (*fmt++ != '%');
+        return fmt;
+}
+
+static const char *consume_num(const char *fmt)
+{
+        for (;*fmt >= '0' && *fmt <= '9'; fmt++)
+                /* do nothing */;
+        return fmt;
+}
+
+static const char *consume_argn(const char *fmt, size_t *arg)
+{
+        const char *p = fmt;
+        size_t val = 0;
+
+        if (*p < '1' || *p > '9')
+                return fmt;
+        do {
+                val = 10*val + (*p++ - '0');
+        } while (*p >= '0' && *p <= '9');
+
+        if (*p != '$')
+                return fmt;
+        *arg = val;
+        return p+1;
+}
+
+static const char *consume_flags(const char *fmt)
+{
+        while (1) {
+                switch (*fmt) {
+                case '#':
+                case '0':
+                case '-':
+                case ' ':
+                case '+':
+                case '\'':
+                case 'I':
+                        fmt++;
+                        continue;
+                }
+                return fmt;
+        }
+}
+
+enum state {
+        BARE,
+        LPRE,
+        LLPRE,
+        HPRE,
+        HHPRE,
+        BIGLPRE,
+        ZTPRE,
+        JPRE,
+        STOP
+};
+
+enum type {
+        NONE,
+        PTR,
+        INT,
+        UINT,
+        ULLONG,
+        LONG,
+        ULONG,
+        SHORT,
+        USHORT,
+        CHAR,
+        UCHAR,
+        LLONG,
+        SIZET,
+        IMAX,
+        UMAX,
+        PDIFF,
+        UIPTR,
+        DBL,
+        LDBL,
+        MAXTYPE
+};
+
+static const short pa_types[MAXTYPE] = {
+        [NONE]   = PA_INT,
+        [PTR]    = PA_POINTER,
+        [INT]    = PA_INT,
+        [UINT]   = PA_INT,
+        [ULLONG] = PA_INT | PA_FLAG_LONG_LONG,
+        [LONG]   = PA_INT | PA_FLAG_LONG,
+        [ULONG]  = PA_INT | PA_FLAG_LONG,
+        [SHORT]  = PA_INT | PA_FLAG_SHORT,
+        [USHORT] = PA_INT | PA_FLAG_SHORT,
+        [CHAR]   = PA_CHAR,
+        [UCHAR]  = PA_CHAR,
+        [LLONG]  = PA_INT | PA_FLAG_LONG_LONG,
+        [SIZET]  = PA_INT | PA_FLAG_LONG,
+        [IMAX]   = PA_INT | PA_FLAG_LONG_LONG,
+        [UMAX]   = PA_INT | PA_FLAG_LONG_LONG,
+        [PDIFF]  = PA_INT | PA_FLAG_LONG_LONG,
+        [UIPTR]  = PA_INT | PA_FLAG_LONG,
+        [DBL]    = PA_DOUBLE,
+        [LDBL]   = PA_DOUBLE | PA_FLAG_LONG_DOUBLE
+};
+
+#define S(x) [(x)-'A']
+#define E(x) (STOP + (x))
+
+static const unsigned char states[]['z'-'A'+1] = {
+        { /* 0: bare types */
+                S('d') = E(INT), S('i') = E(INT),
+                S('o') = E(UINT),S('u') = E(UINT),S('x') = E(UINT), S('X') = E(UINT),
+                S('e') = E(DBL), S('f') = E(DBL), S('g') = E(DBL),  S('a') = E(DBL),
+                S('E') = E(DBL), S('F') = E(DBL), S('G') = E(DBL),  S('A') = E(DBL),
+                S('c') = E(CHAR),S('C') = E(INT),
+                S('s') = E(PTR), S('S') = E(PTR), S('p') = E(UIPTR),S('n') = E(PTR),
+                S('m') = E(NONE),
+                S('l') = LPRE,   S('h') = HPRE, S('L') = BIGLPRE,
+                S('z') = ZTPRE,  S('j') = JPRE, S('t') = ZTPRE
+        }, { /* 1: l-prefixed */
+                S('d') = E(LONG), S('i') = E(LONG),
+                S('o') = E(ULONG),S('u') = E(ULONG),S('x') = E(ULONG),S('X') = E(ULONG),
+                S('e') = E(DBL),  S('f') = E(DBL),  S('g') = E(DBL),  S('a') = E(DBL),
+                S('E') = E(DBL),  S('F') = E(DBL),  S('G') = E(DBL),  S('A') = E(DBL),
+                S('c') = E(INT),  S('s') = E(PTR),  S('n') = E(PTR),
+                S('l') = LLPRE
+        }, { /* 2: ll-prefixed */
+                S('d') = E(LLONG), S('i') = E(LLONG),
+                S('o') = E(ULLONG),S('u') = E(ULLONG),
+                S('x') = E(ULLONG),S('X') = E(ULLONG),
+                S('n') = E(PTR)
+        }, { /* 3: h-prefixed */
+                S('d') = E(SHORT), S('i') = E(SHORT),
+                S('o') = E(USHORT),S('u') = E(USHORT),
+                S('x') = E(USHORT),S('X') = E(USHORT),
+                S('n') = E(PTR),
+                S('h') = HHPRE
+        }, { /* 4: hh-prefixed */
+                S('d') = E(CHAR), S('i') = E(CHAR),
+                S('o') = E(UCHAR),S('u') = E(UCHAR),
+                S('x') = E(UCHAR),S('X') = E(UCHAR),
+                S('n') = E(PTR)
+        }, { /* 5: L-prefixed */
+                S('e') = E(LDBL),S('f') = E(LDBL),S('g') = E(LDBL), S('a') = E(LDBL),
+                S('E') = E(LDBL),S('F') = E(LDBL),S('G') = E(LDBL), S('A') = E(LDBL),
+                S('n') = E(PTR)
+        }, { /* 6: z- or t-prefixed (assumed to be same size) */
+                S('d') = E(PDIFF),S('i') = E(PDIFF),
+                S('o') = E(SIZET),S('u') = E(SIZET),
+                S('x') = E(SIZET),S('X') = E(SIZET),
+                S('n') = E(PTR)
+        }, { /* 7: j-prefixed */
+                S('d') = E(IMAX), S('i') = E(IMAX),
+                S('o') = E(UMAX), S('u') = E(UMAX),
+                S('x') = E(UMAX), S('X') = E(UMAX),
+                S('n') = E(PTR)
+        }
+};
+
+size_t parse_printf_format(const char *fmt, size_t n, int *types)
+{
+        size_t i = 0;
+        size_t last = 0;
+
+        memset(types, 0, n);
+
+        while (1) {
+                size_t arg;
+                unsigned int state;
+
+                fmt = consume_nonarg(fmt);
+                if (*fmt == '\0')
+                        break;
+                if (*fmt == '%') {
+                        fmt++;
+                        continue;
+                }
+                arg = 0;
+                fmt = consume_argn(fmt, &arg);
+                /* flags */
+                fmt = consume_flags(fmt);
+                /* width */
+                if (*fmt == '*') {
+                        size_t warg = 0;
+                        fmt = consume_argn(fmt+1, &warg);
+                        if (warg == 0)
+                                warg = ++i;
+                        if (warg > last)
+                                last = warg;
+                        if (warg <= n && types[warg-1] == NONE)
+                                types[warg-1] = INT;
+                } else
+                        fmt = consume_num(fmt);
+                /* precision */
+                if (*fmt == '.') {
+                        fmt++;
+                        if (*fmt == '*') {
+                                size_t parg = 0;
+                                fmt = consume_argn(fmt+1, &parg);
+                                if (parg == 0)
+                                        parg = ++i;
+                                if (parg > last)
+                                        last = parg;
+                                if (parg <= n && types[parg-1] == NONE)
+                                        types[parg-1] = INT;
+                        } else {
+                                if (*fmt == '-')
+                                        fmt++;
+                                fmt = consume_num(fmt);
+                        }
+                }
+                /* length modifier and conversion specifier */
+                state = BARE;
+                do {
+                        unsigned char c = *fmt++;
+
+                        if (c < 'A' || c > 'z')
+                                continue;
+                        state = states[state]S(c);
+                        if (state == 0)
+                                continue;
+                } while (state < STOP);
+
+                if (state == E(NONE))
+                        continue;
+
+                if (arg == 0)
+                        arg = ++i;
+                if (arg > last)
+                        last = arg;
+                if (arg <= n)
+                        types[arg-1] = state - STOP;
+        }
+
+        if (last > n)
+                last = n;
+        for (i = 0; i < last; i++)
+                types[i] = pa_types[types[i]];
+
+        return last;
+}
--- /dev/null
+++ b/include/printf.h
@@ -0,0 +1,41 @@
+/***
+  Copyright 2014 Emil Renner Berthing
+  With parts from the GNU C Library
+  Copyright 1991-2014 Free Software Foundation, Inc.
+
+  This file is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  This file is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+***/
+
+#pragma once
+
+#include <stddef.h>
+
+enum {				/* C type: */
+  PA_INT,			/* int */
+  PA_CHAR,			/* int, cast to char */
+  PA_WCHAR,			/* wide char */
+  PA_STRING,			/* const char *, a '\0'-terminated string */
+  PA_WSTRING,			/* const wchar_t *, wide character string */
+  PA_POINTER,			/* void * */
+  PA_FLOAT,			/* float */
+  PA_DOUBLE,			/* double */
+  PA_LAST
+};
+
+/* Flag bits that can be set in a type returned by `parse_printf_format'.  */
+#define	PA_FLAG_MASK		0xff00
+#define	PA_FLAG_LONG_LONG	(1 << 8)
+#define	PA_FLAG_LONG_DOUBLE	PA_FLAG_LONG_LONG
+#define	PA_FLAG_LONG		(1 << 9)
+#define	PA_FLAG_SHORT		(1 << 10)
+#define	PA_FLAG_PTR		(1 << 11)
+
+size_t parse_printf_format(const char *fmt, size_t n, int *types);

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: qsort_r.patch --]
[-- Type: text/x-patch; name="qsort_r.patch", Size: 4007 bytes --]

--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -52,10 +52,13 @@
 char *getenv (const char *);
 
 int system (const char *);
 
+typedef int (*__compar_fn_t)(const void *, const void *);
+typedef int (*comparison_fn_t)(const void *, const void *);
 void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
 void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
+void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);
 
 int abs (int);
 long labs (long);
 long long llabs (long long);
--- a/src/stdlib/qsort.c	2017-01-01 04:27:17.000000000 +0100
+++ b/src/stdlib/qsort.c	2017-01-29 00:21:27.194887091 +0100
@@ -28,7 +28,7 @@
 #include "atomic.h"
 #define ntz(x) a_ctz_l((x))
 
-typedef int (*cmpfun)(const void *, const void *);
+typedef int (*cmpfun)(const void *, const void *, void *);
 
 static inline int pntz(size_t p[2]) {
 	int r = ntz(p[0] - 1);
@@ -85,7 +85,7 @@
 	p[1] >>= n;
 }
 
-static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size_t lp[])
+static void sift(unsigned char *head, size_t width, cmpfun cmp, void* arg, int pshift, size_t lp[])
 {
 	unsigned char *rt, *lf;
 	unsigned char *ar[14 * sizeof(size_t) + 1];
@@ -96,10 +96,10 @@
 		rt = head - width;
 		lf = head - width - lp[pshift - 2];
 
-		if((*cmp)(ar[0], lf) >= 0 && (*cmp)(ar[0], rt) >= 0) {
+		if((*cmp)(ar[0], lf, arg) >= 0 && (*cmp)(ar[0], rt, arg) >= 0) {
 			break;
 		}
-		if((*cmp)(lf, rt) >= 0) {
+		if((*cmp)(lf, rt, arg) >= 0) {
 			ar[i++] = lf;
 			head = lf;
 			pshift -= 1;
@@ -112,7 +112,7 @@
 	cycle(width, ar, i);
 }
 
-static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], int pshift, int trusty, size_t lp[])
+static void trinkle(unsigned char *head, size_t width, cmpfun cmp, void* arg, size_t pp[2], int pshift, int trusty, size_t lp[])
 {
 	unsigned char *stepson,
 	              *rt, *lf;
@@ -127,13 +127,13 @@
 	ar[0] = head;
 	while(p[0] != 1 || p[1] != 0) {
 		stepson = head - lp[pshift];
-		if((*cmp)(stepson, ar[0]) <= 0) {
+		if((*cmp)(stepson, ar[0], arg) <= 0) {
 			break;
 		}
 		if(!trusty && pshift > 1) {
 			rt = head - width;
 			lf = head - width - lp[pshift - 2];
-			if((*cmp)(rt, stepson) >= 0 || (*cmp)(lf, stepson) >= 0) {
+			if((*cmp)(rt, stepson, arg) >= 0 || (*cmp)(lf, stepson, arg) >= 0) {
 				break;
 			}
 		}
@@ -147,11 +147,11 @@
 	}
 	if(!trusty) {
 		cycle(width, ar, i);
-		sift(head, width, cmp, pshift, lp);
+		sift(head, width, cmp, arg, pshift, lp);
 	}
 }
 
-void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
+void qsort_r(void *base, size_t nel, size_t width, cmpfun cmp, void* arg)
 {
 	size_t lp[12*sizeof(size_t)];
 	size_t i, size = width * nel;
@@ -170,14 +170,14 @@
 
 	while(head < high) {
 		if((p[0] & 3) == 3) {
-			sift(head, width, cmp, pshift, lp);
+			sift(head, width, cmp, arg, pshift, lp);
 			shr(p, 2);
 			pshift += 2;
 		} else {
 			if(lp[pshift - 1] >= high - head) {
-				trinkle(head, width, cmp, p, pshift, 0, lp);
+				trinkle(head, width, cmp, arg, p, pshift, 0, lp);
 			} else {
-				sift(head, width, cmp, pshift, lp);
+				sift(head, width, cmp, arg, pshift, lp);
 			}
 			
 			if(pshift == 1) {
@@ -193,7 +193,7 @@
 		head += width;
 	}
 
-	trinkle(head, width, cmp, p, pshift, 0, lp);
+	trinkle(head, width, cmp, arg, p, pshift, 0, lp);
 
 	while(pshift != 1 || p[0] != 1 || p[1] != 0) {
 		if(pshift <= 1) {
@@ -205,11 +205,16 @@
 			pshift -= 2;
 			p[0] ^= 7;
 			shr(p, 1);
-			trinkle(head - lp[pshift] - width, width, cmp, p, pshift + 1, 1, lp);
+			trinkle(head - lp[pshift] - width, width, cmp, arg, p, pshift + 1, 1, lp);
 			shl(p, 1);
 			p[0] |= 1;
-			trinkle(head - width, width, cmp, p, pshift, 1, lp);
+			trinkle(head - width, width, cmp, arg, p, pshift, 1, lp);
 		}
 		head -= width;
 	}
 }
+
+void qsort(void *base, size_t nel, size_t width, int (*cmp)(const void *, const void *))
+{
+	return qsort_r (base, nel, width, (cmpfun)cmp, NULL);
+}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #7: secure_getenv.patch --]
[-- Type: text/x-patch; name="secure_getenv.patch", Size: 457 bytes --]

--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -50,7 +50,8 @@
 int at_quick_exit (void (*) (void));
 _Noreturn void quick_exit (int);
 
 char *getenv (const char *);
+char *secure_getenv (const char *);
 
 int system (const char *);
 
--- /dev/null
+++ b/src/env/secure_getenv.c
@@ -0,0 +1,8 @@
+#define _DEFAULT_SOURCE 1
+#include <stdlib.h>
+#include <unistd.h>
+
+char *secure_getenv(const char *name)
+{
+	return issetugid() ? NULL : getenv(name);
+}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: strndupa.patch --]
[-- Type: text/x-patch; name="strndupa.patch", Size: 770 bytes --]

--- a/include/string.h
+++ b/include/string.h
@@ -85,7 +85,21 @@
 #endif
 
 #ifdef _GNU_SOURCE
-#define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
+#ifdef __GNUC__
+#define strdupa(x)	(__extension__({ \
+			const char* __old = (x); \
+			size_t __len = strlen(x) + 1; \
+			char* __new = (char*)alloca(__len); \
+			(char*)memcpy(__new, __old, __len); \
+			}))
+#define strndupa(x,y)	(__extension__({ \
+			const char* __old = (x); \
+			size_t __len = strnlen(x, (y)); \
+			char* __new = (char*)alloca(__len + 1); \
+			__new[__len] = 0; \
+			(char*)memcpy(__new, __old, __len); \
+			}))
+#endif
 int strverscmp (const char *, const char *);
 int strcasecmp_l (const char *, const char *, locale_t);
 int strncasecmp_l (const char *, const char *, size_t, locale_t);

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #9: utmpx.h.patch --]
[-- Type: text/x-patch; name="utmpx.h.patch", Size: 258 bytes --]

--- a/include/utmpx.h
+++ b/include/utmpx.h
@@ -55,6 +55,12 @@
 #define USER_PROCESS    7
 #define DEAD_PROCESS    8
 
+
+#ifdef _GNU_SOURCE
+#define _PATH_UTMPX "/dev/null/utmp"
+#define _PATH_WTMPX "/dev/null/wtmp"
+#endif
+
 #ifdef __cplusplus
 }
 #endif

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #10: stub_macros.patch --]
[-- Type: text/x-patch; name="stub_macros.patch", Size: 751 bytes --]

define unimplemented macros to 0 so that systemd compiles
--- a/include/glob.h
+++ b/include/glob.h
@@ -22,6 +22,7 @@
 int  glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict);
 void globfree(glob_t *);
 
+#define GLOB_BRACE 0
 #define GLOB_ERR      0x01
 #define GLOB_MARK     0x02
 #define GLOB_NOSORT   0x04
--- a/include/regex.h
+++ b/include/regex.h
@@ -31,6 +31,7 @@
 
 #define REG_NOTBOL      1
 #define REG_NOTEOL      2
+#define REG_STARTEND    0
 
 #define REG_OK          0
 #define REG_NOMATCH     1
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -140,6 +140,8 @@
 #define EAI_IDN_ENCODE -105
 #define NI_MAXHOST 255
 #define NI_MAXSERV 32
+#define NI_IDN 0
+#define NI_IDN_USE_STD3_ASCII_RULES 0
 #endif
 
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: additional patches for musl
  2018-12-16  0:01 additional patches for musl сергей волковичь
@ 2018-12-16  1:34 ` A. Wilcox
  2018-12-16  1:57 ` Rich Felker
  1 sibling, 0 replies; 4+ messages in thread
From: A. Wilcox @ 2018-12-16  1:34 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 1442 bytes --]

On 12/15/18 18:01, сергей волковичь wrote:
> cabulertion.
> i finded additional patches for implementing some missing musl features.
> 
> 
> -- реклама -----------------------------------------------------------
> Поторопись зарегистрировать самый короткий почтовый адрес @i.ua
> https://mail.i.ua/reg - и получи 1Gb для хранения писем
> 

Hi there.

First of all, welcome and thank you for sending your patches.

I think the canonicalize_file_name and nftw stuff may be okay, though it
does add some bloat.  The qsort_r code may be as well.  These should be
looked at by the musl maintainers themselves to determine suitability
and issues.  (I know the nftw stuff would be useful for a few packages,
myself.)

The utmpx patch should probably be merged.

The printf stuff is LGPL licensed while musl is MIT.  That won't be
workable because the licenses are incompatible.

The strndupa patch does not give an alternative for non-GNU C compilers
and it seems rather arbitrary and gratuitous.  It is better to make the
software more portable than add this, IMO.

The glob and regex macros are going to break code and those are a firm
NAK from me, though I don't know how others feel about them.

Hope this helps.

Best,
--arw
-- 
A. Wilcox (awilfox)
Project Lead, Adélie Linux
https://www.adelielinux.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: additional patches for musl
  2018-12-16  0:01 additional patches for musl сергей волковичь
  2018-12-16  1:34 ` A. Wilcox
@ 2018-12-16  1:57 ` Rich Felker
  2018-12-16  2:16   ` Khem Raj
  1 sibling, 1 reply; 4+ messages in thread
From: Rich Felker @ 2018-12-16  1:57 UTC (permalink / raw)
  To: musl

On Sun, Dec 16, 2018 at 02:01:56AM +0200, сергей волковичь wrote:
> cabulertion.
> i finded additional patches for implementing some missing musl features.



> --- a/include/stdlib.h
> +++ b/include/stdlib.h
> @@ -120,6 +120,9 @@
>  #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
>   || defined(_BSD_SOURCE)
>  char *realpath (const char *__restrict, char *__restrict);
> +#ifdef _GNU_SOURCE
> +char *canonicalize_file_name (const char *__restrict);
> +#endif

Small nit but rather than adding new #ifdef _GNU_SOURCE sections for
each declaration, any new ones should be added under the existing
section if there is one (and in stdlib.h there is).

>  long int random (void);
>  void srandom (unsigned int);
>  char *initstate (unsigned int, char *, size_t);
> --- a/src/misc/realpath.c
> +++ b/src/misc/realpath.c
> @@ -42,4 +42,9 @@
>  err:
>  	__syscall(SYS_close, fd);
>  	return 0;
>  }
> +
> +char *canonicalize_file_name(const char *restrict filename)
> +{
> +	return realpath(filename, NULL);
> +}

This can't go in the same file as realpath because it's not in the
reserved namespace. Further it's probably not an acceptable addition
since it's not widely used and has no advantages over the standard way
of writing the exact same thing using realpath directly.

> --- a/include/netdb.h
> +++ b/include/netdb.h
> @@ -124,6 +124,8 @@
>  #define NO_RECOVERY    3
>  #define NO_DATA        4
>  #define NO_ADDRESS     NO_DATA
> +#define NETDB_INTERNAL -1
> +#define NETDB_SUCCESS  0
>  #endif




> --- a/include/ftw.h
> +++ b/include/ftw.h
> @@ -20,6 +20,14 @@
>  #define FTW_MOUNT 2
>  #define FTW_CHDIR 4
>  #define FTW_DEPTH 8
> +
> +#ifdef _GNU_SOURCE
> +#define FTW_ACTIONRETVAL 16
> +#define FTW_CONTINUE 0
> +#define FTW_STOP 1
> +#define FTW_SKIP_SUBTREE 2
> +#define FTW_SKIP_SIBLINGS 3
> +#endif

This one and the corresponding functional change is probably worth
consideration. I've seen a few a

>  
>  struct FTW {
>  	int base;
> --- a/src/misc/nftw.c
> +++ b/src/misc/nftw.c
> @@ -1,3 +1,8 @@
> +#define FTW_ACTIONRETVAL 16
> +#define FTW_CONTINUE 0
> +#define FTW_STOP 1
> +#define FTW_SKIP_SUBTREE 2
> +#define FTW_SKIP_SIBLINGS 3
>  #include <ftw.h>
>  #include <dirent.h>
>  #include <sys/stat.h>
> @@ -58,8 +58,20 @@
>  	lev.level = new.level;
>  	lev.base = h ? h->base : (name=strrchr(path, '/')) ? name-path : 0;
>  
> -	if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
> -		return r;
> +	if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
> +		if (flags & FTW_ACTIONRETVAL)
> +			switch (r) {
> +				case FTW_SKIP_SUBTREE:
> +					h = NULL;
> +				case FTW_CONTINUE:
> +					break;
> +				case FTW_SKIP_SIBLINGS:
> +				case FTW_STOP:
> +					return r;
> +			}
> +		else
> +			return r;
> +	}
>  
>  	for (; h; h = h->chain)
>  		if (h->dev == st.st_dev && h->ino == st.st_ino)
> @@ -82,7 +94,10 @@
>  				strcpy(path+j+1, de->d_name);
>  				if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) {
>  					closedir(d);
> -					return r;
> +					if ((flags & FTW_ACTIONRETVAL) && r == FTW_SKIP_SIBLINGS)
> +						break;
> +					else
> +						return r;
>  				}
>  			}
>  			closedir(d);
> @@ -93,8 +108,16 @@
>  	}
>  
>  	path[l] = 0;
> -	if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
> -		return r;
> +	if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
> +		if (flags & FTW_ACTIONRETVAL)
> +			switch (r) {
> +				case FTW_SKIP_SIBLINGS:
> +				case FTW_STOP:
> +					return r;
> +			}
> +		else
> +			return r;
> +	}
>  
>  	return 0;
>  }

> --- /dev/null
> +++ b/src/misc/parse-printf-format.c
> @@ -0,0 +1,265 @@
> +/***
> +  Copyright 2014 Emil Renner Berthing
> +  With parts from the musl C library
> +  Copyright 2005-2014 Rich Felker, et al.
> +
> +  This file is free software; you can redistribute it and/or modify it
> +  under the terms of the GNU Lesser General Public License as published by
> +  the Free Software Foundation; either version 2.1 of the License, or
> +  (at your option) any later version.

Please do not send license-incompatible patches to musl.

> --- /dev/null
> +++ b/include/printf.h
> @@ -0,0 +1,41 @@
> +/***
> +  Copyright 2014 Emil Renner Berthing
> +  With parts from the GNU C Library
> +  Copyright 1991-2014 Free Software Foundation, Inc.
> +
> +  This file is free software; you can redistribute it and/or modify it
> +  under the terms of the GNU Lesser General Public License as published by

Likewise.

> +  the Free Software Foundation; either version 2.1 of the License, or
> +  (at your option) any later version.
> +
> +  This file is distributed in the hope that it will be useful, but
> +  WITHOUT ANY WARRANTY; without even the implied warranty of
> +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +  Lesser General Public License for more details.
> +***/
> +
> +#pragma once

#pragma once is not valid C. There is a universal standard way to do this.

> --- a/include/stdlib.h
> +++ b/include/stdlib.h
> @@ -52,10 +52,13 @@
>  char *getenv (const char *);
>  
>  int system (const char *);
>  
> +typedef int (*__compar_fn_t)(const void *, const void *);

This is in the internal namespace and it's an error for any
application to be using it.

> +typedef int (*comparison_fn_t)(const void *, const void *);

This is presumably a GNU extension (so would need to be in the
appropriate #ifdef block if added) but it probably doesn't meet the
usefulness criterion. Any code using this non-portable construct can
trivially be fixed to be portable.

>  void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
>  void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
> +void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);

qsort_r is an open issue pending action with the BSDs and the Austin
Group for unifying and standardizing it. Historically some BSDs had an
opposite-argument-order function by the same name which is why musl
has not added it. It might be good to go now; we need to check.

> --- a/src/stdlib/qsort.c	2017-01-01 04:27:17.000000000 +0100
> +++ b/src/stdlib/qsort.c	2017-01-29 00:21:27.194887091 +0100
> @@ -28,7 +28,7 @@
>  #include "atomic.h"
>  #define ntz(x) a_ctz_l((x))
>  
> -typedef int (*cmpfun)(const void *, const void *);
> +typedef int (*cmpfun)(const void *, const void *, void *);
>  
>  static inline int pntz(size_t p[2]) {
>  	int r = ntz(p[0] - 1);
> @@ -85,7 +85,7 @@
>  	p[1] >>= n;
>  }
>  
> -static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size_t lp[])
> +static void sift(unsigned char *head, size_t width, cmpfun cmp, void* arg, int pshift, size_t lp[])

Passing the extra context arg all the way through everything possibly
has significant performance hit for the standard qsort function. This
needs to be measured, and if so, either 2 separate versions need to be
built, or qsort_r needs to be implemented on top of qsort using TLS.

> [...]
> +
> +void qsort(void *base, size_t nel, size_t width, int (*cmp)(const void *, const void *))
> +{
> +	return qsort_r (base, nel, width, (cmpfun)cmp, NULL);
> +}

This cast and subsequent calling the cmp function with the incorrect
signature has undefined behavior and can't be used.

> --- a/include/stdlib.h
> +++ b/include/stdlib.h
> @@ -50,7 +50,8 @@
>  int at_quick_exit (void (*) (void));
>  _Noreturn void quick_exit (int);
>  
>  char *getenv (const char *);
> +char *secure_getenv (const char *);

Addition of this function is probably ok, but it needs to be under the
proper _GNU_SOURCE test.

>  
>  int system (const char *);
>  
> --- /dev/null
> +++ b/src/env/secure_getenv.c
> @@ -0,0 +1,8 @@
> +#define _DEFAULT_SOURCE 1
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +char *secure_getenv(const char *name)
> +{
> +	return issetugid() ? NULL : getenv(name);
> +}

> --- a/include/string.h
> +++ b/include/string.h
> @@ -85,7 +85,21 @@
>  #endif
>  
>  #ifdef _GNU_SOURCE
> -#define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
> +#ifdef __GNUC__
> +#define strdupa(x)	(__extension__({ \
> +			const char* __old = (x); \
> +			size_t __len = strlen(x) + 1; \
> +			char* __new = (char*)alloca(__len); \
> +			(char*)memcpy(__new, __old, __len); \
> +			}))
> +#define strndupa(x,y)	(__extension__({ \
> +			const char* __old = (x); \
> +			size_t __len = strnlen(x, (y)); \
> +			char* __new = (char*)alloca(__len + 1); \
> +			__new[__len] = 0; \
> +			(char*)memcpy(__new, __old, __len); \
> +			}))
> +#endif

This has been discussed before and we have a pending patch somewhere
that does it in another way. I'll see if I can dig it up and comment
based on that. Ultimately stdndupa is a really bad idea, but if it's
purely inline in a header there's not much burden on us by having it.

> --- a/include/utmpx.h
> +++ b/include/utmpx.h
> @@ -55,6 +55,12 @@
>  #define USER_PROCESS    7
>  #define DEAD_PROCESS    8
>  
> +
> +#ifdef _GNU_SOURCE
> +#define _PATH_UTMPX "/dev/null/utmp"
> +#define _PATH_WTMPX "/dev/null/wtmp"
> +#endif
> +
>  #ifdef __cplusplus
>  }
>  #endif

I'm not sure if this is a good idea or not. Those paths have been
problematic in the past.

> define unimplemented macros to 0 so that systemd compiles
> --- a/include/glob.h
> +++ b/include/glob.h
> @@ -22,6 +22,7 @@
>  int  glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict);
>  void globfree(glob_t *);
>  
> +#define GLOB_BRACE 0

This is definitely not acceptable. It advertises the existence of a
feature we don't have, making it impossible for applications to make
correct use of #ifdef to decide whether to use that feature or whether
to use their own replacement for the glob function that provides it.

If your goal in all this is to build systemd, a better approach is
just using the systemd patches others have already done. systemd
policy is *opposed* to writing portable code, or to making any
promises about what level of GNU extensions they require and will
require in the future. So if we just added a bunch of random stuff to
make systemd work out of the box, a few months or a year from now we'd
find that it doesn't work anymore, and we have to either add whatever
other new glibc thing they're demanding is, or accept that we added a
bunch of junk for nothing. This has been discussed a lot before and
it's not a game musl is willing to play.

> --- a/include/regex.h
> +++ b/include/regex.h
> @@ -31,6 +31,7 @@
>  
>  #define REG_NOTBOL      1
>  #define REG_NOTEOL      2
> +#define REG_STARTEND    0

Likewise this. There has been a request to add it before, and I think
there's a patch somewhere doing just that. The main concern is
long-term cost. The current regex implementation has sufficient
overhead that it doesn't matter, but if we do a better one at some
point in the future it might come back to bite us. I think it's
probably a good idea to add though.

>  #define REG_OK          0
>  #define REG_NOMATCH     1
> --- a/include/netdb.h
> +++ b/include/netdb.h
> @@ -140,6 +140,8 @@
>  #define EAI_IDN_ENCODE -105
>  #define NI_MAXHOST 255
>  #define NI_MAXSERV 32
> +#define NI_IDN 0
> +#define NI_IDN_USE_STD3_ASCII_RULES 0
>  #endif

The intent is to do IDN without any special flag, in which case
defining it as 0 would possibly be the right thing to do, but at
present it's another case of wrongly advertising a feature that's not
present and breaks application logic.

Rich


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: additional patches for musl
  2018-12-16  1:57 ` Rich Felker
@ 2018-12-16  2:16   ` Khem Raj
  0 siblings, 0 replies; 4+ messages in thread
From: Khem Raj @ 2018-12-16  2:16 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 13979 bytes --]

On Sat, Dec 15, 2018 at 5:57 PM Rich Felker <dalias@libc.org> wrote:

> On Sun, Dec 16, 2018 at 02:01:56AM +0200, сергей волковичь wrote:
> > cabulertion.
> > i finded additional patches for implementing some missing musl features.
>

This seems to be as if you are trying to port musl to systemd I think
Opposite would be a better approach qsort_r probably is a good to consider
everything else I am not so sure

In oepnembedded we have patched systemd to
Undo these things which are being introduced here please take a look

>
>
>
> > --- a/include/stdlib.h
> > +++ b/include/stdlib.h
> > @@ -120,6 +120,9 @@
> >  #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
> >   || defined(_BSD_SOURCE)
> >  char *realpath (const char *__restrict, char *__restrict);
> > +#ifdef _GNU_SOURCE
> > +char *canonicalize_file_name (const char *__restrict);
> > +#endif
>
> Small nit but rather than adding new #ifdef _GNU_SOURCE sections for
> each declaration, any new ones should be added under the existing
> section if there is one (and in stdlib.h there is).
>
> >  long int random (void);
> >  void srandom (unsigned int);
> >  char *initstate (unsigned int, char *, size_t);
> > --- a/src/misc/realpath.c
> > +++ b/src/misc/realpath.c
> > @@ -42,4 +42,9 @@
> >  err:
> >       __syscall(SYS_close, fd);
> >       return 0;
> >  }
> > +
> > +char *canonicalize_file_name(const char *restrict filename)
> > +{
> > +     return realpath(filename, NULL);
> > +}
>
> This can't go in the same file as realpath because it's not in the
> reserved namespace. Further it's probably not an acceptable addition
> since it's not widely used and has no advantages over the standard way
> of writing the exact same thing using realpath directly.
>
> > --- a/include/netdb.h
> > +++ b/include/netdb.h
> > @@ -124,6 +124,8 @@
> >  #define NO_RECOVERY    3
> >  #define NO_DATA        4
> >  #define NO_ADDRESS     NO_DATA
> > +#define NETDB_INTERNAL -1
> > +#define NETDB_SUCCESS  0
> >  #endif
>
>
>
>
> > --- a/include/ftw.h
> > +++ b/include/ftw.h
> > @@ -20,6 +20,14 @@
> >  #define FTW_MOUNT 2
> >  #define FTW_CHDIR 4
> >  #define FTW_DEPTH 8
> > +
> > +#ifdef _GNU_SOURCE
> > +#define FTW_ACTIONRETVAL 16
> > +#define FTW_CONTINUE 0
> > +#define FTW_STOP 1
> > +#define FTW_SKIP_SUBTREE 2
> > +#define FTW_SKIP_SIBLINGS 3
> > +#endif
>
> This one and the corresponding functional change is probably worth
> consideration. I've seen a few a
>
> >
> >  struct FTW {
> >       int base;
> > --- a/src/misc/nftw.c
> > +++ b/src/misc/nftw.c
> > @@ -1,3 +1,8 @@
> > +#define FTW_ACTIONRETVAL 16
> > +#define FTW_CONTINUE 0
> > +#define FTW_STOP 1
> > +#define FTW_SKIP_SUBTREE 2
> > +#define FTW_SKIP_SIBLINGS 3
> >  #include <ftw.h>
> >  #include <dirent.h>
> >  #include <sys/stat.h>
> > @@ -58,8 +58,20 @@
> >       lev.level = new.level;
> >       lev.base = h ? h->base : (name=strrchr(path, '/')) ? name-path : 0;
> >
> > -     if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
> > -             return r;
> > +     if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
> > +             if (flags & FTW_ACTIONRETVAL)
> > +                     switch (r) {
> > +                             case FTW_SKIP_SUBTREE:
> > +                                     h = NULL;
> > +                             case FTW_CONTINUE:
> > +                                     break;
> > +                             case FTW_SKIP_SIBLINGS:
> > +                             case FTW_STOP:
> > +                                     return r;
> > +                     }
> > +             else
> > +                     return r;
> > +     }
> >
> >       for (; h; h = h->chain)
> >               if (h->dev == st.st_dev && h->ino == st.st_ino)
> > @@ -82,7 +94,10 @@
> >                               strcpy(path+j+1, de->d_name);
> >                               if ((r=do_nftw(path, fn, fd_limit-1,
> flags, &new))) {
> >                                       closedir(d);
> > -                                     return r;
> > +                                     if ((flags & FTW_ACTIONRETVAL) &&
> r == FTW_SKIP_SIBLINGS)
> > +                                             break;
> > +                                     else
> > +                                             return r;
> >                               }
> >                       }
> >                       closedir(d);
> > @@ -93,8 +108,16 @@
> >       }
> >
> >       path[l] = 0;
> > -     if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev)))
> > -             return r;
> > +     if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) {
> > +             if (flags & FTW_ACTIONRETVAL)
> > +                     switch (r) {
> > +                             case FTW_SKIP_SIBLINGS:
> > +                             case FTW_STOP:
> > +                                     return r;
> > +                     }
> > +             else
> > +                     return r;
> > +     }
> >
> >       return 0;
> >  }
>
> > --- /dev/null
> > +++ b/src/misc/parse-printf-format.c
> > @@ -0,0 +1,265 @@
> > +/***
> > +  Copyright 2014 Emil Renner Berthing
> > +  With parts from the musl C library
> > +  Copyright 2005-2014 Rich Felker, et al.
> > +
> > +  This file is free software; you can redistribute it and/or modify it
> > +  under the terms of the GNU Lesser General Public License as published
> by
> > +  the Free Software Foundation; either version 2.1 of the License, or
> > +  (at your option) any later version.
>
> Please do not send license-incompatible patches to musl.
>
> > --- /dev/null
> > +++ b/include/printf.h
> > @@ -0,0 +1,41 @@
> > +/***
> > +  Copyright 2014 Emil Renner Berthing
> > +  With parts from the GNU C Library
> > +  Copyright 1991-2014 Free Software Foundation, Inc.
> > +
> > +  This file is free software; you can redistribute it and/or modify it
> > +  under the terms of the GNU Lesser General Public License as published
> by
>
> Likewise.
>
> > +  the Free Software Foundation; either version 2.1 of the License, or
> > +  (at your option) any later version.
> > +
> > +  This file is distributed in the hope that it will be useful, but
> > +  WITHOUT ANY WARRANTY; without even the implied warranty of
> > +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > +  Lesser General Public License for more details.
> > +***/
> > +
> > +#pragma once
>
> #pragma once is not valid C. There is a universal standard way to do this.
>
> > --- a/include/stdlib.h
> > +++ b/include/stdlib.h
> > @@ -52,10 +52,13 @@
> >  char *getenv (const char *);
> >
> >  int system (const char *);
> >
> > +typedef int (*__compar_fn_t)(const void *, const void *);
>
> This is in the internal namespace and it's an error for any
> application to be using it.
>
> > +typedef int (*comparison_fn_t)(const void *, const void *);
>
> This is presumably a GNU extension (so would need to be in the
> appropriate #ifdef block if added) but it probably doesn't meet the
> usefulness criterion. Any code using this non-portable construct can
> trivially be fixed to be portable.
>
> >  void *bsearch (const void *, const void *, size_t, size_t, int
> (*)(const void *, const void *));
> >  void qsort (void *, size_t, size_t, int (*)(const void *, const void
> *));
> > +void qsort_r (void *, size_t, size_t, int (*)(const void *, const void
> *, void *), void *);
>
> qsort_r is an open issue pending action with the BSDs and the Austin
> Group for unifying and standardizing it. Historically some BSDs had an
> opposite-argument-order function by the same name which is why musl
> has not added it. It might be good to go now; we need to check.
>
> > --- a/src/stdlib/qsort.c      2017-01-01 04:27:17.000000000 +0100
> > +++ b/src/stdlib/qsort.c      2017-01-29 00:21:27.194887091 +0100
> > @@ -28,7 +28,7 @@
> >  #include "atomic.h"
> >  #define ntz(x) a_ctz_l((x))
> >
> > -typedef int (*cmpfun)(const void *, const void *);
> > +typedef int (*cmpfun)(const void *, const void *, void *);
> >
> >  static inline int pntz(size_t p[2]) {
> >       int r = ntz(p[0] - 1);
> > @@ -85,7 +85,7 @@
> >       p[1] >>= n;
> >  }
> >
> > -static void sift(unsigned char *head, size_t width, cmpfun cmp, int
> pshift, size_t lp[])
> > +static void sift(unsigned char *head, size_t width, cmpfun cmp, void*
> arg, int pshift, size_t lp[])
>
> Passing the extra context arg all the way through everything possibly
> has significant performance hit for the standard qsort function. This
> needs to be measured, and if so, either 2 separate versions need to be
> built, or qsort_r needs to be implemented on top of qsort using TLS.
>
> > [...]
> > +
> > +void qsort(void *base, size_t nel, size_t width, int (*cmp)(const void
> *, const void *))
> > +{
> > +     return qsort_r (base, nel, width, (cmpfun)cmp, NULL);
> > +}
>
> This cast and subsequent calling the cmp function with the incorrect
> signature has undefined behavior and can't be used.
>
> > --- a/include/stdlib.h
> > +++ b/include/stdlib.h
> > @@ -50,7 +50,8 @@
> >  int at_quick_exit (void (*) (void));
> >  _Noreturn void quick_exit (int);
> >
> >  char *getenv (const char *);
> > +char *secure_getenv (const char *);
>
> Addition of this function is probably ok, but it needs to be under the
> proper _GNU_SOURCE test.
>
> >
> >  int system (const char *);
> >
> > --- /dev/null
> > +++ b/src/env/secure_getenv.c
> > @@ -0,0 +1,8 @@
> > +#define _DEFAULT_SOURCE 1
> > +#include <stdlib.h>
> > +#include <unistd.h>
> > +
> > +char *secure_getenv(const char *name)
> > +{
> > +     return issetugid() ? NULL : getenv(name);
> > +}
>
> > --- a/include/string.h
> > +++ b/include/string.h
> > @@ -85,7 +85,21 @@
> >  #endif
> >
> >  #ifdef _GNU_SOURCE
> > -#define      strdupa(x)      strcpy(alloca(strlen(x)+1),x)
> > +#ifdef __GNUC__
> > +#define strdupa(x)   (__extension__({ \
> > +                     const char* __old = (x); \
> > +                     size_t __len = strlen(x) + 1; \
> > +                     char* __new = (char*)alloca(__len); \
> > +                     (char*)memcpy(__new, __old, __len); \
> > +                     }))
> > +#define strndupa(x,y)        (__extension__({ \
> > +                     const char* __old = (x); \
> > +                     size_t __len = strnlen(x, (y)); \
> > +                     char* __new = (char*)alloca(__len + 1); \
> > +                     __new[__len] = 0; \
> > +                     (char*)memcpy(__new, __old, __len); \
> > +                     }))
> > +#endif
>
> This has been discussed before and we have a pending patch somewhere
> that does it in another way. I'll see if I can dig it up and comment
> based on that. Ultimately stdndupa is a really bad idea, but if it's
> purely inline in a header there's not much burden on us by having it.
>
> > --- a/include/utmpx.h
> > +++ b/include/utmpx.h
> > @@ -55,6 +55,12 @@
> >  #define USER_PROCESS    7
> >  #define DEAD_PROCESS    8
> >
> > +
> > +#ifdef _GNU_SOURCE
> > +#define _PATH_UTMPX "/dev/null/utmp"
> > +#define _PATH_WTMPX "/dev/null/wtmp"
> > +#endif
> > +
> >  #ifdef __cplusplus
> >  }
> >  #endif
>
> I'm not sure if this is a good idea or not. Those paths have been
> problematic in the past.
>
> > define unimplemented macros to 0 so that systemd compiles
> > --- a/include/glob.h
> > +++ b/include/glob.h
> > @@ -22,6 +22,7 @@
> >  int  glob(const char *__restrict, int, int (*)(const char *, int),
> glob_t *__restrict);
> >  void globfree(glob_t *);
> >
> > +#define GLOB_BRACE 0
>
> This is definitely not acceptable. It advertises the existence of a
> feature we don't have, making it impossible for applications to make
> correct use of #ifdef to decide whether to use that feature or whether
> to use their own replacement for the glob function that provides it.
>
> If your goal in all this is to build systemd, a better approach is
> just using the systemd patches others have already done. systemd
> policy is *opposed* to writing portable code, or to making any
> promises about what level of GNU extensions they require and will
> require in the future. So if we just added a bunch of random stuff to
> make systemd work out of the box, a few months or a year from now we'd
> find that it doesn't work anymore, and we have to either add whatever
> other new glibc thing they're demanding is, or accept that we added a
> bunch of junk for nothing. This has been discussed a lot before and
> it's not a game musl is willing to play.
>
> > --- a/include/regex.h
> > +++ b/include/regex.h
> > @@ -31,6 +31,7 @@
> >
> >  #define REG_NOTBOL      1
> >  #define REG_NOTEOL      2
> > +#define REG_STARTEND    0
>
> Likewise this. There has been a request to add it before, and I think
> there's a patch somewhere doing just that. The main concern is
> long-term cost. The current regex implementation has sufficient
> overhead that it doesn't matter, but if we do a better one at some
> point in the future it might come back to bite us. I think it's
> probably a good idea to add though.
>
> >  #define REG_OK          0
> >  #define REG_NOMATCH     1
> > --- a/include/netdb.h
> > +++ b/include/netdb.h
> > @@ -140,6 +140,8 @@
> >  #define EAI_IDN_ENCODE -105
> >  #define NI_MAXHOST 255
> >  #define NI_MAXSERV 32
> > +#define NI_IDN 0
> > +#define NI_IDN_USE_STD3_ASCII_RULES 0
> >  #endif
>
> The intent is to do IDN without any special flag, in which case
> defining it as 0 would possibly be the right thing to do, but at
> present it's another case of wrongly advertising a feature that's not
> present and breaks application logic.
>
> Rich
>

[-- Attachment #2: Type: text/html, Size: 17155 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-16  2:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-16  0:01 additional patches for musl сергей волковичь
2018-12-16  1:34 ` A. Wilcox
2018-12-16  1:57 ` Rich Felker
2018-12-16  2:16   ` Khem Raj

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).