diff options
Diffstat (limited to 'tmux.c')
-rw-r--r-- | tmux.c | 72 |
1 files changed, 23 insertions, 49 deletions
@@ -48,11 +48,8 @@ time_t start_time; char socket_path[MAXPATHLEN]; int login_shell; char *environ_path; -pid_t environ_pid = -1; -int environ_session_id = -1; __dead void usage(void); -void parseenvironment(void); char *makesocketpath(const char *); #ifndef HAVE___PROGNAME @@ -127,39 +124,6 @@ areshell(const char *shell) return (0); } -const char* -get_full_path(const char *wd, const char *path) -{ - static char newpath[MAXPATHLEN]; - char oldpath[MAXPATHLEN]; - - if (getcwd(oldpath, sizeof oldpath) == NULL) - return (NULL); - if (chdir(wd) != 0) - return (NULL); - if (realpath(path, newpath) != 0) - return (NULL); - chdir(oldpath); - return (newpath); -} - -void -parseenvironment(void) -{ - char *env, path[256]; - long pid; - int id; - - if ((env = getenv("TMUX")) == NULL) - return; - - if (sscanf(env, "%255[^,],%ld,%d", path, &pid, &id) != 3) - return; - environ_path = xstrdup(path); - environ_pid = pid; - environ_session_id = id; -} - char * makesocketpath(const char *label) { @@ -184,7 +148,8 @@ makesocketpath(const char *label) errno = ENOTDIR; return (NULL); } - if (sb.st_uid != uid || (sb.st_mode & (S_IRWXG|S_IRWXO)) != 0) { + if (sb.st_uid != uid || (!S_ISDIR(sb.st_mode) && + sb.st_mode & (S_IRWXG|S_IRWXO)) != 0) { errno = EACCES; return (NULL); } @@ -240,8 +205,10 @@ int main(int argc, char **argv) { struct passwd *pw; - char *s, *path, *label, *home, **var; - int opt, flags, quiet, keys; + char *s, *path, *label, *home, **var, tmp[MAXPATHLEN]; + char in[256]; + long long pid; + int opt, flags, quiet, keys, session; #if defined(DEBUG) && defined(__OpenBSD__) malloc_options = (char *) "AFGJPX"; @@ -255,17 +222,17 @@ main(int argc, char **argv) while ((opt = getopt(argc, argv, "2c:Cdf:lL:qS:uUVv")) != -1) { switch (opt) { case '2': - flags |= IDENTIFY_256COLOURS; + flags |= CLIENT_256COLOURS; break; case 'c': free(shell_cmd); shell_cmd = xstrdup(optarg); break; case 'C': - if (flags & IDENTIFY_CONTROL) - flags |= IDENTIFY_TERMIOS; + if (flags & CLIENT_CONTROL) + flags |= CLIENT_CONTROLCONTROL; else - flags |= IDENTIFY_CONTROL; + flags |= CLIENT_CONTROL; break; case 'V': printf("%s %s\n", __progname, VERSION); @@ -289,7 +256,7 @@ main(int argc, char **argv) path = xstrdup(optarg); break; case 'u': - flags |= IDENTIFY_UTF8; + flags |= CLIENT_UTF8; break; case 'v': debug_level++; @@ -304,7 +271,7 @@ main(int argc, char **argv) if (shell_cmd != NULL && argc != 0) usage(); - if (!(flags & IDENTIFY_UTF8)) { + if (!(flags & CLIENT_UTF8)) { /* * If the user has set whichever of LC_ALL, LC_CTYPE or LANG * exist (in that order) to contain UTF-8, it is a safe @@ -318,12 +285,14 @@ main(int argc, char **argv) } if (s != NULL && (strcasestr(s, "UTF-8") != NULL || strcasestr(s, "UTF8") != NULL)) - flags |= IDENTIFY_UTF8; + flags |= CLIENT_UTF8; } environ_init(&global_environ); for (var = environ; *var != NULL; var++) environ_put(&global_environ, *var); + if (getcwd(tmp, sizeof tmp) != NULL) + environ_set(&global_environ, "PWD", tmp); options_init(&global_options, NULL); options_table_populate_tree(server_options_table, &global_options); @@ -337,7 +306,7 @@ main(int argc, char **argv) options_table_populate_tree(window_options_table, &global_w_options); /* Enable UTF-8 if the first client is on UTF-8 terminal. */ - if (flags & IDENTIFY_UTF8) { + if (flags & CLIENT_UTF8) { options_set_number(&global_s_options, "status-utf8", 1); options_set_number(&global_s_options, "mouse-utf8", 1); options_set_number(&global_w_options, "utf8", 1); @@ -370,11 +339,15 @@ main(int argc, char **argv) } } + /* Get path from environment. */ + s = getenv("TMUX"); + if (s != NULL && sscanf(s, "%255[^,],%lld,%d", in, &pid, &session) == 3) + environ_path = xstrdup(in); + /* * Figure out the socket path. If specified on the command-line with -S * or -L, use it, otherwise try $TMUX or assume -L default. */ - parseenvironment(); if (path == NULL) { /* If no -L, use the environment. */ if (label == NULL) { @@ -387,7 +360,8 @@ main(int argc, char **argv) /* -L or default set. */ if (label != NULL) { if ((path = makesocketpath(label)) == NULL) { - fprintf(stderr, "can't create socket\n"); + fprintf(stderr, "can't create socket: %s\n", + strerror(errno)); exit(1); } } |