summaryrefslogtreecommitdiffstats
path: root/cmd-string.c
authortcunha <tcunha>2009-08-09 17:48:55 (GMT)
committer tcunha <tcunha>2009-08-09 17:48:55 (GMT)
commit8769c1f9a8aabb212ff0299f082a4d579cff352c (patch) (side-by-side diff)
tree06e44c9058a0cc8c581b8b97415a1a2c697fefeb /cmd-string.c
parentf404e4caff4618405b94478a0d5f258895c0bc7c (diff)
downloadtmux-old-8769c1f9a8aabb212ff0299f082a4d579cff352c.zip
tmux-old-8769c1f9a8aabb212ff0299f082a4d579cff352c.tar.gz
tmux-old-8769c1f9a8aabb212ff0299f082a4d579cff352c.tar.bz2
Sync OpenBSD patchset 231:
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 session 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 'cmd-string.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cmd-string.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/cmd-string.c b/cmd-string.c
index eabc338..d6bbc97 100644
--- a/cmd-string.c
+++ b/cmd-string.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-string.c,v 1.22 2009/08/09 15:26:24 tcunha Exp $ */
+/* $Id: cmd-string.c,v 1.23 2009/08/09 17:48:55 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <[email protected]>
@@ -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;