.Nd get and set user and system-wide variables for variant symlinks
.Sh SYNOPSIS
.Nm
-.Op Fl adpqsu
+.Op Fl adpqsux
.Oo
.Ar var Ns Op Ns Cm = Ns Ar data
.Ar ...
.Oc
+.Nm
+.Fl x
+.Oo
+.Ar var Ns Op Ns Cm = Ns Ar data
+.Ar ...
+.Oc
+.Ar command
+.Ar args
.Sh DESCRIPTION
The
.Nm
.Nm
is run as its own process, using this option to set a variable will not
affect your shell's namespace.
+Instead you might want to use the
+.Fl x
+option to set local varsyms and exec a command.
.It Fl q
Quiet mode.
When retrieving a variable only its data is printed.
.It Fl u
This option causes variables to be set on a per-user-id basis and restricts
retrievals to user-specific variables.
-This is the default.
+This is the default unless
+.Fl x
+is used.
+.It Fl x
+This option causes variables to be set only within the
+.Nm
+process and its children, and also allows you to specify a command and
+arguments to exec after the var=data specifications.
.El
.Sh DIAGNOSTICS
The
#include <unistd.h>
#include <sys/varsym.h>
-static void usage(void);
static void dumpvars(char *buf, int bytes);
+static int doexec(char **av);
+static void usage(void);
int
main(int ac, char **av)
int deleteOpt = 0;
int verboseOpt = 1;
int allOpt = 0;
+ int execok = 0;
- while ((i = getopt(ac, av, "adhpqsu")) != -1) {
+ while ((i = getopt(ac, av, "adhpqsux")) != -1) {
switch (i) {
case 'a':
allOpt = 1;
mask = VARSYM_USER_MASK;
level = VARSYM_USER;
break;
+ case 'x':
+ mask = VARSYM_PROC_MASK;
+ level = VARSYM_PROC;
+ execok = 1;
+ break;
case 'h':
default:
usage();
if (data)
*data++ = 0;
- if (deleteOpt) {
+ if (execok) {
+ if (deleteOpt) {
+ usage();
+ exit(1);
+ }
+ if (data) {
+ error = varsym_set(level, name, data);
+ } else {
+ error = doexec(av + optind);
+ }
+ } else if (deleteOpt) {
error = varsym_set(level, name, NULL);
- }
- else if (data) {
+ } else if (data) {
error = varsym_set(level, name, data);
- }
- else {
+ } else {
error = varsym_get(mask, name, buf, sizeof(buf));
if (error >= 0 && error <= (int)sizeof(buf)) {
if (verboseOpt)
static void
dumpvars(char *buf, int bytes)
{
- int b;
- int i;
- char *vname = NULL;
- char *vdata = NULL;
-
- for (b = i = 0; i < bytes; ++i) {
- if (buf[i] == 0) {
- if (vname == NULL) {
- vname = buf + b;
- } else {
- vdata = buf + b;
- printf("%s=%s\n", vname, vdata);
- vname = vdata = NULL;
- }
- b = i + 1;
+ int b;
+ int i;
+ char *vname = NULL;
+ char *vdata = NULL;
+
+ for (b = i = 0; i < bytes; ++i) {
+ if (buf[i] == 0) {
+ if (vname == NULL) {
+ vname = buf + b;
+ } else {
+ vdata = buf + b;
+ printf("%s=%s\n", vname, vdata);
+ vname = vdata = NULL;
+ }
+ b = i + 1;
+ }
}
- }
+}
+
+static int
+doexec(char **av)
+{
+ int error;
+
+ error = execvp(av[0], av);
+ return (error);
}
static void