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)
{
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;
}
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
} } 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.-_/"
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);
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);
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. */
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;
}
/* 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;
}
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 */
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);
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 */
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);