Index: stable/10/usr.bin/getconf/confstr.gperf =================================================================== --- stable/10/usr.bin/getconf/confstr.gperf (revision 324123) +++ stable/10/usr.bin/getconf/confstr.gperf (revision 324124) @@ -1,70 +1,81 @@ %{ /* * Copyright is disclaimed as to the contents of this file. * * $FreeBSD$ */ #include #include #include #include "getconf.h" /* * Override gperf's built-in external scope. */ static const struct map *in_word_set(const char *str); /* * The Standard seems a bit ambiguous over whether the POSIX_V6_* * are specified with or without a leading underscore, so we just * use both. */ %} struct map { const char *name; int key; int valid; }; %% PATH, _CS_PATH POSIX_V6_ILP32_OFF32_CFLAGS, _CS_POSIX_V6_ILP32_OFF32_CFLAGS POSIX_V6_ILP32_OFF32_LDFLAGS, _CS_POSIX_V6_ILP32_OFF32_LDFLAGS POSIX_V6_ILP32_OFF32_LIBS, _CS_POSIX_V6_ILP32_OFF32_LIBS POSIX_V6_ILP32_OFFBIG_CFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS POSIX_V6_ILP32_OFFBIG_LDFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS POSIX_V6_ILP32_OFFBIG_LIBS, _CS_POSIX_V6_ILP32_OFFBIG_LIBS POSIX_V6_LP64_OFF64_CFLAGS, _CS_POSIX_V6_LP64_OFF64_CFLAGS POSIX_V6_LP64_OFF64_LDFLAGS, _CS_POSIX_V6_LP64_OFF64_LDFLAGS POSIX_V6_LP64_OFF64_LIBS, _CS_POSIX_V6_LP64_OFF64_LIBS POSIX_V6_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS POSIX_V6_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS POSIX_V6_LPBIG_OFFBIG_LIBS, _CS_POSIX_V6_LPBIG_OFFBIG_LIBS POSIX_V6_WIDTH_RESTRICTED_ENVS, _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS _POSIX_V6_ILP32_OFF32_CFLAGS, _CS_POSIX_V6_ILP32_OFF32_CFLAGS _POSIX_V6_ILP32_OFF32_LDFLAGS, _CS_POSIX_V6_ILP32_OFF32_LDFLAGS _POSIX_V6_ILP32_OFF32_LIBS, _CS_POSIX_V6_ILP32_OFF32_LIBS _POSIX_V6_ILP32_OFFBIG_CFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS _POSIX_V6_ILP32_OFFBIG_LDFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS _POSIX_V6_ILP32_OFFBIG_LIBS, _CS_POSIX_V6_ILP32_OFFBIG_LIBS _POSIX_V6_LP64_OFF64_CFLAGS, _CS_POSIX_V6_LP64_OFF64_CFLAGS _POSIX_V6_LP64_OFF64_LDFLAGS, _CS_POSIX_V6_LP64_OFF64_LDFLAGS _POSIX_V6_LP64_OFF64_LIBS, _CS_POSIX_V6_LP64_OFF64_LIBS _POSIX_V6_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS _POSIX_V6_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS _POSIX_V6_LPBIG_OFFBIG_LIBS, _CS_POSIX_V6_LPBIG_OFFBIG_LIBS _POSIX_V6_WIDTH_RESTRICTED_ENVS, _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS %% int find_confstr(const char *name, int *key) { const struct map *rv; rv = in_word_set(name); if (rv != NULL) { if (rv->valid) { *key = rv->key; return 1; } return -1; } return 0; } + +void +foreach_confstr(void (*func)(const char *, int)) +{ + const struct map *mp; + + for (mp = wordlist; mp->name != NULL; mp++) { + if (mp->valid) + func(mp->name, mp->key); + } +} Index: stable/10/usr.bin/getconf/getconf.1 =================================================================== --- stable/10/usr.bin/getconf/getconf.1 (revision 324123) +++ stable/10/usr.bin/getconf/getconf.1 (revision 324124) @@ -1,207 +1,225 @@ .\" .\" Copyright 2000 Massachusetts Institute of Technology .\" .\" Permission to use, copy, modify, and distribute this software and .\" its documentation for any purpose and without fee is hereby .\" granted, provided that both the above copyright notice and this .\" permission notice appear in all copies, that both the above .\" copyright notice and this permission notice appear in all .\" supporting documentation, and that the name of M.I.T. not be used .\" in advertising or publicity pertaining to distribution of the .\" software without specific, written prior permission. M.I.T. makes .\" no representations about the suitability of this software for any .\" purpose. It is provided "as is" without express or implied .\" warranty. .\" .\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS .\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT .\" SHALL M.I.T. 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. .\" .\" $FreeBSD$ .\" -.Dd August 8, 2016 +.Dd September 15, 2017 .Dt GETCONF 1 .Os .Sh NAME .Nm getconf .Nd retrieve standard configuration variables .Sh SYNOPSIS .Nm +.Fl a +.Op Ar file +.Nm .Op Fl v Ar environment .Ar path_var .Ar file .Nm .Op Fl v Ar environment .Ar system_var .Sh DESCRIPTION The .Nm -utility prints the value of a +utility prints the values of .Tn POSIX or .Tn X/Open -path or system configuration variable to the standard output. -If the specified variable is undefined, the string +path or system configuration variables to the standard output. +If a variable is undefined, the string .Dq Li undefined is output. .Pp -The first form of the command, with two mandatory +The first form of the command displays all of the path or system configuration +variables to standard output. +If +.Ar file +is provided, +all path configuration variables are reported for +.Ar file +using +.Xr pathconf 2 . +Otherwise, +all system configuration variables are reported using +.Xr confstr 3 +and +.Xr sysconf 3. +.Pp +The second form of the command, with two mandatory arguments, retrieves file- and file system-specific configuration variables using .Xr pathconf 2 . -The second form, with a single argument, retrieves system +The third form, with a single argument, retrieves system configuration variables using .Xr confstr 3 and .Xr sysconf 3 , depending on the type of variable. As an extension, the second form can also be used to query static limits from .In limits.h . .Pp All .Xr sysconf 3 and .Xr pathconf 2 variables use the same name as the manifest constants defined in the relevant standard C-language bindings, including any leading underscore or prefix. That is to say, .Ar system_var might be .Dv ARG_MAX or .Dv _POSIX_VERSION , as opposed to the .Xr sysconf 3 names .Dv _SC_ARG_MAX or .Dv _SC_POSIX_VERSION . Variables retrieved from .Xr confstr 3 have the leading .Ql _CS_ stripped off; thus, .Dv _CS_PATH is queried by a .Ar system_var of .Dq Li PATH . .Ss Programming Environments The .Fl v Ar environment option specifies a .St -p1003.1-2001 programming environment under which the values are to be queried. This option currently does nothing, but may in the future be used to select between 32-bit and 64-bit execution environments on platforms which support both. Specifying an environment which is not supported on the current execution platform gives undefined results. .Pp The standard programming environments are as follows: .Bl -tag -width ".Li POSIX_V6_LPBIG_OFFBIG" -offset indent .It Li POSIX_V6_ILP32_OFF32 Exactly 32-bit integer, long, pointer, and file offset. .Sy Supported platforms : None. .It Li POSIX_V6_ILP32_OFFBIG Exactly 32-bit integer, long, and pointer; at least 64-bit file offset. .Sy Supported platforms : .Tn IA32 , .Tn PowerPC . .It Li POSIX_V6_LP64_OFF64 Exactly 32-bit integer; exactly 64-bit long, pointer, and file offset. .Sy Supported platforms : .Tn AMD64 , .Tn SPARC64 . .It Li POSIX_V6_LPBIG_OFFBIG At least 32-bit integer; at least 64-bit long, pointer, and file offset. .Sy Supported platforms : None. .El .Pp The command: .Pp .Dl "getconf POSIX_V6_WIDTH_RESTRICTED_ENVS" .Pp returns a newline-separated list of environments in which the width of certain fundamental types is no greater than the width of the native C type .Vt long . At present, all programming environments supported by .Fx have this property. Several of the .Xr confstr 3 variables provide information on the necessary compiler and linker flags to use the standard programming environments described above. .Sh EXIT STATUS .Ex -std .Sh EXAMPLES The command: .Pp .Dl "getconf PATH" .Pp will display the system default setting for the .Ev PATH environment variable. .Pp The command: .Pp .Dl "getconf NAME_MAX /tmp" .Pp will display the maximum length of a filename in the .Pa /tmp directory. .Pp The command: .Pp .Dl "getconf -v POSIX_V6_LPBIG_OFFBIG LONG_MAX" .Pp will display the maximum value of the C type .Vt long in the .Li POSIX_V6_LPBIG_OFFBIG programming environment, if the system supports that environment. .Sh DIAGNOSTICS Use of a .Ar system_var or .Ar path_var which is completely unrecognized is considered an error, causing a diagnostic message to be written to standard error. One which is known but merely undefined does not result in an error indication. The .Nm utility recognizes all of the variables defined for .St -p1003.1-2001 , including those which are not currently implemented. .Sh SEE ALSO .Xr pathconf 2 , .Xr confstr 3 , .Xr sysconf 3 .Sh STANDARDS The .Nm utility is expected to be compliant with .St -p1003.1-2001 . .Sh HISTORY The .Nm utility first appeared in .Fx 5.0 . .Sh AUTHORS .An Garrett A. Wollman Aq wollman@lcs.mit.edu Index: stable/10/usr.bin/getconf/getconf.c =================================================================== --- stable/10/usr.bin/getconf/getconf.c (revision 324123) +++ stable/10/usr.bin/getconf/getconf.c (revision 324124) @@ -1,190 +1,280 @@ /* * Copyright 2000 Massachusetts Institute of Technology * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby * granted, provided that both the above copyright notice and this * permission notice appear in all copies, that both the above * copyright notice and this permission notice appear in all * supporting documentation, and that the name of M.I.T. not be used * in advertising or publicity pertaining to distribution of the * software without specific, written prior permission. M.I.T. makes * no representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied * warranty. * * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT * SHALL M.I.T. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include #include #include "getconf.h" +static void do_allsys(void); +static void do_allpath(const char *path); static void do_confstr(const char *name, int key); static void do_sysconf(const char *name, int key); static void do_pathconf(const char *name, int key, const char *path); static void usage(void) { fprintf(stderr, -"usage: getconf [-v prog_env] system_var\n" +"usage: getconf -a [pathname]\n" +" getconf [-v prog_env] system_var\n" " getconf [-v prog_env] path_var pathname\n"); exit(EX_USAGE); } int main(int argc, char **argv) { + bool aflag; int c, key, valid; const char *name, *vflag, *alt_path; intmax_t limitval; + aflag = false; vflag = NULL; - while ((c = getopt(argc, argv, "v:")) != -1) { + while ((c = getopt(argc, argv, "av:")) != -1) { switch (c) { + case 'a': + aflag = true; + break; case 'v': vflag = optarg; break; default: usage(); } } + if (aflag) { + if (vflag != NULL) + usage(); + if (argv[optind] == NULL) + do_allsys(); + else + do_allpath(argv[optind]); + return (0); + } + if ((name = argv[optind]) == NULL) usage(); if (vflag != NULL) { if ((valid = find_progenv(vflag, &alt_path)) == 0) errx(EX_USAGE, "invalid programming environment %s", vflag); if (valid > 0 && alt_path != NULL) { if (argv[optind + 1] == NULL) execl(alt_path, "getconf", argv[optind], (char *)NULL); else execl(alt_path, "getconf", argv[optind], argv[optind + 1], (char *)NULL); err(EX_OSERR, "execl: %s", alt_path); } if (valid < 0) errx(EX_UNAVAILABLE, "environment %s is not available", vflag); } if (argv[optind + 1] == NULL) { /* confstr or sysconf */ if ((valid = find_limit(name, &limitval)) != 0) { if (valid > 0) printf("%" PRIdMAX "\n", limitval); else printf("undefined\n"); return 0; } if ((valid = find_confstr(name, &key)) != 0) { if (valid > 0) do_confstr(name, key); else printf("undefined\n"); } else { valid = find_sysconf(name, &key); if (valid > 0) { do_sysconf(name, key); } else if (valid < 0) { printf("undefined\n"); } else errx(EX_USAGE, "no such configuration parameter `%s'", name); } } else { valid = find_pathconf(name, &key); if (valid != 0) { if (valid > 0) do_pathconf(name, key, argv[optind + 1]); else printf("undefined\n"); } else errx(EX_USAGE, "no such path configuration parameter `%s'", name); } return 0; +} + +static void +do_onestr(const char *name, int key) +{ + size_t len; + + errno = 0; + len = confstr(key, 0, 0); + if (len == 0 && errno != 0) { + warn("confstr: %s", name); + return; + } + printf("%s: ", name); + if (len == 0) + printf("undefined\n"); + else { + char buf[len + 1]; + + confstr(key, buf, len); + printf("%s\n", buf); + } +} + +static void +do_onesys(const char *name, int key) +{ + long value; + + errno = 0; + value = sysconf(key); + if (value == -1 && errno != 0) { + warn("sysconf: %s", name); + return; + } + printf("%s: ", name); + if (value == -1) + printf("undefined\n"); + else + printf("%ld\n", value); +} + +static void +do_allsys(void) +{ + + foreach_confstr(do_onestr); + foreach_sysconf(do_onesys); +} + +static void +do_onepath(const char *name, int key, const char *path) +{ + long value; + + errno = 0; + value = pathconf(path, key); + if (value == -1 && errno != EINVAL && errno != 0) + warn("pathconf: %s", name); + printf("%s: ", name); + if (value == -1) + printf("undefined\n"); + else + printf("%ld\n", value); +} + +static void +do_allpath(const char *path) +{ + + foreach_pathconf(do_onepath, path); } static void do_confstr(const char *name, int key) { size_t len; int savederr; savederr = errno; errno = 0; len = confstr(key, 0, 0); if (len == 0) { if (errno) err(EX_OSERR, "confstr: %s", name); else printf("undefined\n"); } else { char buf[len + 1]; confstr(key, buf, len); printf("%s\n", buf); } errno = savederr; } static void do_sysconf(const char *name, int key) { long value; errno = 0; value = sysconf(key); if (value == -1 && errno != 0) err(EX_OSERR, "sysconf: %s", name); else if (value == -1) printf("undefined\n"); else printf("%ld\n", value); } static void do_pathconf(const char *name, int key, const char *path) { long value; errno = 0; value = pathconf(path, key); if (value == -1 && errno != 0) err(EX_OSERR, "pathconf: %s", name); else if (value == -1) printf("undefined\n"); else printf("%ld\n", value); } Index: stable/10/usr.bin/getconf/getconf.h =================================================================== --- stable/10/usr.bin/getconf/getconf.h (revision 324123) +++ stable/10/usr.bin/getconf/getconf.h (revision 324124) @@ -1,43 +1,47 @@ /* * Copyright 2000 Massachusetts Institute of Technology * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby * granted, provided that both the above copyright notice and this * permission notice appear in all copies, that both the above * copyright notice and this permission notice appear in all * supporting documentation, and that the name of M.I.T. not be used * in advertising or publicity pertaining to distribution of the * software without specific, written prior permission. M.I.T. makes * no representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied * warranty. * * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT * SHALL M.I.T. 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. * * $FreeBSD$ */ #ifdef STABLE typedef long long intmax_t; #define PRIdMAX "lld" #else #include #endif int find_confstr(const char *name, int *key); int find_limit(const char *name, intmax_t *value); int find_pathconf(const char *name, int *key); int find_progenv(const char *name, const char **alt_path); int find_sysconf(const char *name, int *key); +void foreach_confstr(void (*func)(const char *, int)); +void foreach_pathconf(void (*func)(const char *, int, const char *), + const char *path); +void foreach_sysconf(void (*func)(const char *, int)); Index: stable/10/usr.bin/getconf/pathconf.gperf =================================================================== --- stable/10/usr.bin/getconf/pathconf.gperf (revision 324123) +++ stable/10/usr.bin/getconf/pathconf.gperf (revision 324124) @@ -1,70 +1,82 @@ %{ /* * Copyright is disclaimed as to the contents of this file. * * $FreeBSD$ */ #include #include #include #include "getconf.h" /* * Override gperf's built-in external scope. */ static const struct map *in_word_set(const char *str); %} struct map { const char *name; int key; int valid; }; %% ACL_EXTENDED, _PC_ACL_EXTENDED ACL_NFS4, _PC_ACL_NFS4 ACL_PATH_MAX, _PC_ACL_PATH_MAX CAP_PRESENT, _PC_CAP_PRESENT FILESIZEBITS, _PC_FILESIZEBITS INF_PRESENT, _PC_INF_PRESENT LINK_MAX, _PC_LINK_MAX MAC_PRESENT, _PC_MAC_PRESENT MAX_CANON, _PC_MAX_CANON MAX_INPUT, _PC_MAX_INPUT MIN_HOLE_SIZE, _PC_MIN_HOLE_SIZE NAME_MAX, _PC_NAME_MAX PATH_MAX, _PC_PATH_MAX PIPE_BUF, _PC_PIPE_BUF POSIX_ALLOC_SIZE_MIN, _PC_ALLOC_SIZE_MIN POSIX_REC_INCR_XFER_SIZE, _PC_REC_INCR_XFER_SIZE POSIX_REC_MAX_XFER_SIZE, _PC_REC_MAX_XFER_SIZE POSIX_REC_MIN_XFER_SIZE, _PC_REC_MIN_XFER_SIZE POSIX_REC_XFER_ALIGN, _PC_REC_XFER_ALIGN SYMLINK_MAX, _PC_SYMLINK_MAX TRUSTEDBSD_ACL_EXTENDED, _PC_ACL_EXTENDED TRUSTEDBSD_ACL_NFS4, _PC_ACL_NFS4 TRUSTEDBSD_ACL_PATH_MAX, _PC_ACL_PATH_MAX TRUSTEDBSD_CAP_PRESENT, _PC_CAP_PRESENT TRUSTEDBSD_INF_PRESENT, _PC_INF_PRESENT TRUSTEDBSD_MAC_PRESENT, _PC_MAC_PRESENT _POSIX_CHOWN_RESTRICTED, _PC_CHOWN_RESTRICTED _POSIX_NO_TRUNC, _PC_NO_TRUNC _POSIX_VDISABLE, _PC_VDISABLE _POSIX_ASYNC_IO, _PC_ASYNC_IO _POSIX_PRIO_IO, _PC_PRIO_IO _POSIX_SYNC_IO, _PC_SYNC_IO %% int find_pathconf(const char *name, int *key) { const struct map *rv; rv = in_word_set(name); if (rv != NULL) { if (rv->valid) { *key = rv->key; return 1; } return -1; } return 0; } + +void +foreach_pathconf(void (*func)(const char *, int, const char *), + const char *path) +{ + const struct map *mp; + + for (mp = wordlist; mp->name != NULL; mp++) { + if (mp->valid) + func(mp->name, mp->key, path); + } +} Index: stable/10/usr.bin/getconf/sysconf.gperf =================================================================== --- stable/10/usr.bin/getconf/sysconf.gperf (revision 324123) +++ stable/10/usr.bin/getconf/sysconf.gperf (revision 324124) @@ -1,149 +1,160 @@ %{ /* * Copyright is disclaimed as to the contents of this file. * * $FreeBSD$ */ #include #include #include #include "getconf.h" /* * Override gperf's built-in external scope. */ static const struct map *in_word_set(const char *str); %} struct map { const char *name; int key; int valid; }; %% AIO_LISTIO_MAX, _SC_AIO_LISTIO_MAX AIO_MAX, _SC_AIO_MAX AIO_PRIO_DELTA_MAX, _SC_AIO_PRIO_DELTA_MAX ARG_MAX, _SC_ARG_MAX ATEXIT_MAX, _SC_ATEXIT_MAX BC_BASE_MAX, _SC_BC_BASE_MAX BC_DIM_MAX, _SC_BC_DIM_MAX BC_SCALE_MAX, _SC_BC_SCALE_MAX BC_STRING_MAX, _SC_BC_STRING_MAX CHILD_MAX, _SC_CHILD_MAX CLK_TCK, _SC_CLK_TCK COLL_WEIGHTS_MAX, _SC_COLL_WEIGHTS_MAX DELAYTIMER_MAX, _SC_DELAYTIMER_MAX EXPR_NEST_MAX, _SC_EXPR_NEST_MAX GETGR_R_SIZE_MAX, _SC_GETGR_R_SIZE_MAX GETPW_R_SIZE_MAX, _SC_GETPW_R_SIZE_MAX HOST_NAME_MAX, _SC_HOST_NAME_MAX IOV_MAX, _SC_IOV_MAX LINE_MAX, _SC_LINE_MAX LOGIN_NAME_MAX, _SC_LOGIN_NAME_MAX MQ_OPEN_MAX, _SC_MQ_OPEN_MAX MQ_PRIO_MAX, _SC_MQ_PRIO_MAX NGROUPS_MAX, _SC_NGROUPS_MAX NPROCESSORS_CONF, _SC_NPROCESSORS_CONF NPROCESSORS_ONLN, _SC_NPROCESSORS_ONLN OPEN_MAX, _SC_OPEN_MAX PAGESIZE, _SC_PAGESIZE PAGE_SIZE, _SC_PAGESIZE PASS_MAX, _SC_PASS_MAX PTHREAD_DESTRUCTOR_ITERATIONS, _SC_THREAD_DESTRUCTOR_ITERATIONS PTHREAD_KEYS_MAX, _SC_THREAD_KEYS_MAX PTHREAD_STACK_MIN, _SC_THREAD_STACK_MIN PTHREAD_THREADS_MAX, _SC_THREAD_THREADS_MAX RE_DUP_MAX, _SC_RE_DUP_MAX RTSIG_MAX, _SC_RTSIG_MAX SEM_NSEMS_MAX, _SC_SEM_NSEMS_MAX SEM_VALUE_MAX, _SC_SEM_VALUE_MAX SIGQUEUE_MAX, _SC_SIGQUEUE_MAX STREAM_MAX, _SC_STREAM_MAX SYMLOOP_MAX, _SC_SYMLOOP_MAX TIMER_MAX, _SC_TIMER_MAX TTY_NAME_MAX, _SC_TTY_NAME_MAX TZNAME_MAX, _SC_TZNAME_MAX _POSIX2_CHAR_TERM, _SC_2_CHAR_TERM _POSIX2_C_BIND, _SC_2_C_BIND _POSIX2_C_DEV, _SC_2_C_DEV _POSIX2_C_VERSION, _SC_2_C_VERSION _POSIX2_FORT_DEV, _SC_2_FORT_DEV _POSIX2_FORT_RUN, _SC_2_FORT_RUN _POSIX2_LOCALEDEF, _SC_2_LOCALEDEF _POSIX2_SW_DEV, _SC_2_SW_DEV _POSIX2_UPE, _SC_2_UPE _POSIX2_VERSION, _SC_2_VERSION _POSIX_ASYNCHRONOUS_IO, _SC_ASYNCHRONOUS_IO _POSIX_BARRIERS, _SC_BARRIERS _POSIX_CLOCK_SELECTION, _SC_CLOCK_SELECTION _POSIX_CPUTIME, _SC_CPUTIME _POSIX_FILE_LOCKING, _SC_FILE_LOCKING _POSIX_FSYNC, _SC_FSYNC _POSIX_IPV6, _SC_IPV6 _POSIX_JOB_CONTROL, _SC_JOB_CONTROL _POSIX_MAPPED_FILES, _SC_MAPPED_FILES _POSIX_MEMLOCK, _SC_MEMLOCK _POSIX_MEMLOCK_RANGE, _SC_MEMLOCK_RANGE _POSIX_MEMORY_PROTECTION, _SC_MEMORY_PROTECTION _POSIX_MESSAGE_PASSING, _SC_MESSAGE_PASSING _POSIX_MONOTONIC_CLOCK, _SC_MONOTONIC_CLOCK _POSIX_PRIORITIZED_IO, _SC_PRIORITIZED_IO _POSIX_PRIORITY_SCHEDULING, _SC_PRIORITY_SCHEDULING _POSIX_READER_WRITER_LOCKS, _SC_READER_WRITER_LOCKS _POSIX_REALTIME_SIGNALS, _SC_REALTIME_SIGNALS _POSIX_REGEXP, _SC_REGEXP _POSIX_SAVED_IDS, _SC_SAVED_IDS _POSIX_SEMAPHORES, _SC_SEMAPHORES _POSIX_SHARED_MEMORY_OBJECTS, _SC_SHARED_MEMORY_OBJECTS _POSIX_SHELL, _SC_SHELL _POSIX_SPAWN, _SC_SPAWN _POSIX_SPIN_LOCKS, _SC_SPIN_LOCKS _POSIX_SPORADIC_SERVER, _SC_SPORADIC_SERVER _POSIX_SYNCHRONIZED_IO, _SC_SYNCHRONIZED_IO _POSIX_THREADS, _SC_THREADS _POSIX_THREAD_ATTR_STACKADDR, _SC_THREAD_ATTR_STACKADDR _POSIX_THREAD_ATTR_STACKSIZE, _SC_THREAD_ATTR_STACKSIZE _POSIX_THREAD_CPUTIME, _SC_THREAD_CPUTIME _POSIX_THREAD_PRIORITY_SCHEDULING, _SC_THREAD_PRIORITY_SCHEDULING _POSIX_THREAD_PRIO_INHERIT, _SC_THREAD_PRIO_INHERIT _POSIX_THREAD_PRIO_PROTECT, _SC_THREAD_PRIO_PROTECT _POSIX_THREAD_PROCESS_SHARED, _SC_THREAD_PROCESS_SHARED _POSIX_THREAD_SAFE_FUNCTIONS, _SC_THREAD_SAFE_FUNCTIONS _POSIX_THREAD_SPORADIC_SERVER, _SC_THREAD_SPORADIC_SERVER _POSIX_TIMEOUTS, _SC_TIMEOUTS _POSIX_TRACE, _SC_TRACE _POSIX_TRACE_EVENT_FILTER, _SC_TRACE_EVENT_FILTER _POSIX_TRACE_INHERIT, _SC_TRACE_INHERIT _POSIX_TRACE_LOG, _SC_TRACE_LOG _POSIX_TIMERS, _SC_TIMERS _POSIX_TYPED_MEMORY_OBJECTS, _SC_TYPED_MEMORY_OBJECTS _POSIX_VERSION, _SC_VERSION _POSIX_V6_ILP32_OFF32, _SC_V6_ILP32_OFF32 _POSIX_V6_ILP32_OFFBIG, _SC_V6_ILP32_OFFBIG _POSIX_V6_LP64_OFF64, _SC_V6_LP64_OFF64 _POSIX_V6_LPBIG_OFFBIG, _SC_V6_LPBIG_OFFBIG _XOPEN_CRYPT, _SC_XOPEN_CRYPT _XOPEN_ENH_I18N, _SC_XOPEN_ENH_I18N _XOPEN_LEGACY, _SC_XOPEN_LEGACY _XOPEN_REALTIME, _SC_XOPEN_REALTIME _XOPEN_REALTIME_THREADS, _SC_XOPEN_REALTIME_THREADS _XOPEN_SHM, _SC_XOPEN_SHM _XOPEN_UNIX, _SC_XOPEN_UNIX _XOPEN_VERSION, _SC_XOPEN_VERSION _XOPEN_XCU_VERSION, _SC_XCU_VERSION %% int find_sysconf(const char *name, int *key) { const struct map *rv; rv = in_word_set(name); if (rv != NULL) { if (rv->valid) { *key = rv->key; return 1; } return -1; } return 0; } + +void +foreach_sysconf(void (*func)(const char *, int)) +{ + const struct map *mp; + + for (mp = wordlist; mp->name != NULL; mp++) { + if (mp->valid) + func(mp->name, mp->key); + } +} Index: stable/10 =================================================================== --- stable/10 (revision 324123) +++ stable/10 (revision 324124) Property changes on: stable/10 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r323631 Index: stable/11/usr.bin/getconf/confstr.gperf =================================================================== --- stable/11/usr.bin/getconf/confstr.gperf (revision 324123) +++ stable/11/usr.bin/getconf/confstr.gperf (revision 324124) @@ -1,70 +1,81 @@ %{ /* * Copyright is disclaimed as to the contents of this file. * * $FreeBSD$ */ #include #include #include #include "getconf.h" /* * Override gperf's built-in external scope. */ static const struct map *in_word_set(const char *str); /* * The Standard seems a bit ambiguous over whether the POSIX_V6_* * are specified with or without a leading underscore, so we just * use both. */ %} struct map { const char *name; int key; int valid; }; %% PATH, _CS_PATH POSIX_V6_ILP32_OFF32_CFLAGS, _CS_POSIX_V6_ILP32_OFF32_CFLAGS POSIX_V6_ILP32_OFF32_LDFLAGS, _CS_POSIX_V6_ILP32_OFF32_LDFLAGS POSIX_V6_ILP32_OFF32_LIBS, _CS_POSIX_V6_ILP32_OFF32_LIBS POSIX_V6_ILP32_OFFBIG_CFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS POSIX_V6_ILP32_OFFBIG_LDFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS POSIX_V6_ILP32_OFFBIG_LIBS, _CS_POSIX_V6_ILP32_OFFBIG_LIBS POSIX_V6_LP64_OFF64_CFLAGS, _CS_POSIX_V6_LP64_OFF64_CFLAGS POSIX_V6_LP64_OFF64_LDFLAGS, _CS_POSIX_V6_LP64_OFF64_LDFLAGS POSIX_V6_LP64_OFF64_LIBS, _CS_POSIX_V6_LP64_OFF64_LIBS POSIX_V6_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS POSIX_V6_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS POSIX_V6_LPBIG_OFFBIG_LIBS, _CS_POSIX_V6_LPBIG_OFFBIG_LIBS POSIX_V6_WIDTH_RESTRICTED_ENVS, _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS _POSIX_V6_ILP32_OFF32_CFLAGS, _CS_POSIX_V6_ILP32_OFF32_CFLAGS _POSIX_V6_ILP32_OFF32_LDFLAGS, _CS_POSIX_V6_ILP32_OFF32_LDFLAGS _POSIX_V6_ILP32_OFF32_LIBS, _CS_POSIX_V6_ILP32_OFF32_LIBS _POSIX_V6_ILP32_OFFBIG_CFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS _POSIX_V6_ILP32_OFFBIG_LDFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS _POSIX_V6_ILP32_OFFBIG_LIBS, _CS_POSIX_V6_ILP32_OFFBIG_LIBS _POSIX_V6_LP64_OFF64_CFLAGS, _CS_POSIX_V6_LP64_OFF64_CFLAGS _POSIX_V6_LP64_OFF64_LDFLAGS, _CS_POSIX_V6_LP64_OFF64_LDFLAGS _POSIX_V6_LP64_OFF64_LIBS, _CS_POSIX_V6_LP64_OFF64_LIBS _POSIX_V6_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS _POSIX_V6_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS _POSIX_V6_LPBIG_OFFBIG_LIBS, _CS_POSIX_V6_LPBIG_OFFBIG_LIBS _POSIX_V6_WIDTH_RESTRICTED_ENVS, _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS %% int find_confstr(const char *name, int *key) { const struct map *rv; rv = in_word_set(name); if (rv != NULL) { if (rv->valid) { *key = rv->key; return 1; } return -1; } return 0; } + +void +foreach_confstr(void (*func)(const char *, int)) +{ + const struct map *mp; + + for (mp = wordlist; mp->name != NULL; mp++) { + if (mp->valid) + func(mp->name, mp->key); + } +} Index: stable/11/usr.bin/getconf/getconf.1 =================================================================== --- stable/11/usr.bin/getconf/getconf.1 (revision 324123) +++ stable/11/usr.bin/getconf/getconf.1 (revision 324124) @@ -1,207 +1,225 @@ .\" .\" Copyright 2000 Massachusetts Institute of Technology .\" .\" Permission to use, copy, modify, and distribute this software and .\" its documentation for any purpose and without fee is hereby .\" granted, provided that both the above copyright notice and this .\" permission notice appear in all copies, that both the above .\" copyright notice and this permission notice appear in all .\" supporting documentation, and that the name of M.I.T. not be used .\" in advertising or publicity pertaining to distribution of the .\" software without specific, written prior permission. M.I.T. makes .\" no representations about the suitability of this software for any .\" purpose. It is provided "as is" without express or implied .\" warranty. .\" .\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS .\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT .\" SHALL M.I.T. 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. .\" .\" $FreeBSD$ .\" -.Dd August 8, 2016 +.Dd September 15, 2017 .Dt GETCONF 1 .Os .Sh NAME .Nm getconf .Nd retrieve standard configuration variables .Sh SYNOPSIS .Nm +.Fl a +.Op Ar file +.Nm .Op Fl v Ar environment .Ar path_var .Ar file .Nm .Op Fl v Ar environment .Ar system_var .Sh DESCRIPTION The .Nm -utility prints the value of a +utility prints the values of .Tn POSIX or .Tn X/Open -path or system configuration variable to the standard output. -If the specified variable is undefined, the string +path or system configuration variables to the standard output. +If a variable is undefined, the string .Dq Li undefined is output. .Pp -The first form of the command, with two mandatory +The first form of the command displays all of the path or system configuration +variables to standard output. +If +.Ar file +is provided, +all path configuration variables are reported for +.Ar file +using +.Xr pathconf 2 . +Otherwise, +all system configuration variables are reported using +.Xr confstr 3 +and +.Xr sysconf 3. +.Pp +The second form of the command, with two mandatory arguments, retrieves file- and file system-specific configuration variables using .Xr pathconf 2 . -The second form, with a single argument, retrieves system +The third form, with a single argument, retrieves system configuration variables using .Xr confstr 3 and .Xr sysconf 3 , depending on the type of variable. As an extension, the second form can also be used to query static limits from .In limits.h . .Pp All .Xr sysconf 3 and .Xr pathconf 2 variables use the same name as the manifest constants defined in the relevant standard C-language bindings, including any leading underscore or prefix. That is to say, .Ar system_var might be .Dv ARG_MAX or .Dv _POSIX_VERSION , as opposed to the .Xr sysconf 3 names .Dv _SC_ARG_MAX or .Dv _SC_POSIX_VERSION . Variables retrieved from .Xr confstr 3 have the leading .Ql _CS_ stripped off; thus, .Dv _CS_PATH is queried by a .Ar system_var of .Dq Li PATH . .Ss Programming Environments The .Fl v Ar environment option specifies a .St -p1003.1-2001 programming environment under which the values are to be queried. This option currently does nothing, but may in the future be used to select between 32-bit and 64-bit execution environments on platforms which support both. Specifying an environment which is not supported on the current execution platform gives undefined results. .Pp The standard programming environments are as follows: .Bl -tag -width ".Li POSIX_V6_LPBIG_OFFBIG" -offset indent .It Li POSIX_V6_ILP32_OFF32 Exactly 32-bit integer, long, pointer, and file offset. .Sy Supported platforms : None. .It Li POSIX_V6_ILP32_OFFBIG Exactly 32-bit integer, long, and pointer; at least 64-bit file offset. .Sy Supported platforms : .Tn IA32 , .Tn PowerPC . .It Li POSIX_V6_LP64_OFF64 Exactly 32-bit integer; exactly 64-bit long, pointer, and file offset. .Sy Supported platforms : .Tn AMD64 , .Tn SPARC64 . .It Li POSIX_V6_LPBIG_OFFBIG At least 32-bit integer; at least 64-bit long, pointer, and file offset. .Sy Supported platforms : None. .El .Pp The command: .Pp .Dl "getconf POSIX_V6_WIDTH_RESTRICTED_ENVS" .Pp returns a newline-separated list of environments in which the width of certain fundamental types is no greater than the width of the native C type .Vt long . At present, all programming environments supported by .Fx have this property. Several of the .Xr confstr 3 variables provide information on the necessary compiler and linker flags to use the standard programming environments described above. .Sh EXIT STATUS .Ex -std .Sh EXAMPLES The command: .Pp .Dl "getconf PATH" .Pp will display the system default setting for the .Ev PATH environment variable. .Pp The command: .Pp .Dl "getconf NAME_MAX /tmp" .Pp will display the maximum length of a filename in the .Pa /tmp directory. .Pp The command: .Pp .Dl "getconf -v POSIX_V6_LPBIG_OFFBIG LONG_MAX" .Pp will display the maximum value of the C type .Vt long in the .Li POSIX_V6_LPBIG_OFFBIG programming environment, if the system supports that environment. .Sh DIAGNOSTICS Use of a .Ar system_var or .Ar path_var which is completely unrecognized is considered an error, causing a diagnostic message to be written to standard error. One which is known but merely undefined does not result in an error indication. The .Nm utility recognizes all of the variables defined for .St -p1003.1-2001 , including those which are not currently implemented. .Sh SEE ALSO .Xr pathconf 2 , .Xr confstr 3 , .Xr sysconf 3 .Sh STANDARDS The .Nm utility is expected to be compliant with .St -p1003.1-2001 . .Sh HISTORY The .Nm utility first appeared in .Fx 5.0 . .Sh AUTHORS .An Garrett A. Wollman Aq Mt wollman@lcs.mit.edu Index: stable/11/usr.bin/getconf/getconf.c =================================================================== --- stable/11/usr.bin/getconf/getconf.c (revision 324123) +++ stable/11/usr.bin/getconf/getconf.c (revision 324124) @@ -1,190 +1,280 @@ /* * Copyright 2000 Massachusetts Institute of Technology * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby * granted, provided that both the above copyright notice and this * permission notice appear in all copies, that both the above * copyright notice and this permission notice appear in all * supporting documentation, and that the name of M.I.T. not be used * in advertising or publicity pertaining to distribution of the * software without specific, written prior permission. M.I.T. makes * no representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied * warranty. * * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT * SHALL M.I.T. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include #include #include "getconf.h" +static void do_allsys(void); +static void do_allpath(const char *path); static void do_confstr(const char *name, int key); static void do_sysconf(const char *name, int key); static void do_pathconf(const char *name, int key, const char *path); static void usage(void) { fprintf(stderr, -"usage: getconf [-v prog_env] system_var\n" +"usage: getconf -a [pathname]\n" +" getconf [-v prog_env] system_var\n" " getconf [-v prog_env] path_var pathname\n"); exit(EX_USAGE); } int main(int argc, char **argv) { + bool aflag; int c, key, valid; const char *name, *vflag, *alt_path; intmax_t limitval; + aflag = false; vflag = NULL; - while ((c = getopt(argc, argv, "v:")) != -1) { + while ((c = getopt(argc, argv, "av:")) != -1) { switch (c) { + case 'a': + aflag = true; + break; case 'v': vflag = optarg; break; default: usage(); } } + if (aflag) { + if (vflag != NULL) + usage(); + if (argv[optind] == NULL) + do_allsys(); + else + do_allpath(argv[optind]); + return (0); + } + if ((name = argv[optind]) == NULL) usage(); if (vflag != NULL) { if ((valid = find_progenv(vflag, &alt_path)) == 0) errx(EX_USAGE, "invalid programming environment %s", vflag); if (valid > 0 && alt_path != NULL) { if (argv[optind + 1] == NULL) execl(alt_path, "getconf", argv[optind], (char *)NULL); else execl(alt_path, "getconf", argv[optind], argv[optind + 1], (char *)NULL); err(EX_OSERR, "execl: %s", alt_path); } if (valid < 0) errx(EX_UNAVAILABLE, "environment %s is not available", vflag); } if (argv[optind + 1] == NULL) { /* confstr or sysconf */ if ((valid = find_limit(name, &limitval)) != 0) { if (valid > 0) printf("%" PRIdMAX "\n", limitval); else printf("undefined\n"); return 0; } if ((valid = find_confstr(name, &key)) != 0) { if (valid > 0) do_confstr(name, key); else printf("undefined\n"); } else { valid = find_sysconf(name, &key); if (valid > 0) { do_sysconf(name, key); } else if (valid < 0) { printf("undefined\n"); } else errx(EX_USAGE, "no such configuration parameter `%s'", name); } } else { valid = find_pathconf(name, &key); if (valid != 0) { if (valid > 0) do_pathconf(name, key, argv[optind + 1]); else printf("undefined\n"); } else errx(EX_USAGE, "no such path configuration parameter `%s'", name); } return 0; +} + +static void +do_onestr(const char *name, int key) +{ + size_t len; + + errno = 0; + len = confstr(key, 0, 0); + if (len == 0 && errno != 0) { + warn("confstr: %s", name); + return; + } + printf("%s: ", name); + if (len == 0) + printf("undefined\n"); + else { + char buf[len + 1]; + + confstr(key, buf, len); + printf("%s\n", buf); + } +} + +static void +do_onesys(const char *name, int key) +{ + long value; + + errno = 0; + value = sysconf(key); + if (value == -1 && errno != 0) { + warn("sysconf: %s", name); + return; + } + printf("%s: ", name); + if (value == -1) + printf("undefined\n"); + else + printf("%ld\n", value); +} + +static void +do_allsys(void) +{ + + foreach_confstr(do_onestr); + foreach_sysconf(do_onesys); +} + +static void +do_onepath(const char *name, int key, const char *path) +{ + long value; + + errno = 0; + value = pathconf(path, key); + if (value == -1 && errno != EINVAL && errno != 0) + warn("pathconf: %s", name); + printf("%s: ", name); + if (value == -1) + printf("undefined\n"); + else + printf("%ld\n", value); +} + +static void +do_allpath(const char *path) +{ + + foreach_pathconf(do_onepath, path); } static void do_confstr(const char *name, int key) { size_t len; int savederr; savederr = errno; errno = 0; len = confstr(key, 0, 0); if (len == 0) { if (errno) err(EX_OSERR, "confstr: %s", name); else printf("undefined\n"); } else { char buf[len + 1]; confstr(key, buf, len); printf("%s\n", buf); } errno = savederr; } static void do_sysconf(const char *name, int key) { long value; errno = 0; value = sysconf(key); if (value == -1 && errno != 0) err(EX_OSERR, "sysconf: %s", name); else if (value == -1) printf("undefined\n"); else printf("%ld\n", value); } static void do_pathconf(const char *name, int key, const char *path) { long value; errno = 0; value = pathconf(path, key); if (value == -1 && errno != 0) err(EX_OSERR, "pathconf: %s", name); else if (value == -1) printf("undefined\n"); else printf("%ld\n", value); } Index: stable/11/usr.bin/getconf/getconf.h =================================================================== --- stable/11/usr.bin/getconf/getconf.h (revision 324123) +++ stable/11/usr.bin/getconf/getconf.h (revision 324124) @@ -1,43 +1,47 @@ /* * Copyright 2000 Massachusetts Institute of Technology * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby * granted, provided that both the above copyright notice and this * permission notice appear in all copies, that both the above * copyright notice and this permission notice appear in all * supporting documentation, and that the name of M.I.T. not be used * in advertising or publicity pertaining to distribution of the * software without specific, written prior permission. M.I.T. makes * no representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied * warranty. * * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT * SHALL M.I.T. 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. * * $FreeBSD$ */ #ifdef STABLE typedef long long intmax_t; #define PRIdMAX "lld" #else #include #endif int find_confstr(const char *name, int *key); int find_limit(const char *name, intmax_t *value); int find_pathconf(const char *name, int *key); int find_progenv(const char *name, const char **alt_path); int find_sysconf(const char *name, int *key); +void foreach_confstr(void (*func)(const char *, int)); +void foreach_pathconf(void (*func)(const char *, int, const char *), + const char *path); +void foreach_sysconf(void (*func)(const char *, int)); Index: stable/11/usr.bin/getconf/pathconf.gperf =================================================================== --- stable/11/usr.bin/getconf/pathconf.gperf (revision 324123) +++ stable/11/usr.bin/getconf/pathconf.gperf (revision 324124) @@ -1,70 +1,82 @@ %{ /* * Copyright is disclaimed as to the contents of this file. * * $FreeBSD$ */ #include #include #include #include "getconf.h" /* * Override gperf's built-in external scope. */ static const struct map *in_word_set(const char *str); %} struct map { const char *name; int key; int valid; }; %% ACL_EXTENDED, _PC_ACL_EXTENDED ACL_NFS4, _PC_ACL_NFS4 ACL_PATH_MAX, _PC_ACL_PATH_MAX CAP_PRESENT, _PC_CAP_PRESENT FILESIZEBITS, _PC_FILESIZEBITS INF_PRESENT, _PC_INF_PRESENT LINK_MAX, _PC_LINK_MAX MAC_PRESENT, _PC_MAC_PRESENT MAX_CANON, _PC_MAX_CANON MAX_INPUT, _PC_MAX_INPUT MIN_HOLE_SIZE, _PC_MIN_HOLE_SIZE NAME_MAX, _PC_NAME_MAX PATH_MAX, _PC_PATH_MAX PIPE_BUF, _PC_PIPE_BUF POSIX_ALLOC_SIZE_MIN, _PC_ALLOC_SIZE_MIN POSIX_REC_INCR_XFER_SIZE, _PC_REC_INCR_XFER_SIZE POSIX_REC_MAX_XFER_SIZE, _PC_REC_MAX_XFER_SIZE POSIX_REC_MIN_XFER_SIZE, _PC_REC_MIN_XFER_SIZE POSIX_REC_XFER_ALIGN, _PC_REC_XFER_ALIGN SYMLINK_MAX, _PC_SYMLINK_MAX TRUSTEDBSD_ACL_EXTENDED, _PC_ACL_EXTENDED TRUSTEDBSD_ACL_NFS4, _PC_ACL_NFS4 TRUSTEDBSD_ACL_PATH_MAX, _PC_ACL_PATH_MAX TRUSTEDBSD_CAP_PRESENT, _PC_CAP_PRESENT TRUSTEDBSD_INF_PRESENT, _PC_INF_PRESENT TRUSTEDBSD_MAC_PRESENT, _PC_MAC_PRESENT _POSIX_CHOWN_RESTRICTED, _PC_CHOWN_RESTRICTED _POSIX_NO_TRUNC, _PC_NO_TRUNC _POSIX_VDISABLE, _PC_VDISABLE _POSIX_ASYNC_IO, _PC_ASYNC_IO _POSIX_PRIO_IO, _PC_PRIO_IO _POSIX_SYNC_IO, _PC_SYNC_IO %% int find_pathconf(const char *name, int *key) { const struct map *rv; rv = in_word_set(name); if (rv != NULL) { if (rv->valid) { *key = rv->key; return 1; } return -1; } return 0; } + +void +foreach_pathconf(void (*func)(const char *, int, const char *), + const char *path) +{ + const struct map *mp; + + for (mp = wordlist; mp->name != NULL; mp++) { + if (mp->valid) + func(mp->name, mp->key, path); + } +} Index: stable/11/usr.bin/getconf/sysconf.gperf =================================================================== --- stable/11/usr.bin/getconf/sysconf.gperf (revision 324123) +++ stable/11/usr.bin/getconf/sysconf.gperf (revision 324124) @@ -1,149 +1,160 @@ %{ /* * Copyright is disclaimed as to the contents of this file. * * $FreeBSD$ */ #include #include #include #include "getconf.h" /* * Override gperf's built-in external scope. */ static const struct map *in_word_set(const char *str); %} struct map { const char *name; int key; int valid; }; %% AIO_LISTIO_MAX, _SC_AIO_LISTIO_MAX AIO_MAX, _SC_AIO_MAX AIO_PRIO_DELTA_MAX, _SC_AIO_PRIO_DELTA_MAX ARG_MAX, _SC_ARG_MAX ATEXIT_MAX, _SC_ATEXIT_MAX BC_BASE_MAX, _SC_BC_BASE_MAX BC_DIM_MAX, _SC_BC_DIM_MAX BC_SCALE_MAX, _SC_BC_SCALE_MAX BC_STRING_MAX, _SC_BC_STRING_MAX CHILD_MAX, _SC_CHILD_MAX CLK_TCK, _SC_CLK_TCK COLL_WEIGHTS_MAX, _SC_COLL_WEIGHTS_MAX DELAYTIMER_MAX, _SC_DELAYTIMER_MAX EXPR_NEST_MAX, _SC_EXPR_NEST_MAX GETGR_R_SIZE_MAX, _SC_GETGR_R_SIZE_MAX GETPW_R_SIZE_MAX, _SC_GETPW_R_SIZE_MAX HOST_NAME_MAX, _SC_HOST_NAME_MAX IOV_MAX, _SC_IOV_MAX LINE_MAX, _SC_LINE_MAX LOGIN_NAME_MAX, _SC_LOGIN_NAME_MAX MQ_OPEN_MAX, _SC_MQ_OPEN_MAX MQ_PRIO_MAX, _SC_MQ_PRIO_MAX NGROUPS_MAX, _SC_NGROUPS_MAX NPROCESSORS_CONF, _SC_NPROCESSORS_CONF NPROCESSORS_ONLN, _SC_NPROCESSORS_ONLN OPEN_MAX, _SC_OPEN_MAX PAGESIZE, _SC_PAGESIZE PAGE_SIZE, _SC_PAGESIZE PASS_MAX, _SC_PASS_MAX PTHREAD_DESTRUCTOR_ITERATIONS, _SC_THREAD_DESTRUCTOR_ITERATIONS PTHREAD_KEYS_MAX, _SC_THREAD_KEYS_MAX PTHREAD_STACK_MIN, _SC_THREAD_STACK_MIN PTHREAD_THREADS_MAX, _SC_THREAD_THREADS_MAX RE_DUP_MAX, _SC_RE_DUP_MAX RTSIG_MAX, _SC_RTSIG_MAX SEM_NSEMS_MAX, _SC_SEM_NSEMS_MAX SEM_VALUE_MAX, _SC_SEM_VALUE_MAX SIGQUEUE_MAX, _SC_SIGQUEUE_MAX STREAM_MAX, _SC_STREAM_MAX SYMLOOP_MAX, _SC_SYMLOOP_MAX TIMER_MAX, _SC_TIMER_MAX TTY_NAME_MAX, _SC_TTY_NAME_MAX TZNAME_MAX, _SC_TZNAME_MAX _POSIX2_CHAR_TERM, _SC_2_CHAR_TERM _POSIX2_C_BIND, _SC_2_C_BIND _POSIX2_C_DEV, _SC_2_C_DEV _POSIX2_C_VERSION, _SC_2_C_VERSION _POSIX2_FORT_DEV, _SC_2_FORT_DEV _POSIX2_FORT_RUN, _SC_2_FORT_RUN _POSIX2_LOCALEDEF, _SC_2_LOCALEDEF _POSIX2_SW_DEV, _SC_2_SW_DEV _POSIX2_UPE, _SC_2_UPE _POSIX2_VERSION, _SC_2_VERSION _POSIX_ASYNCHRONOUS_IO, _SC_ASYNCHRONOUS_IO _POSIX_BARRIERS, _SC_BARRIERS _POSIX_CLOCK_SELECTION, _SC_CLOCK_SELECTION _POSIX_CPUTIME, _SC_CPUTIME _POSIX_FILE_LOCKING, _SC_FILE_LOCKING _POSIX_FSYNC, _SC_FSYNC _POSIX_IPV6, _SC_IPV6 _POSIX_JOB_CONTROL, _SC_JOB_CONTROL _POSIX_MAPPED_FILES, _SC_MAPPED_FILES _POSIX_MEMLOCK, _SC_MEMLOCK _POSIX_MEMLOCK_RANGE, _SC_MEMLOCK_RANGE _POSIX_MEMORY_PROTECTION, _SC_MEMORY_PROTECTION _POSIX_MESSAGE_PASSING, _SC_MESSAGE_PASSING _POSIX_MONOTONIC_CLOCK, _SC_MONOTONIC_CLOCK _POSIX_PRIORITIZED_IO, _SC_PRIORITIZED_IO _POSIX_PRIORITY_SCHEDULING, _SC_PRIORITY_SCHEDULING _POSIX_READER_WRITER_LOCKS, _SC_READER_WRITER_LOCKS _POSIX_REALTIME_SIGNALS, _SC_REALTIME_SIGNALS _POSIX_REGEXP, _SC_REGEXP _POSIX_SAVED_IDS, _SC_SAVED_IDS _POSIX_SEMAPHORES, _SC_SEMAPHORES _POSIX_SHARED_MEMORY_OBJECTS, _SC_SHARED_MEMORY_OBJECTS _POSIX_SHELL, _SC_SHELL _POSIX_SPAWN, _SC_SPAWN _POSIX_SPIN_LOCKS, _SC_SPIN_LOCKS _POSIX_SPORADIC_SERVER, _SC_SPORADIC_SERVER _POSIX_SYNCHRONIZED_IO, _SC_SYNCHRONIZED_IO _POSIX_THREADS, _SC_THREADS _POSIX_THREAD_ATTR_STACKADDR, _SC_THREAD_ATTR_STACKADDR _POSIX_THREAD_ATTR_STACKSIZE, _SC_THREAD_ATTR_STACKSIZE _POSIX_THREAD_CPUTIME, _SC_THREAD_CPUTIME _POSIX_THREAD_PRIORITY_SCHEDULING, _SC_THREAD_PRIORITY_SCHEDULING _POSIX_THREAD_PRIO_INHERIT, _SC_THREAD_PRIO_INHERIT _POSIX_THREAD_PRIO_PROTECT, _SC_THREAD_PRIO_PROTECT _POSIX_THREAD_PROCESS_SHARED, _SC_THREAD_PROCESS_SHARED _POSIX_THREAD_SAFE_FUNCTIONS, _SC_THREAD_SAFE_FUNCTIONS _POSIX_THREAD_SPORADIC_SERVER, _SC_THREAD_SPORADIC_SERVER _POSIX_TIMEOUTS, _SC_TIMEOUTS _POSIX_TRACE, _SC_TRACE _POSIX_TRACE_EVENT_FILTER, _SC_TRACE_EVENT_FILTER _POSIX_TRACE_INHERIT, _SC_TRACE_INHERIT _POSIX_TRACE_LOG, _SC_TRACE_LOG _POSIX_TIMERS, _SC_TIMERS _POSIX_TYPED_MEMORY_OBJECTS, _SC_TYPED_MEMORY_OBJECTS _POSIX_VERSION, _SC_VERSION _POSIX_V6_ILP32_OFF32, _SC_V6_ILP32_OFF32 _POSIX_V6_ILP32_OFFBIG, _SC_V6_ILP32_OFFBIG _POSIX_V6_LP64_OFF64, _SC_V6_LP64_OFF64 _POSIX_V6_LPBIG_OFFBIG, _SC_V6_LPBIG_OFFBIG _XOPEN_CRYPT, _SC_XOPEN_CRYPT _XOPEN_ENH_I18N, _SC_XOPEN_ENH_I18N _XOPEN_LEGACY, _SC_XOPEN_LEGACY _XOPEN_REALTIME, _SC_XOPEN_REALTIME _XOPEN_REALTIME_THREADS, _SC_XOPEN_REALTIME_THREADS _XOPEN_SHM, _SC_XOPEN_SHM _XOPEN_UNIX, _SC_XOPEN_UNIX _XOPEN_VERSION, _SC_XOPEN_VERSION _XOPEN_XCU_VERSION, _SC_XCU_VERSION %% int find_sysconf(const char *name, int *key) { const struct map *rv; rv = in_word_set(name); if (rv != NULL) { if (rv->valid) { *key = rv->key; return 1; } return -1; } return 0; } + +void +foreach_sysconf(void (*func)(const char *, int)) +{ + const struct map *mp; + + for (mp = wordlist; mp->name != NULL; mp++) { + if (mp->valid) + func(mp->name, mp->key); + } +} Index: stable/11 =================================================================== --- stable/11 (revision 324123) +++ stable/11 (revision 324124) Property changes on: stable/11 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r323631