From 42d080fef4cc63e2cb5f660d8d95357104160216 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 2 Oct 2018 16:19:18 -0700 Subject: getconf: add pathconf(3) variables. Also improve the -l output to include sections (because you need to know whether you're dealing with a pathconf variable to supply the required path). --- toys/posix/getconf.c | 87 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 33 deletions(-) (limited to 'toys/posix/getconf.c') diff --git a/toys/posix/getconf.c b/toys/posix/getconf.c index a9ef298a..d10365b5 100644 --- a/toys/posix/getconf.c +++ b/toys/posix/getconf.c @@ -6,17 +6,19 @@ * * Deviations from posix: no -v because nothing says what it should DO. -USE_GETCONF(NEWTOY(getconf, "l", TOYFLAG_USR|TOYFLAG_BIN)) +USE_GETCONF(NEWTOY(getconf, ">2l", TOYFLAG_USR|TOYFLAG_BIN)) config GETCONF bool "getconf" default y help - usage: getconf [-l] [NAME...] + usage: getconf -l + usage: getconf NAME + usage: getconf NAME PATH - Get system configuration values. + Get system configuration values. Values from pathconf(3) require a path. - -l List available value names + -l List available value names (grouped by source) */ #define FOR_getconf @@ -94,6 +96,16 @@ struct config sysconfs[] = { CONF(NPROCESSORS_ONLN) }; +// Probe the live system with a path +struct config pathconfs[] = { +#undef CONF +#define CONF(n) {#n,_PC_ ## n} + CONF(ASYNC_IO), CONF(CHOWN_RESTRICTED), CONF(FILESIZEBITS), CONF(LINK_MAX), + CONF(MAX_CANON), CONF(MAX_INPUT), CONF(NAME_MAX), CONF(NO_TRUNC), + CONF(PATH_MAX), CONF(PIPE_BUF), CONF(PRIO_IO), CONF(SYMLINK_MAX), + CONF(SYNC_IO), CONF(VDISABLE), +}; + // Strings out of a header struct config confstrs[] = { #undef CONF @@ -130,41 +142,50 @@ struct config others[] = { void getconf_main(void) { - struct config *configs[] = {sysconfs, confstrs, limits, others}; - char **args; - int i, j, lens[] = {ARRAY_LEN(sysconfs), ARRAY_LEN(confstrs), - ARRAY_LEN(limits), ARRAY_LEN(others)}; + struct config *configs[] = {sysconfs, pathconfs, confstrs, limits, others}, + *c = NULL; + int i, j, lens[] = {ARRAY_LEN(sysconfs), ARRAY_LEN(pathconfs), + ARRAY_LEN(confstrs), ARRAY_LEN(limits), ARRAY_LEN(others)}; + char *name, *config_names[] = {"sysconf(3)", "pathconf(3)", "confstr(3)", + "", "Misc"}; if (toys.optflags&FLAG_l) { - for (i = 0; i<4; i++) for (j = 0; jname, name)) continue; - - if (!i) printf("%ld\n", sysconf(c->value)); - else if (i==1) { - confstr(c->value, toybuf, sizeof(toybuf)); - puts(toybuf); - } else if (i==2) printf("%d\n", c->value); - // For legacy kernel build - else if (sizeof(long)==4 && !j) - puts("-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"); - - goto cont; - } - error_msg("bad '%s'", name); -cont: - ; + // Find the config. + for (i = 0; i<5; i++) for (j = 0; jname, name)) goto found; + } + error_msg("bad '%s'", name); + + found: + // Check that we do/don't have the extra path argument. + if (i==1) { + if (toys.optc!=2) help_exit("%s needs a path", name); + } else if (toys.optc!=1) help_exit("%s does not take a path", name); + + if (!i) printf("%ld\n", sysconf(c->value)); + else if (i==1) printf("%ld\n", pathconf(toys.optargs[1], c->value)); + else if (i==2) { + confstr(c->value, toybuf, sizeof(toybuf)); + puts(toybuf); + } else if (i==3) printf("%d\n", c->value); + // For legacy kernel build + else if (sizeof(long)==4 && !j) { + puts("-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"); } } -- cgit v1.2.3