[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor/master] Make it compile on Windows™.



commit 3be9d76fa2e56a9715e8151d9b6802da5b38512a
Author: George Kadianakis <desnacked@xxxxxxxxx>
Date:   Fri Oct 7 15:44:44 2011 +0200

    Make it compile on Windowsâ?¢.
---
 src/common/util.c   |    8 +++-----
 src/or/transports.c |   20 ++++++++++++++------
 src/or/transports.h |    2 +-
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index 4a66e93..a0777ea 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2966,20 +2966,18 @@ int
 tor_terminate_process(pid_t pid)
 {
 #ifdef MS_WINDOWS
-  DWORD pid_win = pid;
-  DWORD err;
   HANDLE handle;
   /* If the signal is outside of what GenerateConsoleCtrlEvent can use,
      attempt to open and terminate the process. */
   handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
-  if (handle == NULL)
+  if (!handle)
     return -1;
 
-  if (TerminateProcess(handle, sig) == 0)
+  if (!TerminateProcess(handle, 0))
     return -1;
   else
     return 0;
-#else /* *nix */
+#else /* Unix */
   return kill(pid, SIGTERM);
 #endif
 }
diff --git a/src/or/transports.c b/src/or/transports.c
index 465b8e1..c531fe7 100644
--- a/src/or/transports.c
+++ b/src/or/transports.c
@@ -234,7 +234,7 @@ proxy_prepare_for_restart(managed_proxy_t *mp)
   /* kill the old obfsproxy process */
   tor_terminate_process(mp->pid);
   mp->pid = 0;
-  fclose(mp->stdout);
+  fclose(mp->_stdout);
 
   /* destroy all its old transports. we no longer use them. */
   SMARTLIST_FOREACH_BEGIN(mp->transports, const char *, t_name) {
@@ -277,14 +277,22 @@ launch_managed_proxy(managed_proxy_t *mp)
   free_execve_args(envp);
 
   /* Set stdout/stderr pipes to be non-blocking */
-  fcntl(stdout_pipe, F_SETFL, O_NONBLOCK);
+#ifdef _WIN32
+  {
+    u_long nonblocking = 1;
+    ioctlsocket(stdout_pipe, FIONBIO, &nonblocking);
+  }
+#else
+    fcntl(stdout_pipe, F_SETFL, O_NONBLOCK);
+#endif
+
   /* Open the buffered IO streams */
   stdout_read = fdopen(stdout_pipe, "r");
 
   log_info(LD_CONFIG, "Managed proxy has spawned at PID %d.", pid);
 
   mp->conf_state = PT_PROTO_LAUNCHED;
-  mp->stdout = stdout_read;
+  mp->_stdout = stdout_read;
   mp->pid = pid;
 
   return 0;
@@ -344,7 +352,7 @@ configure_proxy(managed_proxy_t *mp)
   tor_assert(mp->conf_state != PT_PROTO_INFANT);
 
   while (1) {
-    r = get_string_from_pipe(mp->stdout, stdout_buf,
+    r = get_string_from_pipe(mp->_stdout, stdout_buf,
                              sizeof(stdout_buf) - 1);
 
     if (r  == IO_STREAM_OKAY) { /* got a line; handle it! */
@@ -456,8 +464,8 @@ managed_proxy_destroy(managed_proxy_t *mp)
   smartlist_remove(managed_proxy_list, mp);
 
   /* close its stdout stream */
-  if (mp->stdout)
-    fclose(mp->stdout);
+  if (mp->_stdout)
+    fclose(mp->_stdout);
 
   /* free the argv */
   free_execve_args(mp->argv);
diff --git a/src/or/transports.h b/src/or/transports.h
index 0b5cd5f..4a93387 100644
--- a/src/or/transports.h
+++ b/src/or/transports.h
@@ -47,7 +47,7 @@ typedef struct {
 
   int is_server; /* is it a server proxy? */
 
-  FILE *stdout; /* a stream to its stdout
+  FILE *_stdout; /* a stream to its stdout
                    (closed in managed_proxy_destroy()) */
 
   int pid; /* The Process ID this managed proxy is using. */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits