From 21cbb6fe887a30f0777521ec10f0d0d9c2a7da7e Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Fri, 13 Mar 2015 21:03:10 +0100 Subject: unistd.h: put getppid under XOPEN2K8 Add __LEAF to all __THROW, introduce non-leaf __THROWNL Adjust affected spots accordingly. Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/getrusage.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libc') diff --git a/libc/sysdeps/linux/common/getrusage.c b/libc/sysdeps/linux/common/getrusage.c index 3e719f294..fb7614be8 100644 --- a/libc/sysdeps/linux/common/getrusage.c +++ b/libc/sysdeps/linux/common/getrusage.c @@ -10,4 +10,5 @@ #include #include #include +#include _syscall2(int, getrusage, __rusage_who_t, who, struct rusage *, usage) -- cgit v1.2.3 From 8ee422cffbfd3e2a16265fe6680a8dde2f5e58fe Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Thu, 12 Mar 2015 02:21:12 +0300 Subject: resolv: fix unaligned tmp buffer corner-case On execution of "inet/gethost_r-align" test I noticed failure due to unaligned access (instaed of 4-byte aligned 1-byte aligned address was attempted to be accessed). Further investigation confirmed this nice and helpful test failure. Following commit removed usage of ALIGN_BUFFER_OFFSET on entry to __read_etc_hosts_r(): http://git.uclibc.org/uClibc/commit/?id=f65e66078b9f4d2d7f0fc336dee36e78fc467c0f So indeed if target architecture doesn't allow unaligned access and provided tmp buffer is not word aligned (and we will deal with pointers which means word-sized data units), then CPU will fail during execution. In case of ARC we'll see "Unaligned access" exception like this: --->8--- # potentially unexpected fatal signal 7. Path: /root/uClibc/test/inet/gethost_r-align CPU: 0 PID: 5514 Comm: gethost_r-align Not tainted 3.13.11 #2 task: 8f42a580 ti: 8f40e000 task.ti: 8f40e000 [ECR ]: 0x00230400 => Misaligned r/w from 0x5fdab341 [EFA ]: 0x5fdab341 [BLINK ]: 0x20032a18 [ERET ]: 0x20032a3c @off 0x12a3c in [/lib/libuClibc-0.9.34-git.so] VMA: 0x20020000 to 0x20062000 [STAT32]: 0x00000086 : U E2 E1 BTA: 0x20046014 SP: 0x5fdab260 FP: 0x00000000 LPS: 0x20046064 LPE: 0x20046068 LPC: 0x00000000 r00: 0x5fdab341 r01: 0x00000005 r02: 0x00000015 r03: 0x00000000 r04: 0x5fdab358 r05: 0x00000000 r06: 0x0a0a0a00 r07: 0x00000000 r08: 0x0000003f r09: 0x20067050 r10: 0x00000000 r11: 0x00000014 r12: 0x00000001 r13: 0x00000000 r14: 0x20060660 r15: 0x20060661 r16: 0x00000006 r17: 0x5fdab371 r18: 0x00000018 r19: 0x5fdab2b4 r20: 0x00020000 r21: 0x00000000 r22: 0x00029068 r23: 0x5fdab371 r24: 0x00010000 r25: 0x00000000 --->8--- To fix this problem we'll re-introduce tmp buffer force alignment before config parser invocation. Signed-off-by: Alexey Brodkin Cc: Vineet Gupta Cc: Waldemar Brodkorb Signed-off-by: Bernhard Reutner-Fischer --- libc/inet/resolv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index cfc1eee9b..31e63810b 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -1615,9 +1615,13 @@ int __read_etc_hosts_r( #endif ; int ret = HOST_NOT_FOUND; + /* make sure pointer is aligned */ + int i = ALIGN_BUFFER_OFFSET(buf); + buf += i; + buflen -= i; *h_errnop = NETDB_INTERNAL; - if (buflen < aliaslen + if (/* (ssize_t)buflen < 0 || */ buflen < aliaslen || (buflen - aliaslen) < BUFSZ + 1) return ERANGE; if (parser == NULL) -- cgit v1.2.3 From 75d9bf2dc57f89532a25ab9942b8bea468585199 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 17 Mar 2015 20:54:58 +0100 Subject: include: silence __leaf warning Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/makedev.c | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 libc/sysdeps/linux/common/makedev.c (limited to 'libc') diff --git a/libc/sysdeps/linux/common/makedev.c b/libc/sysdeps/linux/common/makedev.c new file mode 100644 index 000000000..d7761671b --- /dev/null +++ b/libc/sysdeps/linux/common/makedev.c @@ -0,0 +1,42 @@ +/* Definitions of functions to access `dev_t' values. + Copyright (C) 2003-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library 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. + + The GNU C Library 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. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +unsigned int +gnu_dev_major (unsigned long long int dev) +{ + return ((dev >> 8) & 0xfff) | ((unsigned int) (dev >> 32) & ~0xfff); +} +libc_hidden_def(gnu_dev_major) + +unsigned int +gnu_dev_minor (unsigned long long int dev) +{ + return (dev & 0xff) | ((unsigned int) (dev >> 12) & ~0xff); +} +libc_hidden_def(gnu_dev_minor) + +unsigned long long int +gnu_dev_makedev (unsigned int major, unsigned int minor) +{ + return ((minor & 0xff) | ((major & 0xfff) << 8) + | (((unsigned long long int) (minor & ~0xff)) << 12) + | (((unsigned long long int) (major & ~0xfff)) << 32)); +} -- cgit v1.2.3 From 6f4d5a7f53ee7f277b31bbff638bbccecf22f66f Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 17 Mar 2015 21:19:10 +0100 Subject: libc: update strverscmp Closes bugzilla #7936 Signed-off-by: Bernhard Reutner-Fischer --- libc/string/strverscmp.c | 69 ++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) (limited to 'libc') diff --git a/libc/string/strverscmp.c b/libc/string/strverscmp.c index 714f4ed67..7818a9186 100644 --- a/libc/string/strverscmp.c +++ b/libc/string/strverscmp.c @@ -1,13 +1,8 @@ -/* GNU's strverscmp() function, taken from glibc 2.3.2 sources - */ - /* Compare strings while treating digits characters numerically. - Copyright (C) 1997, 2002 Free Software Foundation, Inc. + Copyright (C) 1997-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jean-François Bignolles , 1997. - Derived work for uClibc by Hai Zaar, Codefidence Ltd - The GNU C Library 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 @@ -22,63 +17,54 @@ License along with the GNU C Library; if not, see . */ +#include #include #include -#include - /* states: S_N: normal, S_I: comparing integral part, S_F: comparing - fractional parts, S_Z: idem but with leading Zeroes only */ + fractionnal parts, S_Z: idem but with leading Zeroes only */ #define S_N 0x0 -#define S_I 0x4 -#define S_F 0x8 -#define S_Z 0xC +#define S_I 0x3 +#define S_F 0x6 +#define S_Z 0x9 /* result_type: CMP: return diff; LEN: compare using len_diff/diff */ #define CMP 2 #define LEN 3 -/* using more efficient isdigit() */ -#undef isdigit -#define isdigit(a) ((unsigned)((a) - '0') <= 9) /* Compare S1 and S2 as strings holding indices/version numbers, returning less than, equal to or greater than zero if S1 is less than, equal to or greater than S2 (for more info, see the texinfo doc). */ + int strverscmp (const char *s1, const char *s2) { const unsigned char *p1 = (const unsigned char *) s1; const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - int state; - int diff; - /* Symbol(s) 0 [1-9] others (padding) - Transition (10) 0 (01) d (00) x (11) - */ + /* Symbol(s) 0 [1-9] others + Transition (10) 0 (01) d (00) x */ static const uint8_t next_state[] = { - /* state x d 0 - */ - /* S_N */ S_N, S_I, S_Z, S_N, - /* S_I */ S_N, S_I, S_I, S_I, - /* S_F */ S_N, S_F, S_F, S_F, - /* S_Z */ S_N, S_F, S_Z, S_Z + /* state x d 0 */ + /* S_N */ S_N, S_I, S_Z, + /* S_I */ S_N, S_I, S_I, + /* S_F */ S_N, S_F, S_F, + /* S_Z */ S_N, S_F, S_Z }; static const int8_t result_type[] = { - /* state x/x x/d x/0 x/- d/x d/d d/0 d/- - 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */ - - /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP, - +1, LEN, LEN, CMP, CMP, CMP, CMP, CMP, - /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP, - -1, CMP, CMP, CMP + /* state x/x x/d x/0 d/x d/d d/0 0/x 0/d 0/0 */ + + /* S_N */ CMP, CMP, CMP, CMP, LEN, CMP, CMP, CMP, CMP, + /* S_I */ CMP, -1, -1, +1, LEN, LEN, +1, LEN, LEN, + /* S_F */ CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, + /* S_Z */ CMP, +1, +1, -1, CMP, CMP, -1, CMP, CMP }; + unsigned char c1, c2; + int state, diff; if (p1 == p2) return 0; @@ -86,17 +72,20 @@ int strverscmp (const char *s1, const char *s2) c1 = *p1++; c2 = *p2++; /* Hint: '0' is a digit too. */ - state = S_N | ((c1 == '0') + (isdigit (c1) != 0)); + state = S_N + ((c1 == '0') + (isdigit (c1) != 0)); - while ((diff = c1 - c2) == 0 && c1 != '\0') + while ((diff = c1 - c2) == 0) { + if (c1 == '\0') + return diff; + state = next_state[state]; c1 = *p1++; c2 = *p2++; - state |= (c1 == '0') + (isdigit (c1) != 0); + state += (c1 == '0') + (isdigit (c1) != 0); } - state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))]; + state = result_type[state * 3 + (((c2 == '0') + (isdigit (c2) != 0)))]; switch (state) { -- cgit v1.2.3 From 6c4538905e65ceb203f59aaa9a61728e81c6bc0a Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 22:32:22 +0100 Subject: libm: Add missing C99 float/ld wrappers Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/bits/mathcalls.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libc') diff --git a/libc/sysdeps/linux/common/bits/mathcalls.h b/libc/sysdeps/linux/common/bits/mathcalls.h index 84b793c96..9bebb5190 100644 --- a/libc/sysdeps/linux/common/bits/mathcalls.h +++ b/libc/sysdeps/linux/common/bits/mathcalls.h @@ -74,8 +74,22 @@ __MATHCALLI (atan2,, (_Mdouble_ __y, _Mdouble_ __x)) /* Cosine of X. */ __MATHCALLI (cos,, (_Mdouble_ __x)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(cosl) +# endif +# if defined _LIBC && defined _Mfloat_ +libm_hidden_proto(cosf) +# endif + /* Sine of X. */ __MATHCALLI (sin,, (_Mdouble_ __x)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(sinl) +# endif +# if defined _LIBC && defined _Mfloat_ +libm_hidden_proto(sinf) +# endif + /* Tangent of X. */ __MATHCALLI (tan,, (_Mdouble_ __x)) @@ -111,6 +125,9 @@ __END_NAMESPACE_C99 _Mdouble_BEGIN_NAMESPACE /* Exponential function of X. */ __MATHCALLI (exp,, (_Mdouble_ __x)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(expl) +# endif /* Break VALUE into a normalized fraction and an integral power of 2. */ __MATHCALLI (frexp,, (_Mdouble_ __x, int *__exponent)) @@ -173,6 +190,9 @@ _Mdouble_END_NAMESPACE __BEGIN_NAMESPACE_C99 /* Return `sqrt(X*X + Y*Y)'. */ __MATHCALLI (hypot,, (_Mdouble_ __x, _Mdouble_ __y)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(hypotl) +# endif __END_NAMESPACE_C99 #endif @@ -298,6 +318,9 @@ __MATHCALLI (rint,, (_Mdouble_ __x)) /* Return X + epsilon if X < Y, X - epsilon if X > Y. */ __MATHCALLX (nextafter,, (_Mdouble_ __x, _Mdouble_ __y), (__const__)) +# if defined _LIBC && defined _Mlong_double_ +libm_hidden_proto(nextafterl) +# endif # if defined __USE_ISOC99 && !defined __LDBL_COMPAT __MATHCALLX (nexttoward,, (_Mdouble_ __x, long double __y), (__const__)) # endif -- cgit v1.2.3 From 85cfbc035370d2a3715ea9de3e590ba83fae52d1 Mon Sep 17 00:00:00 2001 From: Zhiqiang Zhang Date: Wed, 18 Mar 2015 18:44:50 +0800 Subject: malloc: checked_request2size failure deadlocks For some rarely cases(almost App bugs), calling malloc with a very largre size, checked_request2size check will fail,set ENOMEM, and return 0 to caller. But this will let __malloc_lock futex locked and owned by the caller. In multithread circumstance, other thread calling malloc/calloc will NOT succeed and get locked. Signed-off-by: Zhiqiang Zhang Signed-off-by: Bernhard Reutner-Fischer --- libc/stdlib/malloc-standard/malloc.c | 5 +++-- libc/stdlib/malloc-standard/memalign.c | 2 +- libc/stdlib/malloc-standard/realloc.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'libc') diff --git a/libc/stdlib/malloc-standard/malloc.c b/libc/stdlib/malloc-standard/malloc.c index 2abb5bbdd..fd33b50c7 100644 --- a/libc/stdlib/malloc-standard/malloc.c +++ b/libc/stdlib/malloc-standard/malloc.c @@ -832,8 +832,6 @@ void* malloc(size_t bytes) } #endif - __MALLOC_LOCK; - av = get_malloc_state(); /* Convert request size to internal form by adding (sizeof(size_t)) bytes overhead plus possibly more to obtain necessary alignment and/or @@ -845,6 +843,9 @@ void* malloc(size_t bytes) checked_request2size(bytes, nb); + __MALLOC_LOCK; + av = get_malloc_state(); + /* Bypass search if no frees yet */ diff --git a/libc/stdlib/malloc-standard/memalign.c b/libc/stdlib/malloc-standard/memalign.c index 6303c1dd9..e9ae5a7b9 100644 --- a/libc/stdlib/malloc-standard/memalign.c +++ b/libc/stdlib/malloc-standard/memalign.c @@ -52,8 +52,8 @@ void* memalign(size_t alignment, size_t bytes) alignment = a; } - __MALLOC_LOCK; checked_request2size(bytes, nb); + __MALLOC_LOCK; /* Strategy: find a spot within that chunk that meets the alignment * request, and then possibly free the leading and trailing space. */ diff --git a/libc/stdlib/malloc-standard/realloc.c b/libc/stdlib/malloc-standard/realloc.c index e060b70ea..e49d11125 100644 --- a/libc/stdlib/malloc-standard/realloc.c +++ b/libc/stdlib/malloc-standard/realloc.c @@ -54,9 +54,9 @@ void* realloc(void* oldmem, size_t bytes) return NULL; } + checked_request2size(bytes, nb); __MALLOC_LOCK; av = get_malloc_state(); - checked_request2size(bytes, nb); oldp = mem2chunk(oldmem); oldsize = chunksize(oldp); -- cgit v1.2.3 From be61486447ab447ac24892845af92489fe0b7148 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 18 Mar 2015 23:11:39 +0100 Subject: malloc-standard: Add locking to malloc_trim Closes bugzilla #4586 Signed-off-by: Bernhard Reutner-Fischer --- libc/stdlib/malloc-standard/free.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/stdlib/malloc-standard/free.c b/libc/stdlib/malloc-standard/free.c index 39e54d635..8b7a81fca 100644 --- a/libc/stdlib/malloc-standard/free.c +++ b/libc/stdlib/malloc-standard/free.c @@ -104,9 +104,13 @@ static int __malloc_trim(size_t pad, mstate av) */ int malloc_trim(size_t pad) { + int r; + __MALLOC_LOCK; mstate av = get_malloc_state(); __malloc_consolidate(av); - return __malloc_trim(pad, av); + r = __malloc_trim(pad, av); + __MALLOC_UNLOCK; + return r; } /* -- cgit v1.2.3 From 9faa7e94b824e1dc5fd9ce1b6f16c1b3f13c601a Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Sat, 23 Jun 2012 13:26:30 -0700 Subject: atexit_old: Do not add it to shared libc atexit should only be in either uclibc_nonshared.a shared libc case or libc.a in static build case Signed-off-by: Khem Raj Signed-off-by: Bernhard Reutner-Fischer --- libc/stdlib/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libc') diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in index 880de78d8..071f91119 100644 --- a/libc/stdlib/Makefile.in +++ b/libc/stdlib/Makefile.in @@ -61,7 +61,6 @@ CSRC-$(if $(findstring yyy,$(UCLIBC_HAS_FLOATS)$(UCLIBC_HAS_WCHAR)$(UCLIBC_HAS_X # multi source _atexit.c CSRC-y += __cxa_atexit.c __cxa_finalize.c __exit_handler.c exit.c on_exit.c -CSRC-$(COMPAT_ATEXIT) += old_atexit.c STDLIB_DIR := $(top_srcdir)libc/stdlib STDLIB_OUT := $(top_builddir)libc/stdlib @@ -71,11 +70,12 @@ STDLIB_OBJ := $(patsubst %.c,$(STDLIB_OUT)/%.o,$(CSRC-y)) libc-y += $(STDLIB_OBJ) libc-static-y += $(STDLIB_OUT)/atexit.o $(STDLIB_OUT)/system.o +libc-static-$(COMPAT_ATEXIT) += $(STDLIB_OUT)/old_atexit.o libc-shared-y += $(STDLIB_OUT)/system.oS # this should always be the PIC version, because it could be used in shared libs libc-nonshared-y += $(STDLIB_OUT)/atexit.os - +libc-nonshared-$(COMPAT_ATEXIT) += $(STDLIB_OUT)/old_atexit.os libc-nomulti-y += $(STDLIB_OUT)/labs.o $(STDLIB_OUT)/atol.o $(STDLIB_OUT)/_stdlib_strto_l.o $(STDLIB_OUT)/_stdlib_strto_ll.o libc-nomulti-$(UCLIBC_HAS_XLOCALE) += $(STDLIB_OUT)/_stdlib_strto_l_l.o $(STDLIB_OUT)/_stdlib_strto_ll_l.o -- cgit v1.2.3 From bfb988452cc66ddf93f69a199c50ea1c14e9ccb7 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Sat, 23 Jun 2012 14:21:17 -0700 Subject: nptl/arm: Move aeabi_read_tp to uclibc_nonshared.a Otherwise it creates wrong references from shared libs Signed-off-by: Khem Raj Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arm/Makefile.arch | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/sysdeps/linux/arm/Makefile.arch b/libc/sysdeps/linux/arm/Makefile.arch index 3054273df..cda3db206 100644 --- a/libc/sysdeps/linux/arm/Makefile.arch +++ b/libc/sysdeps/linux/arm/Makefile.arch @@ -13,7 +13,9 @@ SSRC-y := \ vfork.S clone.S SSRC-$(UCLIBC_HAS_LFS) += mmap64.S -SSRC-$(UCLIBC_HAS_THREADS_NATIVE) += libc-aeabi_read_tp.S libc-thumb_atomics.S +SSRC-$(UCLIBC_HAS_THREADS_NATIVE) += libc-thumb_atomics.S +libc-nonshared-$(UCLIBC_HAS_THREADS_NATIVE) += $(ARCH_OUT)/libc-aeabi_read_tp.os +libc-static-$(UCLIBC_HAS_THREADS_NATIVE) += $(ARCH_OUT)/libc-aeabi_read_tp.o CSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += makecontext.c SSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += getcontext.S setcontext.S swapcontext.S -- cgit v1.2.3 From 5c3661fda947c1bc5e597be081c355b51c595794 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 22 Mar 2015 14:47:29 +0100 Subject: libc: Fix vfprintf compilation without HAS_FLOATS Signed-off-by: Bernhard Reutner-Fischer --- libc/stdio/_fpmaxtostr.h | 22 +++++++++++----------- libc/stdio/_vfprintf.c | 15 --------------- 2 files changed, 11 insertions(+), 26 deletions(-) (limited to 'libc') diff --git a/libc/stdio/_fpmaxtostr.h b/libc/stdio/_fpmaxtostr.h index b4e7321c2..7694629ec 100644 --- a/libc/stdio/_fpmaxtostr.h +++ b/libc/stdio/_fpmaxtostr.h @@ -11,39 +11,39 @@ #define _FPMAXTOSTR_H 1 #include -#ifdef __UCLIBC_HAS_FLOATS__ - #define __need_size_t #include #include #include #include #include -#include -#include + +#ifdef __UCLIBC_HAS_FLOATS__ +# include +# include /* WARNING: Adjust _fp_out_wide() in _vfprintf.c if this changes! */ /* With 32 bit ints, we can get 9 decimal digits per block. */ -#define DIGITS_PER_BLOCK 9 +# define DIGITS_PER_BLOCK 9 -#define NUM_DIGIT_BLOCKS ((DECIMAL_DIG+DIGITS_PER_BLOCK-1)/DIGITS_PER_BLOCK) +# define NUM_DIGIT_BLOCKS ((DECIMAL_DIG+DIGITS_PER_BLOCK-1)/DIGITS_PER_BLOCK) /* WARNING: Adjust _fp_out_wide() in _vfprintf.c if this changes! */ /* extra space for '-', '.', 'e+###', and nul */ -#define BUF_SIZE ( 3 + NUM_DIGIT_BLOCKS * DIGITS_PER_BLOCK ) +# define BUF_SIZE ( 3 + NUM_DIGIT_BLOCKS * DIGITS_PER_BLOCK ) /* psm: why do these internals differ? */ -#ifdef __USE_OLD_VFPRINTF__ +# ifdef __USE_OLD_VFPRINTF__ typedef void (__fp_outfunc_t)(FILE *fp, intptr_t type, intptr_t len, intptr_t buf); extern size_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info, __fp_outfunc_t fp_outfunc) attribute_hidden; -#else +# else typedef size_t (__fp_outfunc_t)(FILE *fp, intptr_t type, intptr_t len, intptr_t buf); extern ssize_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info, __fp_outfunc_t fp_outfunc) attribute_hidden; -#endif +# endif -#endif /* __UCLIBC_HAS_FLOATS__ */ +# endif /* __UCLIBC_HAS_FLOATS__ */ #endif /* _FPMAXTOSTR_H */ diff --git a/libc/stdio/_vfprintf.c b/libc/stdio/_vfprintf.c index 01ee218e5..a795f4979 100644 --- a/libc/stdio/_vfprintf.c +++ b/libc/stdio/_vfprintf.c @@ -121,18 +121,6 @@ #error Apparently, LONG_LONG_MAX is defined but LLONG_MAX is not. You need to fix your toolchain headers to support the standard macros for (unsigned) long long. #endif -/**********************************************************************/ -/* These provide some control over printf's feature set */ - -/* Now controlled by uClibc_config.h. */ -/* #define __UCLIBC_HAS_FLOATS__ 1 */ - -/* Now controlled by uClibc_config.h. */ -/* #define __UCLIBC_HAS_PRINTF_M_SPEC__ */ - - -/**********************************************************************/ - #include "_fpmaxtostr.h" #undef __STDIO_HAS_VSNPRINTF @@ -142,9 +130,6 @@ /**********************************************************************/ -/* Now controlled by uClibc_config.h. */ -/* #define __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */ - #ifdef __UCLIBC_MJN3_ONLY__ # ifdef L_register_printf_function /* emit only once */ -- cgit v1.2.3 From 09ff424905d5de0b2a21a3960d9756a90b07ba26 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 22 Mar 2015 14:47:29 +0100 Subject: libc: add getrandom(2) Introduce a for it. /* FIXME: aren't there a couple of __restrict and const missing ? */ extern int getrandom(void *__buf, size_t count, unsigned int flags) __nonnull ((1)) __wur; Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/Makefile.in | 1 + libc/sysdeps/linux/common/bits/kernel-features.h | 5 ++++ libc/sysdeps/linux/common/getrandom.c | 14 ++++++++++ libc/sysdeps/linux/common/stubs.c | 4 +++ libc/sysdeps/linux/common/sys/random.h | 33 ++++++++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 libc/sysdeps/linux/common/getrandom.c create mode 100644 libc/sysdeps/linux/common/sys/random.h (limited to 'libc') diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in index 8ee956b6b..82525984a 100644 --- a/libc/sysdeps/linux/common/Makefile.in +++ b/libc/sysdeps/linux/common/Makefile.in @@ -27,6 +27,7 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \ eventfd.c \ eventfd_read.c \ eventfd_write.c \ + getrandom.c \ inotify.c \ ioperm.c \ iopl.c \ diff --git a/libc/sysdeps/linux/common/bits/kernel-features.h b/libc/sysdeps/linux/common/bits/kernel-features.h index 6184c2b9d..708bb4906 100644 --- a/libc/sysdeps/linux/common/bits/kernel-features.h +++ b/libc/sysdeps/linux/common/bits/kernel-features.h @@ -507,3 +507,8 @@ #if defined __x86_64__ && __LINUX_KERNEL_VERSION >= 0x030100 # define __ASSUME_GETCPU_SYSCALL 1 #endif + +/* getrandom syscall (widely) appeared around 4.0.0 */ +#if __LINUX_KERNEL_VERSION >= 0x040000 +# define __ASSUME_GETRANDOM_SYSCALL 1 +#endif diff --git a/libc/sysdeps/linux/common/getrandom.c b/libc/sysdeps/linux/common/getrandom.c new file mode 100644 index 000000000..d33d5224a --- /dev/null +++ b/libc/sysdeps/linux/common/getrandom.c @@ -0,0 +1,14 @@ +/* vi: set sw=4 ts=4: */ +/* + * getrandom() for uClibc + * + * Copyright (C) 2015 Bernhard Reutner-Fischer + * + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + */ + +#include +#include +#ifdef __NR_getrandom +_syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags) +#endif diff --git a/libc/sysdeps/linux/common/stubs.c b/libc/sysdeps/linux/common/stubs.c index 2c50307aa..19a33714a 100644 --- a/libc/sysdeps/linux/common/stubs.c +++ b/libc/sysdeps/linux/common/stubs.c @@ -157,6 +157,10 @@ make_stub(getpeername) make_stub(getpgrp) #endif +#if !defined __NR_getrandom && defined __UCLIBC_LINUX_SPECIFIC__ +make_stub(getrandom) +#endif + #if !defined __NR_getsockname && !defined __NR_socketcall && defined __UCLIBC_HAS_SOCKET__ make_stub(getsockname) #endif diff --git a/libc/sysdeps/linux/common/sys/random.h b/libc/sysdeps/linux/common/sys/random.h new file mode 100644 index 000000000..42f802576 --- /dev/null +++ b/libc/sysdeps/linux/common/sys/random.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2015 Bernhard Reutner-Fischer + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. +*/ + +#ifndef _SYS_RANDOM_H +#define _SYS_RANDOM_H 1 +#include + +__BEGIN_DECLS + +#if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU +# if 0 /*def __ASSUME_GETRANDOM_SYSCALL */ +# include +# else +# undef GRND_NONBLOCK +# undef GRND_RANDOM +/* + * Flags for getrandom(2) + * + * GRND_NONBLOCK Don't block and return EAGAIN instead + * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom + */ +# define GRND_NONBLOCK 0x0001 +# define GRND_RANDOM 0x0002 +# endif +/* FIXME: aren't there a couple of __restrict and const missing ? */ +extern int getrandom(void *__buf, size_t count, unsigned int flags) + __nonnull ((1)) __wur; +#endif + +__END_DECLS + +#endif /* sys/random.h */ -- cgit v1.2.3 From 9277fe13156a6ff2b055fe8a58d2863115c36b6a Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:09:45 +0100 Subject: Revert "utent.c, wtent.c: move functions from utxent.c" This reverts commit 84135275cfeebc0b233c1c96eeada4d4178a0b18. This change is said to make systemd deadlock (cannot reproduce this) Signed-off-by: Bernhard Reutner-Fischer Conflicts: include/utmp.h --- libc/misc/utmp/utent.c | 80 ++++++++++++------------------------------------- libc/misc/utmp/utxent.c | 4 +-- libc/misc/utmp/wtent.c | 14 ++------- 3 files changed, 22 insertions(+), 76 deletions(-) (limited to 'libc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index a35bb2b84..07ca44eb2 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -19,9 +19,6 @@ #include #include #include -#ifdef __UCLIBC_HAS_UTMPX__ -# include -#endif #include #include @@ -34,7 +31,7 @@ static const char default_file_name[] = _PATH_UTMP; static const char *static_ut_name = default_file_name; /* This function must be called with the LOCK held */ -static void __setutent_unlocked(void) +static void __setutent(void) { if (static_fd < 0) { static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); @@ -53,24 +50,19 @@ static void __setutent_unlocked(void) lseek(static_fd, 0, SEEK_SET); } #if defined __UCLIBC_HAS_THREADS__ -static void __setutent(void) +void setutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); - __setutent_unlocked(); + __setutent(); __UCLIBC_MUTEX_UNLOCK(utmplock); } #else -static void __setutent(void); -strong_alias(__setutent_unlocked,__setutent) -#endif strong_alias(__setutent,setutent) - -#ifdef __UCLIBC_HAS_UTMPX__ -strong_alias(__setutent,setutxent) #endif +libc_hidden_def(setutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutent_unlocked(void) +static struct utmp *__getutent(void) { if (static_fd < 0) { __setutent(); @@ -86,27 +78,19 @@ static struct utmp *__getutent_unlocked(void) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -static struct utmp *__getutent(void) +struct utmp *getutent(void) { struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent_unlocked(); + ret = __getutent(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -static struct utmp *__getutent(void); -strong_alias(__getutent_unlocked,__getutent) -#endif strong_alias(__getutent,getutent) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *getutxent(void) -{ - return (struct utmpx *) __getutent (); -} #endif +libc_hidden_def(getutent) static void __endutent(void) { @@ -117,13 +101,10 @@ static void __endutent(void) __UCLIBC_MUTEX_UNLOCK(utmplock); } strong_alias(__endutent,endutent) - -#ifdef __UCLIBC_HAS_UTMPX__ -strong_alias(__endutent,endutxent) -#endif +libc_hidden_def(endutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) +static struct utmp *__getutid(const struct utmp *utmp_entry) { struct utmp *lutmp; unsigned type; @@ -133,7 +114,7 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) type = utmp_entry->ut_type - 1; type /= 4; - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __getutent()) != NULL) { if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ return lutmp; @@ -147,34 +128,26 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -static struct utmp *__getutid(const struct utmp *utmp_entry) +struct utmp *getutid(const struct utmp *utmp_entry) { struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid_unlocked(utmp_entry); + ret = __getutid(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -static struct utmp *__getutid(const struct utmp *utmp_entry); -strong_alias(__getutid_unlocked,__getutid) -#endif strong_alias(__getutid,getutid) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *getutxid(const struct utmpx *utmp_entry) -{ - return (struct utmpx *) __getutid ((const struct utmp *) utmp_entry); -} #endif +libc_hidden_def(getutid) static struct utmp *__getutline(const struct utmp *utmp_entry) { struct utmp *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __getutent()) != NULL) { if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) { break; @@ -185,13 +158,7 @@ static struct utmp *__getutline(const struct utmp *utmp_entry) return lutmp; } strong_alias(__getutline,getutline) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *getutxline(const struct utmpx *utmp_entry) -{ - return (struct utmpx *) __getutline ((const struct utmp *) utmp_entry); -} -#endif +libc_hidden_def(getutline) static struct utmp *__pututline(const struct utmp *utmp_entry) { @@ -200,7 +167,7 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) the file pointer where they want it, everything will work out. */ lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); - if (__getutid_unlocked(utmp_entry) != NULL) + if (__getutid(utmp_entry) != NULL) lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); else lseek(static_fd, (off_t) 0, SEEK_END); @@ -211,13 +178,7 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) return (struct utmp *)utmp_entry; } strong_alias(__pututline,pututline) - -#ifdef __UCLIBC_HAS_UTMPX__ -struct utmpx *pututxline (const struct utmpx *utmp_entry) -{ - return (struct utmpx *) __pututline ((const struct utmp *) utmp_entry); -} -#endif +libc_hidden_def(pututline) static int __utmpname(const char *new_ut_name) { @@ -241,7 +202,4 @@ static int __utmpname(const char *new_ut_name) return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ } strong_alias(__utmpname,utmpname) - -#ifdef __UCLIBC_HAS_UTMPX__ -strong_alias(__utmpname,utmpxname) -#endif +libc_hidden_def(utmpname) diff --git a/libc/misc/utmp/utxent.c b/libc/misc/utmp/utxent.c index 71157ccd8..a0e80a662 100644 --- a/libc/misc/utmp/utxent.c +++ b/libc/misc/utmp/utxent.c @@ -13,7 +13,6 @@ #include #include -#if 0 /* moved to utent.c */ void setutxent(void) { setutent (); @@ -49,12 +48,10 @@ int utmpxname (const char *new_ut_name) return utmpname (new_ut_name); } -/* moved to wtent.c */ void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx) { updwtmp (wtmpx_file, (const struct utmp *) utmpx); } -#endif /* Copy the information in UTMPX to UTMP. */ void getutmp (const struct utmpx *utmpx, struct utmp *utmp) @@ -107,3 +104,4 @@ void getutmpx (const struct utmp *utmp, struct utmpx *utmpx) utmpx->ut_time = utmp->ut_time; #endif } + diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c index 9b3ad5084..b5e4ee576 100644 --- a/libc/misc/utmp/wtent.c +++ b/libc/misc/utmp/wtent.c @@ -11,9 +11,6 @@ #include #include #include -#ifdef __UCLIBC_HAS_UTMPX__ -# include -#endif #include #include #include @@ -36,7 +33,7 @@ void logwtmp (const char *line, const char *name, const char *host) } #endif -static void __updwtmp(const char *wtmp_file, const struct utmp *lutmp) +void updwtmp(const char *wtmp_file, const struct utmp *lutmp) { int fd; @@ -49,11 +46,4 @@ static void __updwtmp(const char *wtmp_file, const struct utmp *lutmp) } } } -strong_alias(__updwtmp,updwtmp) - -#ifdef __UCLIBC_HAS_UTMPX__ -void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx) -{ - __updwtmp (wtmpx_file, (const struct utmp *) utmpx); -} -#endif +libc_hidden_def(updwtmp) -- cgit v1.2.3 From eee76e42f32f90af4e64a254810fcb767297fecf Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:15 +0100 Subject: libc: TIME64_COMPAT32 for sparc, mips Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/bits/utmp.h | 4 ++-- libc/sysdeps/linux/common/bits/utmpx.h | 2 +- libc/sysdeps/linux/mips/bits/wordsize.h | 3 +++ libc/sysdeps/linux/powerpc/bits/wordsize.h | 2 +- libc/sysdeps/linux/sparc/bits/wordsize.h | 1 + libc/sysdeps/linux/x86_64/bits/wordsize.h | 9 ++++++--- 6 files changed, 14 insertions(+), 7 deletions(-) (limited to 'libc') diff --git a/libc/sysdeps/linux/common/bits/utmp.h b/libc/sysdeps/linux/common/bits/utmp.h index c13380ab8..6ece31e34 100644 --- a/libc/sysdeps/linux/common/bits/utmp.h +++ b/libc/sysdeps/linux/common/bits/utmp.h @@ -36,7 +36,7 @@ previous logins. */ struct lastlog { -#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 +#ifdef __WORDSIZE_TIME64_COMPAT32 int32_t ll_time; #else __time_t ll_time; @@ -69,7 +69,7 @@ struct utmp /* The ut_session and ut_tv fields must be the same size when compiled 32- and 64-bit. This allows data files and shared memory to be shared between 32- and 64-bit applications. */ -#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 +#ifdef __WORDSIZE_TIME64_COMPAT32 int32_t ut_session; /* Session ID, used for windowing. */ struct { diff --git a/libc/sysdeps/linux/common/bits/utmpx.h b/libc/sysdeps/linux/common/bits/utmpx.h index 87626f085..815fc90b8 100644 --- a/libc/sysdeps/linux/common/bits/utmpx.h +++ b/libc/sysdeps/linux/common/bits/utmpx.h @@ -66,7 +66,7 @@ struct utmpx /* The fields ut_session and ut_tv must be the same size when compiled 32- and 64-bit. This allows files and shared memory to be shared between 32- and 64-bit applications. */ -#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 +#ifdef __WORDSIZE_TIME64_COMPAT32 __int32_t ut_session; /* Session ID, used for windowing. */ struct { diff --git a/libc/sysdeps/linux/mips/bits/wordsize.h b/libc/sysdeps/linux/mips/bits/wordsize.h index 39e15062c..fe130806c 100644 --- a/libc/sysdeps/linux/mips/bits/wordsize.h +++ b/libc/sysdeps/linux/mips/bits/wordsize.h @@ -16,3 +16,6 @@ . */ #define __WORDSIZE _MIPS_SZPTR +#if _MIPS_SIM == _ABI64 +# define __WORDSIZE_TIME64_COMPAT32 1 +#endif diff --git a/libc/sysdeps/linux/powerpc/bits/wordsize.h b/libc/sysdeps/linux/powerpc/bits/wordsize.h index cf934234f..3e8a1e0a1 100644 --- a/libc/sysdeps/linux/powerpc/bits/wordsize.h +++ b/libc/sysdeps/linux/powerpc/bits/wordsize.h @@ -2,7 +2,7 @@ #if defined __powerpc64__ # define __WORDSIZE 64 -# define __WORDSIZE_COMPAT32 1 +# define __WORDSIZE_TIME64_COMPAT32 1 #else # define __WORDSIZE 32 #endif diff --git a/libc/sysdeps/linux/sparc/bits/wordsize.h b/libc/sysdeps/linux/sparc/bits/wordsize.h index c0e600ed5..aa15dbc7a 100644 --- a/libc/sysdeps/linux/sparc/bits/wordsize.h +++ b/libc/sysdeps/linux/sparc/bits/wordsize.h @@ -2,6 +2,7 @@ #if defined __arch64__ || defined __sparcv9 # define __WORDSIZE 64 +# define __WORDSIZE_TIME64_COMPAT32 1 #else # define __WORDSIZE 32 #endif diff --git a/libc/sysdeps/linux/x86_64/bits/wordsize.h b/libc/sysdeps/linux/x86_64/bits/wordsize.h index e55524100..9db982c90 100644 --- a/libc/sysdeps/linux/x86_64/bits/wordsize.h +++ b/libc/sysdeps/linux/x86_64/bits/wordsize.h @@ -1,9 +1,12 @@ /* Determine the wordsize from the preprocessor defines. */ -#if defined __x86_64__ +#if defined __x86_64__ && !defined __ILP32__ # define __WORDSIZE 64 -/* This makes /var/run/utmp compatible with 32-bit environment: */ -# define __WORDSIZE_COMPAT32 1 #else # define __WORDSIZE 32 #endif + +#ifdef __x86_64__ +/* This makes /var/run/utmp compatible with 32-bit environment: */ +# define __WORDSIZE_TIME64_COMPAT32 1 +#endif -- cgit v1.2.3 From 4da43e9f2e4f2f7593427003e37b87287c7b16cf Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:21 +0100 Subject: buildsys: HAS_UTMP (XPG2, SVr4 compat) knob Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/Makefile.in | 4 +++- libc/misc/utmp/utent.c | 1 + libc/misc/utmp/utxent.c | 1 + libc/misc/utmp/wtent.c | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/misc/utmp/Makefile.in b/libc/misc/utmp/Makefile.in index 535efb150..715341c85 100644 --- a/libc/misc/utmp/Makefile.in +++ b/libc/misc/utmp/Makefile.in @@ -7,7 +7,9 @@ subdirs += libc/misc/utmp -CSRC-y := utent.c wtent.c +CSRC-y := +CSRC-$(if $(findstring y,$(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX)),y) += wtent.c +CSRC-$(UCLIBC_HAS_UTMP) += utent.c CSRC-$(UCLIBC_HAS_UTMPX) += utxent.c MISC_UTMP_DIR := $(top_srcdir)libc/misc/utmp diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 07ca44eb2..6e1567865 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* utent.c */ /* Let it be known that this is very possibly the worst standard ever. HP-UX does one thing, someone else does another, linux another... If anyone diff --git a/libc/misc/utmp/utxent.c b/libc/misc/utmp/utxent.c index a0e80a662..c32e4da49 100644 --- a/libc/misc/utmp/utxent.c +++ b/libc/misc/utmp/utxent.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* * utexent.c : Support for accessing user accounting database. * Copyright (C) 2010 STMicroelectronics Ltd. diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c index b5e4ee576..30939ea43 100644 --- a/libc/misc/utmp/wtent.c +++ b/libc/misc/utmp/wtent.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* * Copyright (C) 2000-2006 Erik Andersen * -- cgit v1.2.3 From d0f60a600bafc3f6dfc844418d310cf6a4e38c92 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:24 +0100 Subject: utmp: add _unlocked suffix to internal helpers Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'libc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 6e1567865..87fe42b16 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -21,8 +21,8 @@ #include #include #include - #include + __UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER); /* Some global crap */ @@ -32,7 +32,7 @@ static const char default_file_name[] = _PATH_UTMP; static const char *static_ut_name = default_file_name; /* This function must be called with the LOCK held */ -static void __setutent(void) +static void __setutent_unlocked(void) { if (static_fd < 0) { static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); @@ -54,19 +54,19 @@ static void __setutent(void) void setutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); - __setutent(); + __setutent_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); } #else -strong_alias(__setutent,setutent) +strong_alias(__setutent_unlocked,setutent) #endif libc_hidden_def(setutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutent(void) +static struct utmp *__getutent_unlocked(void) { if (static_fd < 0) { - __setutent(); + __setutent_unlocked(); if (static_fd < 0) { return NULL; } @@ -84,12 +84,12 @@ struct utmp *getutent(void) struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent(); + ret = __getutent_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutent,getutent) +strong_alias(__getutent_unlocked,getutent) #endif libc_hidden_def(getutent) @@ -105,7 +105,7 @@ strong_alias(__endutent,endutent) libc_hidden_def(endutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutid(const struct utmp *utmp_entry) +static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) { struct utmp *lutmp; unsigned type; @@ -115,7 +115,7 @@ static struct utmp *__getutid(const struct utmp *utmp_entry) type = utmp_entry->ut_type - 1; type /= 4; - while ((lutmp = __getutent()) != NULL) { + while ((lutmp = __getutent_unlocked()) != NULL) { if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ return lutmp; @@ -134,12 +134,12 @@ struct utmp *getutid(const struct utmp *utmp_entry) struct utmp *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid(utmp_entry); + ret = __getutid_unlocked(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutid,getutid) +strong_alias(__getutid_unlocked,getutid) #endif libc_hidden_def(getutid) @@ -148,7 +148,7 @@ static struct utmp *__getutline(const struct utmp *utmp_entry) struct utmp *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent()) != NULL) { + while ((lutmp = __getutent_unlocked()) != NULL) { if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) { break; @@ -168,7 +168,7 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) the file pointer where they want it, everything will work out. */ lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); - if (__getutid(utmp_entry) != NULL) + if (__getutid_unlocked(utmp_entry) != NULL) lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); else lseek(static_fd, (off_t) 0, SEEK_END); -- cgit v1.2.3 From 97c9f52239301c81c021b8be187ac07ddf33496d Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:28 +0100 Subject: utmp: Remove unneeded aliases Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'libc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 87fe42b16..c45820e3a 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -143,7 +143,7 @@ strong_alias(__getutid_unlocked,getutid) #endif libc_hidden_def(getutid) -static struct utmp *__getutline(const struct utmp *utmp_entry) +struct utmp *getutline(const struct utmp *utmp_entry) { struct utmp *lutmp; @@ -158,10 +158,9 @@ static struct utmp *__getutline(const struct utmp *utmp_entry) __UCLIBC_MUTEX_UNLOCK(utmplock); return lutmp; } -strong_alias(__getutline,getutline) libc_hidden_def(getutline) -static struct utmp *__pututline(const struct utmp *utmp_entry) +struct utmp *pututline(const struct utmp *utmp_entry) { __UCLIBC_MUTEX_LOCK(utmplock); /* Ignore the return value. That way, if they've already positioned @@ -178,10 +177,9 @@ static struct utmp *__pututline(const struct utmp *utmp_entry) __UCLIBC_MUTEX_UNLOCK(utmplock); return (struct utmp *)utmp_entry; } -strong_alias(__pututline,pututline) libc_hidden_def(pututline) -static int __utmpname(const char *new_ut_name) +int utmpname(const char *new_ut_name) { __UCLIBC_MUTEX_LOCK(utmplock); if (new_ut_name != NULL) { @@ -202,5 +200,4 @@ static int __utmpname(const char *new_ut_name) __UCLIBC_MUTEX_UNLOCK(utmplock); return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ } -strong_alias(__utmpname,utmpname) libc_hidden_def(utmpname) -- cgit v1.2.3 From 6cba32e6e9a1910ea0a5277fd39484047094e478 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:38 +0100 Subject: utmp: indent indent only, no code changes Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 194 +++++++++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 95 deletions(-) (limited to 'libc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index c45820e3a..4d71f5e29 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -34,28 +34,28 @@ static const char *static_ut_name = default_file_name; /* This function must be called with the LOCK held */ static void __setutent_unlocked(void) { - if (static_fd < 0) { - static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); if (static_fd < 0) { - static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC); - if (static_fd < 0) { - return; /* static_fd remains < 0 */ - } - } + static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); + if (static_fd < 0) { + static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC); + if (static_fd < 0) { + return; /* static_fd remains < 0 */ + } + } #ifndef __ASSUME_O_CLOEXEC - /* Make sure the file will be closed on exec() */ - fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC); + /* Make sure the file will be closed on exec() */ + fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC); #endif - return; - } - lseek(static_fd, 0, SEEK_SET); + return; + } + lseek(static_fd, 0, SEEK_SET); } #if defined __UCLIBC_HAS_THREADS__ void setutent(void) { - __UCLIBC_MUTEX_LOCK(utmplock); - __setutent_unlocked(); - __UCLIBC_MUTEX_UNLOCK(utmplock); + __UCLIBC_MUTEX_LOCK(utmplock); + __setutent_unlocked(); + __UCLIBC_MUTEX_UNLOCK(utmplock); } #else strong_alias(__setutent_unlocked,setutent) @@ -65,28 +65,28 @@ libc_hidden_def(setutent) /* This function must be called with the LOCK held */ static struct utmp *__getutent_unlocked(void) { - if (static_fd < 0) { - __setutent_unlocked(); if (static_fd < 0) { - return NULL; + __setutent_unlocked(); + if (static_fd < 0) + return NULL; } - } - if (read_not_cancel(static_fd, &static_utmp, sizeof(static_utmp)) == sizeof(static_utmp)) { - return &static_utmp; - } + if (read_not_cancel(static_fd, &static_utmp, + sizeof(static_utmp)) == sizeof(static_utmp)) { + return &static_utmp; + } - return NULL; + return NULL; } #if defined __UCLIBC_HAS_THREADS__ struct utmp *getutent(void) { - struct utmp *ret; + struct utmp *ret; - __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent_unlocked(); - __UCLIBC_MUTEX_UNLOCK(utmplock); - return ret; + __UCLIBC_MUTEX_LOCK(utmplock); + ret = __getutent_unlocked(); + __UCLIBC_MUTEX_UNLOCK(utmplock); + return ret; } #else strong_alias(__getutent_unlocked,getutent) @@ -95,11 +95,11 @@ libc_hidden_def(getutent) static void __endutent(void) { - __UCLIBC_MUTEX_LOCK(utmplock); - if (static_fd >= 0) - close_not_cancel_no_status(static_fd); - static_fd = -1; - __UCLIBC_MUTEX_UNLOCK(utmplock); + __UCLIBC_MUTEX_LOCK(utmplock); + if (static_fd >= 0) + close_not_cancel_no_status(static_fd); + static_fd = -1; + __UCLIBC_MUTEX_UNLOCK(utmplock); } strong_alias(__endutent,endutent) libc_hidden_def(endutent) @@ -107,36 +107,38 @@ libc_hidden_def(endutent) /* This function must be called with the LOCK held */ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) { - struct utmp *lutmp; - unsigned type; - - /* We use the fact that constants we are interested in are: */ - /* RUN_LVL=1, ... OLD_TIME=4; INIT_PROCESS=5, ... USER_PROCESS=8 */ - type = utmp_entry->ut_type - 1; - type /= 4; - - while ((lutmp = __getutent_unlocked()) != NULL) { - if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { - /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ - return lutmp; + struct utmp *lutmp; + unsigned type; + + /* We use the fact that constants we are interested in are: */ + /* RUN_LVL=1, ... OLD_TIME=4; INIT_PROCESS=5, ... USER_PROCESS=8 */ + type = utmp_entry->ut_type - 1; + type /= 4; + + while ((lutmp = __getutent_unlocked()) != NULL) { + if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { + /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ + return lutmp; + } + if (type == 1 + && strncmp(lutmp->ut_id, utmp_entry->ut_id, + sizeof(lutmp->ut_id)) == 0) { + /* INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, DEAD_PROCESS */ + return lutmp; + } } - if (type == 1 && strncmp(lutmp->ut_id, utmp_entry->ut_id, sizeof(lutmp->ut_id)) == 0) { - /* INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, DEAD_PROCESS */ - return lutmp; - } - } - return NULL; + return NULL; } #if defined __UCLIBC_HAS_THREADS__ struct utmp *getutid(const struct utmp *utmp_entry) { - struct utmp *ret; + struct utmp *ret; - __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid_unlocked(utmp_entry); - __UCLIBC_MUTEX_UNLOCK(utmplock); - return ret; + __UCLIBC_MUTEX_LOCK(utmplock); + ret = __getutid_unlocked(utmp_entry); + __UCLIBC_MUTEX_UNLOCK(utmplock); + return ret; } #else strong_alias(__getutid_unlocked,getutid) @@ -145,59 +147,61 @@ libc_hidden_def(getutid) struct utmp *getutline(const struct utmp *utmp_entry) { - struct utmp *lutmp; - - __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent_unlocked()) != NULL) { - if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { - if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) { - break; - } + struct utmp *lutmp; + + __UCLIBC_MUTEX_LOCK(utmplock); + while ((lutmp = __getutent_unlocked()) != NULL) { + if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { + if (strncmp(lutmp->ut_line, utmp_entry->ut_line, + sizeof(lutmp->ut_line)) == 0) { + break; + } + } } - } - __UCLIBC_MUTEX_UNLOCK(utmplock); - return lutmp; + __UCLIBC_MUTEX_UNLOCK(utmplock); + return lutmp; } libc_hidden_def(getutline) struct utmp *pututline(const struct utmp *utmp_entry) { - __UCLIBC_MUTEX_LOCK(utmplock); - /* Ignore the return value. That way, if they've already positioned - the file pointer where they want it, everything will work out. */ - lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); - - if (__getutid_unlocked(utmp_entry) != NULL) + __UCLIBC_MUTEX_LOCK(utmplock); + /* Ignore the return value. That way, if they've already positioned + the file pointer where they want it, everything will work out. */ lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); - else - lseek(static_fd, (off_t) 0, SEEK_END); - if (write(static_fd, utmp_entry, sizeof(struct utmp)) != sizeof(struct utmp)) - utmp_entry = NULL; - __UCLIBC_MUTEX_UNLOCK(utmplock); - return (struct utmp *)utmp_entry; + if (__getutid_unlocked(utmp_entry) != NULL) + lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); + else + lseek(static_fd, (off_t) 0, SEEK_END); + if (write(static_fd, utmp_entry, sizeof(struct utmp)) + != sizeof(struct utmp)) + utmp_entry = NULL; + + __UCLIBC_MUTEX_UNLOCK(utmplock); + return (struct utmp *)utmp_entry; } libc_hidden_def(pututline) int utmpname(const char *new_ut_name) { - __UCLIBC_MUTEX_LOCK(utmplock); - if (new_ut_name != NULL) { - if (static_ut_name != default_file_name) - free((char *)static_ut_name); - static_ut_name = strdup(new_ut_name); - if (static_ut_name == NULL) { - /* We should probably whine about out-of-memory - * errors here... Instead just reset to the default */ - static_ut_name = default_file_name; + __UCLIBC_MUTEX_LOCK(utmplock); + if (new_ut_name != NULL) { + if (static_ut_name != default_file_name) + free((char *)static_ut_name); + static_ut_name = strdup(new_ut_name); + if (static_ut_name == NULL) { + /* We should probably whine about out-of-memory + * errors here... Instead just reset to the default */ + static_ut_name = default_file_name; + } } - } - if (static_fd >= 0) { - close_not_cancel_no_status(static_fd); - static_fd = -1; - } - __UCLIBC_MUTEX_UNLOCK(utmplock); - return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ + if (static_fd >= 0) { + close_not_cancel_no_status(static_fd); + static_fd = -1; + } + __UCLIBC_MUTEX_UNLOCK(utmplock); + return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ } libc_hidden_def(utmpname) -- cgit v1.2.3 From 40effcf4c1e9a2fb9169d9189bdc9b1c888f9345 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Tue, 24 Mar 2015 00:11:49 +0100 Subject: mips: switch float_t to float Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/mips/bits/mathdef.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'libc') diff --git a/libc/sysdeps/linux/mips/bits/mathdef.h b/libc/sysdeps/linux/mips/bits/mathdef.h index 1c636a199..6afe20d8a 100644 --- a/libc/sysdeps/linux/mips/bits/mathdef.h +++ b/libc/sysdeps/linux/mips/bits/mathdef.h @@ -25,10 +25,9 @@ #if defined __USE_ISOC99 && defined _MATH_H && !defined _MATH_H_MATHDEF # define _MATH_H_MATHDEF 1 -/* Normally, there is no long double type and the `float' and `double' - expressions are evaluated as `double'. */ -typedef double float_t; /* `float' expressions are evaluated as - `double'. */ +/* MIPS has both `float' and `double' arithmetic. */ +typedef float float_t; /* `float' expressions are evaluated as + `float'. */ typedef double double_t; /* `double' expressions are evaluated as `double'. */ -- cgit v1.2.3 From 2b33716c08cc506e57115e34b5fe11d8d5477398 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:37 +0100 Subject: utmp: Remove unneeded alias Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/utent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'libc') diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index 4d71f5e29..a258cb46d 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -93,7 +93,7 @@ strong_alias(__getutent_unlocked,getutent) #endif libc_hidden_def(getutent) -static void __endutent(void) +void endutent(void) { __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd >= 0) @@ -101,7 +101,6 @@ static void __endutent(void) static_fd = -1; __UCLIBC_MUTEX_UNLOCK(utmplock); } -strong_alias(__endutent,endutent) libc_hidden_def(endutent) /* This function must be called with the LOCK held */ -- cgit v1.2.3 From 6ff9c31abc14f207265ab214370982ecb3bfe428 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 25 Mar 2015 23:59:45 +0100 Subject: utmp: favour POSIX utmpx over SVID utmp Note: _PATH_UTMPX == _PATH_UTMP and the utmp struct is identical to the utmpx struct so this only changes the external API entrypoints and NOT the underlying data source. This saves about 500b (~1300b from previously ~1950) while at it. Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/utmp/Makefile.in | 4 +- libc/misc/utmp/utent.c | 121 +++++++++++++++++++++--------------- libc/misc/utmp/utxent.c | 108 -------------------------------- libc/misc/utmp/wtent.c | 50 --------------- libc/sysdeps/linux/sh/bits/atomic.h | 12 +++- 5 files changed, 82 insertions(+), 213 deletions(-) delete mode 100644 libc/misc/utmp/utxent.c delete mode 100644 libc/misc/utmp/wtent.c (limited to 'libc') diff --git a/libc/misc/utmp/Makefile.in b/libc/misc/utmp/Makefile.in index 715341c85..6c54ade96 100644 --- a/libc/misc/utmp/Makefile.in +++ b/libc/misc/utmp/Makefile.in @@ -8,9 +8,7 @@ subdirs += libc/misc/utmp CSRC-y := -CSRC-$(if $(findstring y,$(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX)),y) += wtent.c -CSRC-$(UCLIBC_HAS_UTMP) += utent.c -CSRC-$(UCLIBC_HAS_UTMPX) += utxent.c +CSRC-$(if $(findstring y,$(UCLIBC_HAS_UTMP)$(UCLIBC_HAS_UTMPX)),y) += utent.c MISC_UTMP_DIR := $(top_srcdir)libc/misc/utmp MISC_UTMP_OUT := $(top_builddir)libc/misc/utmp diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c index a258cb46d..3671bb05c 100644 --- a/libc/misc/utmp/utent.c +++ b/libc/misc/utmp/utent.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include "internal/utmp.h" #include #include @@ -27,17 +27,17 @@ __UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER); /* Some global crap */ static int static_fd = -1; -static struct utmp static_utmp; -static const char default_file_name[] = _PATH_UTMP; -static const char *static_ut_name = default_file_name; +static struct UT static_utmp; +static const char default_file[] = __DEFAULT_PATH_UTMP; +static const char *current_file = default_file; /* This function must be called with the LOCK held */ -static void __setutent_unlocked(void) +static void __set_unlocked(void) { if (static_fd < 0) { - static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC); + static_fd = open_not_cancel_2(current_file, O_RDWR | O_CLOEXEC); if (static_fd < 0) { - static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC); + static_fd = open_not_cancel_2(current_file, O_RDONLY | O_CLOEXEC); if (static_fd < 0) { return; /* static_fd remains < 0 */ } @@ -51,22 +51,23 @@ static void __setutent_unlocked(void) lseek(static_fd, 0, SEEK_SET); } #if defined __UCLIBC_HAS_THREADS__ -void setutent(void) +void set(void) { __UCLIBC_MUTEX_LOCK(utmplock); - __setutent_unlocked(); + __set_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); } #else -strong_alias(__setutent_unlocked,setutent) +strong_alias(__set_unlocked,set) #endif -libc_hidden_def(setutent) +/* not used in libc_hidden_def(set) */ +other(setutxent,setutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutent_unlocked(void) +static struct UT *__get_unlocked(void) { if (static_fd < 0) { - __setutent_unlocked(); + __set_unlocked(); if (static_fd < 0) return NULL; } @@ -79,21 +80,22 @@ static struct utmp *__getutent_unlocked(void) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -struct utmp *getutent(void) +struct UT *get(void) { - struct utmp *ret; + struct UT *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutent_unlocked(); + ret = __get_unlocked(); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutent_unlocked,getutent) +strong_alias(__get_unlocked,get) #endif -libc_hidden_def(getutent) +/* not used in libc_hidden_def(get) */ +other(getutxent,getutent) -void endutent(void) +void end(void) { __UCLIBC_MUTEX_LOCK(utmplock); if (static_fd >= 0) @@ -101,12 +103,13 @@ void endutent(void) static_fd = -1; __UCLIBC_MUTEX_UNLOCK(utmplock); } -libc_hidden_def(endutent) +/* not used in libc_hidden_def(end) */ +other(endutxent,endutent) /* This function must be called with the LOCK held */ -static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) +static struct UT *__getid_unlocked(const struct UT *utmp_entry) { - struct utmp *lutmp; + struct UT *lutmp; unsigned type; /* We use the fact that constants we are interested in are: */ @@ -114,7 +117,7 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) type = utmp_entry->ut_type - 1; type /= 4; - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __get_unlocked()) != NULL) { if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) { /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */ return lutmp; @@ -130,26 +133,27 @@ static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry) return NULL; } #if defined __UCLIBC_HAS_THREADS__ -struct utmp *getutid(const struct utmp *utmp_entry) +struct UT *getid(const struct UT *utmp_entry) { - struct utmp *ret; + struct UT *ret; __UCLIBC_MUTEX_LOCK(utmplock); - ret = __getutid_unlocked(utmp_entry); + ret = __getid_unlocked(utmp_entry); __UCLIBC_MUTEX_UNLOCK(utmplock); return ret; } #else -strong_alias(__getutid_unlocked,getutid) +strong_alias(__getid_unlocked,getid) #endif -libc_hidden_def(getutid) +/* not used in libc_hidden_def(getid) */ +other(getutxid,getutid) -struct utmp *getutline(const struct utmp *utmp_entry) +struct UT *getline(const struct UT *utmp_entry) { - struct utmp *lutmp; + struct UT *lutmp; __UCLIBC_MUTEX_LOCK(utmplock); - while ((lutmp = __getutent_unlocked()) != NULL) { + while ((lutmp = __get_unlocked()) != NULL) { if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) { if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) { @@ -160,39 +164,41 @@ struct utmp *getutline(const struct utmp *utmp_entry) __UCLIBC_MUTEX_UNLOCK(utmplock); return lutmp; } -libc_hidden_def(getutline) +/* libc_hidden_def(getline) */ +other(getutxline,getutline) -struct utmp *pututline(const struct utmp *utmp_entry) +struct UT *putline(const struct UT *utmp_entry) { __UCLIBC_MUTEX_LOCK(utmplock); /* Ignore the return value. That way, if they've already positioned the file pointer where they want it, everything will work out. */ - lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); + lseek(static_fd, (off_t) - sizeof(struct UT), SEEK_CUR); - if (__getutid_unlocked(utmp_entry) != NULL) - lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR); + if (__getid_unlocked(utmp_entry) != NULL) + lseek(static_fd, (off_t) - sizeof(struct UT), SEEK_CUR); else lseek(static_fd, (off_t) 0, SEEK_END); - if (write(static_fd, utmp_entry, sizeof(struct utmp)) - != sizeof(struct utmp)) + if (write(static_fd, utmp_entry, sizeof(struct UT)) + != sizeof(struct UT)) utmp_entry = NULL; __UCLIBC_MUTEX_UNLOCK(utmplock); - return (struct utmp *)utmp_entry; + return (struct UT *)utmp_entry; } -libc_hidden_def(pututline) +/* not used in libc_hidden_def(putline) */ +other(pututxline,pututline) -int utmpname(const char *new_ut_name) +int name(const char *new_file) { __UCLIBC_MUTEX_LOCK(utmplock); - if (new_ut_name != NULL) { - if (static_ut_name != default_file_name) - free((char *)static_ut_name); - static_ut_name = strdup(new_ut_name); - if (static_ut_name == NULL) { + if (new_file != NULL) { + if (current_file != default_file) + free((char *)current_file); + current_file = strdup(new_file); + if (current_file == NULL) { /* We should probably whine about out-of-memory * errors here... Instead just reset to the default */ - static_ut_name = default_file_name; + current_file = default_file; } } @@ -201,6 +207,23 @@ int utmpname(const char *new_ut_name) static_fd = -1; } __UCLIBC_MUTEX_UNLOCK(utmplock); - return 0; /* or maybe return -(static_ut_name != new_ut_name)? */ + return 0; /* or maybe return -(current_file != new_file)? */ } -libc_hidden_def(utmpname) +/* not used in libc_hidden_def(name) */ +other(utmpxname,utmpname) + +void updw(const char *wtmp_file, const struct UT *lutmp) +{ + int fd; + + fd = open_not_cancel_2(wtmp_file, O_APPEND | O_WRONLY); + if (fd >= 0) { + if (lockf(fd, F_LOCK, 0) == 0) { + write_not_cancel(fd, lutmp, sizeof(struct UT)); + lockf(fd, F_ULOCK, 0); + close_not_cancel_no_status(fd); + } + } +} +/* not used in libc_hidden_def(updw) */ +other(updwtmpx,updwtmp) diff --git a/libc/misc/utmp/utxent.c b/libc/misc/utmp/utxent.c deleted file mode 100644 index c32e4da49..000000000 --- a/libc/misc/utmp/utxent.c +++ /dev/null @@ -1,108 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * utexent.c : Support for accessing user accounting database. - * Copyright (C) 2010 STMicroelectronics Ltd. - * - * Author: Salvatore Cro - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - * - */ - -#include -#include -#include -#include - -void setutxent(void) -{ - setutent (); -} - -void endutxent(void) -{ - endutent (); -} - -struct utmpx *getutxent(void) -{ - return (struct utmpx *) getutent (); -} - -struct utmpx *getutxid(const struct utmpx *utmp_entry) -{ - return (struct utmpx *) getutid ((const struct utmp *) utmp_entry); -} - -struct utmpx *getutxline(const struct utmpx *utmp_entry) -{ - return (struct utmpx *) getutline ((const struct utmp *) utmp_entry); -} - -struct utmpx *pututxline (const struct utmpx *utmp_entry) -{ - return (struct utmpx *) pututline ((const struct utmp *) utmp_entry); -} - -int utmpxname (const char *new_ut_name) -{ - return utmpname (new_ut_name); -} - -void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx) -{ - updwtmp (wtmpx_file, (const struct utmp *) utmpx); -} - -/* Copy the information in UTMPX to UTMP. */ -void getutmp (const struct utmpx *utmpx, struct utmp *utmp) -{ -#if _HAVE_UT_TYPE - 0 - utmp->ut_type = utmpx->ut_type; -#endif -#if _HAVE_UT_PID - 0 - utmp->ut_pid = utmpx->ut_pid; -#endif - memcpy (utmp->ut_line, utmpx->ut_line, sizeof (utmp->ut_line)); - memcpy (utmp->ut_user, utmpx->ut_user, sizeof (utmp->ut_user)); -#if _HAVE_UT_ID - 0 - memcpy (utmp->ut_id, utmpx->ut_id, sizeof (utmp->ut_id)); -#endif -#if _HAVE_UT_HOST - 0 - memcpy (utmp->ut_host, utmpx->ut_host, sizeof (utmp->ut_host)); -#endif -#if _HAVE_UT_TV - 0 - utmp->ut_tv.tv_sec = utmpx->ut_tv.tv_sec; - utmp->ut_tv.tv_usec = utmpx->ut_tv.tv_usec; -#else - utmp->ut_time = utmpx->ut_time; -#endif -} - -/* Copy the information in UTMP to UTMPX. */ -void getutmpx (const struct utmp *utmp, struct utmpx *utmpx) -{ - memset (utmpx, 0, sizeof (struct utmpx)); - -#if _HAVE_UT_TYPE - 0 - utmpx->ut_type = utmp->ut_type; -#endif -#if _HAVE_UT_PID - 0 - utmpx->ut_pid = utmp->ut_pid; -#endif - memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line)); - memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user)); -#if _HAVE_UT_ID - 0 - memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id)); -#endif -#if _HAVE_UT_HOST - 0 - memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host)); -#endif -#if _HAVE_UT_TV - 0 - utmpx->ut_tv.tv_sec = utmp->ut_tv.tv_sec; - utmpx->ut_tv.tv_usec = utmp->ut_tv.tv_usec; -#else - utmpx->ut_time = utmp->ut_time; -#endif -} - diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c deleted file mode 100644 index 30939ea43..000000000 --- a/libc/misc/utmp/wtent.c +++ /dev/null @@ -1,50 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Copyright (C) 2000-2006 Erik Andersen - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - */ - -/* wtmp support rubbish (i.e. complete crap) */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#if 0 -/* This is enabled in uClibc/libutil/logwtmp.c */ -void logwtmp (const char *line, const char *name, const char *host) -{ - struct utmp lutmp; - memset(&lutmp, 0, sizeof(lutmp)); - - lutmp.ut_type = (name && *name) ? USER_PROCESS : DEAD_PROCESS; - lutmp.ut_pid = getpid(); - strncpy(lutmp.ut_line, line, sizeof(lutmp.ut_line)-1); - strncpy(lutmp.ut_name, name, sizeof(lutmp.ut_name)-1); - strncpy(lutmp.ut_host, host, sizeof(lutmp.ut_host)-1); - gettimeofday(&(lutmp.ut_tv), NULL); - - updwtmp(_PATH_WTMP, &lutmp); -} -#endif - -void updwtmp(const char *wtmp_file, const struct utmp *lutmp) -{ - int fd; - - fd = open_not_cancel_2(wtmp_file, O_APPEND | O_WRONLY); - if (fd >= 0) { - if (lockf(fd, F_LOCK, 0) == 0) { - write_not_cancel(fd, lutmp, sizeof(struct utmp)); - lockf(fd, F_ULOCK, 0); - close_not_cancel_no_status(fd); - } - } -} -libc_hidden_def(updwtmp) diff --git a/libc/sysdeps/linux/sh/bits/atomic.h b/libc/sysdeps/linux/sh/bits/atomic.h index 745c85c1d..18ae9ea77 100644 --- a/libc/sysdeps/linux/sh/bits/atomic.h +++ b/libc/sysdeps/linux/sh/bits/atomic.h @@ -68,6 +68,12 @@ typedef uintmax_t uatomic_max_t; r1: saved stack pointer */ +#if __GNUC_PREREQ (4, 7) +# define rNOSP "u" +#else +# define rNOSP "r" +#endif + /* Avoid having lots of different versions of compare and exchange, by having this one complicated version. Parameters: bwl: b, w or l for 8, 16 and 32 bit versions. @@ -94,7 +100,7 @@ typedef uintmax_t uatomic_max_t; movt %0\n\ .endif\n" \ : "=&r" (__arch_result) \ - : "r" (mem), "r" (newval), "r" (oldval) \ + : rNOSP (mem), rNOSP (newval), rNOSP (oldval) \ : "r0", "r1", "t", "memory"); \ __arch_result; }) @@ -150,7 +156,7 @@ typedef uintmax_t uatomic_max_t; mov." #bwl " %1,@%2\n\ 1: mov r1,r15" \ : "=&r" (old), "=&r"(new) \ - : "r" (mem), "r" (value) \ + : rNOSP (mem), rNOSP (value) \ : "r0", "r1", "memory"); \ }) @@ -194,7 +200,7 @@ typedef uintmax_t uatomic_max_t; mov." #bwl " %0,@%1\n\ 1: mov r1,r15" \ : "=&r" (__new) \ - : "r" (mem), "r" (__value) \ + : rNOSP (mem), rNOSP (__value) \ : "r0", "r1", "memory"); \ __new; \ }) -- cgit v1.2.3 From fc673e14203e1c9aea353d99ff89a17d46b2ad93 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 26 Mar 2015 00:03:05 +0100 Subject: SH: add 't' to syscall clobber list Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/sh/bits/syscalls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/sysdeps/linux/sh/bits/syscalls.h b/libc/sysdeps/linux/sh/bits/syscalls.h index b308276c5..efd423ed3 100644 --- a/libc/sysdeps/linux/sh/bits/syscalls.h +++ b/libc/sysdeps/linux/sh/bits/syscalls.h @@ -122,7 +122,7 @@ __asm__ __volatile__ (SYSCALL_INST_STR##nr SYSCALL_INST_PAD \ : "=z" (resultvar) \ : "r" (r3) ASMFMT_##nr \ - : "memory" \ + : "memory", "t" \ ); \ (int) resultvar; \ }) \ -- cgit v1.2.3 From d3c60fc490d714d7610a91555cec67952409b189 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Thu, 26 Mar 2015 18:07:04 +0530 Subject: ARC/signal: shield sa_restorer from compiler toggle side-effects when building uClibc with -O0 (DODEBUG build) the default sigrestorer had some extra glue code generated for stack manipulation which was messing up resume from signal path. So annotate the function with -Os so that gcc would only generate the bare min 2 instruction TRAP sequence Reported-and-Debugged-by: Alexey Brodkin Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arc/sigaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libc') diff --git a/libc/sysdeps/linux/arc/sigaction.c b/libc/sysdeps/linux/arc/sigaction.c index 4a4c9e2d0..67ca38aca 100644 --- a/libc/sysdeps/linux/arc/sigaction.c +++ b/libc/sysdeps/linux/arc/sigaction.c @@ -13,7 +13,8 @@ /* * Default sigretrun stub if user doesn't specify SA_RESTORER */ -static void __default_rt_sa_restorer(void) +static void attribute_optimize("Os") __attribute_noinline__ +__default_rt_sa_restorer(void) { INTERNAL_SYSCALL_NCS(__NR_rt_sigreturn, , 0); } -- cgit v1.2.3 From 24946289317ea23bb0d1814cca0a499a905f7d6f Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Thu, 26 Mar 2015 14:25:37 +0530 Subject: ARC: don't hard-code ELF_NGREG Signed-off-by: Alexey Brodkin Signed-off-by: Vineet Gupta [updated changelog] Signed-off-by: Vineet Gupta Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/arc/sys/procfs.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'libc') diff --git a/libc/sysdeps/linux/arc/sys/procfs.h b/libc/sysdeps/linux/arc/sys/procfs.h index a9e375b33..a47430340 100755 --- a/libc/sysdeps/linux/arc/sys/procfs.h +++ b/libc/sysdeps/linux/arc/sys/procfs.h @@ -20,17 +20,14 @@ #include #include #include +#include __BEGIN_DECLS /* Type for a general-purpose register. */ typedef unsigned long elf_greg_t; -/* And the whole bunch of them. We could have used `struct - user_regs' directly in the typedef, but tradition says that - the register set is an array, which does have some peculiar - semantics, so leave it that way. */ -#define ELF_NGREG 40 +#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t)) typedef elf_greg_t elf_gregset_t[ELF_NGREG]; typedef struct { } elf_fpregset_t; -- cgit v1.2.3