void tmate_session_init(void) { tmate_catch_sigsegv(); tmate_encoder_init(&tmate_session.encoder); tmate_decoder_init(&tmate_session.decoder); TAILQ_INIT(&tmate_session.clients); tmate_session.need_passphrase = 0; tmate_session.passphrase = NULL; /* The header will be written as soon as the first client connects */ tmate_write_header(); }
int main(int argc, char **argv) { char *path, *label, **var, tmp[PATH_MAX], *shellcmd = NULL; const char *s; int opt, flags, keys; #if defined(DEBUG) && defined(__OpenBSD__) malloc_options = (char *) "AFGJPX"; #endif setlocale(LC_TIME, ""); tzset(); if (**argv == '-') flags = CLIENT_LOGIN; else flags = 0; #ifdef TMATE tmate_catch_sigsegv(); flags |= CLIENT_256COLOURS | CLIENT_UTF8; #endif label = path = NULL; while ((opt = getopt(argc, argv, "2c:Cdf:lL:qS:uUVv")) != -1) { switch (opt) { case '2': flags |= CLIENT_256COLOURS; break; case 'c': free(shellcmd); shellcmd = xstrdup(optarg); break; case 'C': if (flags & CLIENT_CONTROL) flags |= CLIENT_CONTROLCONTROL; else flags |= CLIENT_CONTROL; break; case 'V': printf("%s %s\n", __progname, VERSION); exit(0); case 'f': set_cfg_file(optarg); break; case 'l': flags |= CLIENT_LOGIN; break; case 'L': free(label); label = xstrdup(optarg); break; case 'q': break; case 'S': free(path); path = xstrdup(optarg); break; case 'u': flags |= CLIENT_UTF8; break; case 'v': log_add_level(); break; default: usage(); } } argc -= optind; argv += optind; if (shellcmd != NULL && argc != 0) usage(); #ifdef __OpenBSD__ if (pledge("stdio rpath wpath cpath flock fattr unix getpw sendfd " "recvfd proc exec tty ps", NULL) != 0) err(1, "pledge"); #endif /* * tmux is a UTF-8 terminal, so if TMUX is set, assume UTF-8. * Otherwise, if the user has set LC_ALL, LC_CTYPE or LANG to contain * UTF-8, it is a safe assumption that either they are using a UTF-8 * terminal, or if not they know that output from UTF-8-capable * programs may be wrong. */ if (getenv("TMUX") != NULL) flags |= CLIENT_UTF8; else { s = getenv("LC_ALL"); if (s == NULL || *s == '\0') s = getenv("LC_CTYPE"); if (s == NULL || *s == '\0') s = getenv("LANG"); if (s == NULL || *s == '\0') s = ""; if (strcasestr(s, "UTF-8") != NULL || strcasestr(s, "UTF8") != NULL) flags |= CLIENT_UTF8; } global_hooks = hooks_create(NULL); global_environ = environ_create(); for (var = environ; *var != NULL; var++) environ_put(global_environ, *var); if (getcwd(tmp, sizeof tmp) != NULL) environ_set(global_environ, "PWD", "%s", tmp); global_options = options_create(NULL); options_table_populate_tree(OPTIONS_TABLE_SERVER, global_options); global_s_options = options_create(NULL); options_table_populate_tree(OPTIONS_TABLE_SESSION, global_s_options); options_set_string(global_s_options, "default-shell", "%s", getshell()); global_w_options = options_create(NULL); options_table_populate_tree(OPTIONS_TABLE_WINDOW, global_w_options); /* Override keys to vi if VISUAL or EDITOR are set. */ if ((s = getenv("VISUAL")) != NULL || (s = getenv("EDITOR")) != NULL) { if (strrchr(s, '/') != NULL) s = strrchr(s, '/') + 1; if (strstr(s, "vi") != NULL) keys = MODEKEY_VI; else keys = MODEKEY_EMACS; options_set_number(global_s_options, "status-keys", keys); options_set_number(global_w_options, "mode-keys", keys); } /* * If socket is specified on the command-line with -S or -L, it is * used. Otherwise, $TMUX is checked and if that fails "default" is * used. */ if (path == NULL && label == NULL) { s = getenv("TMUX"); if (s != NULL && *s != '\0' && *s != ',') { path = xstrdup(s); path[strcspn (path, ",")] = '\0'; } } if (path == NULL && (path = make_label(label)) == NULL) { fprintf(stderr, "can't create socket: %s\n", strerror(errno)); exit(1); } socket_path = path; free(label); /* Pass control to the client. */ exit(client_main(event_init(), argc, argv, flags, shellcmd)); }