]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Use socketclose on windows as appropriate; end pid files with newline
authorNick Mathewson <nickm@torproject.org>
Wed, 28 Apr 2004 21:14:56 +0000 (21:14 +0000)
committerNick Mathewson <nickm@torproject.org>
Wed, 28 Apr 2004 21:14:56 +0000 (21:14 +0000)
svn:r1745

src/common/util.c
src/common/util.h
src/or/connection.c
src/or/connection_edge.c
src/or/cpuworker.c
src/or/dns.c

index 9c834db589dec266ba9e59a5ff4a788976a55e80..a7c1adecbafb983ecdb1e3a9e73170935f91b7c0 100644 (file)
@@ -930,7 +930,7 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
         goto tidy_up_and_fail;
     if (size != sizeof(listen_addr))
         goto abort_tidy_up_and_fail;
-    close(listener);
+    tor_close_socket(listener);
     /* Now check we are talking to ourself by matching port and host on the
        two sockets.  */
     if (getsockname(connector, (struct sockaddr *) &connect_addr, &size) == -1)
@@ -955,11 +955,11 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
     {
         int save_errno = errno;
         if (listener != -1)
-            close(listener);
+            tor_close_socket(listener);
         if (connector != -1)
-            close(connector);
+            tor_close_socket(connector);
         if (acceptor != -1)
-            close(acceptor);
+            tor_close_socket(acceptor);
         errno = save_errno;
         return -1;
     }
@@ -1319,7 +1319,7 @@ void write_pidfile(char *filename) {
     log_fn(LOG_WARN, "unable to open %s for writing: %s", filename,
            strerror(errno));
   } else {
-    fprintf(pidfile, "%d", (int)getpid());
+    fprintf(pidfile, "%d\n", (int)getpid());
     fclose(pidfile);
   }
 #endif
index aedc9ae60bec142215895887e9f2dfac8cc3511c..555aa6b050bb5f5251893201bdf10b7237710728 100644 (file)
  } } while (0)
 #endif
 
+#ifdef MS_WINDOWS
+#define tor_close_socket(s) socketclose(s)
+#else
+#define tor_close_socket(s) close(s)
+#endif
+
 /* legal characters in a filename */
 #define CONFIG_LEGAL_FILENAME_CHARACTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/"
 
index a2e1a95eea7b171e445dcf4a9f33689ff29d245f..1b1f4c4b1573bbb2afd99450313c767d0bb730fe 100644 (file)
@@ -121,7 +121,7 @@ void connection_free(connection_t *conn) {
 
   if(conn->s >= 0) {
     log_fn(LOG_INFO,"closing fd %d.",conn->s);
-    close(conn->s);
+    tor_close_socket(conn->s);
   }
   memset(conn, 0xAA, sizeof(connection_t)); /* poison memory */
   free(conn);
@@ -150,7 +150,7 @@ void connection_close_immediate(connection_t *conn)
     log_fn(LOG_INFO,"Closing connection (fd %d, type %s, state %d) with data on outbuf.",
            conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state);
   }
-  close(conn->s);
+  tor_close_socket(conn->s);
   conn->s = -1;
   if(!connection_is_listener(conn)) {
     buf_clear(conn->outbuf);
@@ -399,7 +399,7 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
     if(!ERRNO_CONN_EINPROGRESS(errno)) {
       /* yuck. kill it. */
       log_fn(LOG_INFO,"Connect() to %s:%u failed: %s",address,port,strerror(errno));
-      close(s);
+      tor_close_socket(s);
       return -1;
     } else {
       /* it's in progress. set state appropriately and return. */
index 3eb4d9ba6e671ca93f4b967ed8fca50e2023a51f..365b39ad97cd8782fea3b3a23c01a40c9f71db0c 100644 (file)
@@ -1091,7 +1091,7 @@ int connection_ap_make_bridge(char *address, uint16_t port) {
 
   if(connection_add(conn) < 0) { /* no space, forget it */
     connection_free(conn); /* this closes fd[0] */
-    close(fd[1]);
+    tor_close_socket(fd[1]);
     return -1;
   }
 
@@ -1101,7 +1101,7 @@ int connection_ap_make_bridge(char *address, uint16_t port) {
   /* attaching to a dirty circuit is fine */
   if (connection_ap_handshake_attach_circuit(conn) < 0) {
     connection_mark_for_close(conn, 0);
-    close(fd[1]);
+    tor_close_socket(fd[1]);
     return -1;
   }
 
index 8da39515dcfa228730e4e3c54bd35cd5f1550b51..fb5a9d85a71c20caf514460f461bb30f4629fdb2 100644 (file)
@@ -149,7 +149,7 @@ int cpuworker_main(void *data) {
   char tag[TAG_LEN];
   crypto_pk_env_t *onion_key = NULL, *last_onion_key = NULL;
 
-  close(fdarray[0]); /* this is the side of the socketpair the parent uses */
+  tor_close_socket(fdarray[0]); /* this is the side of the socketpair the parent uses */
   fd = fdarray[1]; /* this side is ours */
 #ifndef MS_WINDOWS
   connection_free_all(); /* so the child doesn't hold the parent's fd's open */
@@ -220,7 +220,7 @@ static int spawn_cpuworker(void) {
 
   spawn_func(cpuworker_main, (void*)fd);
   log_fn(LOG_DEBUG,"just spawned a worker.");
-  close(fd[1]); /* we don't need the worker's side of the pipe */
+  tor_close_socket(fd[1]); /* we don't need the worker's side of the pipe */
 
   conn = connection_new(CONN_TYPE_CPUWORKER);
 
index ee836b52b010cc36b08a6b6e215fb944308ec043..2cb4cb6182faa4e605f0750b757b791e7b4e322c 100644 (file)
@@ -455,7 +455,7 @@ int dnsworker_main(void *data) {
   int *fdarray = data;
   int fd;
 
-  close(fdarray[0]); /* this is the side of the socketpair the parent uses */
+  tor_close_socket(fdarray[0]); /* this is the side of the socketpair the parent uses */
   fd = fdarray[1]; /* this side is ours */
 #ifndef MS_WINDOWS
   connection_free_all(); /* so the child doesn't hold the parent's fd's open */
@@ -509,7 +509,7 @@ static int spawn_dnsworker(void) {
 
   spawn_func(dnsworker_main, (void*)fd);
   log_fn(LOG_DEBUG,"just spawned a worker.");
-  close(fd[1]); /* we don't need the worker's side of the pipe */
+  tor_close_socket(fd[1]); /* we don't need the worker's side of the pipe */
 
   conn = connection_new(CONN_TYPE_DNSWORKER);