diff options
Diffstat (limited to 'sysdeps/unix/sysv')
-rw-r--r-- | sysdeps/unix/sysv/linux/dl-execstack.c | 24 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/ia64/has_cpuclock.c | 10 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/if_index.c | 9 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/ifaddrs.c | 166 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/netlinkaccess.h | 3 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c | 8 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c | 6 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/sleep.c | 1 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/sys/quota.h | 89 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/sysctl.c | 1 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/system.c | 1 |
11 files changed, 238 insertions, 80 deletions
diff --git a/sysdeps/unix/sysv/linux/dl-execstack.c b/sysdeps/unix/sysv/linux/dl-execstack.c index 6ef9679045..0a5b83b69c 100644 --- a/sysdeps/unix/sysv/linux/dl-execstack.c +++ b/sysdeps/unix/sysv/linux/dl-execstack.c @@ -24,6 +24,7 @@ #include <stdbool.h> #include <stackinfo.h> #include <caller.h> +#include <sysdep.h> #include "kernel-features.h" @@ -38,6 +39,7 @@ _dl_make_stack_executable (void **stack_endp) /* This gives us the highest/lowest page that needs to be changed. */ uintptr_t page = ((uintptr_t) *stack_endp & -(intptr_t) GLRO(dl_pagesize)); + int result = 0; /* Challenge the caller. */ if (__builtin_expect (__check_caller (RETURN_ADDRESS (0), @@ -60,7 +62,10 @@ _dl_make_stack_executable (void **stack_endp) no_growsupdown = true; else # endif - return errno; + { + result = errno; + goto out; + } } #endif @@ -85,7 +90,10 @@ _dl_make_stack_executable (void **stack_endp) else { if (errno != ENOMEM) /* Unexpected failure mode. */ - return errno; + { + result = errno; + goto out; + } if (size == GLRO(dl_pagesize)) /* We just tried to mprotect the top hole page and failed. @@ -108,7 +116,10 @@ _dl_make_stack_executable (void **stack_endp) else { if (errno != ENOMEM) /* Unexpected failure mode. */ - return errno; + { + result = errno; + goto out; + } if (size == GLRO(dl_pagesize)) /* We just tried to mprotect the lowest hole page and failed. @@ -133,6 +144,11 @@ _dl_make_stack_executable (void **stack_endp) /* Remember that we changed the permission. */ GL(dl_stack_flags) |= PF_X; - return 0; + out: +#ifdef check_consistency + check_consistency (); +#endif + + return result; } rtld_hidden_def (_dl_make_stack_executable) diff --git a/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c b/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c index ee19161272..883508a562 100644 --- a/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c +++ b/sysdeps/unix/sysv/linux/ia64/has_cpuclock.c @@ -21,7 +21,7 @@ #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> - +#include <not-cancel.h> static int itc_usable; @@ -31,18 +31,18 @@ has_cpuclock (void) if (__builtin_expect (itc_usable == 0, 0)) { int newval = 1; - int fd = open ("/proc/sal/itc_drift", O_RDONLY); + int fd = open_not_cancel_2 ("/proc/sal/itc_drift", O_RDONLY); if (__builtin_expect (fd != -1, 1)) { char buf[16]; /* We expect the file to contain a single digit followed by a newline. If the format changes we better not rely on the file content. */ - if (read (fd, buf, sizeof buf) != 2 || buf[0] != '0' - || buf[1] != '\n') + if (read_not_cancel (fd, buf, sizeof buf) != 2 + || buf[0] != '0' || buf[1] != '\n') newval = -1; - close (fd); + close_not_cancel_no_status (fd); } itc_usable = newval; diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c index 377ccf5199..f434bbe7d1 100644 --- a/sysdeps/unix/sysv/linux/if_index.c +++ b/sysdeps/unix/sysv/linux/if_index.c @@ -188,12 +188,8 @@ if_nameindex_netlink (void) /* Tell the kernel that we wish to get a list of all - active interfaces. */ - if (__netlink_sendreq (&nh, RTM_GETLINK) < 0) - goto exit_close; - - /* Collect all data for every interface. */ - if (__netlink_receive (&nh) < 0) + active interfaces. Collect all data for every interface. */ + if (__netlink_request (&nh, RTM_GETLINK) < 0) goto exit_free; /* Count the interfaces. */ @@ -290,7 +286,6 @@ if_nameindex_netlink (void) exit_free: __netlink_free_handle (&nh); - exit_close: __netlink_close (&nh); return idx; diff --git a/sysdeps/unix/sysv/linux/ifaddrs.c b/sysdeps/unix/sysv/linux/ifaddrs.c index 8a052e212d..6f43475ca9 100644 --- a/sysdeps/unix/sysv/linux/ifaddrs.c +++ b/sysdeps/unix/sysv/linux/ifaddrs.c @@ -17,6 +17,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <alloca.h> #include <assert.h> #include <errno.h> #include <ifaddrs.h> @@ -24,6 +25,7 @@ #include <netinet/in.h> #include <netpacket/packet.h> #include <stdbool.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> @@ -84,7 +86,7 @@ __netlink_free_handle (struct netlink_handle *h) } -int +static int __netlink_sendreq (struct netlink_handle *h, int type) { struct @@ -114,15 +116,39 @@ __netlink_sendreq (struct netlink_handle *h, int type) int -__netlink_receive (struct netlink_handle *h) +__netlink_request (struct netlink_handle *h, int type) { struct netlink_res *nlm_next; - char buf[4096]; - struct iovec iov = { buf, sizeof (buf) }; + struct netlink_res **new_nlm_list; + static volatile size_t buf_size = 4096; + char *buf; struct sockaddr_nl nladdr; struct nlmsghdr *nlmh; - int read_len; + ssize_t read_len; bool done = false; + bool use_malloc = false; + + if (__netlink_sendreq (h, type) < 0) + return -1; + + size_t this_buf_size = buf_size; + if (__libc_use_alloca (this_buf_size)) + buf = alloca (this_buf_size); + else + { + buf = malloc (this_buf_size); + if (buf != NULL) + use_malloc = true; + else + goto out_fail; + } + + struct iovec iov = { buf, this_buf_size }; + + if (h->nlm_list != NULL) + new_nlm_list = &h->end_ptr->next; + else + new_nlm_list = &h->nlm_list; while (! done) { @@ -136,33 +162,66 @@ __netlink_receive (struct netlink_handle *h) read_len = TEMP_FAILURE_RETRY (__recvmsg (h->fd, &msg, 0)); if (read_len < 0) - return -1; + goto out_fail; - if (msg.msg_flags & MSG_TRUNC) - return -1; + if (nladdr.nl_pid != 0) + continue; - nlm_next = (struct netlink_res *) malloc (sizeof (struct netlink_res) - + read_len); - if (nlm_next == NULL) - return -1; - nlm_next->next = NULL; - nlm_next->nlh = memcpy (nlm_next + 1, buf, read_len); - nlm_next->size = read_len; - nlm_next->seq = h->seq; - if (h->nlm_list == NULL) - h->nlm_list = nlm_next; - else - h->end_ptr->next = nlm_next; - h->end_ptr = nlm_next; + if (__builtin_expect (msg.msg_flags & MSG_TRUNC, 0)) + { + if (this_buf_size >= SIZE_MAX / 2) + goto out_fail; + + nlm_next = *new_nlm_list; + while (nlm_next != NULL) + { + struct netlink_res *tmpptr; + + tmpptr = nlm_next->next; + free (nlm_next); + nlm_next = tmpptr; + } + *new_nlm_list = NULL; + + if (__libc_use_alloca (2 * this_buf_size)) + buf = extend_alloca (buf, this_buf_size, 2 * this_buf_size); + else + { + this_buf_size *= 2; + + char *new_buf = realloc (use_malloc ? buf : NULL, this_buf_size); + if (new_buf == NULL) + goto out_fail; + new_buf = buf; + use_malloc = true; + } + buf_size = this_buf_size; + + iov.iov_base = buf; + iov.iov_len = this_buf_size; + + /* Increase sequence number, so that we can distinguish + between old and new request messages. */ + h->seq++; + + if (__netlink_sendreq (h, type) < 0) + goto out_fail; + + continue; + } + + size_t count = 0; + size_t remaining_len = read_len; for (nlmh = (struct nlmsghdr *) buf; - NLMSG_OK (nlmh, (size_t) read_len); - nlmh = (struct nlmsghdr *) NLMSG_NEXT (nlmh, read_len)) + NLMSG_OK (nlmh, remaining_len); + nlmh = (struct nlmsghdr *) NLMSG_NEXT (nlmh, remaining_len)) { - if (nladdr.nl_pid != 0 || (pid_t) nlmh->nlmsg_pid != h->pid + if ((pid_t) nlmh->nlmsg_pid != h->pid || nlmh->nlmsg_seq != h->seq) continue; + ++count; if (nlmh->nlmsg_type == NLMSG_DONE) { /* We found the end, leave the loop. */ @@ -176,11 +235,38 @@ __netlink_receive (struct netlink_handle *h) errno = EIO; else errno = -nlerr->error; - return -1; + goto out_fail; } } + + /* If there was nothing with the expected nlmsg_pid and nlmsg_seq, + there is no point to record it. */ + if (count == 0) + continue; + + nlm_next = (struct netlink_res *) malloc (sizeof (struct netlink_res) + + read_len); + if (nlm_next == NULL) + goto out_fail; + nlm_next->next = NULL; + nlm_next->nlh = memcpy (nlm_next + 1, buf, read_len); + nlm_next->size = read_len; + nlm_next->seq = h->seq; + if (h->nlm_list == NULL) + h->nlm_list = nlm_next; + else + h->end_ptr->next = nlm_next; + h->end_ptr = nlm_next; } + + if (use_malloc) + free (buf); return 0; + +out_fail: + if (use_malloc) + free (buf); + return -1; } @@ -268,7 +354,7 @@ getifaddrs (struct ifaddrs **ifap) unsigned int i, newlink, newaddr, newaddr_idx; int *map_newlink_data; size_t ifa_data_size = 0; /* Size to allocate for all ifa_data. */ - char *ifa_data_ptr; /* Pointer to the unused part of memory for + char *ifa_data_ptr; /* Pointer to the unused part of memory for ifa_data. */ int result = 0; @@ -288,28 +374,20 @@ getifaddrs (struct ifaddrs **ifap) #endif /* Tell the kernel that we wish to get a list of all - active interfaces. */ - if (__netlink_sendreq (&nh, RTM_GETLINK) < 0) - { - result = -1; - goto exit_close; - } - /* Collect all data for every interface. */ - if (__netlink_receive (&nh) < 0) + active interfaces, collect all data for every interface. */ + if (__netlink_request (&nh, RTM_GETLINK) < 0) { result = -1; goto exit_free; } - /* Now ask the kernel for all addresses which are assigned - to an interface. Since we store the addresses after the - interfaces in the list, we will later always find the - interface before the corresponding addresses. */ + to an interface and collect all data for every interface. + Since we store the addresses after the interfaces in the + list, we will later always find the interface before the + corresponding addresses. */ ++nh.seq; - if (__netlink_sendreq (&nh, RTM_GETADDR) < 0 - /* Collect all data for every interface. */ - || __netlink_receive (&nh) < 0) + if (__netlink_request (&nh, RTM_GETADDR) < 0) { result = -1; goto exit_free; @@ -327,7 +405,7 @@ getifaddrs (struct ifaddrs **ifap) continue; /* Walk through all entries we got from the kernel and look, which - message type they contain. */ + message type they contain. */ for (nlh = nlp->nlh; NLMSG_OK (nlh, size); nlh = NLMSG_NEXT (nlh, size)) { /* Check if the message is what we want. */ @@ -423,7 +501,7 @@ getifaddrs (struct ifaddrs **ifap) /* Interfaces are stored in the first "newlink" entries of our list, starting in the order as we got from the kernel. */ - ifa_index = map_newlink (ifim->ifi_index - 1, ifas, + ifa_index = map_newlink (ifim->ifi_index - 1, ifas, map_newlink_data, newlink); ifas[ifa_index].ifa.ifa_flags = ifim->ifi_flags; @@ -767,8 +845,6 @@ getifaddrs (struct ifaddrs **ifap) exit_free: __netlink_free_handle (&nh); - - exit_close: __netlink_close (&nh); return result; diff --git a/sysdeps/unix/sysv/linux/netlinkaccess.h b/sysdeps/unix/sysv/linux/netlinkaccess.h index 6672e714ff..f0b8e364bc 100644 --- a/sysdeps/unix/sysv/linux/netlinkaccess.h +++ b/sysdeps/unix/sysv/linux/netlinkaccess.h @@ -55,8 +55,7 @@ extern int __no_netlink_support attribute_hidden; extern int __netlink_open (struct netlink_handle *h); extern void __netlink_close (struct netlink_handle *h); extern void __netlink_free_handle (struct netlink_handle *h); -extern int __netlink_sendreq (struct netlink_handle *h, int type); -extern int __netlink_receive (struct netlink_handle *h); +extern int __netlink_request (struct netlink_handle *h, int type); #endif /* netlinkaccess.h */ diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c index e79d74cb75..069f94bd9d 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ftruncate64.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc. +/* Copyright (C) 1997-2002, 2005 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 @@ -28,7 +28,7 @@ #ifdef __NR_ftruncate64 #ifndef __ASSUME_TRUNCATE64_SYSCALL /* The variable is shared between all wrappers around *truncate64 calls. */ -extern int have_no_truncate64; +extern int __have_no_truncate64; #endif @@ -39,7 +39,7 @@ __ftruncate64 (fd, length) off64_t length; { #ifndef __ASSUME_TRUNCATE64_SYSCALL - if (! have_no_truncate64) + if (! __have_no_truncate64) #endif { #ifndef __ASSUME_TRUNCATE64_SYSCALL @@ -57,7 +57,7 @@ __ftruncate64 (fd, length) #ifndef __ASSUME_TRUNCATE64_SYSCALL __set_errno (saved_errno); - have_no_truncate64 = 1; + __have_no_truncate64 = 1; #endif } diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c index ce8ebc2a97..01698a419f 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/truncate64.c @@ -29,7 +29,7 @@ #ifdef __NR_truncate64 #ifndef __ASSUME_TRUNCATE64_SYSCALL /* The variable is shared between all wrappers around *truncate64 calls. */ -int have_no_truncate64; +int __have_no_truncate64; #endif @@ -40,7 +40,7 @@ truncate64 (path, length) off64_t length; { #ifndef __ASSUME_TRUNCATE64_SYSCALL - if (! have_no_truncate64) + if (! __have_no_truncate64) #endif { #ifndef __ASSUME_TRUNCATE64_SYSCALL @@ -58,7 +58,7 @@ truncate64 (path, length) #ifndef __ASSUME_TRUNCATE64_SYSCALL __set_errno (saved_errno); - have_no_truncate64 = 1; + __have_no_truncate64 = 1; #endif } diff --git a/sysdeps/unix/sysv/linux/sleep.c b/sysdeps/unix/sysv/linux/sleep.c index d94e4f62fd..4f2b8acc55 100644 --- a/sysdeps/unix/sysv/linux/sleep.c +++ b/sysdeps/unix/sysv/linux/sleep.c @@ -21,6 +21,7 @@ #include <errno.h> #include <time.h> #include <signal.h> +#include <string.h> /* For the real memset prototype. */ #include <unistd.h> #include <sys/param.h> diff --git a/sysdeps/unix/sysv/linux/sys/quota.h b/sysdeps/unix/sysv/linux/sys/quota.h index a8baf40a91..be2810e0c7 100644 --- a/sysdeps/unix/sysv/linux/sys/quota.h +++ b/sysdeps/unix/sysv/linux/sys/quota.h @@ -41,6 +41,14 @@ #include <sys/types.h> /* + * Select between different incompatible quota versions. + * Default to the version used by Linux kernel version 2.4.22 + * or later. */ +#ifndef _LINUX_QUOTA_VERSION +# define _LINUX_QUOTA_VERSION 2 +#endif + +/* * Convert diskblocks to blocks and the other way around. * currently only to fool the BSD source. :-) */ @@ -94,21 +102,33 @@ #define SUBCMDSHIFT 8 #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) -#define Q_QUOTAON 0x0100 /* enable quotas */ -#define Q_QUOTAOFF 0x0200 /* disable quotas */ -#define Q_GETQUOTA 0x0300 /* get limits and usage */ -#define Q_SETQUOTA 0x0400 /* set limits and usage */ -#define Q_SETUSE 0x0500 /* set usage */ -#define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ -#define Q_SETQLIM 0x0700 /* set limits */ -#define Q_GETSTATS 0x0800 /* get collected stats */ -#define Q_RSQUASH 0x1000 /* set root_squash option */ +#if _LINUX_QUOTA_VERSION < 2 +# define Q_QUOTAON 0x0100 /* enable quotas */ +# define Q_QUOTAOFF 0x0200 /* disable quotas */ +# define Q_GETQUOTA 0x0300 /* get limits and usage */ +# define Q_SETQUOTA 0x0400 /* set limits and usage */ +# define Q_SETUSE 0x0500 /* set usage */ +# define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ +# define Q_SETQLIM 0x0700 /* set limits */ +# define Q_GETSTATS 0x0800 /* get collected stats */ +# define Q_RSQUASH 0x1000 /* set root_squash option */ +#else +# define Q_SYNC 0x800001 /* sync disk copy of a filesystems quotas */ +# define Q_QUOTAON 0x800002 /* turn quotas on */ +# define Q_QUOTAOFF 0x800003 /* turn quotas off */ +# define Q_GETFMT 0x800004 /* get quota format used on given filesystem */ +# define Q_GETINFO 0x800005 /* get information about quota files */ +# define Q_SETINFO 0x800006 /* set information about quota files */ +# define Q_GETQUOTA 0x800007 /* get user quota structure */ +# define Q_SETQUOTA 0x800008 /* set user quota structure */ +#endif /* * The following structure defines the format of the disk quota file * (as it appears on disk) - the file is an array of these structures * indexed by user or group number. */ +#if _LINUX_QUOTA_VERSION < 2 struct dqblk { u_int32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */ @@ -120,13 +140,45 @@ struct dqblk time_t dqb_btime; /* time limit for excessive disk use */ time_t dqb_itime; /* time limit for excessive files */ }; +#else + +/* Flags that indicate which fields in dqblk structure are valid. */ +#define QIF_BLIMITS 1 +#define QIF_SPACE 2 +#define QIF_ILIMITS 4 +#define QIF_INODES 8 +#define QIF_BTIME 16 +#define QIF_ITIME 32 +#define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS) +#define QIF_USAGE (QIF_SPACE | QIF_INODES) +#define QIF_TIMES (QIF_BTIME | QIF_ITIME) +#define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES) + +struct dqblk + { + u_int64_t dqb_bhardlimit; /* absolute limit on disk quota blocks alloc */ + u_int64_t dqb_bsoftlimit; /* preferred limit on disk quota blocks */ + u_int64_t dqb_curspace; /* current quota block count */ + u_int64_t dqb_ihardlimit; /* maximum # allocated inodes */ + u_int64_t dqb_isoftlimit; /* preferred inode limit */ + u_int64_t dqb_curinodes; /* current # allocated inodes */ + u_int64_t dqb_btime; /* time limit for excessive disk use */ + u_int64_t dqb_itime; /* time limit for excessive files */ + u_int32_t dqb_valid; /* bitmask of QIF_* constants */ + }; +#endif /* * Shorthand notation. */ #define dq_bhardlimit dq_dqb.dqb_bhardlimit #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit -#define dq_curblocks dq_dqb.dqb_curblocks +#if _LINUX_QUOTA_VERSION < 2 +# define dq_curblocks dq_dqb.dqb_curblocks +#else +# define dq_curspace dq_dqb.dqb_curspace +# define dq_valid dq_dqb.dqb_valid +#endif #define dq_ihardlimit dq_dqb.dqb_ihardlimit #define dq_isoftlimit dq_dqb.dqb_isoftlimit #define dq_curinodes dq_dqb.dqb_curinodes @@ -135,6 +187,7 @@ struct dqblk #define dqoff(UID) ((loff_t)((UID) * sizeof (struct dqblk))) +#if _LINUX_QUOTA_VERSION < 2 struct dqstats { u_int32_t lookups; @@ -147,6 +200,22 @@ struct dqstats u_int32_t free_dquots; u_int32_t syncs; }; +#else + +/* Flags that indicate which fields in dqinfo structure are valid. */ +# define IIF_BGRACE 1 +# define IIF_IGRACE 2 +# define IIF_FLAGS 4 +# define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS) + +struct dqinfo + { + u_int64_t dqi_bgrace; + u_int64_t dqi_igrace; + u_int32_t dqi_flags; + u_int32_t dqi_valid; + }; +#endif __BEGIN_DECLS diff --git a/sysdeps/unix/sysv/linux/sysctl.c b/sysdeps/unix/sysv/linux/sysctl.c index 7e601acf2c..1cdeb12638 100644 --- a/sysdeps/unix/sysv/linux/sysctl.c +++ b/sysdeps/unix/sysv/linux/sysctl.c @@ -18,6 +18,7 @@ 02111-1307 USA. */ #include <errno.h> +#include <string.h> /* For the real memset prototype. */ #include <sys/sysctl.h> #include <sysdep.h> diff --git a/sysdeps/unix/sysv/linux/system.c b/sysdeps/unix/sysv/linux/system.c index 3fdff04c22..688487cb9f 100644 --- a/sysdeps/unix/sysv/linux/system.c +++ b/sysdeps/unix/sysv/linux/system.c @@ -18,6 +18,7 @@ #include <sched.h> #include <signal.h> +#include <string.h> /* For the real memset prototype. */ #include <sysdep.h> #include <unistd.h> #include <sys/wait.h> |