From df7c7e52e8be2b65dbfc4ffc49ccf6b0c6c42b76 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 25 Feb 2007 00:50:24 +0000 Subject: [PATCH] Since r7265, a user could not launch a PuTTY session to a specific host by simply specifying a hostname on the command line -- this would bring up the config dialog. Use a slightly more sophisticated notion of whether the user meant to launch a session. git-svn-id: svn://svn.tartarus.org/sgt/putty@7321 cda61777-01e9-0310-a592-d414129be87e --- unix/gtkwin.c | 18 +++++++++++++----- unix/unix.h | 2 +- unix/uxpterm.c | 2 +- unix/uxputty.c | 4 +++- windows/window.c | 14 ++++++++++---- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 311cf38a..388d4225 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -2408,7 +2408,7 @@ static void help(FILE *fp) { } } -int do_cmdline(int argc, char **argv, int do_everything, +int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch, struct gui_data *inst, Config *cfg) { int err = 0; @@ -2614,7 +2614,8 @@ int do_cmdline(int argc, char **argv, int do_everything, exit(1); } else if(p[0] != '-' && (!do_everything || - process_nonoption_arg(p, cfg))) { + process_nonoption_arg(p, cfg, + allow_launch))) { /* do nothing */ } else { @@ -3477,15 +3478,22 @@ int pt_main(int argc, char **argv) /* Splatter this argument so it doesn't clutter a ps listing */ memset(argv[1], 0, strlen(argv[1])); } else { - if (do_cmdline(argc, argv, 0, inst, &inst->cfg)) + /* By default, we bring up the config dialog, rather than launching + * a session. This gets set to TRUE if something happens to change + * that (e.g., a hostname is specified on the command-line). */ + int allow_launch = FALSE; + if (do_cmdline(argc, argv, 0, &allow_launch, inst, &inst->cfg)) exit(1); /* pre-defaults pass to get -class */ do_defaults(NULL, &inst->cfg); - if (do_cmdline(argc, argv, 1, inst, &inst->cfg)) + if (do_cmdline(argc, argv, 1, &allow_launch, inst, &inst->cfg)) exit(1); /* post-defaults, do everything */ cmdline_run_saved(&inst->cfg); - if ((!loaded_session || !cfg_launchable(&inst->cfg)) && + if (loaded_session) + allow_launch = TRUE; + + if ((!allow_launch || !cfg_launchable(&inst->cfg)) && !cfgbox(&inst->cfg)) exit(0); /* config box hit Cancel */ } diff --git a/unix/unix.h b/unix/unix.h index 9c52de6d..90faf5a6 100644 --- a/unix/unix.h +++ b/unix/unix.h @@ -80,7 +80,7 @@ int reallyclose(void *frontend); /* Things pterm.c needs from {ptermm,uxputty}.c */ char *make_default_wintitle(char *hostname); -int process_nonoption_arg(char *arg, Config *cfg); +int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch); /* pterm.c needs this special function in xkeysym.c */ int keysym_to_unicode(int keysym); diff --git a/unix/uxpterm.c b/unix/uxpterm.c index 50fdad92..c20c14a2 100644 --- a/unix/uxpterm.c +++ b/unix/uxpterm.c @@ -33,7 +33,7 @@ void cleanup_exit(int code) exit(code); } -int process_nonoption_arg(char *arg, Config *cfg) +int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch) { return 0; /* pterm doesn't have any. */ } diff --git a/unix/uxputty.c b/unix/uxputty.c index 0abc1ff8..54e0d71b 100644 --- a/unix/uxputty.c +++ b/unix/uxputty.c @@ -53,7 +53,7 @@ static int got_host = 0; const int use_event_log = 1, new_session = 1, saved_sessions = 1; -int process_nonoption_arg(char *arg, Config *cfg) +int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch) { char *p, *q = arg; @@ -104,6 +104,8 @@ int process_nonoption_arg(char *arg, Config *cfg) cfg->host[sizeof(cfg->host) - 1] = '\0'; got_host = 1; } + if (got_host) + *allow_launch = TRUE; return 1; } diff --git a/windows/window.c b/windows/window.c index f654d2ad..1df5feeb 100644 --- a/windows/window.c +++ b/windows/window.c @@ -361,6 +361,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { char *p; int got_host = 0; + /* By default, we bring up the config dialog, rather than launching + * a session. This gets set to TRUE if something happens to change + * that (e.g., a hostname is specified on the command-line). */ + int allow_launch = FALSE; default_protocol = be_default_protocol; /* Find the appropriate default port. */ @@ -397,7 +401,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) if (!cfg_launchable(&cfg) && !do_config()) { cleanup_exit(0); } - loaded_session = TRUE; /* allow it to be launched directly */ + allow_launch = TRUE; /* allow it to be launched directly */ } else if (*p == '&') { /* * An initial & means we've been given a command line @@ -413,10 +417,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) cfg = *cp; UnmapViewOfFile(cp); CloseHandle(filemap); - loaded_session = TRUE; } else if (!do_config()) { cleanup_exit(0); } + allow_launch = TRUE; } else { /* * Otherwise, break up the command line and deal with @@ -541,8 +545,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) cmdline_run_saved(&cfg); - if ((!loaded_session || !cfg_launchable(&cfg)) && - !do_config()) { + if (loaded_session || got_host) + allow_launch = TRUE; + + if ((!allow_launch || !cfg_launchable(&cfg)) && !do_config()) { cleanup_exit(0); } -- 2.11.0