From aebbf047d272096bb92705ab95a106d6004a4e3d Mon Sep 17 00:00:00 2001 From: Paolo Mainardi Date: Sat, 2 Nov 2013 18:02:39 +0100 Subject: [PATCH] host name is now an input argument Closes #7 --- tmate-decoder.c | 12 ++++-------- tmate-slave.c | 16 ++++++++++++++-- tmate.h | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/tmate-decoder.c b/tmate-decoder.c index 0451d72c..dd803af9 100644 --- a/tmate-decoder.c +++ b/tmate-decoder.c @@ -99,7 +99,6 @@ static void unpack_array(struct tmate_unpacker *uk, static void tmate_header(struct tmate_decoder *decoder, struct tmate_unpacker *uk) { - char hostname[128]; char port_arg[16] = {0}; char *client_version = xstrdup("< 1.8.6"); @@ -117,17 +116,14 @@ static void tmate_header(struct tmate_decoder *decoder, free(client_version); - if (gethostname(hostname, sizeof(hostname)) < 0) - tmate_fatal("cannot get hostname"); - if (tmate_port != 22) sprintf(port_arg, " -p%d", tmate_port); - tmate_notify("Remote session read only: ssh%s ro-%s@%s.%s (clear your screen if you share this)", - port_arg, tmate_session_token_ro, hostname, TMATE_DOMAIN); + tmate_notify("Remote session read only: ssh%s ro-%s@%s (clear your screen if you share this)", + port_arg, tmate_session_token_ro, tmate_host); - tmate_notify("Remote session: ssh%s %s@%s.%s", - port_arg, tmate_session_token, hostname, TMATE_DOMAIN); + tmate_notify("Remote session: ssh%s %s@%s", + port_arg, tmate_session_token, tmate_host); } extern u_int next_window_pane_id; diff --git a/tmate-slave.c b/tmate-slave.c index c82f2278..1b21960d 100644 --- a/tmate-slave.c +++ b/tmate-slave.c @@ -18,6 +18,8 @@ #include "tmate.h" int tmate_port = TMATE_DEFAULT_PORT; +char *tmate_host; + struct tmate_encoder *tmate_encoder; int tmux_socket_fd; const char *tmate_session_token = "main"; @@ -39,7 +41,7 @@ extern int client_connect(char *path, int start_server); static void usage(void) { - fprintf(stderr, "usage: tmate-slave [-k keys_dir] [-l logfile] [-p PORT] [-r logfile] [-v]\n"); + fprintf(stderr, "usage: tmate-slave [-k keys_dir] [-l logfile] [-p port] [-r logfile] [-h host] [-v]\n"); } void tmate_reopen_logfile(void) @@ -68,7 +70,7 @@ int main(int argc, char **argv, char **envp) const char *replay_file = NULL; #endif - while ((opt = getopt(argc, argv, "p:l:vk:r:")) != -1) { + while ((opt = getopt(argc, argv, "p:l:vk:r:h:")) != -1) { switch (opt) { case 'p': tmate_port = atoi(optarg); @@ -89,12 +91,22 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "Record/Replay not enabled\n"); #endif break; + case 'h': + tmate_host = xstrdup(optarg); + break; default: usage(); return 1; } } + if (!tmate_host) { + char hostname[255]; + if (gethostname(hostname, sizeof(hostname)) < 0) + tmate_fatal("cannot get hostname"); + tmate_host = xstrdup(hostname); + } + cmdline = *argv; cmdline_end = *envp; diff --git a/tmate.h b/tmate.h index a576a30b..cf838ec4 100644 --- a/tmate.h +++ b/tmate.h @@ -21,7 +21,6 @@ do { \ /* tmate-encoder.c */ #define TMATE_LATEST_VERSION "1.8.9" -#define TMATE_DOMAIN "tmate.io" enum tmate_client_commands { TMATE_NOTIFY, @@ -163,6 +162,7 @@ extern void tmate_ssh_server_main(const char *keys_dir, int port); extern int tmate_port; extern struct tmate_encoder *tmate_encoder; extern int tmux_socket_fd; +extern char *tmate_host; extern const char *tmate_session_token; extern const char *tmate_session_token_ro;