summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2018-08-21 05:46:07 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2018-08-21 05:46:07 -0500
commite6d152980fb19a38525ed107a31d0b8997ab549e (patch)
tree4a65a0ce3d709bb713bf7786f53210ae4a0e6cca
parentdf2737fd0a3d597b91934794a5ae61f81eba6df8 (diff)
downloadshimmy-e6d152980fb19a38525ed107a31d0b8997ab549e.tar.gz
shimmy-e6d152980fb19a38525ed107a31d0b8997ab549e.tar.bz2
shimmy-e6d152980fb19a38525ed107a31d0b8997ab549e.tar.xz
shimmy-e6d152980fb19a38525ed107a31d0b8997ab549e.zip
getconf: Support path variables
-rw-r--r--getconf/getconf.124
-rw-r--r--getconf/getconf.c57
2 files changed, 61 insertions, 20 deletions
diff --git a/getconf/getconf.1 b/getconf/getconf.1
index 35f9c13..58341ff 100644
--- a/getconf/getconf.1
+++ b/getconf/getconf.1
@@ -1,21 +1,17 @@
-.Dd April 9, 2016
+.Dd August 21, 2018
.Dt GETCONF 1 "Base Commands Manual"
.Os "Adélie Linux"
-
.Sh NAME
.Nm getconf
.Nd get system configuration values
-
.Sh SYNOPSIS
.Nm
.Op Fl v Ar specification
.Ar system_var
-
.Nm
.Op Fl v Ar specification
.Ar path_var
.Ar pathname
-
.Sh DESCRIPTION
In the first form, the
.Nm
@@ -24,9 +20,9 @@ utility prints the value of the system variable specified by
on the currently running system, under the specification given for the
.Fl v
argument if specified.
-
+.Pp
Valid system variables are one of the following:
-
+.Pp
.Bl -bullet -offset indent -compact
.It
The variable name of a valid parameter to the
@@ -58,7 +54,7 @@ header as specified in
.St -p1003.1-2008 ,
excluding braces.
.El
-
+.Pp
In the second form, the
.Nm
utility prints the value of the path variable specified by
@@ -68,43 +64,33 @@ for the path specified by
on the currently running system, under the specification given for the
.Fl v
argument if specified.
-
+.Pp
Valid path variables are those accepted by the
.Xr fpathconf 3
function as specified in
.St -p1003.1-2008 ,
exluding braces.
-
.Sh OPTIONS
.Bl -tag
.It -v
Indicates the specification to use. Currently, this option is unsupported and
will be ignored.
.El
-
.Sh DIAGNOSTICS
.Ex -std
-
.Sh SEE ALSO
-
.Xr confstr 3 ,
.Xr fpathconf 3 ,
.Xr sysconf 3 .
-
.Sh STANDARDS
The eventual goal for the
.Nm
utility is full conformance to
.St -p1003.1 2013 Edition.
-
.Sh AUTHORS
.An A. Wilcox
.Aq awilfox@adelielinux.org
-
.Sh BUGS
The
.Fl v
argument is not currently handled correctly.
-.Pp
-.Ar path_var
-variables are not yet supported.
diff --git a/getconf/getconf.c b/getconf/getconf.c
index 8ede268..01265f1 100644
--- a/getconf/getconf.c
+++ b/getconf/getconf.c
@@ -393,6 +393,27 @@ const var_map_t limit_vars[] = {
const int limit_count = sizeof(limit_vars) / sizeof(limit_vars[0]);
+const var_map_t path_vars[] = {
+ { "FILESIZEBITS", _PC_FILESIZEBITS },
+ { "LINK_MAX", _PC_LINK_MAX },
+ { "MAX_CANON", _PC_MAX_CANON },
+ { "MAX_INPUT", _PC_MAX_INPUT },
+ { "NAME_MAX", _PC_NAME_MAX },
+ { "PATH_MAX", _PC_PATH_MAX },
+ { "PIPE_BUF", _PC_PIPE_BUF },
+ { "POSIX2_SYMLINKS", _PC_2_SYMLINKS },
+ { "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 }
+};
+
+
+const int path_count = sizeof(path_vars) / sizeof (path_vars[0]);
+
+
int do_system_var(char *environment, char *system_var)
{
int var;
@@ -499,7 +520,41 @@ int do_system_var(char *environment, char *system_var)
int do_path_var(char *environment, char *path_var, char *pathname)
{
- return -1;
+ int var;
+
+ for(var = 0; var < path_count; var++)
+ {
+ long int result;
+
+ if(strcasecmp(path_vars[var].variable, path_var) != 0)
+ {
+ continue;
+ }
+
+ if(path_vars[var].value == _UNDEFINED_VARIABLE_)
+ {
+ printf("undefined\n");
+ return 0;
+ }
+
+ errno = 0;
+
+ result = pathconf(pathname, path_vars[var].value);
+ if(errno != 0)
+ {
+ /* We know that this is a valid symbol, so don't break
+ * expectations.
+ */
+ printf("undefined\n");
+ return 0;
+ }
+
+ printf("%ld\n", result);
+ return 0;
+ }
+
+ fprintf(stderr, "%s: not a recognised system variable\n", path_var);
+ return EINVAL;
}