]> code.delx.au - gnu-emacs/blobdiff - src/w32proc.c
(set-auto-mode): Run multiple mode: specs in left-to-right order.
[gnu-emacs] / src / w32proc.c
index 62b373e642f860ac1e430a5bc7e9c57080d0cae3..01ffd33bebb1aa1df81a34da1e2ad03c92b7690b 100644 (file)
@@ -61,9 +61,7 @@ Lisp_Object Vwin32_pipe_read_delay;
    nil means no, t means yes. */
 Lisp_Object Vwin32_downcase_file_names;
 
-/* Keep track of whether we have already started a DOS program, and
-   whether we can run them in the first place. */
-BOOL can_run_dos_process;
+/* Keep track of whether we have already started a DOS program. */
 BOOL dos_process_running;
 
 #ifndef SYS_SIGLIST_DECLARED
@@ -384,7 +382,7 @@ reap_subprocess (child_process *cp)
       cp->procinfo.hThread = NULL;
 
       /* If this was a DOS process, indicate that it is now safe to
-        start a new one. */
+        start a new one.  */
       if (cp->is_dos_process)
        dos_process_running = FALSE;
     }
@@ -622,9 +620,9 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
   /* Check if program is a DOS executable, and if so whether we are
      allowed to start it. */
   is_dos_binary = win32_is_dos_binary (cmdname);
-  if (is_dos_binary && (!can_run_dos_process || dos_process_running))
+  if (is_dos_binary && dos_process_running)
     {
-      errno = (can_run_dos_process) ? EAGAIN : EINVAL;
+      errno = EAGAIN;
       return -1;
     }
   
@@ -1055,9 +1053,11 @@ sys_kill (int pid, int sig)
   else
     {
       /* Kill the process.  On Win32 this doesn't kill child processes
-        so it doesn't work very well for shells which is why it's
-        not used in every case.  */
-      if (!TerminateProcess (proc_hand, 0xff))
+        so it doesn't work very well for shells which is why it's not
+        used in every case.  Also, don't try to terminate DOS processes
+        (on Win95), because this will hang Emacs. */
+      if (!(cp && cp->is_dos_process)
+         && !TerminateProcess (proc_hand, 0xff))
         {
          DebPrint (("sys_kill.TerminateProcess returned %d "
                     "for pid %lu\n", GetLastError (), pid));
@@ -1156,9 +1156,82 @@ reset_standard_handles (int in, int out, int err, HANDLE handles[3])
   SetStdHandle (STD_ERROR_HANDLE, handles[2]);
 }
 
+#ifdef HAVE_SOCKETS
+
+/* To avoid problems with winsock implementations that work over dial-up
+   connections causing or requiring a connection to exist while Emacs is
+   running, Emacs no longer automatically loads winsock on startup if it
+   is present.  Instead, it will be loaded when open-network-stream is
+   first called.
+
+   To allow full control over when winsock is loaded, we provide these
+   two functions to dynamically load and unload winsock.  This allows
+   dial-up users to only be connected when they actually need to use
+   socket services.  */
+
+/* From nt.c */
+extern HANDLE winsock_lib;
+extern BOOL term_winsock (void);
+extern BOOL init_winsock (int load_now);
+
+extern Lisp_Object Vsystem_name;
+
+DEFUN ("win32-has-winsock", Fwin32_has_winsock, Swin32_has_winsock, 0, 1, 0,
+  "Test for presence of the Windows socket library `winsock'.\n\
+Returns non-nil if winsock support is present, nil otherwise.\n\
+\n\
+If the optional argument LOAD-NOW is non-nil, the winsock library is\n\
+also loaded immediately if not already loaded.  If winsock is loaded,\n\
+the winsock local hostname is returned (since this may be different from\n\
+the value of `system-name' and should supplant it), otherwise t is\n\
+returned to indicate winsock support is present.")
+  (load_now)
+     Lisp_Object load_now;
+{
+  int have_winsock;
+
+  have_winsock = init_winsock (!NILP (load_now));
+  if (have_winsock)
+    {
+      if (winsock_lib != NULL)
+       {
+         /* Return new value for system-name.  The best way to do this
+            is to call init_system_name, saving and restoring the
+            original value to avoid side-effects.  */
+         Lisp_Object orig_hostname = Vsystem_name;
+         Lisp_Object hostname;
+
+         init_system_name ();
+         hostname = Vsystem_name;
+         Vsystem_name = orig_hostname;
+         return hostname;
+       }
+      return Qt;
+    }
+  return Qnil;
+}
+
+DEFUN ("win32-unload-winsock", Fwin32_unload_winsock, Swin32_unload_winsock,
+       0, 0, 0,
+  "Unload the Windows socket library `winsock' if loaded.\n\
+This is provided to allow dial-up socket connections to be disconnected\n\
+when no longer needed.  Returns nil without unloading winsock if any\n\
+socket connections still exist.")
+  ()
+{
+  return term_winsock () ? Qt : Qnil;
+}
+
+#endif /* HAVE_SOCKETS */
+
 \f
 syms_of_ntproc ()
 {
+#ifdef HAVE_SOCKETS
+  defsubr (&Swin32_has_winsock);
+  defsubr (&Swin32_unload_winsock);
+#endif
+
   DEFVAR_LISP ("win32-quote-process-args", &Vwin32_quote_process_args,
     "Non-nil enables quoting of process arguments to ensure correct parsing.\n\
 Because Windows does not directly pass argv arrays to child processes,\n\