Commit 93226417 authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

Use socketclose on windows as appropriate; end pid files with newline


svn:r1745
parent dd335d9b
......@@ -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
......
......@@ -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.-_/"
......
......@@ -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. */
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment