summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-string.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2009-08-08 21:52:43 +0000
committernicm <nicm@openbsd.org>2009-08-08 21:52:43 +0000
commit6f7d62ebc9d2569213457966b9dab344dd30c124 (patch)
treedb1575bc7a8f723d64cf32fa11b69f42b628e4dd /usr.bin/tmux/cmd-string.c
parentTidy function a little by using a temporary variable. (diff)
downloadwireguard-openbsd-6f7d62ebc9d2569213457966b9dab344dd30c124.tar.xz
wireguard-openbsd-6f7d62ebc9d2569213457966b9dab344dd30c124.zip
Infrastructure and commands to manage the environment for processes started
within tmux. There is a global environment, copied from the external environment when the server is started and each sesssion has an (initially empty) session environment which overrides it. New commands set-environment and show-environment manipulate or display the environments. A new session option, update-environment, is a space-separated list of variables which are updated from the external environment into the session environment every time a new session is created - the default is DISPLAY.
Diffstat (limited to 'usr.bin/tmux/cmd-string.c')
-rw-r--r--usr.bin/tmux/cmd-string.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/usr.bin/tmux/cmd-string.c b/usr.bin/tmux/cmd-string.c
index 2094d35b9c6..450279b1c4c 100644
--- a/usr.bin/tmux/cmd-string.c
+++ b/usr.bin/tmux/cmd-string.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-string.c,v 1.5 2009/08/03 14:10:54 nicm Exp $ */
+/* $OpenBSD: cmd-string.c,v 1.6 2009/08/08 21:52:43 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -59,21 +59,11 @@ int
cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
{
size_t p;
- int ch, argc, rval, have_arg;
- char **argv, *buf, *t, *u;
+ int ch, i, argc, rval, have_arg;
+ char **argv, *buf, *t;
+ const char *whitespace, *equals;
size_t len;
- if ((t = strchr(s, ' ')) == NULL && (t = strchr(s, '\t')) == NULL)
- t = strchr(s, '\0');
- if ((u = strchr(s, '=')) != NULL && u < t) {
- if (putenv(xstrdup(s)) != 0) {
- xasprintf(cause, "assignment failed: %s", s);
- return (-1);
- }
- *cmdlist = NULL;
- return (0);
- }
-
argv = NULL;
argc = 0;
@@ -147,6 +137,18 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
if (argc == 0)
goto out;
+ for (i = 0; i < argc; i++) {
+ equals = strchr(argv[i], '=');
+ whitespace = argv[i] + strcspn(argv[i], " \t");
+ if (equals == NULL || equals > whitespace)
+ break;
+ environ_put(&global_environ, argv[i]);
+ memmove(&argv[i], &argv[i + 1], argc - i - 1);
+ argc--;
+ }
+ if (argc == 0)
+ goto out;
+
*cmdlist = cmd_list_parse(argc, argv, cause);
if (*cmdlist == NULL)
goto out;