+++ /dev/null
-===================================================================
-RCS file: /cvs/glibc/libc/malloc/malloc.c,v
-retrieving revision 1.87
-retrieving revision 1.87.2.3
-diff -u -r1.87 -r1.87.2.3
---- libc/malloc/malloc.c 2001/09/19 03:23:27 1.87
-+++ libc/malloc/malloc.c 2002/08/09 18:28:55 1.87.2.3
-@@ -1,5 +1,5 @@
- /* Malloc implementation for multiple threads without lock contention.
-- Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
-+ Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>
- and Doug Lea <dl@cs.oswego.edu>, 1996.
-@@ -19,7 +19,7 @@
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
--/* $Id$
-+/* $Id$
-
- This work is mainly derived from malloc-2.6.4 by Doug Lea
- <dl@cs.oswego.edu>, which is available from:
-@@ -3795,14 +3795,26 @@
- {
- arena *ar_ptr;
- mchunkptr p, oldtop;
-- INTERNAL_SIZE_T sz, csz, oldtopsize;
-+ INTERNAL_SIZE_T bytes, sz, csz, oldtopsize;
- Void_t* mem;
-
- #if defined _LIBC || defined MALLOC_HOOKS
- __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, __const __malloc_ptr_t)) =
- __malloc_hook;
-+
-+ /* size_t is unsigned so the behavior on overflow is defined. */
-+ bytes = n * elem_size;
-+#define HALF_INTERNAL_SIZE_T \
-+ (((INTERNAL_SIZE_T) 1) << (8 * sizeof (INTERNAL_SIZE_T) / 2))
-+ if (__builtin_expect ((n | elem_size) >= HALF_INTERNAL_SIZE_T, 0)) {
-+ if (elem_size != 0 && bytes / elem_size != n) {
-+ __set_errno (ENOMEM);
-+ return 0;
-+ }
-+ }
-+
- if (hook != NULL) {
-- sz = n * elem_size;
-+ sz = bytes;
- #if defined __GNUC__ && __GNUC__ >= 2
- mem = (*hook)(sz, RETURN_ADDRESS (0));
- #else
-@@ -3819,7 +3831,7 @@
- }
- #endif
-
-- if(request2size(n * elem_size, sz))
-+ if(request2size(bytes, sz))
- return 0;
- arena_get(ar_ptr, sz);
- if(!ar_ptr)
-@@ -3862,7 +3874,7 @@
- }
- if (p == 0) return 0;
- }
-- mem = BOUNDED_N(chunk2mem(p), n * elem_size);
-+ mem = BOUNDED_N(chunk2mem(p), bytes);
-
- /* Two optional cases in which clearing not necessary */
-
-@@ -4899,9 +4911,9 @@
- {
- void *mem;
-
-- /* Test whether the SIZE argument is valid. It must be a power of
-- two multiple of sizeof (void *). */
-- if (size % sizeof (void *) != 0 || (size & (size - 1)) != 0)
-+ /* Test whether the ALIGNMENT argument is valid. It must be a power
-+ of two multiple of sizeof (void *). */
-+ if (alignment % sizeof (void *) != 0 || (alignment & (alignment - 1)) != 0)
- return EINVAL;
-
- mem = __libc_memalign (alignment, size);
+++ /dev/null
-Index: libc/sysdeps/i386/Makefile
-===================================================================
-RCS file: /cvs/glibc/libc/sysdeps/i386/Makefile,v
-retrieving revision 1.11
-retrieving revision 1.11.2.1
-diff -u -r1.11 -r1.11.2.1
---- libc/sysdeps/i386/Makefile 17 Sep 1999 16:59:13 -0000 1.11
-+++ libc/sysdeps/i386/Makefile 28 Feb 2002 19:39:16 -0000 1.11.2.1
-@@ -9,6 +9,12 @@
- # On i686 we must avoid generating the trampoline functions generated
- # to get the GOT pointer.
- CFLAGS-initfini.s += -march=i386 -mcpu=i386
-+
-+ifeq (yes,$(build-shared))
-+# Compatibility
-+sysdep_routines += divdi3
-+shared-only-routines += divdi3
-+endif
- endif
-
- ifeq ($(subdir),db2)
-Index: libc/sysdeps/m68k/Makefile
-===================================================================
-RCS file: /cvs/glibc/libc/sysdeps/m68k/Makefile,v
-retrieving revision 1.20
-retrieving revision 1.20.2.1
-diff -u -r1.20 -r1.20.2.1
---- libc/sysdeps/m68k/Makefile 6 Jul 2001 04:55:55 -0000 1.20
-+++ libc/sysdeps/m68k/Makefile 28 Feb 2002 19:39:18 -0000 1.20.2.1
-@@ -33,6 +33,14 @@
- # The 68k `long double' is a distinct type we support.
- long-double-fcts = yes
-
-+ifeq ($(subdir),csu)
-+ifeq (yes,$(build-shared))
-+# Compatibility
-+sysdep_routines += divdi3
-+shared-only-routines += divdi3
-+endif
-+endif
-+
- ifeq ($(subdir),elf)
- CFLAGS-rtld.c += -Wno-uninitialized -Wno-unused
- endif
-Index: libc/sysdeps/s390/s390-32/Makefile
-===================================================================
-RCS file: /cvs/glibc/libc/sysdeps/s390/s390-32/Makefile,v
-retrieving revision 1.1
-retrieving revision 1.1.2.1
-diff -u -r1.1 -r1.1.2.1
---- libc/sysdeps/s390/s390-32/Makefile 16 Mar 2001 08:59:44 -0000 1.1
-+++ libc/sysdeps/s390/s390-32/Makefile 28 Feb 2002 19:39:19 -0000 1.1.2.1
-@@ -1,5 +1,13 @@
- pic-ccflag = -fpic
-
-+ifeq ($(subdir),csu)
-+ifeq (yes,$(build-shared))
-+# Compatibility
-+sysdep_routines += divdi3
-+shared-only-routines += divdi3
-+endif
-+endif
-+
- ifeq ($(subdir),gmon)
- sysdep_routines += s390-mcount
- endif
-Index: libc/sysdeps/wordsize-32/divdi3.c
-===================================================================
-RCS file: sysdeps/wordsize-32/divdi3.c
-diff -N sysdeps/wordsize-32/divdi3.c
---- /dev/null 1 Jan 1970 00:00:00 -0000
-+++ libc/sysdeps/wordsize-32/divdi3.c 28 Feb 2002 19:38:59 -0000 1.1.2.1
-@@ -0,0 +1,327 @@
-+/* 64-bit multiplication and division
-+ Copyright (C) 1989, 1992-1999, 2000, 2001, 2002
-+ 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, write to the Free
-+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-+ 02111-1307 USA. */
-+
-+#include <endian.h>
-+#include <stdlib.h>
-+#include <bits/wordsize.h>
-+
-+#if __WORDSIZE != 32
-+#error This is for 32-bit targets only
-+#endif
-+
-+typedef unsigned int UQItype __attribute__ ((mode (QI)));
-+typedef int SItype __attribute__ ((mode (SI)));
-+typedef unsigned int USItype __attribute__ ((mode (SI)));
-+typedef int DItype __attribute__ ((mode (DI)));
-+typedef unsigned int UDItype __attribute__ ((mode (DI)));
-+#define Wtype SItype
-+#define HWtype SItype
-+#define DWtype DItype
-+#define UWtype USItype
-+#define UHWtype USItype
-+#define UDWtype UDItype
-+#define W_TYPE_SIZE 32
-+
-+#include <stdlib/longlong.h>
-+
-+#if __BYTE_ORDER == __BIG_ENDIAN
-+struct DWstruct { Wtype high, low;};
-+#elif __BYTE_ORDER == __LITTLE_ENDIAN
-+struct DWstruct { Wtype low, high;};
-+#else
-+#error Unhandled endianity
-+#endif
-+typedef union { struct DWstruct s; DWtype ll; } DWunion;
-+
-+static UDWtype
-+__udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
-+{
-+ DWunion ww;
-+ DWunion nn, dd;
-+ DWunion rr;
-+ UWtype d0, d1, n0, n1, n2;
-+ UWtype q0, q1;
-+ UWtype b, bm;
-+
-+ nn.ll = n;
-+ dd.ll = d;
-+
-+ d0 = dd.s.low;
-+ d1 = dd.s.high;
-+ n0 = nn.s.low;
-+ n1 = nn.s.high;
-+
-+#if !UDIV_NEEDS_NORMALIZATION
-+ if (d1 == 0)
-+ {
-+ if (d0 > n1)
-+ {
-+ /* 0q = nn / 0D */
-+
-+ udiv_qrnnd (q0, n0, n1, n0, d0);
-+ q1 = 0;
-+
-+ /* Remainder in n0. */
-+ }
-+ else
-+ {
-+ /* qq = NN / 0d */
-+
-+ if (d0 == 0)
-+ d0 = 1 / d0; /* Divide intentionally by zero. */
-+
-+ udiv_qrnnd (q1, n1, 0, n1, d0);
-+ udiv_qrnnd (q0, n0, n1, n0, d0);
-+
-+ /* Remainder in n0. */
-+ }
-+
-+ if (rp != 0)
-+ {
-+ rr.s.low = n0;
-+ rr.s.high = 0;
-+ *rp = rr.ll;
-+ }
-+ }
-+
-+#else /* UDIV_NEEDS_NORMALIZATION */
-+
-+ if (d1 == 0)
-+ {
-+ if (d0 > n1)
-+ {
-+ /* 0q = nn / 0D */
-+
-+ count_leading_zeros (bm, d0);
-+
-+ if (bm != 0)
-+ {
-+ /* Normalize, i.e. make the most significant bit of the
-+ denominator set. */
-+
-+ d0 = d0 << bm;
-+ n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
-+ n0 = n0 << bm;
-+ }
-+
-+ udiv_qrnnd (q0, n0, n1, n0, d0);
-+ q1 = 0;
-+
-+ /* Remainder in n0 >> bm. */
-+ }
-+ else
-+ {
-+ /* qq = NN / 0d */
-+
-+ if (d0 == 0)
-+ d0 = 1 / d0; /* Divide intentionally by zero. */
-+
-+ count_leading_zeros (bm, d0);
-+
-+ if (bm == 0)
-+ {
-+ /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
-+ conclude (the most significant bit of n1 is set) /\ (the
-+ leading quotient digit q1 = 1).
-+
-+ This special case is necessary, not an optimization.
-+ (Shifts counts of W_TYPE_SIZE are undefined.) */
-+
-+ n1 -= d0;
-+ q1 = 1;
-+ }
-+ else
-+ {
-+ /* Normalize. */
-+
-+ b = W_TYPE_SIZE - bm;
-+
-+ d0 = d0 << bm;
-+ n2 = n1 >> b;
-+ n1 = (n1 << bm) | (n0 >> b);
-+ n0 = n0 << bm;
-+
-+ udiv_qrnnd (q1, n1, n2, n1, d0);
-+ }
-+
-+ /* n1 != d0... */
-+
-+ udiv_qrnnd (q0, n0, n1, n0, d0);
-+
-+ /* Remainder in n0 >> bm. */
-+ }
-+
-+ if (rp != 0)
-+ {
-+ rr.s.low = n0 >> bm;
-+ rr.s.high = 0;
-+ *rp = rr.ll;
-+ }
-+ }
-+#endif /* UDIV_NEEDS_NORMALIZATION */
-+
-+ else
-+ {
-+ if (d1 > n1)
-+ {
-+ /* 00 = nn / DD */
-+
-+ q0 = 0;
-+ q1 = 0;
-+
-+ /* Remainder in n1n0. */
-+ if (rp != 0)
-+ {
-+ rr.s.low = n0;
-+ rr.s.high = n1;
-+ *rp = rr.ll;
-+ }
-+ }
-+ else
-+ {
-+ /* 0q = NN / dd */
-+
-+ count_leading_zeros (bm, d1);
-+ if (bm == 0)
-+ {
-+ /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
-+ conclude (the most significant bit of n1 is set) /\ (the
-+ quotient digit q0 = 0 or 1).
-+
-+ This special case is necessary, not an optimization. */
-+
-+ /* The condition on the next line takes advantage of that
-+ n1 >= d1 (true due to program flow). */
-+ if (n1 > d1 || n0 >= d0)
-+ {
-+ q0 = 1;
-+ sub_ddmmss (n1, n0, n1, n0, d1, d0);
-+ }
-+ else
-+ q0 = 0;
-+
-+ q1 = 0;
-+
-+ if (rp != 0)
-+ {
-+ rr.s.low = n0;
-+ rr.s.high = n1;
-+ *rp = rr.ll;
-+ }
-+ }
-+ else
-+ {
-+ UWtype m1, m0;
-+ /* Normalize. */
-+
-+ b = W_TYPE_SIZE - bm;
-+
-+ d1 = (d1 << bm) | (d0 >> b);
-+ d0 = d0 << bm;
-+ n2 = n1 >> b;
-+ n1 = (n1 << bm) | (n0 >> b);
-+ n0 = n0 << bm;
-+
-+ udiv_qrnnd (q0, n1, n2, n1, d1);
-+ umul_ppmm (m1, m0, q0, d0);
-+
-+ if (m1 > n1 || (m1 == n1 && m0 > n0))
-+ {
-+ q0--;
-+ sub_ddmmss (m1, m0, m1, m0, d1, d0);
-+ }
-+
-+ q1 = 0;
-+
-+ /* Remainder in (n1n0 - m1m0) >> bm. */
-+ if (rp != 0)
-+ {
-+ sub_ddmmss (n1, n0, n1, n0, m1, m0);
-+ rr.s.low = (n1 << b) | (n0 >> bm);
-+ rr.s.high = n1 >> bm;
-+ *rp = rr.ll;
-+ }
-+ }
-+ }
-+ }
-+
-+ ww.s.low = q0;
-+ ww.s.high = q1;
-+ return ww.ll;
-+}
-+
-+DWtype
-+__divdi3 (DWtype u, DWtype v)
-+{
-+ Wtype c = 0;
-+ DWtype w;
-+
-+ if (u < 0)
-+ {
-+ c = ~c;
-+ u = -u;
-+ }
-+ if (v < 0)
-+ {
-+ c = ~c;
-+ v = -v;
-+ }
-+ w = __udivmoddi4 (u, v, NULL);
-+ if (c)
-+ w = -w;
-+ return w;
-+}
-+
-+DWtype
-+__moddi3 (DWtype u, DWtype v)
-+{
-+ Wtype c = 0;
-+ DWtype w;
-+
-+ if (u < 0)
-+ {
-+ c = ~c;
-+ u = -u;
-+ }
-+ if (v < 0)
-+ {
-+ c = ~c;
-+ v = -v;
-+ }
-+ __udivmoddi4 (u, v, &w);
-+ if (c)
-+ w = -w;
-+ return w;
-+}
-+
-+UDWtype
-+__udivdi3 (UDWtype u, UDWtype v)
-+{
-+ return __udivmoddi4 (u, v, NULL);
-+}
-+
-+UDWtype
-+__umoddi3 (UDWtype u, UDWtype v)
-+{
-+ UDWtype w;
-+
-+ __udivmoddi4 (u, v, &w);
-+ return w;
-+}
+++ /dev/null
-diff -ur glibc-2.2.5/linuxthreads/internals.h glibc-2.2.5-/linuxthreads/internals.h
---- glibc-2.2.5/linuxthreads/internals.h Thu Nov 29 08:44:16 2001
-+++ glibc-2.2.5-/linuxthreads/internals.h Fri Oct 4 09:22:55 2002
-@@ -552,7 +552,7 @@
- /* Prototypes for compatibility functions. */
- extern int __pthread_attr_init_2_1 (pthread_attr_t *__attr);
- extern int __pthread_attr_init_2_0 (pthread_attr_t *__attr);
--extern int __pthread_create_2_1 (pthread_t *__restrict __thread,
-+extern int __pthread_create_2_1 (pthread_t *__restrict __athread,
- const pthread_attr_t *__attr,
- void *(*__start_routine) (void *),
- void *__restrict __arg);
-diff -ur glibc-2.2.5/linuxthreads/sysdeps/pthread/pthread.h glibc-2.2.5-/linuxthreads/sysdeps/pthread/pthread.h
---- glibc-2.2.5/linuxthreads/sysdeps/pthread/pthread.h Thu Mar 15 22:12:31 2001
-+++ glibc-2.2.5-/linuxthreads/sysdeps/pthread/pthread.h Fri Oct 4 09:22:45 2002
-@@ -160,7 +160,7 @@
- /* Create a thread with given attributes ATTR (or default attributes
- if ATTR is NULL), and call function START_ROUTINE with given
- arguments ARG. */
--extern int pthread_create (pthread_t *__restrict __thread,
-+extern int pthread_create (pthread_t *__restrict __athread,
- __const pthread_attr_t *__restrict __attr,
- void *(*__start_routine) (void *),
- void *__restrict __arg) __THROW;
-@@ -588,7 +588,7 @@
- extern int pthread_setcanceltype (int __type, int *__oldtype) __THROW;
-
- /* Cancel THREAD immediately or at the next possibility. */
--extern int pthread_cancel (pthread_t __thread) __THROW;
-+extern int pthread_cancel (pthread_t __athread) __THROW;
-
- /* Test for pending cancellation for the current thread and terminate
- the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
-diff -ur glibc-2.2.5/linuxthreads/sysdeps/unix/sysv/linux/bits/sigthread.h glibc-2.2.5-/linuxthreads/sysdeps/unix/sysv/linux/bits/sigthread.h
---- glibc-2.2.5/linuxthreads/sysdeps/unix/sysv/linux/bits/sigthread.h Mon Aug 21 08:48:03 2000
-+++ glibc-2.2.5-/linuxthreads/sysdeps/unix/sysv/linux/bits/sigthread.h Fri Oct 4 09:22:21 2002
-@@ -33,6 +33,6 @@
- __sigset_t *__restrict __oldmask)__THROW;
-
- /* Send signal SIGNO to the given thread. */
--extern int pthread_kill (pthread_t __thread, int __signo) __THROW;
-+extern int pthread_kill (pthread_t __athread, int __signo) __THROW;
-
- #endif /* bits/sigthread.h */
+++ /dev/null
-diff -Nru glibc-2.2.4.orig/elf/ldconfig.c glibc-2.2.4/elf/ldconfig.c
---- glibc-2.2.4.orig/elf/ldconfig.c Mon Jul 23 19:53:40 2001
-+++ glibc-2.2.4/elf/ldconfig.c Wed Jan 30 13:13:09 2002
-@@ -697,8 +697,11 @@
- a directory. */
- if (__builtin_expect (stat64 (real_file_name, &stat_buf), 0))
- {
-- if (opt_verbose)
-- error (0, errno, _("Cannot stat %s"), file_name);
-+ if (strstr (file_name, ".so") != NULL)
-+ unlink (real_file_name);
-+ else
-+ if (opt_verbose)
-+ error (0, errno, _("Cannot stat %s"), file_name);
- continue;
- }
- is_dir = S_ISDIR (stat_buf.st_mode);
+++ /dev/null
---- glibc-2.2.5/resolv/nss_dns/dns-network.c.orig Fri Jul 6 06:55:39 2001
-+++ glibc-2.2.5/resolv/nss_dns/dns-network.c Fri Jul 19 21:47:19 2002
-@@ -328,7 +328,9 @@
- }
- cp += n;
- *alias_pointer++ = bp;
-- bp += strlen (bp) + 1;
-+ n = strlen (bp) + 1;
-+ bp += n;
-+ linebuflen -= n;
- result->n_addrtype = class == C_IN ? AF_INET : AF_UNSPEC;
- ++have_answer;
- }
+++ /dev/null
-===================================================================
-RCS file: /cvs/glibc/libc/sunrpc/xdr_array.c,v
-retrieving revision 1.5
-retrieving revision 1.5.2.1
-diff -u -r1.5 -r1.5.2.1
---- libc/sunrpc/xdr_array.c 2001/08/17 04:48:31 1.5
-+++ libc/sunrpc/xdr_array.c 2002/08/02 01:35:39 1.5.2.1
-@@ -45,6 +45,7 @@
- #include <rpc/types.h>
- #include <rpc/xdr.h>
- #include <libintl.h>
-+#include <limits.h>
-
- #ifdef USE_IN_LIBIO
- # include <wchar.h>
-@@ -81,7 +82,11 @@
- return FALSE;
- }
- c = *sizep;
-- if ((c > maxsize) && (xdrs->x_op != XDR_FREE))
-+ /*
-+ * XXX: Let the overflow possibly happen with XDR_FREE because mem_free()
-+ * doesn't actually use its second argument anyway.
-+ */
-+ if ((c > maxsize || c > UINT_MAX / elsize) && (xdrs->x_op != XDR_FREE))
- {
- return FALSE;
- }
+++ /dev/null
-diff -urN glibc-2.2.5.org/resolv/gethnamaddr.c glibc-2.2.5/resolv/gethnamaddr.c
---- glibc-2.2.5.org/resolv/gethnamaddr.c Tue Jan 29 20:06:05 2002
-+++ glibc-2.2.5/resolv/gethnamaddr.c Sun Feb 3 14:37:40 2002
-@@ -690,7 +690,7 @@
- uaddr[n] & 0xf,
- (uaddr[n] >> 4) & 0xf));
- }
-- strcpy(qp, "ip6.arpa");
-+ strcpy(qp, "ip6.int");
- break;
- default:
- abort();
-diff -urN glibc-2.2.5.org/resolv/nss_dns/dns-host.c glibc-2.2.5/resolv/nss_dns/dns-host.c
---- glibc-2.2.5.org/resolv/nss_dns/dns-host.c Tue Jan 29 20:06:05 2002
-+++ glibc-2.2.5/resolv/nss_dns/dns-host.c Sun Feb 3 14:37:56 2002
-@@ -282,7 +282,7 @@
- qp = qbuf;
- for (n = IN6ADDRSZ - 1; n >= 0; n--)
- qp += sprintf (qp, "%x.%x.", uaddr[n] & 0xf, (uaddr[n] >> 4) & 0xf);
-- strcpy (qp, "ip6.arpa");
-+ strcpy (qp, "ip6.int");
- break;
- default:
- /* Cannot happen. */
+++ /dev/null
-/*
- * Copyright (c) 2002 Michal Moskal <malekith@pld-linux.org>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Michal Moskal.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY MICHAL MOSKAL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Usage
- * ~~~~~
- *
- * This simple program is aimed to be used as script interpreter in rpm
- * %post scriptlets and the like. It opens file passed as first argument
- * and executes commands found there. Only linear execution is supported.
- * For example, in glibc.spec:
- *
- * %post -p /sbin/postshell
- * ldconfig
- * -telinit q
- *
- * (full patch like /sbin/ldconfig or -/sbin/tellinit will also work).
- *
- * If command starts with - its exit status is ignored. Otherwise last
- * non-zero exit status is returned.
- *
- * There are no builtin commands (yet :).
- *
- * Following commands *will* work as expected (as in Bourne shell):
- *
- * /bin/echo "Foo bar baz"
- * insmod foobar options="foo bar 'qux'"
- * false
- *
- * Following *won't*:
- *
- * exit 1
- * echo foo || echo baz
- * set -x
- *
- * Patches and bugreports are welcome, direct them to Michal Moskal
- * <malekith@pld-linux.org>.
- */
-
-#define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define MAX_LINE 1024
-#define MAX_ARGS 32
-#define SEARCH_PATH { "/sbin/", "/bin/", "/usr/sbin/", "/usr/bin/", NULL }
-
-int exit_status;
-int ignore_status;
-
-void do_execve(char **argv)
-{
- char *path[] = SEARCH_PATH;
- char file[MAX_LINE + 100];
- int i;
-
- if (**argv == '.' || **argv == '/')
- execve(argv[0], argv, environ);
- else
- for (i = 0; path[i]; i++) {
- strcpy(file, path[i]);
- strcat(file, argv[0]);
- execve(file, argv, environ);
- }
-}
-
-int exec_and_wait(char **argv)
-{
- pid_t pid;
-
- pid = fork();
-
- if (pid == -1) {
- perror("fork");
- return -1;
- } else if (pid == 0) {
- /* child. */
- do_execve(argv);
- if (!ignore_status)
- perror(argv[0]);
- exit(127);
- } else {
- int status, err;
-
- err = waitpid(pid, &status, 0);
- if (err < 0) {
- perror("waitpid");
- return -1;
- } else
- return WEXITSTATUS(status);
- }
-}
-
-void split_argv(char **argv, char *s)
-{
- char *dst;
- int argc, delim;
-
- for (argc = 0; argc < MAX_ARGS; argc++) {
- while (*s == ' ' || *s == '\t')
- s++;
-
- if (*s == 0)
- break;
-
- argv[argc] = s;
- dst = s;
-
- while (*s && *s != ' ' && *s != '\t') {
- if (*s == '\'' || *s == '"') {
- delim = *s++;
- while (*s && *s != delim)
- *dst++ = *s++;
- if (*s)
- s++;
- } else {
- *dst++ = *s++;
- }
- }
-
- if (*dst) {
- if (s == dst)
- s++;
- *dst++ = 0;
- }
- }
-
- argv[argc] = NULL;
-}
-
-void exec_line(char *s)
-{
- char *argv[MAX_ARGS + 1];
- int ret;
-
- split_argv(argv, s);
-
- ignore_status = 0;
-
- if (**argv == '-') {
- ignore_status++;
- (*argv)++;
- }
-
- ret = exec_and_wait(argv);
-
- if (ret && !ignore_status)
- exit_status = ret;
-}
-
-void exec_file(FILE *f)
-{
- char line[MAX_LINE];
-
- while (fgets(line, sizeof(line), f)) {
- /* chomp it */
- if (line[strlen(line) - 1] == '\n')
- line[strlen(line) - 1] = 0;
- /* and exec. */
- exec_line(line);
- }
-}
-
-int main(int argc, char **argv)
-{
- FILE *f;
-
- if (argc < 2) {
- fprintf(stderr, "USAGE: %s filename\n", argv[0]);
- exit(1);
- }
-
- f = fopen(argv[1], "r");
-
- if (f == NULL) {
- perror(argv[1]);
- exit(1);
- }
-
- exec_file(f);
- fclose(f);
- exit(exit_status);
-}