-/* $OpenBSD: client.c,v 1.100 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: client.c,v 1.101 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
options_free(global_options);
options_free(global_s_options);
options_free(global_w_options);
- environ_free(&global_environ);
+ environ_free(global_environ);
/* Create stdin handler. */
setblocking(STDIN_FILENO, 0);
-/* $OpenBSD: cmd-attach-session.c,v 1.44 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: cmd-attach-session.c,v 1.45 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
if (!Eflag) {
update = options_get_string(s->options,
"update-environment");
- environ_update(update, &c->environ, &s->environ);
+ environ_update(update, c->environ, s->environ);
}
c->session = s;
if (!Eflag) {
update = options_get_string(s->options,
"update-environment");
- environ_update(update, &c->environ, &s->environ);
+ environ_update(update, c->environ, s->environ);
}
c->session = s;
-/* $OpenBSD: cmd-find.c,v 1.16 2015/10/27 13:23:24 nicm Exp $ */
+/* $OpenBSD: cmd-find.c,v 1.17 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@users.sourceforge.net>
u_int session;
struct session *s;
- envent = environ_find(&c->environ, "TMUX");
+ envent = environ_find(c->environ, "TMUX");
if (envent == NULL)
return (NULL);
-/* $OpenBSD: cmd-new-session.c,v 1.74 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.75 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
struct client *c = cmdq->client, *c0;
struct session *s, *groupwith;
struct window *w;
- struct environ env;
+ struct environ *env;
struct termios tio, *tiop;
const char *newname, *target, *update, *errstr, *template;
const char *path;
path = NULL;
if (c != NULL && c->session == NULL)
- envent = environ_find(&c->environ, "PATH");
+ envent = environ_find(c->environ, "PATH");
else
- envent = environ_find(&global_environ, "PATH");
+ envent = environ_find(global_environ, "PATH");
if (envent != NULL)
path = envent->value;
/* Construct the environment. */
- environ_init(&env);
+ env = environ_create();
if (c != NULL && !args_has(args, 'E')) {
update = options_get_string(global_s_options,
"update-environment");
- environ_update(update, &c->environ, &env);
+ environ_update(update, c->environ, env);
}
/* Create the new session. */
idx = -1 - options_get_number(global_s_options, "base-index");
- s = session_create(newname, argc, argv, path, cwd, &env, tiop, idx, sx,
+ s = session_create(newname, argc, argv, path, cwd, env, tiop, idx, sx,
sy, &cause);
+ environ_free(env);
if (s == NULL) {
cmdq_error(cmdq, "create session failed: %s", cause);
free(cause);
goto error;
}
- environ_free(&env);
/* Set the initial window name if one given. */
if (argc >= 0 && args_has(args, 'n')) {
-/* $OpenBSD: cmd-new-window.c,v 1.48 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.49 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL)
- envent = environ_find(&cmdq->client->environ, "PATH");
+ envent = environ_find(cmdq->client->environ, "PATH");
else
- envent = environ_find(&s->environ, "PATH");
+ envent = environ_find(s->environ, "PATH");
if (envent != NULL)
path = envent->value;
-/* $OpenBSD: cmd-respawn-pane.c,v 1.14 2015/03/31 17:45:10 nicm Exp $ */
+/* $OpenBSD: cmd-respawn-pane.c,v 1.15 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
struct window *w;
struct window_pane *wp;
struct session *s;
- struct environ env;
+ struct environ *env;
const char *path;
char *cause;
u_int idx;
return (CMD_RETURN_ERROR);
}
- environ_init(&env);
- environ_copy(&global_environ, &env);
- environ_copy(&s->environ, &env);
- server_fill_environ(s, &env);
+ env = environ_create();
+ environ_copy(global_environ, env);
+ environ_copy(s->environ, env);
+ server_fill_environ(s, env);
window_pane_reset_mode(wp);
screen_reinit(&wp->base);
path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL)
- envent = environ_find(&cmdq->client->environ, "PATH");
+ envent = environ_find(cmdq->client->environ, "PATH");
else
- envent = environ_find(&s->environ, "PATH");
+ envent = environ_find(s->environ, "PATH");
if (envent != NULL)
path = envent->value;
- if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, -1, &env,
+ if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, -1, env,
s->tio, &cause) != 0) {
cmdq_error(cmdq, "respawn pane failed: %s", cause);
free(cause);
- environ_free(&env);
+ environ_free(env);
return (CMD_RETURN_ERROR);
}
wp->flags |= PANE_REDRAW;
server_status_window(w);
- environ_free(&env);
+ environ_free(env);
return (CMD_RETURN_NORMAL);
}
-/* $OpenBSD: cmd-respawn-window.c,v 1.23 2014/10/20 22:29:25 nicm Exp $ */
+/* $OpenBSD: cmd-respawn-window.c,v 1.24 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
struct window *w;
struct window_pane *wp;
struct session *s;
- struct environ env;
+ struct environ *env;
const char *path;
char *cause;
struct environ_entry *envent;
}
}
- environ_init(&env);
- environ_copy(&global_environ, &env);
- environ_copy(&s->environ, &env);
- server_fill_environ(s, &env);
+ env = environ_create();
+ environ_copy(global_environ, env);
+ environ_copy(s->environ, env);
+ server_fill_environ(s, env);
wp = TAILQ_FIRST(&w->panes);
TAILQ_REMOVE(&w->panes, wp, entry);
path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL)
- envent = environ_find(&cmdq->client->environ, "PATH");
+ envent = environ_find(cmdq->client->environ, "PATH");
else
- envent = environ_find(&s->environ, "PATH");
+ envent = environ_find(s->environ, "PATH");
if (envent != NULL)
path = envent->value;
- if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, -1, &env,
+ if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, -1, env,
s->tio, &cause) != 0) {
cmdq_error(cmdq, "respawn window failed: %s", cause);
free(cause);
- environ_free(&env);
+ environ_free(env);
server_destroy_pane(wp);
return (CMD_RETURN_ERROR);
}
recalculate_sizes();
server_redraw_window(w);
- environ_free(&env);
+ environ_free(env);
return (CMD_RETURN_NORMAL);
}
-/* $OpenBSD: cmd-set-environment.c,v 1.10 2014/10/20 22:29:25 nicm Exp $ */
+/* $OpenBSD: cmd-set-environment.c,v 1.11 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
value = args->argv[1];
if (args_has(self->args, 'g'))
- env = &global_environ;
+ env = global_environ;
else {
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
- env = &s->environ;
+ env = s->environ;
}
if (args_has(self->args, 'u')) {
-/* $OpenBSD: cmd-show-environment.c,v 1.11 2015/08/30 15:43:40 nicm Exp $ */
+/* $OpenBSD: cmd-show-environment.c,v 1.12 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
struct environ_entry *envent;
if (args_has(self->args, 'g'))
- env = &global_environ;
+ env = global_environ;
else {
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
- env = &s->environ;
+ env = s->environ;
}
if (args->argc != 0) {
return (CMD_RETURN_NORMAL);
}
- RB_FOREACH(envent, environ, env)
+ envent = environ_first(env);
+ while (envent != NULL) {
cmd_show_environment_print(self, cmdq, envent);
+ envent = environ_next(envent);
+ }
return (CMD_RETURN_NORMAL);
}
-/* $OpenBSD: cmd-split-window.c,v 1.59 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: cmd-split-window.c,v 1.60 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
struct winlink *wl;
struct window *w;
struct window_pane *wp, *new_wp = NULL;
- struct environ env;
+ struct environ *env;
const char *cmd, *path, *shell, *template;
char **argv, *cause, *new_cause, *cp;
u_int hlimit;
w = wl->window;
server_unzoom_window(w);
- environ_init(&env);
- environ_copy(&global_environ, &env);
- environ_copy(&s->environ, &env);
- server_fill_environ(s, &env);
+ env = environ_create();
+ environ_copy(global_environ, env);
+ environ_copy(s->environ, env);
+ server_fill_environ(s, env);
if (args->argc == 0) {
cmd = options_get_string(s->options, "default-command");
path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL)
- envent = environ_find(&cmdq->client->environ, "PATH");
+ envent = environ_find(cmdq->client->environ, "PATH");
else
- envent = environ_find(&s->environ, "PATH");
+ envent = environ_find(s->environ, "PATH");
if (envent != NULL)
path = envent->value;
- if (window_pane_spawn(new_wp, argc, argv, path, shell, cwd, &env,
+ if (window_pane_spawn(new_wp, argc, argv, path, shell, cwd, env,
s->tio, &cause) != 0)
goto error;
} else
server_status_session(s);
- environ_free(&env);
+ environ_free(env);
if (args_has(args, 'P')) {
if ((template = args_get(args, 'F')) == NULL)
return (CMD_RETURN_NORMAL);
error:
- environ_free(&env);
+ environ_free(env);
if (new_wp != NULL) {
layout_close_pane(new_wp);
window_remove_pane(w, new_wp);
-/* $OpenBSD: cmd-string.c,v 1.20 2014/10/08 17:35:58 nicm Exp $ */
+/* $OpenBSD: cmd-string.c,v 1.21 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
whitespace = argv[0] + strcspn(argv[0], " \t");
if (equals == NULL || equals > whitespace)
break;
- environ_put(&global_environ, argv[0]);
+ environ_put(global_environ, argv[0]);
argc--;
memmove(argv, argv + 1, argc * (sizeof *argv));
}
buf = xrealloc(buf, len + 1);
buf[len] = '\0';
- envent = environ_find(&global_environ, buf);
+ envent = environ_find(global_environ, buf);
free(buf);
if (envent == NULL)
return (xstrdup(""));
last = cmd_string_getc(s, p);
if (last == EOF || last == '/' || last == ' '|| last == '\t') {
- envent = environ_find(&global_environ, "HOME");
+ envent = environ_find(global_environ, "HOME");
if (envent != NULL && *envent->value != '\0')
home = envent->value;
else if ((pw = getpwuid(getuid())) != NULL)
-/* $OpenBSD: cmd-switch-client.c,v 1.32 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: cmd-switch-client.c,v 1.33 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
if (c != NULL && !args_has(args, 'E')) {
update = options_get_string(s->options, "update-environment");
- environ_update(update, &c->environ, &s->environ);
+ environ_update(update, c->environ, s->environ);
}
if (c->session != NULL && c->session != s)
-/* $OpenBSD: environ.c,v 1.8 2015/05/07 07:35:31 nicm Exp $ */
+/* $OpenBSD: environ.c,v 1.9 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
* Environment - manipulate a set of environment variables.
*/
+RB_HEAD(environ, environ_entry);
+int environ_cmp(struct environ_entry *, struct environ_entry *);
+RB_PROTOTYPE(environ, environ_entry, entry, environ_cmp);
RB_GENERATE(environ, environ_entry, entry, environ_cmp);
int
}
/* Initialise the environment. */
-void
-environ_init(struct environ *env)
+struct environ *
+environ_create(void)
{
+ struct environ *env;
+
+ env = xcalloc(1, sizeof *env);
RB_INIT(env);
+
+ return (env);
}
/* Free an environment. */
void
environ_free(struct environ *env)
{
- struct environ_entry *envent;
+ struct environ_entry *envent, *envent1;
- while (!RB_EMPTY(env)) {
- envent = RB_ROOT(env);
+ RB_FOREACH_SAFE(envent, environ, env, envent1) {
RB_REMOVE(environ, env, envent);
free(envent->name);
free(envent->value);
free(envent);
}
+ free(env);
+}
+
+struct environ_entry *
+environ_first(struct environ *env)
+{
+ return (RB_MIN(environ, env));
+}
+
+struct environ_entry *
+environ_next(struct environ_entry *envent)
+{
+ return (RB_NEXT(environ, env, envent));
}
/* Copy one environment into another. */
-/* $OpenBSD: format.c,v 1.90 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.91 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
if (~modifiers & FORMAT_TIMESTRING) {
envent = NULL;
if (ft->s != NULL)
- envent = environ_find(&ft->s->environ, key);
+ envent = environ_find(ft->s->environ, key);
if (envent == NULL)
- envent = environ_find(&global_environ, key);
+ envent = environ_find(global_environ, key);
if (envent != NULL) {
found = envent->value;
goto found;
-/* $OpenBSD: job.c,v 1.36 2015/06/17 16:44:49 nicm Exp $ */
+/* $OpenBSD: job.c,v 1.37 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
void (*callbackfn)(struct job *), void (*freefn)(void *), void *data)
{
struct job *job;
- struct environ env;
+ struct environ *env;
pid_t pid;
int nullfd, out[2];
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0)
return (NULL);
- environ_init(&env);
- environ_copy(&global_environ, &env);
+ env = environ_create();
+ environ_copy(global_environ, env);
if (s != NULL)
- environ_copy(&s->environ, &env);
- server_fill_environ(s, &env);
+ environ_copy(s->environ, env);
+ server_fill_environ(s, env);
switch (pid = fork()) {
case -1:
- environ_free(&env);
+ environ_free(env);
close(out[0]);
close(out[1]);
return (NULL);
if (cwd != -1 && fchdir(cwd) != 0)
chdir("/");
- environ_push(&env);
- environ_free(&env);
+ environ_push(env);
+ environ_free(env);
if (dup2(out[1], STDIN_FILENO) == -1)
fatal("dup2 failed");
}
/* parent */
- environ_free(&env);
+ environ_free(env);
close(out[1]);
job = xmalloc(sizeof *job);
-/* $OpenBSD: server-client.c,v 1.163 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.164 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
if (c->tty.path == NULL)
return (0);
- envent = environ_find(&c->environ, "TMUX");
+ envent = environ_find(c->environ, "TMUX");
if (envent == NULL || *envent->value == '\0')
return (0);
fatal("gettimeofday failed");
memcpy(&c->activity_time, &c->creation_time, sizeof c->activity_time);
- environ_init(&c->environ);
+ c->environ = environ_create();
c->fd = -1;
c->cwd = -1;
cmdq_free(c->cmdq);
c->cmdq = NULL;
- environ_free(&c->environ);
+ environ_free(c->environ);
proc_remove_peer(c->peer);
c->peer = NULL;
if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_IDENTIFY_ENVIRON string");
if (strchr(data, '=') != NULL)
- environ_put(&c->environ, data);
+ environ_put(c->environ, data);
log_debug("client %p IDENTIFY_ENVIRON %s", c, data);
break;
case MSG_IDENTIFY_CLIENTPID:
-/* $OpenBSD: session.c,v 1.56 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.57 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
TAILQ_INIT(&s->lastw);
RB_INIT(&s->windows);
- environ_init(&s->environ);
+ s->environ = environ_create();
if (env != NULL)
- environ_copy(env, &s->environ);
+ environ_copy(env, s->environ);
s->options = options_create(global_s_options);
s->tio = NULL;
log_debug("session %s freed (%d references)", s->name, s->references);
if (s->references == 0) {
- environ_free(&s->environ);
+ environ_free(s->environ);
options_free(s->options);
free(s->name);
{
struct window *w;
struct winlink *wl;
- struct environ env;
+ struct environ *env;
const char *shell;
u_int hlimit;
return (NULL);
}
- environ_init(&env);
- environ_copy(&global_environ, &env);
- environ_copy(&s->environ, &env);
- server_fill_environ(s, &env);
+ env = environ_create();
+ environ_copy(global_environ, env);
+ environ_copy(s->environ, env);
+ server_fill_environ(s, env);
shell = options_get_string(s->options, "default-shell");
if (*shell == '\0' || areshell(shell))
shell = _PATH_BSHELL;
hlimit = options_get_number(s->options, "history-limit");
- w = window_create(name, argc, argv, path, shell, cwd, &env, s->tio,
+ w = window_create(name, argc, argv, path, shell, cwd, env, s->tio,
s->sx, s->sy, hlimit, cause);
if (w == NULL) {
winlink_remove(&s->windows, wl);
- environ_free(&env);
+ environ_free(env);
return (NULL);
}
winlink_set_window(wl, w);
notify_window_linked(s, w);
- environ_free(&env);
+ environ_free(env);
if (options_get_number(s->options, "set-remain-on-exit"))
options_set_number(w->options, "remain-on-exit", 1);
-/* $OpenBSD: tmux.c,v 1.148 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.149 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
struct options *global_options; /* server options */
struct options *global_s_options; /* session options */
struct options *global_w_options; /* window options */
-struct environ global_environ;
+struct environ *global_environ;
char *shell_cmd;
int debug_level;
flags |= CLIENT_UTF8;
}
- environ_init(&global_environ);
+ global_environ = environ_create();
for (var = environ; *var != NULL; var++)
- environ_put(&global_environ, *var);
+ environ_put(global_environ, *var);
if (getcwd(tmp, sizeof tmp) != NULL)
- environ_set(&global_environ, "PWD", tmp);
+ environ_set(global_environ, "PWD", tmp);
global_options = options_create(NULL);
options_table_populate_tree(server_options_table, global_options);
-/* $OpenBSD: tmux.h,v 1.567 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.568 2015/10/28 09:51:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
extern char *__progname;
extern char **environ;
+struct client;
+struct environ;
+struct input_ctx;
+struct mouse_event;
+struct options;
+struct session;
+struct tmuxpeer;
+struct tmuxproc;
+
/* Default global configuration file. */
#define TMUX_CONF "/etc/tmux.conf"
* Window mode. Windows can be in several modes and this is used to call the
* right function to handle input and output.
*/
-struct client;
-struct session;
-struct mouse_event;
struct window_mode {
struct screen *(*init)(struct window_pane *);
void (*free)(struct window_pane *);
};
/* Child window structure. */
-struct input_ctx;
struct window_pane {
u_int id;
u_int active_point;
RB_HEAD(window_pane_tree, window_pane);
/* Window structure. */
-struct options;
struct window {
u_int id;
RB_ENTRY(environ_entry) entry;
};
-RB_HEAD(environ, environ_entry);
/* Client session. */
struct session_group {
struct termios *tio;
- struct environ environ;
+ struct environ *environ;
int references;
};
/* Client connection. */
-struct tmuxproc;
-struct tmuxpeer;
struct client {
struct tmuxpeer *peer;
struct timeval creation_time;
struct timeval activity_time;
- struct environ environ;
+ struct environ *environ;
char *title;
int cwd;
extern struct options *global_options;
extern struct options *global_s_options;
extern struct options *global_w_options;
-extern struct environ global_environ;
+extern struct environ *global_environ;
extern char *shell_cmd;
extern int debug_level;
extern time_t start_time;
void job_died(struct job *, int);
/* environ.c */
-int environ_cmp(struct environ_entry *, struct environ_entry *);
-RB_PROTOTYPE(environ, environ_entry, entry, environ_cmp);
-void environ_init(struct environ *);
+struct environ *environ_create(void);
void environ_free(struct environ *);
+struct environ_entry *environ_first(struct environ *);
+struct environ_entry *environ_next(struct environ_entry *);
void environ_copy(struct environ *, struct environ *);
struct environ_entry *environ_find(struct environ *, const char *);
void environ_set(struct environ *, const char *, const char *);