From 9d66746cf7a1da0544550266a1c5cb53e776aa01 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sat, 4 Apr 2009 05:23:27 +0000 Subject: [PATCH] Clean up sysconf and associated headers. * Fixes for amd64. * Implement more keys. * Namespace cleanups for the include files. Move definitions that are implemented in userspace from sys/unistd.h to unistd.h. * Try to avoid using sysctl and just provide the constants direct. Obtained-from: FreeBSD --- include/limits.h | 97 ++++--- include/unistd.h | 444 +++++++++++++++++++++++++++----- lib/libc/gen/sysconf.c | 525 ++++++++++++++++++++++++++++++-------- sys/sys/_posix.h | 2 +- sys/sys/syslimits.h | 42 +-- sys/sys/unistd.h | 261 ++++++++----------- usr.bin/tip/tip/remote.c | 1 - usr.sbin/inetd/inetd.c | 1 + usr.sbin/rrenumd/parser.y | 1 + 9 files changed, 994 insertions(+), 380 deletions(-) diff --git a/include/limits.h b/include/limits.h index b11b8a46be..ad3bfac713 100644 --- a/include/limits.h +++ b/include/limits.h @@ -31,28 +31,38 @@ * SUCH DAMAGE. * * @(#)limits.h 8.2 (Berkeley) 1/4/94 - * $FreeBSD: src/include/limits.h,v 1.10 1999/08/27 23:44:50 peter Exp $ + * $FreeBSD: src/include/limits.h,v 1.16 2003/04/29 13:35:58 kan Exp $ * $DragonFly: src/include/limits.h,v 1.2 2003/06/17 04:25:56 dillon Exp $ */ #ifndef _LIMITS_H_ #define _LIMITS_H_ -#include -#ifndef _ANSI_SOURCE +#include + +#if __POSIX_VISIBLE #define _POSIX_ARG_MAX 4096 -#define _POSIX_CHILD_MAX 6 +#define _POSIX_CHILD_MAX 25 #define _POSIX_LINK_MAX 8 #define _POSIX_MAX_CANON 255 #define _POSIX_MAX_INPUT 255 #define _POSIX_NAME_MAX 14 -#define _POSIX_NGROUPS_MAX 0 -#define _POSIX_OPEN_MAX 16 -#define _POSIX_PATH_MAX 255 +#define _POSIX_NGROUPS_MAX 8 +#define _POSIX_OPEN_MAX 20 +#define _POSIX_PATH_MAX 256 #define _POSIX_PIPE_BUF 512 #define _POSIX_SSIZE_MAX 32767 #define _POSIX_STREAM_MAX 8 -#define _POSIX_TZNAME_MAX 3 +#define _POSIX_TZNAME_MAX 6 + +#define BC_BASE_MAX 99 /* max ibase/obase values in bc(1) */ +#define BC_DIM_MAX 2048 /* max array elements in bc(1) */ +#define BC_SCALE_MAX 99 /* max scale value in bc(1) */ +#define BC_STRING_MAX 1000 /* max const string length in bc(1) */ +#define COLL_WEIGHTS_MAX 0 /* max weights for order keyword */ +#define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */ +#define LINE_MAX 2048 /* max bytes in an input line */ +#define RE_DUP_MAX 255 /* max RE's in interval notation */ #define _POSIX2_BC_BASE_MAX 99 #define _POSIX2_BC_DIM_MAX 2048 @@ -62,38 +72,63 @@ #define _POSIX2_EXPR_NEST_MAX 32 #define _POSIX2_LINE_MAX 2048 #define _POSIX2_RE_DUP_MAX 255 +#endif +#if __POSIX_VISIBLE >= 199309 +#define _POSIX_AIO_LISTIO_MAX 16 +#define _POSIX_AIO_MAX 1 +#define _POSIX_DELAYTIMER_MAX 32 +#define _POSIX_MQ_OPEN_MAX 8 +#define _POSIX_MQ_PRIO_MAX 32 +#define _POSIX_RTSIG_MAX 8 +#define _POSIX_SEM_NSEMS_MAX 256 +#define _POSIX_SEM_VALUE_MAX 32767 +#define _POSIX_SIGQUEUE_MAX 32 +#define _POSIX_TIMER_MAX 32 +#endif -#ifdef _P1003_1B_VISIBLE +#if __POSIX_VISIBLE >= 199506 +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 +#define _POSIX_THREAD_KEYS_MAX 128 +#define _POSIX_THREAD_THREADS_MAX 64 +#endif -#define _POSIX_AIO_LISTIO_MAX 16 -#define _POSIX_AIO_MAX 1 -#define _POSIX_DELAYTIMER_MAX 32 -#define _POSIX_MQ_OPEN_MAX 8 -#define _POSIX_MQ_PRIO_MAX 32 -#define _POSIX_RTSIG_MAX 0 -#define _POSIX_SEM_NSEMS_MAX 256 -#define _POSIX_SEM_VALUE_MAX 32767 -#define _POSIX_SIGQUEUE_MAX 32 -#define _POSIX_TIMER_MAX 32 +#if __POSIX_VISIBLE >= 200112 +#define _POSIX_HOST_NAME_MAX 255 +#define _POSIX_LOGIN_NAME_MAX 9 +#define _POSIX_SS_REPL_MAX 4 +#define _POSIX_SYMLINK_MAX 255 +#define _POSIX_SYMLOOP_MAX 8 +#define _POSIX_TRACE_EVENT_NAME_MAX 30 +#define _POSIX_TRACE_NAME_MAX 8 +#define _POSIX_TRACE_SYS_MAX 8 +#define _POSIX_TRACE_USER_EVENT_MAX 32 +#define _POSIX_TTY_NAME_MAX 9 +#define _POSIX2_CHARCLASS_NAME_MAX 14 +#define _POSIX2_COLL_WEIGHTS_MAX 2 +#define _POSIX_RE_DUP_MAX _POSIX2_RE_DUP_MAX #endif -#endif /* !_ANSI_SOURCE */ +#if __XSI_VISIBLE +#define _XOPEN_IOV_MAX 16 +#define _XOPEN_NAME_MAX 255 +#define _XOPEN_PATH_MAX 1024 +#define PASS_MAX 128 /* _PASSWORD_LEN from */ + +#define NL_ARGMAX 99 /* max # of position args for printf */ +#define NL_LANGMAX 31 /* max LANG name length */ +#define NL_MSGMAX 32767 +#define NL_NMAX 1 +#define NL_SETMAX 255 +#define NL_TEXTMAX 2048 +#endif -#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE) -#define PASS_MAX 128 /* _PASSWORD_LEN from */ +#define MB_LEN_MAX 6 /* 31-bit UTF-8 */ -#define NL_ARGMAX 99 /* max # of position args for printf */ -#define NL_LANGMAX 31 /* max LANG name length */ -#define NL_MSGMAX 32767 -#define NL_NMAX 1 -#define NL_SETMAX 255 -#define NL_TEXTMAX 2048 -#endif +#include -#include -#if !defined(_ANSI_SOURCE) +#if __POSIX_VISIBLE #include #endif diff --git a/include/unistd.h b/include/unistd.h index 83f2b8cd3b..8d51263e0d 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)unistd.h 8.12 (Berkeley) 4/27/95 - * $FreeBSD: src/include/unistd.h,v 1.35.2.10 2002/04/15 12:52:28 nectar Exp $ + * $FreeBSD: src/include/unistd.h,v 1.93 2009/03/14 19:11:08 das Exp $ * $DragonFly: src/include/unistd.h,v 1.24 2008/06/05 17:53:10 swildner Exp $ */ @@ -39,21 +39,264 @@ #define _UNISTD_H_ #include -#include +#include /* XXX adds too much pollution. */ #include #include -#define STDIN_FILENO 0 /* standard input file descriptor */ +#ifndef _GID_T_DECLARED +typedef __gid_t gid_t; +#define _GID_T_DECLARED +#endif + +#ifndef _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#ifndef _SIZE_T_DECLARED +typedef __size_t size_t; +#define _SIZE_T_DECLARED +#endif + +#ifndef _SSIZE_T_DECLARED +typedef __ssize_t ssize_t; +#define _SSIZE_T_DECLARED +#endif + +#ifndef _UID_T_DECLARED +typedef __uid_t uid_t; +#define _UID_T_DECLARED +#endif + +#define STDIN_FILENO 0 /* standard input file descriptor */ #define STDOUT_FILENO 1 /* standard output file descriptor */ #define STDERR_FILENO 2 /* standard error file descriptor */ -#ifndef _POSIX_SOURCE +#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 #define F_ULOCK 0 /* unlock locked section */ #define F_LOCK 1 /* lock a section for exclusive use */ #define F_TLOCK 2 /* test and lock a section for exclusive use */ #define F_TEST 3 /* test a section for locks by other procs */ #endif +/* + * POSIX options and option groups we unconditionally do or don't + * implement. This list includes those options which are exclusively + * implemented (or not) in user mode. Please keep this list in + * alphabetical order. + * + * Anything which is defined as zero below **must** have an + * implementation for the corresponding sysconf() which is able to + * determine conclusively whether or not the feature is supported. + * Anything which is defined as other than -1 below **must** have + * complete headers, types, and function declarations as specified by + * the POSIX standard; however, if the relevant sysconf() function + * returns -1, the functions may be stubbed out. + */ +#define _POSIX_BARRIERS 200112L +#define _POSIX_READER_WRITER_LOCKS 200112L +#define _POSIX_REGEXP 1 +#define _POSIX_SHELL 1 +#define _POSIX_SPAWN 200112L +#define _POSIX_SPIN_LOCKS 200112L +#define _POSIX_THREAD_ATTR_STACKADDR 200112L +#define _POSIX_THREAD_ATTR_STACKSIZE 200112L +#define _POSIX_THREAD_CPUTIME -1 +#define _POSIX_THREAD_PRIO_INHERIT 200112L +#define _POSIX_THREAD_PRIO_PROTECT 200112L +#define _POSIX_THREAD_PRIORITY_SCHEDULING 200112L +#define _POSIX_THREAD_PROCESS_SHARED -1 +#define _POSIX_THREAD_SAFE_FUNCTIONS -1 +#define _POSIX_THREAD_SPORADIC_SERVER -1 +#define _POSIX_THREADS 200112L +#define _POSIX_TRACE -1 +#define _POSIX_TRACE_EVENT_FILTER -1 +#define _POSIX_TRACE_INHERIT -1 +#define _POSIX_TRACE_LOG -1 +#define _POSIX2_C_BIND 200112L /* mandatory */ +#define _POSIX2_C_DEV -1 /* need c99 utility */ +#define _POSIX2_CHAR_TERM 1 +#define _POSIX2_FORT_DEV -1 /* need fort77 utility */ +#define _POSIX2_FORT_RUN 200112L +#define _POSIX2_LOCALEDEF -1 +#define _POSIX2_PBS -1 +#define _POSIX2_PBS_ACCOUNTING -1 +#define _POSIX2_PBS_CHECKPOINT -1 +#define _POSIX2_PBS_LOCATE -1 +#define _POSIX2_PBS_MESSAGE -1 +#define _POSIX2_PBS_TRACK -1 +#define _POSIX2_SW_DEV -1 /* XXX ??? */ +#define _POSIX2_UPE 200112L +#define _V6_ILP32_OFF32 -1 +#define _V6_ILP32_OFFBIG 0 +#define _V6_LP64_OFF64 0 +#define _V6_LPBIG_OFFBIG -1 + +#if __XSI_VISIBLE +#define _XOPEN_CRYPT -1 /* XXX ??? */ +#define _XOPEN_ENH_I18N -1 /* mandatory in XSI */ +#define _XOPEN_LEGACY -1 +#define _XOPEN_REALTIME -1 +#define _XOPEN_REALTIME_THREADS -1 +#define _XOPEN_UNIX -1 +#endif + +/* Define the POSIX.2 version we target for compliance. */ +#define _POSIX2_VERSION 199212L + +/* + * POSIX-style system configuration variable accessors (for the + * sysconf function). The kernel does not directly implement the + * sysconf() interface; rather, a C library stub translates references + * to sysconf() into calls to sysctl() using a giant switch statement. + * Those that are marked `user' are implemented entirely in the C + * library and never query the kernel. pathconf() is implemented + * directly by the kernel so those are not defined here. + */ +#define _SC_ARG_MAX 1 +#define _SC_CHILD_MAX 2 +#define _SC_CLK_TCK 3 +#define _SC_NGROUPS_MAX 4 +#define _SC_OPEN_MAX 5 +#define _SC_JOB_CONTROL 6 +#define _SC_SAVED_IDS 7 +#define _SC_VERSION 8 +#define _SC_BC_BASE_MAX 9 /* user */ +#define _SC_BC_DIM_MAX 10 /* user */ +#define _SC_BC_SCALE_MAX 11 /* user */ +#define _SC_BC_STRING_MAX 12 /* user */ +#define _SC_COLL_WEIGHTS_MAX 13 /* user */ +#define _SC_EXPR_NEST_MAX 14 /* user */ +#define _SC_LINE_MAX 15 /* user */ +#define _SC_RE_DUP_MAX 16 /* user */ +#define _SC_2_VERSION 17 /* user */ +#define _SC_2_C_BIND 18 /* user */ +#define _SC_2_C_DEV 19 /* user */ +#define _SC_2_CHAR_TERM 20 /* user */ +#define _SC_2_FORT_DEV 21 /* user */ +#define _SC_2_FORT_RUN 22 /* user */ +#define _SC_2_LOCALEDEF 23 /* user */ +#define _SC_2_SW_DEV 24 /* user */ +#define _SC_2_UPE 25 /* user */ +#define _SC_STREAM_MAX 26 /* user */ +#define _SC_TZNAME_MAX 27 /* user */ + +#if __POSIX_VISIBLE >= 199309 +#define _SC_ASYNCHRONOUS_IO 28 +#define _SC_MAPPED_FILES 29 +#define _SC_MEMLOCK 30 +#define _SC_MEMLOCK_RANGE 31 +#define _SC_MEMORY_PROTECTION 32 +#define _SC_MESSAGE_PASSING 33 +#define _SC_PRIORITIZED_IO 34 +#define _SC_PRIORITY_SCHEDULING 35 +#define _SC_REALTIME_SIGNALS 36 +#define _SC_SEMAPHORES 37 +#define _SC_FSYNC 38 +#define _SC_SHARED_MEMORY_OBJECTS 39 +#define _SC_SYNCHRONIZED_IO 40 +#define _SC_TIMERS 41 +#define _SC_AIO_LISTIO_MAX 42 +#define _SC_AIO_MAX 43 +#define _SC_AIO_PRIO_DELTA_MAX 44 +#define _SC_DELAYTIMER_MAX 45 +#define _SC_MQ_OPEN_MAX 46 +#define _SC_PAGESIZE 47 +#define _SC_RTSIG_MAX 48 +#define _SC_SEM_NSEMS_MAX 49 +#define _SC_SEM_VALUE_MAX 50 +#define _SC_SIGQUEUE_MAX 51 +#define _SC_TIMER_MAX 52 +#endif + +#if __POSIX_VISIBLE >= 200112 +#define _SC_2_PBS 59 /* user */ +#define _SC_2_PBS_ACCOUNTING 60 /* user */ +#define _SC_2_PBS_CHECKPOINT 61 /* user */ +#define _SC_2_PBS_LOCATE 62 /* user */ +#define _SC_2_PBS_MESSAGE 63 /* user */ +#define _SC_2_PBS_TRACK 64 /* user */ +#define _SC_ADVISORY_INFO 65 +#define _SC_BARRIERS 66 /* user */ +#define _SC_CLOCK_SELECTION 67 +#define _SC_CPUTIME 68 +#define _SC_FILE_LOCKING 69 +#define _SC_GETGR_R_SIZE_MAX 70 /* user */ +#define _SC_GETPW_R_SIZE_MAX 71 /* user */ +#define _SC_HOST_NAME_MAX 72 +#define _SC_LOGIN_NAME_MAX 73 +#define _SC_MONOTONIC_CLOCK 74 +#define _SC_MQ_PRIO_MAX 75 +#define _SC_READER_WRITER_LOCKS 76 /* user */ +#define _SC_REGEXP 77 /* user */ +#define _SC_SHELL 78 /* user */ +#define _SC_SPAWN 79 /* user */ +#define _SC_SPIN_LOCKS 80 /* user */ +#define _SC_SPORADIC_SERVER 81 +#define _SC_THREAD_ATTR_STACKADDR 82 /* user */ +#define _SC_THREAD_ATTR_STACKSIZE 83 /* user */ +#define _SC_THREAD_CPUTIME 84 /* user */ +#define _SC_THREAD_DESTRUCTOR_ITERATIONS 85 /* user */ +#define _SC_THREAD_KEYS_MAX 86 /* user */ +#define _SC_THREAD_PRIO_INHERIT 87 /* user */ +#define _SC_THREAD_PRIO_PROTECT 88 /* user */ +#define _SC_THREAD_PRIORITY_SCHEDULING 89 /* user */ +#define _SC_THREAD_PROCESS_SHARED 90 /* user */ +#define _SC_THREAD_SAFE_FUNCTIONS 91 /* user */ +#define _SC_THREAD_SPORADIC_SERVER 92 /* user */ +#define _SC_THREAD_STACK_MIN 93 /* user */ +#define _SC_THREAD_THREADS_MAX 94 /* user */ +#define _SC_TIMEOUTS 95 /* user */ +#define _SC_THREADS 96 /* user */ +#define _SC_TRACE 97 /* user */ +#define _SC_TRACE_EVENT_FILTER 98 /* user */ +#define _SC_TRACE_INHERIT 99 /* user */ +#define _SC_TRACE_LOG 100 /* user */ +#define _SC_TTY_NAME_MAX 101 /* user */ +#define _SC_TYPED_MEMORY_OBJECTS 102 +#define _SC_V6_ILP32_OFF32 103 /* user */ +#define _SC_V6_ILP32_OFFBIG 104 /* user */ +#define _SC_V6_LP64_OFF64 105 /* user */ +#define _SC_V6_LPBIG_OFFBIG 106 /* user */ +#define _SC_IPV6 118 +#define _SC_RAW_SOCKETS 119 +#define _SC_SYMLOOP_MAX 120 +#endif + +#if __XSI_VISIBLE +#define _SC_ATEXIT_MAX 107 /* user */ +#define _SC_IOV_MAX 56 +#define _SC_PAGE_SIZE _SC_PAGESIZE +#define _SC_XOPEN_CRYPT 108 /* user */ +#define _SC_XOPEN_ENH_I18N 109 /* user */ +#define _SC_XOPEN_LEGACY 110 /* user */ +#define _SC_XOPEN_REALTIME 111 +#define _SC_XOPEN_REALTIME_THREADS 112 +#define _SC_XOPEN_SHM 113 +#define _SC_XOPEN_STREAMS 114 +#define _SC_XOPEN_UNIX 115 +#define _SC_XOPEN_VERSION 116 +#define _SC_XOPEN_XCU_VERSION 117 /* user */ +#endif + +#if __BSD_VISIBLE +#define _SC_NPROCESSORS_CONF 57 +#define _SC_NPROCESSORS_ONLN 58 +#endif + +/* Extensions found in Solaris and Linux. */ +#define _SC_PHYS_PAGES 121 + +/* Keys for the confstr(3) function. */ +#if __POSIX_VISIBLE >= 199209 +#define _CS_PATH 1 /* default value of PATH */ +#endif + #if __POSIX_VISIBLE >= 200112 #define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 2 #define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 3 @@ -70,9 +313,8 @@ #define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 14 #endif -struct iovec; - __BEGIN_DECLS +/* 1003.1-1990 */ void _exit(int) __dead2; int access(const char *, int); unsigned int alarm(unsigned int); @@ -112,7 +354,6 @@ ssize_t read(int, void *, size_t); int rmdir(const char *); int setgid(gid_t); int setpgid(pid_t, pid_t); -void setproctitle(const char *, ...) __printf0like(1, 2); pid_t setsid(void); int setuid(uid_t); unsigned int sleep(unsigned int); @@ -124,68 +365,158 @@ int ttyname_r(int, char *, size_t); int unlink(const char *); ssize_t write(int, const void *, size_t); +/* 1003.2-1992 */ +#if __POSIX_VISIBLE >= 199209 || __XSI_VISIBLE +size_t confstr(int, char *, size_t); +#ifndef _GETOPT_DECLARED +#define _GETOPT_DECLARED +int getopt(int, char * const [], const char *); + extern char *optarg; /* getopt(3) external variables */ extern int optind, opterr, optopt; -int getopt(int, char * const [], const char *); +#endif /* _GETOPT_DECLARED */ +#endif -#ifndef _POSIX_SOURCE -int acct(const char *); -int async_daemon (void); +/* ISO/IEC 9945-1: 1996 */ +#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE +int fsync(int); + +/* + * ftruncate() was in the POSIX Realtime Extension (it's used for shared + * memory), but truncate() was not. + */ +#ifndef _FTRUNCATE_DECLARED +#define _FTRUNCATE_DECLARED +int ftruncate(int, off_t); +#endif +#endif + +#if __POSIX_VISIBLE >= 199506 +int getlogin_r(char *, int); +#endif + +/* 1003.1-2001 */ +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE +int fchown(int, uid_t, gid_t); +ssize_t readlink(const char * __restrict, char * __restrict, size_t); +#endif +#if __POSIX_VISIBLE >= 200112 +int gethostname(char *, size_t); +int setegid(gid_t); +int seteuid(uid_t); +#endif + +/* 1003.1-2008 */ +#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE +int getsid(pid_t _pid); +int fchdir(int); +int getpgid(pid_t _pid); +int lchown(const char *, uid_t, gid_t); +ssize_t pread(int, void *, size_t, off_t); +ssize_t pwrite(int, const void *, size_t, off_t); + +/* See comment at ftruncate() above. */ +#ifndef _TRUNCATE_DECLARED +#define _TRUNCATE_DECLARED +int truncate(const char *, off_t); +#endif +#endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */ + +/* XXX */ +#if 0 +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE +int faccessat(int, const char *, int, int); +int fchownat(int, const char *, uid_t, gid_t, int); +int fexecve(int, char *const [], char *const []); +int linkat(int, const char *, int, const char *, int); +ssize_t readlinkat(int, const char * __restrict, char * __restrict, size_t); +int symlinkat(const char *, int, const char *); +int unlinkat(int, const char *, int); +#endif /* __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE */ +#endif + +/* + * symlink() was originally in POSIX.1a, which was withdrawn after + * being overtaken by events (1003.1-2001). It was in XPG4.2, and of + * course has been in BSD since 4.2. + */ +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 402 || __BSD_VISIBLE +int symlink(const char * __restrict, const char * __restrict); +#endif + +/* X/Open System Interfaces */ +#if __XSI_VISIBLE +char *crypt(const char *, const char *); +/* char *ctermid(char *); */ /* XXX ??? */ +int encrypt(char *, int); +long gethostid(void); +int lockf(int, int, off_t); +int nice(int); +int setpgrp(pid_t _pid, pid_t _pgrp); /* obsoleted by setpgid() */ +int setregid(gid_t, gid_t); +int setreuid(uid_t, uid_t); + +#ifndef _SWAB_DECLARED +#define _SWAB_DECLARED +void swab(const void * __restrict, void * __restrict, ssize_t); +#endif /* _SWAB_DECLARED */ + +void sync(void); + +#endif /* __XSI_VISIBLE */ + +#if (__XSI_VISIBLE && __XSI_VISIBLE <= 500) || __BSD_VISIBLE int brk(const void *); int chroot(const char *); +int getdtablesize(void); +int getpagesize(void) __pure2; +char *getpass(const char *); +void *sbrk(intptr_t); +#endif + +#if (__XSI_VISIBLE && __XSI_VISIBLE <= 600) || __BSD_VISIBLE +char *getwd(char *); /* obsoleted by getcwd() */ +unsigned int + ualarm(unsigned int, unsigned int); +int usleep(unsigned int); +pid_t vfork(void); +#endif + +#if __BSD_VISIBLE +struct iovec; +int acct(const char *); +int async_daemon(void); int closefrom(int); -size_t confstr(int, char *, size_t); -char *crypt(const char *, const char *); -const char *crypt_get_format(void); +const char * + crypt_get_format(void); int crypt_set_format(const char *); void endusershell(void); int exect(const char *, char * const *, char * const *); +int execvP(const char *, const char *, char * const *); void extexit(int, int, void *); -int fchdir(int); -int fchown(int, uid_t, gid_t); +ssize_t extpread(int, void *, size_t, int, off_t); +ssize_t extpreadv(int, const struct iovec *, u_int, int, off_t); +ssize_t extpwrite(int, const void *, size_t, int, off_t); +ssize_t extpwritev(int, const struct iovec *, u_int, int, off_t); char *fflagstostr(u_long); -int fsync(int); -#ifndef _FTRUNCATE_DECLARED -#define _FTRUNCATE_DECLARED -int ftruncate(int, off_t); -#endif int getdomainname(char *, int); -int getdtablesize(void); int getgrouplist(const char *, gid_t, gid_t *, int *); -long gethostid(void); -int gethostname(char *, size_t); -int getlogin_r(char *, int); mode_t getmode(const void *, mode_t); -int getpagesize(void) __pure2; -char *getpass(const char *); +int getosreldate(void); int getpeereid(int, uid_t *, gid_t *); -int getpgid(pid_t _pid); int getresgid(gid_t *, gid_t *, gid_t *); int getresuid(uid_t *, uid_t *, uid_t *); -int getsid(pid_t _pid); char *getusershell(void); -char *getwd(char *); /* obsoleted by getcwd() */ int initgroups(const char *, gid_t); int iruserok(unsigned long, int, const char *, const char *); int iruserok_sa(const void *, int, int, const char *, const char *); int issetugid(void); -int lchown(const char *, uid_t, gid_t); -int lockf(int, int, off_t); int lwp_create(struct lwp_params *); lwpid_t lwp_gettid(void); -char *mkdtemp(char *); -int mknod(const char *, mode_t, dev_t); int mkstemps(char *, int); char *mktemp(char *); int nfssvc(int, void *); -int nice(int); -ssize_t pread(int, void *, size_t, off_t); -ssize_t extpread(int, void *, size_t, int, off_t); -ssize_t extpreadv(int, const struct iovec *, u_int, int, off_t); int profil(char *, size_t, vm_offset_t, int); -ssize_t pwrite(int, const void *, size_t, off_t); -ssize_t extpwrite(int, const void *, size_t, int, off_t); -ssize_t extpwritev(int, const struct iovec *, u_int, int, off_t); int rcmd(char **, int, const char *, const char *, const char *, int *); int rcmd_af(char **, int, const char *, const char *, const char *, int *, int); @@ -193,61 +524,44 @@ int rcmdsh(char **, int, const char *, const char *, const char *, const char *); char *re_comp(const char *); int re_exec(const char *); -int readlink(const char *, char *, int); int reboot(int); int revoke(const char *); pid_t rfork(int); -pid_t rfork_thread(int, void *, int (*) (void *), void *); +pid_t rfork_thread(int, void *, int (*)(void *), void *); int rresvport(int *); int rresvport_af(int *, int); int ruserok(const char *, int, const char *, const char *); -void *sbrk(intptr_t); int setdomainname(const char *, int); -int setegid(gid_t); -int seteuid(uid_t); int setgroups(int, const gid_t *); void sethostid(long); int sethostname(const char *, int); int setlogin(const char *); void *setmode(const char *); -int setpgrp(pid_t _pid, pid_t _pgrp); /* obsoleted by setpgid() */ -int setregid(gid_t, gid_t); +void setproctitle(const char *_fmt, ...) __printf0like(1, 2); int setresgid(gid_t, gid_t, gid_t); int setresuid(uid_t, uid_t, uid_t); -int setreuid(uid_t, uid_t); int setrgid(gid_t); int setruid(uid_t); void setusershell(void); int strtofflags(char **, u_long *, u_long *); int swapon(const char *); -int symlink(const char *, const char *); -void sync(void); int syscall(int, ...); off_t __syscall(quad_t, ...); -#ifndef _TRUNCATE_DECLARED -#define _TRUNCATE_DECLARED -int truncate(const char *, off_t); -#endif int ttyslot(void); -unsigned int ualarm(unsigned int, unsigned int); int umtx_sleep(volatile const int *, int , int); int umtx_wakeup(volatile const int *, int); int undelete(const char *); int unwhiteout(const char *); -int usleep(unsigned int); void *valloc(size_t); /* obsoleted by malloc() */ -pid_t vfork(void); -int varsym_set(int, const char *, const char *); int varsym_get(int, const char *, char *, int); int varsym_list(int, char *, int, int *); +int varsym_set(int, const char *, const char *); -#endif /* !_POSIX_SOURCE */ +#ifndef _OPTRESET_DECLARED +#define _OPTRESET_DECLARED extern int optreset; /* getopt(3) external variable */ -__END_DECLS - -/* BSD compatibility for certain function declarations */ -#ifdef __BSD_VISIBLE -#include #endif +#endif /* __BSD_VISIBLE */ +__END_DECLS #endif /* !_UNISTD_H_ */ diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c index 9c35c676d4..244aed9528 100644 --- a/lib/libc/gen/sysconf.c +++ b/lib/libc/gen/sysconf.c @@ -13,10 +13,6 @@ * 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 the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -34,19 +30,28 @@ * SUCH DAMAGE. * * @(#)sysconf.c 8.2 (Berkeley) 3/20/94 + * $FreeBSD: src/lib/libc/gen/sysconf.c,v 1.26 2008/02/27 05:56:57 wollman Exp $ * $DragonFly: src/lib/libc/gen/sysconf.c,v 1.5 2008/02/21 12:47:54 hasso Exp $ */ -#include #include #include #include #include +#include #include +#include +#include +#include /* we just need the limits */ #include #include +#include "../stdlib/atexit.h" +#include "../stdtime/tzfile.h" + +#define _PATH_ZONEINFO TZDIR /* from tzfile.h */ + /* * sysconf -- * get configurable system variables. @@ -64,41 +69,66 @@ sysconf(int name) { struct rlimit rl; size_t len; - int mib[2], value; - long defaultresult; + int mib[2], sverrno, value; + long lvalue, defaultresult; + const char *path; - len = sizeof(value); defaultresult = -1; switch (name) { -/* 1003.1 */ case _SC_ARG_MAX: mib[0] = CTL_KERN; mib[1] = KERN_ARGMAX; break; case _SC_CHILD_MAX: - return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : rl.rlim_cur); + if (getrlimit(RLIMIT_NPROC, &rl) != 0) + return (-1); + if (rl.rlim_cur == RLIM_INFINITY) + return (-1); + if (rl.rlim_cur > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + return ((long)rl.rlim_cur); case _SC_CLK_TCK: return (CLK_TCK); - case _SC_JOB_CONTROL: - mib[0] = CTL_KERN; - mib[1] = KERN_JOB_CONTROL; - goto yesno; case _SC_NGROUPS_MAX: mib[0] = CTL_KERN; mib[1] = KERN_NGROUPS; break; case _SC_OPEN_MAX: - return (getrlimit(RLIMIT_NOFILE, &rl) ? -1 : rl.rlim_cur); + if (getrlimit(RLIMIT_NOFILE, &rl) != 0) + return (-1); + if (rl.rlim_cur == RLIM_INFINITY) + return (-1); + if (rl.rlim_cur > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + return ((long)rl.rlim_cur); case _SC_STREAM_MAX: - mib[0] = CTL_USER; - mib[1] = USER_STREAM_MAX; - break; - case _SC_TZNAME_MAX: - mib[0] = CTL_USER; - mib[1] = USER_TZNAME_MAX; - break; + if (getrlimit(RLIMIT_NOFILE, &rl) != 0) + return (-1); + if (rl.rlim_cur == RLIM_INFINITY) + return (-1); + if (rl.rlim_cur > LONG_MAX) { + errno = EOVERFLOW; + return (-1); + } + /* + * struct __sFILE currently has a limitation that + * file descriptors must fit in a signed short. + * This doesn't precisely capture the letter of POSIX + * but approximates the spirit. + */ + if (rl.rlim_cur > SHRT_MAX) + return (SHRT_MAX); + + return ((long)rl.rlim_cur); + case _SC_JOB_CONTROL: + return (_POSIX_JOB_CONTROL); case _SC_SAVED_IDS: + /* XXX - must be 1 */ mib[0] = CTL_KERN; mib[1] = KERN_SAVED_IDS; goto yesno; @@ -106,152 +136,145 @@ sysconf(int name) mib[0] = CTL_KERN; mib[1] = KERN_POSIX1; break; - case _SC_IOV_MAX: - mib[0] = CTL_KERN; - mib[1] = KERN_IOV_MAX; - break; - -/* 1003.2 */ case _SC_BC_BASE_MAX: - mib[0] = CTL_USER; - mib[1] = USER_BC_BASE_MAX; - break; + return (BC_BASE_MAX); case _SC_BC_DIM_MAX: - mib[0] = CTL_USER; - mib[1] = USER_BC_DIM_MAX; - break; + return (BC_DIM_MAX); case _SC_BC_SCALE_MAX: - mib[0] = CTL_USER; - mib[1] = USER_BC_SCALE_MAX; - break; + return (BC_SCALE_MAX); case _SC_BC_STRING_MAX: - mib[0] = CTL_USER; - mib[1] = USER_BC_STRING_MAX; - break; + return (BC_STRING_MAX); case _SC_COLL_WEIGHTS_MAX: - mib[0] = CTL_USER; - mib[1] = USER_COLL_WEIGHTS_MAX; - break; + return (COLL_WEIGHTS_MAX); case _SC_EXPR_NEST_MAX: - mib[0] = CTL_USER; - mib[1] = USER_EXPR_NEST_MAX; - break; + return (EXPR_NEST_MAX); case _SC_LINE_MAX: - mib[0] = CTL_USER; - mib[1] = USER_LINE_MAX; - break; + return (LINE_MAX); case _SC_RE_DUP_MAX: - mib[0] = CTL_USER; - mib[1] = USER_RE_DUP_MAX; - break; + return (RE_DUP_MAX); case _SC_2_VERSION: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_VERSION; - break; + /* + * This is something of a lie, but it would be silly at + * this point to try to deduce this from the contents + * of the filesystem. + */ + return (_POSIX2_VERSION); case _SC_2_C_BIND: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_C_BIND; - goto yesno; + return (_POSIX2_C_BIND); case _SC_2_C_DEV: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_C_DEV; - goto yesno; + return (_POSIX2_C_DEV); case _SC_2_CHAR_TERM: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_CHAR_TERM; - goto yesno; + return (_POSIX2_CHAR_TERM); case _SC_2_FORT_DEV: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_FORT_DEV; - goto yesno; + return (_POSIX2_FORT_DEV); case _SC_2_FORT_RUN: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_FORT_RUN; - goto yesno; + return (_POSIX2_FORT_RUN); case _SC_2_LOCALEDEF: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_LOCALEDEF; - goto yesno; + return (_POSIX2_LOCALEDEF); case _SC_2_SW_DEV: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_SW_DEV; - goto yesno; + return (_POSIX2_SW_DEV); case _SC_2_UPE: - mib[0] = CTL_USER; - mib[1] = USER_POSIX2_UPE; - goto yesno; - -#ifdef _P1003_1B_VISIBLE - /* POSIX.1B */ + return (_POSIX2_UPE); + case _SC_TZNAME_MAX: + path = _PATH_ZONEINFO; +do_NAME_MAX: + sverrno = errno; + errno = 0; + lvalue = pathconf(path, _PC_NAME_MAX); + if (lvalue == -1 && errno != 0) + return (-1); + errno = sverrno; + return (lvalue); case _SC_ASYNCHRONOUS_IO: +#if _POSIX_ASYNCHRONOUS_IO == 0 mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO; - goto yesno; + break; +#else + return (_POSIX_ASYNCHRONOUS_IO); +#endif case _SC_MAPPED_FILES: - mib[0] = CTL_P1003_1B; - mib[1] = CTL_P1003_1B_MAPPED_FILES; - goto yesno; + return (_POSIX_MAPPED_FILES); case _SC_MEMLOCK: - mib[0] = CTL_P1003_1B; - mib[1] = CTL_P1003_1B_MEMLOCK; - goto yesno; + return (_POSIX_MEMLOCK); case _SC_MEMLOCK_RANGE: - mib[0] = CTL_P1003_1B; - mib[1] = CTL_P1003_1B_MEMLOCK_RANGE; - goto yesno; + return (_POSIX_MEMLOCK_RANGE); case _SC_MEMORY_PROTECTION: - mib[0] = CTL_P1003_1B; - mib[1] = CTL_P1003_1B_MEMORY_PROTECTION; - goto yesno; + return (_POSIX_MEMORY_PROTECTION); case _SC_MESSAGE_PASSING: +#if _POSIX_MESSAGE_PASSING == 0 mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_MESSAGE_PASSING; goto yesno; +#else + return (_POSIX_MESSAGE_PASSING); +#endif case _SC_PRIORITIZED_IO: +#if _POSIX_PRIORITIZED_IO == 0 mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_PRIORITIZED_IO; goto yesno; +#else + return (_POSIX_PRIORITIZED_IO); +#endif case _SC_PRIORITY_SCHEDULING: +#if _POSIX_PRIORITY_SCHEDULING == 0 mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING; goto yesno; +#else + return (_POSIX_PRIORITY_SCHEDULING); +#endif case _SC_REALTIME_SIGNALS: +#if _POSIX_REALTIME_SIGNALS == 0 mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_REALTIME_SIGNALS; goto yesno; +#else + return (_POSIX_REALTIME_SIGNALS); +#endif case _SC_SEMAPHORES: +#if _POSIX_SEMAPHORES == 0 mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_SEMAPHORES; goto yesno; +#else + return (_POSIX_SEMAPHORES); +#endif case _SC_FSYNC: - mib[0] = CTL_P1003_1B; - mib[1] = CTL_P1003_1B_FSYNC; - goto yesno; + return (_POSIX_FSYNC); + case _SC_SHARED_MEMORY_OBJECTS: - mib[0] = CTL_P1003_1B; - mib[1] = CTL_P1003_1B_SHARED_MEMORY_OBJECTS; - goto yesno; + return (_POSIX_SHARED_MEMORY_OBJECTS); case _SC_SYNCHRONIZED_IO: +#if _POSIX_SYNCHRONIZED_IO == 0 mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO; goto yesno; +#else + return (_POSIX_SYNCHRONIZED_IO); +#endif case _SC_TIMERS: +#if _POSIX_TIMERS == 0 mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_TIMERS; goto yesno; +#else + return (_POSIX_TIMERS); +#endif case _SC_AIO_LISTIO_MAX: mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX; - goto yesno; + break; case _SC_AIO_MAX: mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_AIO_MAX; - goto yesno; + break; case _SC_AIO_PRIO_DELTA_MAX: mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX; - goto yesno; + break; case _SC_DELAYTIMER_MAX: mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_DELAYTIMER_MAX; @@ -284,23 +307,299 @@ sysconf(int name) case _SC_TIMER_MAX: mib[0] = CTL_P1003_1B; mib[1] = CTL_P1003_1B_TIMER_MAX; - goto yesno; -#endif /* _P1003_1B_VISIBLE */ +yesno: + len = sizeof(value); + if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) + return (-1); + if (value == 0) + return (defaultresult); + return ((long)value); + + case _SC_2_PBS: + case _SC_2_PBS_ACCOUNTING: + case _SC_2_PBS_CHECKPOINT: + case _SC_2_PBS_LOCATE: + case _SC_2_PBS_MESSAGE: + case _SC_2_PBS_TRACK: +#if _POSIX2_PBS == 0 +#error "don't know how to determine _SC_2_PBS" + /* + * This probably requires digging through the filesystem + * to see if the appropriate package has been installed. + * Since we don't currently support this option at all, + * it's not worth the effort to write the code now. + * Figuring out which of the sub-options are supported + * would be even more difficult, so it's probably easier + * to always say ``no''. + */ +#else + return (_POSIX2_PBS); +#endif + case _SC_ADVISORY_INFO: +#if _POSIX_ADVISORY_INFO == 0 +#error "_POSIX_ADVISORY_INFO" +#else + return (_POSIX_ADVISORY_INFO); +#endif + case _SC_BARRIERS: +#if _POSIX_BARRIERS == 0 +#error "_POSIX_BARRIERS" +#else + return (_POSIX_BARRIERS); +#endif + case _SC_CLOCK_SELECTION: +#if _POSIX_CLOCK_SELECTION == 0 +#error "_POSIX_CLOCK_SELECTION" +#else + return (_POSIX_CLOCK_SELECTION); +#endif + case _SC_CPUTIME: +#if _POSIX_CPUTIME == 0 +#error "_POSIX_CPUTIME" +#else + return (_POSIX_CPUTIME); +#endif +#ifdef notdef + case _SC_FILE_LOCKING: + /* + * XXX - The standard doesn't tell us how to define + * _POSIX_FILE_LOCKING, so we can't answer this one. + */ +#endif +#if _POSIX_THREAD_SAFE_FUNCTIONS > -1 + case _SC_GETGR_R_SIZE_MAX: + case _SC_GETPW_R_SIZE_MAX: +#error "somebody needs to implement this" +#endif + case _SC_HOST_NAME_MAX: + return (MAXHOSTNAMELEN - 1); /* does not include \0 */ + case _SC_LOGIN_NAME_MAX: + return (MAXLOGNAME); + case _SC_MONOTONIC_CLOCK: +#if _POSIX_MONOTONIC_CLOCK == 0 +#error "_POSIX_MONOTONIC_CLOCK" +#else + return (_POSIX_MONOTONIC_CLOCK); +#endif +#if _POSIX_MESSAGE_PASSING > -1 + case _SC_MQ_PRIO_MAX: + return (MQ_PRIO_MAX); +#endif + case _SC_READER_WRITER_LOCKS: + return (_POSIX_READER_WRITER_LOCKS); + case _SC_REGEXP: + return (_POSIX_REGEXP); + case _SC_SHELL: + return (_POSIX_SHELL); + case _SC_SPAWN: + return (_POSIX_SPAWN); + case _SC_SPIN_LOCKS: + return (_POSIX_SPIN_LOCKS); + case _SC_SPORADIC_SERVER: +#if _POSIX_SPORADIC_SERVER == 0 +#error "_POSIX_SPORADIC_SERVER" +#else + return (_POSIX_SPORADIC_SERVER); +#endif + case _SC_THREAD_ATTR_STACKADDR: + return (_POSIX_THREAD_ATTR_STACKADDR); + case _SC_THREAD_ATTR_STACKSIZE: + return (_POSIX_THREAD_ATTR_STACKSIZE); + case _SC_THREAD_CPUTIME: + return (_POSIX_THREAD_CPUTIME); + case _SC_THREAD_DESTRUCTOR_ITERATIONS: + return (PTHREAD_DESTRUCTOR_ITERATIONS); + case _SC_THREAD_KEYS_MAX: + return (PTHREAD_KEYS_MAX); + case _SC_THREAD_PRIO_INHERIT: + return (_POSIX_THREAD_PRIO_INHERIT); + case _SC_THREAD_PRIO_PROTECT: + return (_POSIX_THREAD_PRIO_PROTECT); + case _SC_THREAD_PRIORITY_SCHEDULING: + return (_POSIX_THREAD_PRIORITY_SCHEDULING); + case _SC_THREAD_PROCESS_SHARED: + return (_POSIX_THREAD_PROCESS_SHARED); + case _SC_THREAD_SAFE_FUNCTIONS: + return (_POSIX_THREAD_SAFE_FUNCTIONS); + case _SC_THREAD_STACK_MIN: + return (PTHREAD_STACK_MIN); + case _SC_THREAD_THREADS_MAX: + return (PTHREAD_THREADS_MAX); /* XXX wrong type! */ + case _SC_TIMEOUTS: + return (_POSIX_TIMEOUTS); + case _SC_THREADS: + return (_POSIX_THREADS); + case _SC_TRACE: +#if _POSIX_TRACE == 0 +#error "_POSIX_TRACE" + /* While you're implementing this, also do the ones below. */ +#else + return (_POSIX_TRACE); +#endif +#if _POSIX_TRACE > -1 + case _SC_TRACE_EVENT_FILTER: + return (_POSIX_TRACE_EVENT_FILTER); + case _SC_TRACE_INHERIT: + return (_POSIX_TRACE_INHERIT); + case _SC_TRACE_LOG: + return (_POSIX_TRACE_LOG); +#endif + case _SC_TTY_NAME_MAX: + path = _PATH_DEV; + goto do_NAME_MAX; + case _SC_TYPED_MEMORY_OBJECTS: +#if _POSIX_TYPED_MEMORY_OBJECTS == 0 +#error "_POSIX_TYPED_MEMORY_OBJECTS" +#else + return (_POSIX_TYPED_MEMORY_OBJECTS); +#endif + case _SC_V6_ILP32_OFF32: +#if _V6_ILP32_OFF32 == 0 + if (sizeof(int) * CHAR_BIT == 32 && + sizeof(int) == sizeof(long) && + sizeof(long) == sizeof(void *) && + sizeof(void *) == sizeof(off_t)) + return 1; + else + return -1; +#else + return (_V6_ILP32_OFF32); +#endif + case _SC_V6_ILP32_OFFBIG: +#if _V6_ILP32_OFFBIG == 0 + if (sizeof(int) * CHAR_BIT == 32 && + sizeof(int) == sizeof(long) && + sizeof(long) == sizeof(void *) && + sizeof(off_t) * CHAR_BIT >= 64) + return 1; + else + return -1; +#else + return (_V6_ILP32_OFFBIG); +#endif + case _SC_V6_LP64_OFF64: +#if _V6_LP64_OFF64 == 0 + if (sizeof(int) * CHAR_BIT == 32 && + sizeof(long) * CHAR_BIT == 64 && + sizeof(long) == sizeof(void *) && + sizeof(void *) == sizeof(off_t)) + return 1; + else + return -1; +#else + return (_V6_LP64_OFF64); +#endif + case _SC_V6_LPBIG_OFFBIG: +#if _V6_LPBIG_OFFBIG == 0 + if (sizeof(int) * CHAR_BIT >= 32 && + sizeof(long) * CHAR_BIT >= 64 && + sizeof(void *) * CHAR_BIT >= 64 && + sizeof(off_t) * CHAR_BIT >= 64) + return 1; + else + return -1; +#else + return (_V6_LPBIG_OFFBIG); +#endif + case _SC_ATEXIT_MAX: + return (ATEXIT_SIZE); + case _SC_IOV_MAX: + mib[0] = CTL_KERN; + mib[1] = KERN_IOV_MAX; + break; + case _SC_XOPEN_CRYPT: + return (_XOPEN_CRYPT); + case _SC_XOPEN_ENH_I18N: + return (_XOPEN_ENH_I18N); + case _SC_XOPEN_LEGACY: + return (_XOPEN_LEGACY); + case _SC_XOPEN_REALTIME: +#if _XOPEN_REALTIME == 0 + sverrno = errno; + value = sysconf(_SC_ASYNCHRONOUS_IO) > 0 && + sysconf(_SC_MEMLOCK) > 0 && + sysconf(_SC_MEMLOCK_RANGE) > 0 && + sysconf(_SC_MESSAGE_PASSING) > 0 && + sysconf(_SC_PRIORITY_SCHEDULING) > 0 && + sysconf(_SC_REALTIME_SIGNALS) > 0 && + sysconf(_SC_SEMAPHORES) > 0 && + sysconf(_SC_SHARED_MEMORY_OBJECTS) > 0 && + sysconf(_SC_SYNCHRONIZED_IO) > 0 && + sysconf(_SC_TIMERS) > 0; + errno = sverrno; + if (value) + return (200112L); + else + return (-1); +#else + return (_XOPEN_REALTIME); +#endif + case _SC_XOPEN_REALTIME_THREADS: +#if _XOPEN_REALTIME_THREADS == 0 +#error "_XOPEN_REALTIME_THREADS" +#else + return (_XOPEN_REALTIME_THREADS); +#endif + case _SC_XOPEN_SHM: + len = sizeof(lvalue); + sverrno = errno; + if (sysctlbyname("kern.ipc.shmmin", &lvalue, &len, NULL, + 0) == -1) { + errno = sverrno; + return (-1); + } + errno = sverrno; + return (1); + case _SC_XOPEN_STREAMS: + return (_XOPEN_STREAMS); + case _SC_XOPEN_UNIX: + return (_XOPEN_UNIX); +#ifdef _XOPEN_VERSION + case _SC_XOPEN_VERSION: + return (_XOPEN_VERSION); +#endif +#ifdef _XOPEN_XCU_VERSION + case _SC_XOPEN_XCU_VERSION: + return (_XOPEN_XCU_VERSION); +#endif + case _SC_SYMLOOP_MAX: + return (MAXSYMLINKS); + case _SC_RAW_SOCKETS: + return (_POSIX_RAW_SOCKETS); + case _SC_IPV6: +#if _POSIX_IPV6 == 0 + sverrno = errno; + value = socket(PF_INET6, SOCK_DGRAM, 0); + errno = sverrno; + if (value >= 0) { + close(value); + return (200112L); + } else + return (0); +#else + return (_POSIX_IPV6); +#endif + case _SC_NPROCESSORS_CONF: case _SC_NPROCESSORS_ONLN: mib[0] = CTL_HW; mib[1] = HW_NCPU; - goto yesno; + break; -yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) +#ifdef _SC_PHYS_PAGES + case _SC_PHYS_PAGES: + len = sizeof(lvalue); + if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1) return (-1); - if (value == 0) - return (defaultresult); - return (value); - break; + return (lvalue); +#endif + default: errno = EINVAL; return (-1); } - return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value); + len = sizeof(value); + if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) + value = -1; + return ((long)value); } diff --git a/sys/sys/_posix.h b/sys/sys/_posix.h index 559bb503cb..f7de6d4f50 100644 --- a/sys/sys/_posix.h +++ b/sys/sys/_posix.h @@ -73,7 +73,7 @@ /* Default to existing user space version. */ #ifndef _POSIX_VERSION -#define _POSIX_VERSION 199009L +#define _POSIX_VERSION 200112L #endif /* Test for visibility of P1003.1B features: diff --git a/sys/sys/syslimits.h b/sys/sys/syslimits.h index 851dafddc3..ad7c35abd6 100644 --- a/sys/sys/syslimits.h +++ b/sys/sys/syslimits.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,10 +10,6 @@ * 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 the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -31,14 +27,27 @@ * SUCH DAMAGE. * * @(#)syslimits.h 8.1 (Berkeley) 6/2/93 - * $FreeBSD: src/sys/sys/syslimits.h,v 1.9 1999/08/28 00:52:03 peter Exp $ + * $FreeBSD: src/sys/sys/syslimits.h,v 1.23 2007/05/29 15:14:46 cognet Exp $ * $DragonFly: src/sys/sys/syslimits.h,v 1.4 2005/08/23 17:44:22 dillon Exp $ */ #ifndef _SYS_SYSLIMITS_H_ #define _SYS_SYSLIMITS_H_ -#define ARG_MAX 262144 /* max bytes for an exec function */ +#if !defined(_KERNEL) && !defined(_LIMITS_H_) && !defined(_SYS_PARAM_H_) +#ifndef _SYS_CDEFS_H_ +#error this file needs sys/cdefs.h as a prerequisite +#endif +#ifdef __CC_SUPPORTS_WARNING +#warning "No user-serviceable parts inside." +#endif +#endif + +/* + * Do not add any new variables here. (See the comment at the end of + * the file for why.) + */ +#define ARG_MAX 262144 /* max bytes for an exec function */ #ifndef CHILD_MAX #define CHILD_MAX 40 /* max simultaneous processes */ #endif @@ -50,18 +59,17 @@ #ifndef OPEN_MAX #define OPEN_MAX 64 /* max open files per process */ #endif -#define TTY_PATH_MAX 256 /* max tty pathname */ #define PATH_MAX 1024 /* max bytes in pathname */ #define PIPE_BUF 512 /* max bytes for atomic pipe writes */ #define IOV_MAX 1024 /* max elements in i/o vector */ -#define BC_BASE_MAX 99 /* max ibase/obase values in bc(1) */ -#define BC_DIM_MAX 2048 /* max array elements in bc(1) */ -#define BC_SCALE_MAX 99 /* max scale value in bc(1) */ -#define BC_STRING_MAX 1000 /* max const string length in bc(1) */ -#define COLL_WEIGHTS_MAX 0 /* max weights for order keyword */ -#define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */ -#define LINE_MAX 2048 /* max bytes in an input line */ -#define RE_DUP_MAX 255 /* max RE's in interval notation */ - +/* + * We leave the following values undefined to force applications to either + * assume conservative values or call sysconf() to get the current value. + * + * HOST_NAME_MAX + * + * (We should do this for most of the values currently defined here, + * but many programs are not prepared to deal with this yet.) + */ #endif diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h index 23f7b3a7f5..dfa857dc49 100644 --- a/sys/sys/unistd.h +++ b/sys/sys/unistd.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,10 +10,6 @@ * 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 the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -31,63 +27,78 @@ * SUCH DAMAGE. * * @(#)unistd.h 8.2 (Berkeley) 1/7/94 - * $FreeBSD: src/sys/sys/unistd.h,v 1.22.2.2 2000/08/22 01:46:30 jhb Exp $ + * $FreeBSD: src/sys/sys/unistd.h,v 1.50 2009/01/31 10:04:36 trhodes Exp $ * $DragonFly: src/sys/sys/unistd.h,v 1.10 2008/09/22 09:13:21 hasso Exp $ */ #ifndef _SYS_UNISTD_H_ #define _SYS_UNISTD_H_ +#include #include -#include -/* compile-time symbolic constants */ -#define _POSIX_JOB_CONTROL /* implementation supports job control */ +/* + * POSIX options and option groups we unconditionally do or don't + * implement. Those options which are implemented (or not) entirely + * in user mode are defined in . Please keep this list in + * alphabetical order. + * + * Anything which is defined as zero below **must** have an + * implementation for the corresponding sysconf() which is able to + * determine conclusively whether or not the feature is supported. + * Anything which is defined as other than -1 below **must** have + * complete headers, types, and function declarations as specified by + * the POSIX standard; however, if the relevant sysconf() function + * returns -1, the functions may be stubbed out. + */ +#define _POSIX_ADVISORY_INFO -1 +#define _POSIX_ASYNCHRONOUS_IO 0 +#define _POSIX_CHOWN_RESTRICTED 1 +#define _POSIX_CLOCK_SELECTION -1 +#define _POSIX_CPUTIME -1 +#define _POSIX_FSYNC 200112L +#define _POSIX_IPV6 0 +#define _POSIX_JOB_CONTROL 1 +#define _POSIX_MAPPED_FILES 200112L +#define _POSIX_MEMLOCK -1 +#define _POSIX_MEMLOCK_RANGE 200112L +#define _POSIX_MEMORY_PROTECTION 200112L +#define _POSIX_MESSAGE_PASSING -1 +#define _POSIX_MONOTONIC_CLOCK 200112L +#define _POSIX_NO_TRUNC 1 +#define _POSIX_PRIORITIZED_IO -1 +#define _POSIX_PRIORITY_SCHEDULING 200112L +#define _POSIX_RAW_SOCKETS 200112L +#define _POSIX_REALTIME_SIGNALS 200112L +#define _POSIX_SEMAPHORES -1 +#define _POSIX_SHARED_MEMORY_OBJECTS 200112L +#define _POSIX_SPORADIC_SERVER -1 +#define _POSIX_SYNCHRONIZED_IO -1 +#define _POSIX_TIMEOUTS 200112L +#define _POSIX_TIMERS 200112L +#define _POSIX_TYPED_MEMORY_OBJECTS -1 +#define _POSIX_VDISABLE 0xff + +#if __XSI_VISIBLE +#define _XOPEN_SHM 1 +#define _XOPEN_STREAMS -1 +#endif /* * Although we have saved user/group IDs, we do not use them in setuid * as described in POSIX 1003.1, because the feature does not work for * root. We use the saved IDs in seteuid/setegid, which are not currently - * part of the POSIX 1003.1 specification. + * part of the POSIX 1003.1 specification. XXX revisit for 1003.1-2001 + * as this is now mandatory. */ -#ifdef _NOT_AVAILABLE -#define _POSIX_SAVED_IDS /* saved set-user-ID and set-group-ID */ +#ifdef _NOT_AVAILABLE +#define _POSIX_SAVED_IDS 1 /* saved set-user-ID and set-group-ID */ #endif -#define _POSIX2_VERSION 199212L - -/* execution-time symbolic constants */ - /* chown requires appropriate privileges */ -#define _POSIX_CHOWN_RESTRICTED 1 - /* too-long path components generate errors */ -#define _POSIX_NO_TRUNC 1 - /* may disable terminal special characters */ -#define _POSIX_VDISABLE 0xff - -/* - * Threads features: - * - * Note that those commented out are not currently supported by the - * implementation. - */ -#define _POSIX_THREADS 200112L -#define _POSIX_THREAD_ATTR_STACKADDR 200112L -#define _POSIX_THREAD_ATTR_STACKSIZE 200112L -#define _POSIX_THREAD_PRIORITY_SCHEDULING 200112L -#define _POSIX_THREAD_PRIO_INHERIT 200112L -#define _POSIX_THREAD_PRIO_PROTECT 200112L -/* #define _POSIX_THREAD_PROCESS_SHARED */ -/* - * 1003.1c-1995 says on page 38 (2.9.3, paragraph 3) that if _POSIX_THREADS is - * defined, then _POSIX_THREAD_SAFE_FUNCTIONS must also be defined. (This is - * likely a typo (reversed dependency), in which case we would be compliant if - * the typo were officially acknowledged.) However, we do not support all of - * the required _r() interfaces, which means we cannot legitimately define - * _POSIX_THREAD_SAFE_FUNCTIONS. Therefore, we are non-compliant here in two - * ways. - */ -/* #define _POSIX_THREAD_SAFE_FUNCTIONS */ -#define _POSIX_SEMAPHORES 200112L +/* Define the POSIX.1 version we target for compliance. */ +#ifndef _POSIX_VERSION +#define _POSIX_VERSION 200112L +#endif /* access function */ #define F_OK 0 /* test for existence of file */ @@ -96,9 +107,15 @@ #define R_OK 0x04 /* test for read permission */ /* whence values for lseek(2) */ +#ifndef SEEK_SET #define SEEK_SET 0 /* set file offset to offset */ #define SEEK_CUR 1 /* set file offset to current plus offset */ #define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif +#if __BSD_VISIBLE +#define SEEK_DATA 3 /* set file offset to next data past offset */ +#define SEEK_HOLE 4 /* set file offset to next hole past offset */ +#endif #ifndef _POSIX_SOURCE /* whence values for lseek(2); renamed by POSIX 1003.1 */ @@ -118,127 +135,67 @@ #define _PC_NO_TRUNC 8 #define _PC_VDISABLE 9 -/* configurable system variables */ -#define _SC_ARG_MAX 1 -#define _SC_CHILD_MAX 2 -#define _SC_CLK_TCK 3 -#define _SC_NGROUPS_MAX 4 -#define _SC_OPEN_MAX 5 -#define _SC_JOB_CONTROL 6 -#define _SC_SAVED_IDS 7 -#define _SC_VERSION 8 -#define _SC_BC_BASE_MAX 9 -#define _SC_BC_DIM_MAX 10 -#define _SC_BC_SCALE_MAX 11 -#define _SC_BC_STRING_MAX 12 -#define _SC_COLL_WEIGHTS_MAX 13 -#define _SC_EXPR_NEST_MAX 14 -#define _SC_LINE_MAX 15 -#define _SC_RE_DUP_MAX 16 -#define _SC_2_VERSION 17 -#define _SC_2_C_BIND 18 -#define _SC_2_C_DEV 19 -#define _SC_2_CHAR_TERM 20 -#define _SC_2_FORT_DEV 21 -#define _SC_2_FORT_RUN 22 -#define _SC_2_LOCALEDEF 23 -#define _SC_2_SW_DEV 24 -#define _SC_2_UPE 25 -#define _SC_STREAM_MAX 26 -#define _SC_TZNAME_MAX 27 -#define _SC_IOV_MAX 56 - -/* configurable system strings */ -#define _CS_PATH 1 - -#ifdef _P1003_1B_VISIBLE - -#define _POSIX_PRIORITY_SCHEDULING 200112L - -#if 0 -/* Not until the dust settles after the header commit - */ -#define _POSIX_ASYNCHRONOUS_IO -#define _POSIX_MEMLOCK -#define _POSIX_MEMLOCK_RANGE +#if __POSIX_VISIBLE >= 199309 +#define _PC_ASYNC_IO 53 +#define _PC_PRIO_IO 54 +#define _PC_SYNC_IO 55 #endif -/* ??? #define _POSIX_FSYNC 1 */ -#define _POSIX_MAPPED_FILES 200112L -#define _POSIX_SHARED_MEMORY_OBJECTS 200112L - -/* POSIX.1B sysconf options */ -#define _SC_ASYNCHRONOUS_IO 28 -#define _SC_MAPPED_FILES 29 -#define _SC_MEMLOCK 30 -#define _SC_MEMLOCK_RANGE 31 -#define _SC_MEMORY_PROTECTION 32 -#define _SC_MESSAGE_PASSING 33 -#define _SC_PRIORITIZED_IO 34 -#define _SC_PRIORITY_SCHEDULING 35 -#define _SC_REALTIME_SIGNALS 36 -#define _SC_SEMAPHORES 37 -#define _SC_FSYNC 38 -#define _SC_SHARED_MEMORY_OBJECTS 39 -#define _SC_SYNCHRONIZED_IO 40 -#define _SC_TIMERS 41 -#define _SC_AIO_LISTIO_MAX 42 -#define _SC_AIO_MAX 43 -#define _SC_AIO_PRIO_DELTA_MAX 44 -#define _SC_DELAYTIMER_MAX 45 -#define _SC_MQ_OPEN_MAX 46 -#define _SC_PAGESIZE 47 -#define _SC_PAGE_SIZE _SC_PAGESIZE -#define _SC_RTSIG_MAX 48 -#define _SC_SEM_NSEMS_MAX 49 -#define _SC_SEM_VALUE_MAX 50 -#define _SC_SIGQUEUE_MAX 51 -#define _SC_TIMER_MAX 52 - -/* POSIX.1B pathconf and fpathconf options */ -#define _PC_ASYNC_IO 53 -#define _PC_PRIO_IO 54 -#define _PC_SYNC_IO 55 +#if __POSIX_VISIBLE >= 200112 +#define _PC_ALLOC_SIZE_MIN 10 +#define _PC_FILESIZEBITS 12 +#define _PC_REC_INCR_XFER_SIZE 14 +#define _PC_REC_MAX_XFER_SIZE 15 +#define _PC_REC_MIN_XFER_SIZE 16 +#define _PC_REC_XFER_ALIGN 17 +#define _PC_SYMLINK_MAX 18 +#endif -#endif /* _P1003_1B_VISIBLE */ +#if __BSD_VISIBLE +#define _PC_ACL_EXTENDED 59 +#define _PC_ACL_PATH_MAX 60 +#define _PC_CAP_PRESENT 61 +#define _PC_INF_PRESENT 62 +#define _PC_MAC_PRESENT 63 +#endif -#define _SC_NPROCESSORS_CONF 57 -#define _SC_NPROCESSORS_ONLN 58 +/* From OpenSolaris, used by SEEK_DATA/SEEK_HOLE. */ +#define _PC_MIN_HOLE_SIZE 21 -#ifndef _POSIX_SOURCE +#if __BSD_VISIBLE /* * rfork() options. * * XXX currently, operations without RFPROC set are not supported. */ -#define RFNAMEG (1<<0) /* UNIMPL new plan9 `name space' */ -#define RFENVG (1<<1) /* UNIMPL copy plan9 `env space' */ -#define RFFDG (1<<2) /* copy fd table */ -#define RFNOTEG (1<<3) /* UNIMPL create new plan9 `note group' */ -#define RFPROC (1<<4) /* change child (else changes curproc) */ -#define RFMEM (1<<5) /* share `address space' */ -#define RFNOWAIT (1<<6) /* parent need not wait() on child */ -#define RFCNAMEG (1<<10) /* UNIMPL zero plan9 `name space' */ -#define RFCENVG (1<<11) /* UNIMPL zero plan9 `env space' */ -#define RFCFDG (1<<12) /* zero fd table */ -#define RFTHREAD (1<<13) /* enable kernel thread support */ -#define RFSIGSHARE (1<<14) /* share signal handlers */ -#define RFLINUXTHPN (1<<16) /* do linux clone exit parent notification */ -#define RFPGLOCK (1<<30) /* process group interlock for signal race */ -#define RFPPWAIT (1<<31) /* parent sleeps until child exits (vfork) */ -#define RFKERNELONLY (RFPPWAIT|RFPGLOCK) +#define RFNAMEG (1<<0) /* UNIMPL new plan9 `name space' */ +#define RFENVG (1<<1) /* UNIMPL copy plan9 `env space' */ +#define RFFDG (1<<2) /* copy fd table */ +#define RFNOTEG (1<<3) /* UNIMPL create new plan9 `note group' */ +#define RFPROC (1<<4) /* change child (else changes curproc) */ +#define RFMEM (1<<5) /* share `address space' */ +#define RFNOWAIT (1<<6) /* parent need not wait() on child */ +#define RFCNAMEG (1<<10) /* UNIMPL zero plan9 `name space' */ +#define RFCENVG (1<<11) /* UNIMPL zero plan9 `env space' */ +#define RFCFDG (1<<12) /* zero fd table */ +#define RFTHREAD (1<<13) /* enable kernel thread support */ +#define RFSIGSHARE (1<<14) /* share signal handlers */ +#define RFLINUXTHPN (1<<16) /* do linux clone exit parent notification */ +#define RFPGLOCK (1<<30) /* process group interlock for signal race */ +#define RFPPWAIT (1<<31) /* parent sleeps until child exits (vfork) */ +#define RFKERNELONLY (RFPGLOCK | RFPPWAIT) /* * Extended exit extexit() operation modes. */ /* Types of action to communicate exit */ -#define EXTEXIT_SIMPLE 0 -#define EXTEXIT_SETINT 1 -#define EXTEXIT_ACTION(f) ((f) & 0xffff) +#define EXTEXIT_SIMPLE 0 +#define EXTEXIT_SETINT 1 +#define EXTEXIT_ACTION(f) ((f) & 0xffff) /* Types describing what to exit */ -#define EXTEXIT_PROC (0<<16) -#define EXTEXIT_LWP (1<<16) -#define EXTEXIT_WHO(f) ((f) & (0xffff<<16)) +#define EXTEXIT_PROC (0<<16) +#define EXTEXIT_LWP (1<<16) +#define EXTEXIT_WHO(f) ((f) & (0xffff<<16)) /* @@ -252,6 +209,6 @@ struct lwp_params { lwpid_t *tid2; /* Same */ }; -#endif /* !_POSIX_SOURCE */ +#endif /* __BSD_VISIBLE */ #endif /* !_SYS_UNISTD_H_ */ diff --git a/usr.bin/tip/tip/remote.c b/usr.bin/tip/tip/remote.c index 68d5012585..1e243d7524 100644 --- a/usr.bin/tip/tip/remote.c +++ b/usr.bin/tip/tip/remote.c @@ -37,7 +37,6 @@ * $DragonFly: src/usr.bin/tip/tip/remote.c,v 1.4 2005/04/19 05:32:02 cpressey Exp $ */ -#include #include #include #include diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c index b746840046..e775f32589 100644 --- a/usr.sbin/inetd/inetd.c +++ b/usr.sbin/inetd/inetd.c @@ -120,6 +120,7 @@ #include #include #include +#include #include #include #include diff --git a/usr.sbin/rrenumd/parser.y b/usr.sbin/rrenumd/parser.y index 83dd68702b..048a2f6ca0 100644 --- a/usr.sbin/rrenumd/parser.y +++ b/usr.sbin/rrenumd/parser.y @@ -48,6 +48,7 @@ #include #include +#include #include #include #include -- 2.41.0