diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-09-16 22:29:31 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-09-16 22:29:31 +0000 |
commit | 8b15943f7a16cf494b470c2592a9c2b2cf0b957f (patch) | |
tree | 8d8b622401ea6ba26962fe897122dbae43923136 /usr.bin/tmux | |
parent | be4e4dd129be0242558cbefa0c3a1f256120a5ae (diff) |
Hoist some common code out of both branches of an if/else.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/cmd-attach-session.c | 56 |
1 files changed, 19 insertions, 37 deletions
diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c index df7f08d6657..37ad2ce3e43 100644 --- a/usr.bin/tmux/cmd-attach-session.c +++ b/usr.bin/tmux/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-attach-session.c,v 1.41 2015/09/10 08:58:14 nicm Exp $ */ +/* $OpenBSD: cmd-attach-session.c,v 1.42 2015/09/16 22:29:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -93,6 +93,24 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, session_set_current(s, wl); } + if (cflag != NULL) { + ft = format_create(); + format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, + NULL, NULL); + cp = format_expand(ft, cflag); + format_free(ft); + + fd = open(cp, O_RDONLY|O_DIRECTORY); + free(cp); + if (fd == -1) { + cmdq_error(cmdq, "bad working directory: %s", + strerror(errno)); + return (CMD_RETURN_ERROR); + } + close(s->cwd); + s->cwd = fd; + } + if (c->session != NULL) { if (dflag) { /* @@ -108,24 +126,6 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, } } - if (cflag != NULL) { - ft = format_create(); - format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, - NULL, NULL); - cp = format_expand(ft, cflag); - format_free(ft); - - fd = open(cp, O_RDONLY|O_DIRECTORY); - free(cp); - if (fd == -1) { - cmdq_error(cmdq, "bad working directory: %s", - strerror(errno)); - return (CMD_RETURN_ERROR); - } - close(s->cwd); - s->cwd = fd; - } - if (!Eflag) { update = options_get_string(&s->options, "update-environment"); @@ -146,24 +146,6 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, return (CMD_RETURN_ERROR); } - if (cflag != NULL) { - ft = format_create(); - format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, - NULL, NULL); - cp = format_expand(ft, cflag); - format_free(ft); - - fd = open(cp, O_RDONLY|O_DIRECTORY); - free(cp); - if (fd == -1) { - cmdq_error(cmdq, "bad working directory: %s", - strerror(errno)); - return (CMD_RETURN_ERROR); - } - close(s->cwd); - s->cwd = fd; - } - if (rflag) c->flags |= CLIENT_READONLY; |