summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-04-28 21:14:56 +0000
committerNick Mathewson <nickm@torproject.org>2004-04-28 21:14:56 +0000
commit9322641710fec0f90cc47b64748a9795ce7cba9b (patch)
tree98388c1bae7eb6a4162985f3f01e6d0c3e9bf115
parentdd335d9bb25b1e772f0d42aa35d25895d8031c36 (diff)
downloadtor-9322641710fec0f90cc47b64748a9795ce7cba9b.tar.gz
tor-9322641710fec0f90cc47b64748a9795ce7cba9b.zip
Use socketclose on windows as appropriate; end pid files with newline
svn:r1745
-rw-r--r--src/common/util.c10
-rw-r--r--src/common/util.h6
-rw-r--r--src/or/connection.c6
-rw-r--r--src/or/connection_edge.c4
-rw-r--r--src/or/cpuworker.c4
-rw-r--r--src/or/dns.c4
6 files changed, 20 insertions, 14 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 9c834db589..a7c1adecba 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -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
diff --git a/src/common/util.h b/src/common/util.h
index aedc9ae60b..555aa6b050 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -56,6 +56,12 @@
} } 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.-_/"
diff --git a/src/or/connection.c b/src/or/connection.c
index a2e1a95eea..1b1f4c4b15 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -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. */
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 3eb4d9ba6e..365b39ad97 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -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;
}
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 8da39515dc..fb5a9d85a7 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -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);
diff --git a/src/or/dns.c b/src/or/dns.c
index ee836b52b0..2cb4cb6182 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -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);