Ben Hutchings reports that new PuTTY instances created from the saved
authorjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Tue, 8 Mar 2005 23:06:15 +0000 (23:06 +0000)
committerjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Tue, 8 Mar 2005 23:06:15 +0000 (23:06 +0000)
sessions menu (etc) can inherit listening sockets, and that this sometimes
causes trouble. Can't reproduce any problems myself, but let's only allow
inheritance when absolutely necessary -- Duplicate Session -- in which
case there's already going to be trouble with two processes trying to
listen on the same port.

git-svn-id: svn://svn.tartarus.org/sgt/putty@5468 cda61777-01e9-0310-a592-d414129be87e

windows/window.c

index 40c69e5..066c4a4 100644 (file)
@@ -1901,6 +1901,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                char b[2048];
                char c[30], *cl;
                int freecl = FALSE;
+               BOOL inherit_handles;
                STARTUPINFO si;
                PROCESS_INFORMATION pi;
                HANDLE filemap = NULL;
@@ -1929,6 +1930,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                            UnmapViewOfFile(p);
                        }
                    }
+                   inherit_handles = TRUE;
                    sprintf(c, "putty &%p", filemap);
                    cl = c;
                } else if (wParam == IDM_SAVEDSESS) {
@@ -1938,11 +1940,14 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                        char *session = sesslist.sessions[sessno];
                        /* XXX spaces? quotes? "-load"? */
                        cl = dupprintf("putty @%s", session);
+                       inherit_handles = FALSE;
                        freecl = TRUE;
                    } else
                        break;
-               } else
+               } else /* IDM_NEWSESS */ {
                    cl = NULL;
+                   inherit_handles = FALSE;
+               }
 
                GetModuleFileName(NULL, b, sizeof(b) - 1);
                si.cb = sizeof(si);
@@ -1952,7 +1957,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                si.dwFlags = 0;
                si.cbReserved2 = 0;
                si.lpReserved2 = NULL;
-               CreateProcess(b, cl, NULL, NULL, TRUE,
+               CreateProcess(b, cl, NULL, NULL, inherit_handles,
                              NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
 
                if (filemap)