Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rustyrussell/pettycoin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4f503293b3a3
Choose a base ref
...
head repository: rustyrussell/pettycoin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e0eb57c1a051
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 5, 2014

  1. Always flush stdout before a fork().

    Otherwise we can get weird double-printing effects.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 5, 2014
    Copy the full SHA
    9b1e264 View commit details
  2. dns: don't leave zombies behind.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 5, 2014
    Copy the full SHA
    4dae21c View commit details
  3. peer.c: prepend peer log messages with peer number.

    Easier to read than IP addresses, and used in some places like dev-listtodo.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 5, 2014
    Copy the full SHA
    e0eb57c View commit details
Showing with 20 additions and 4 deletions.
  1. +12 −1 dns.c
  2. +1 −0 generating.c
  3. +6 −3 peer.c
  4. +1 −0 pettycoin-gateway.c
13 changes: 12 additions & 1 deletion dns.c
Original file line number Diff line number Diff line change
@@ -7,8 +7,10 @@
#include <ccan/read_write_all/read_write_all.h>
#include <ccan/tal/tal.h>
#include <netdb.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>

/* Async dns helper. */
struct dns_info {
@@ -17,6 +19,7 @@ struct dns_info {
struct protocol_net_address *);
void *pkt;
size_t num_addresses;
int pid;
struct protocol_net_address *addresses;
};

@@ -120,6 +123,11 @@ static struct io_plan *init_dns_conn(struct io_conn *conn, struct dns_info *d)
return io_read_packet(conn, &d->pkt, start_connecting, d);
}

static void reap_child(struct io_conn *conn, struct dns_info *d)
{
waitpid(d->pid, NULL, 0);
}

tal_t *dns_resolve_and_connect(struct state *state,
const char *name, const char *port,
struct io_plan *(*init)(struct io_conn *,
@@ -139,7 +147,9 @@ tal_t *dns_resolve_and_connect(struct state *state,
return NULL;
}

switch (fork()) {
fflush(stdout);
d->pid = fork();
switch (d->pid) {
case -1:
warn("Forking for dns lookup");
return NULL;
@@ -151,6 +161,7 @@ tal_t *dns_resolve_and_connect(struct state *state,

close(pfds[1]);
conn = io_new_conn(state, pfds[0], init_dns_conn, d);
io_set_finish(conn, reap_child, d);
tal_steal(conn, d);
return d;
}
1 change: 1 addition & 0 deletions generating.c
Original file line number Diff line number Diff line change
@@ -270,6 +270,7 @@ static void exec_generator(struct generator *gen)
if (pipe(outfd) != 0 || pipe(infd) != 0)
fatal(gen->state, "pipe: %s", strerror(errno));

fflush(stdout);
gen->pid = fork();
if (gen->pid == -1)
fatal(gen->state, "fork: %s", strerror(errno));
9 changes: 6 additions & 3 deletions peer.c
Original file line number Diff line number Diff line change
@@ -1704,7 +1704,8 @@ struct io_plan *peer_connected(struct io_conn *conn, struct state *state,
{
/* Conn owns peer; peer vanishes if conn does. */
struct peer *peer = tal(conn, struct peer);
char prefix[INET6_ADDRSTRLEN + strlen(":65000:")];
char prefix[strlen("Peer ") + STR_MAX_CHARS(unsigned int) + strlen(" @")
+ INET6_ADDRSTRLEN + strlen(":65000:")];

peer->peer_num = get_peernum(state->peer_map);
if (peer->peer_num == MAX_PEERS) {
@@ -1727,8 +1728,10 @@ struct io_plan *peer_connected(struct io_conn *conn, struct state *state,
peer->fd = io_conn_fd(conn);

/* Use address as log prefix. */
if (inet_ntop(AF_INET6, addr->addr, prefix, sizeof(prefix)) == NULL)
strcpy(prefix, "UNCONVERTABLE-IPV6");
sprintf(prefix, "Peer %u @", peer->peer_num);
if (inet_ntop(AF_INET6, addr->addr, prefix + strlen(prefix),
INET6_ADDRSTRLEN) == NULL)
strcat(prefix, "UNCONVERTABLE-IPV6");
sprintf(prefix + strlen(prefix), ":%u:", le16_to_cpu(addr->port));
peer->log = new_log(peer, state->log,
prefix, state->log_level, PEER_LOG_MAX);
1 change: 1 addition & 0 deletions pettycoin-gateway.c
Original file line number Diff line number Diff line change
@@ -201,6 +201,7 @@ static char *ask_process(const tal_t *ctx,
if (pipe(fds) != 0)
return NULL;

fflush(stdout);
switch (fork()) {
case -1:
return NULL;