Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Allow 32-bit putty to work with Cygwin64.
Browse files Browse the repository at this point in the history
Patch from Michael Berganovsky <rupor0mail@gmail.com>
  • Loading branch information
FireEgl authored and FauxFaux committed Sep 1, 2013
1 parent fad4d3a commit 4925118
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions putty.h
Expand Up @@ -747,6 +747,7 @@ void cleanup_exit(int);
X(INT, NONE, serflow) \
/* Cygterm options */ \
X(INT, NONE, cygautopath) \
X(INT, NONE, cygterm64) \
X(STR, NONE, cygcmd) \
/* Keyboard options */ \
X(INT, NONE, bksp_is_delete) \
Expand Down
2 changes: 2 additions & 0 deletions settings.c
Expand Up @@ -689,6 +689,7 @@ void save_open_settings(void *sesskey, Conf *conf)
write_setting_i(sesskey, "SerialFlowControl", conf_get_int(conf, CONF_serflow));
write_setting_s(sesskey, "WindowClass", conf_get_str(conf, CONF_winclass));
write_setting_i(sesskey, "CygtermAutoPath", conf_get_int(conf, CONF_cygautopath));
write_setting_i(sesskey, "Cygterm64", conf_get_int(conf, CONF_cygterm64));
write_setting_s(sesskey, "CygtermCommand", conf_get_str(conf, CONF_cygcmd));
}

Expand Down Expand Up @@ -1064,6 +1065,7 @@ void load_open_settings(void *sesskey, Conf *conf)
gppi(sesskey, "SerialParity", SER_PAR_NONE, conf, CONF_serparity);
gppi(sesskey, "SerialFlowControl", SER_FLOW_XONXOFF, conf, CONF_serflow);
gppi(sesskey, "CygtermAutoPath", 1, conf, CONF_cygautopath);
gppi(sesskey, "Cygterm64", 0, conf, CONF_cygterm64);
gpps(sesskey, "CygtermCommand", "-", conf, CONF_cygcmd);
gpps(sesskey, "WindowClass", "", conf, CONF_winclass);
}
Expand Down
12 changes: 12 additions & 0 deletions windows/cygcfg.c
Expand Up @@ -3,6 +3,11 @@

extern void config_protocolbuttons_handler(union control *, void *, void *, int);

static int is64Bits()
{
return (NULL != GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process")) ? 1 : 0;
}

void cygterm_setup_config_box(struct controlbox *b, int midsession)
{
union control *c;
Expand Down Expand Up @@ -38,6 +43,13 @@ void cygterm_setup_config_box(struct controlbox *b, int midsession)
HELPCTX(no_help),
conf_checkbox_handler,
I(CONF_cygautopath));
if( is64Bits() )
{
ctrl_checkbox(s, "Use Cygwin64", 'u',
HELPCTX(no_help),
conf_checkbox_handler,
I(CONF_cygterm64));
}
}
}

Expand Down
23 changes: 15 additions & 8 deletions windows/cygterm.c
Expand Up @@ -11,8 +11,10 @@

#ifdef __INTERIX
#define CTHELPER "posix.exe /u /c cthelper.exe"
#define CTHELPER64 "posix.exe /u /c cthelper64.exe"
#else
#define CTHELPER "cthelper"
#define CTHELPER64 "cthelper64"
#endif

#if !defined(CYGTERM_DEBUG)
Expand Down Expand Up @@ -127,7 +129,7 @@ cygterm_accepting(Plug plug, OSSocket sock)
}


static char *getCygwinBin(void);
static char *getCygwinBin(int use64);
static void appendPath(const char *append);
static size_t makeAttributes(char *buf, Conf *conf);
static const char *spawnChild(char *cmd, LPPROCESS_INFORMATION ppi, PHANDLE pin);
Expand Down Expand Up @@ -196,7 +198,12 @@ cygterm_init(void *frontend_handle, void **backend_handle,
}

/* Build cthelper command line */
cmdlinelen = sprintf(cmdline, CTHELPER" %u %s ", cport, conf_get_str(local->conf, CONF_termtype));
if(conf_get_int(conf, CONF_cygterm64)) {
cmdlinelen = sprintf(cmdline, CTHELPER64" %u %s ", cport, conf_get_str(local->conf, CONF_termtype));
}
else {
cmdlinelen = sprintf(cmdline, CTHELPER" %u %s ", cport, conf_get_str(local->conf, CONF_termtype));
}
cmdlinelen += makeAttributes(cmdline + cmdlinelen, conf);

command = conf_get_str(conf, CONF_cygcmd);
Expand All @@ -215,7 +222,7 @@ cygterm_init(void *frontend_handle, void **backend_handle,

/* Add the Cygwin /bin path to the PATH. */
if (conf_get_int(conf, CONF_cygautopath)) {
char *cygwinBinPath = getCygwinBin();
char *cygwinBinPath = getCygwinBin(conf_get_int(conf, CONF_cygterm64));
if (!cygwinBinPath) {
/* we'll try anyway */
cygterm_debug("cygwin bin directory not found");
Expand Down Expand Up @@ -443,12 +450,12 @@ makeAttributes(char *buf, Conf *conf)

/* Utility functions for spawning cthelper process */
static BOOL
getRegistry(char *valueData, LPDWORD psize, HKEY key, const char *subKey, const char *valueName)
getRegistry(char *valueData, LPDWORD psize, HKEY key, const char *subKey, const char *valueName, int use64)
{
HKEY k;
LONG ret;

if (ERROR_SUCCESS != (ret = RegOpenKey(key, subKey, &k)))
if (ERROR_SUCCESS != (ret = RegOpenKeyEx(key, subKey, 0, KEY_READ | (use64 ? KEY_WOW64_64KEY : KEY_WOW64_32KEY), &k )))
return ret;

ERROR_SUCCESS == (ret = RegQueryInfoKey(k, 0, 0, 0, 0, 0, 0, 0, 0, psize, 0, 0))
Expand All @@ -469,16 +476,16 @@ getRegistry(char *valueData, LPDWORD psize, HKEY key, const char *subKey, const
"rootdir"

static char *
getCygwinBin(void)
getCygwinBin(int use64)
{
char *dir;
DWORD size = MAX_PATH;

dir = smalloc(size);
dir[0] = '\0';

if (ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_U_SETUP_ROOTDIR)
|| ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_S_SETUP_ROOTDIR))
if (ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_U_SETUP_ROOTDIR, use64)
|| ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_S_SETUP_ROOTDIR, use64))
{
strcat(dir, "\\bin");
}
Expand Down

0 comments on commit 4925118

Please sign in to comment.