From d5e5744aca1c0984712b180a009bbaadd76dfd0d Mon Sep 17 00:00:00 2001 From: "fergus.henderson" Date: Fri, 8 Oct 2010 18:29:16 +0000 Subject: Apply patch from Jeremy Murphy , tested and reviewed by cheepero@gmail.com, to address "distcc-mon-gnome displays multiple rows for same host/slot". git-svn-id: http://distcc.googlecode.com/svn/trunk@732 01de4be4-8c4a-0410-9132-4925637da917 --- src/clirpc.c | 2 +- src/compile.c | 2 +- src/remote.c | 8 ++++---- src/state.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++----------- src/state.h | 10 ++++++++-- src/where.c | 8 +++++--- 6 files changed, 65 insertions(+), 22 deletions(-) diff --git a/src/clirpc.c b/src/clirpc.c index 30ce99f..b6ef48b 100644 --- a/src/clirpc.c +++ b/src/clirpc.c @@ -162,7 +162,7 @@ int dcc_retrieve_results(int net_fd, /* We've started to see the response, so the server is done * compiling. */ - dcc_note_state(DCC_PHASE_RECEIVE, NULL, NULL); + dcc_note_state(DCC_PHASE_RECEIVE, NULL, NULL, DCC_REMOTE); if ((ret = dcc_r_cc_status(net_fd, status))) return ret; diff --git a/src/compile.c b/src/compile.c index 29dec33..08c4c95 100644 --- a/src/compile.c +++ b/src/compile.c @@ -375,7 +375,7 @@ static int dcc_compile_local(char *argv[], int status; dcc_note_execution(dcc_hostdef_local, argv); - dcc_note_state(DCC_PHASE_COMPILE, input_name, "localhost"); + dcc_note_state(DCC_PHASE_COMPILE, input_name, "localhost", DCC_LOCAL); /* We don't do any redirection of file descriptors when running locally, * so if for example cpp is being used in a pipeline we should be fine. */ diff --git a/src/remote.c b/src/remote.c index c15211e..ee5d63c 100644 --- a/src/remote.c +++ b/src/remote.c @@ -105,7 +105,7 @@ static int dcc_wait_for_cpp(pid_t cpp_pid, int ret; if (cpp_pid) { - dcc_note_state(DCC_PHASE_CPP, NULL, NULL); + dcc_note_state(DCC_PHASE_CPP, NULL, NULL, DCC_LOCAL); /* Wait for cpp to finish (if not already done), check the * result, then send the .i file */ @@ -216,7 +216,7 @@ int dcc_compile_remote(char **argv, rs_log_warning("gettimeofday failed"); dcc_note_execution(host, argv); - dcc_note_state(DCC_PHASE_CONNECT, input_fname, host->hostname); + dcc_note_state(DCC_PHASE_CONNECT, input_fname, host->hostname, DCC_REMOTE); /* For ssh support, we need to allow for separate fds writing to and * reading from the network, because our connection to the ssh client may @@ -244,7 +244,7 @@ int dcc_compile_remote(char **argv, } #endif - dcc_note_state(DCC_PHASE_SEND, NULL, NULL); + dcc_note_state(DCC_PHASE_SEND, NULL, NULL, DCC_REMOTE); if (host->cpp_where == DCC_CPP_ON_SERVER) { if ((ret = dcc_send_header(to_net_fd, argv, host))) { @@ -289,7 +289,7 @@ int dcc_compile_remote(char **argv, /* OK, now all of the source has at least made it into the * client's TCP transmission queue, sometime soon the server will * start compiling it. */ - dcc_note_state(DCC_PHASE_COMPILE, NULL, host->hostname); + dcc_note_state(DCC_PHASE_COMPILE, NULL, host->hostname, DCC_REMOTE); /* If cpp failed, just abandon the connection, without trying to * receive results. */ diff --git a/src/state.c b/src/state.c index 4cf2e1e..ec24de5 100644 --- a/src/state.c +++ b/src/state.c @@ -43,8 +43,10 @@ const char *dcc_state_prefix = "binstate_"; -struct dcc_task_state my_state; +static struct dcc_task_state *my_state = NULL; +static struct dcc_task_state local_state, remote_state; +static struct dcc_task_state *direct_my_state(const enum dcc_host target); /** * @file @@ -182,7 +184,7 @@ static int dcc_write_state(int fd) /* Write out as one big blob. fd is positioned at the start of * the file. */ - if ((ret = dcc_writex(fd, &my_state, sizeof my_state))) + if ((ret = dcc_writex(fd, my_state, sizeof *my_state))) return ret; return 0; @@ -199,34 +201,38 @@ static int dcc_write_state(int fd) **/ int dcc_note_state(enum dcc_phase state, const char *source_file, - const char *host) + const char *host, enum dcc_host target) { int fd; int ret; char *fname; struct timeval tv; - my_state.struct_size = sizeof my_state; - my_state.magic = DCC_STATE_MAGIC; - my_state.cpid = (unsigned long) getpid(); + + if (!direct_my_state(target)) + return -1; + + my_state->struct_size = sizeof *my_state; + my_state->magic = DCC_STATE_MAGIC; + my_state->cpid = (unsigned long) getpid(); if ((ret = dcc_get_state_filename(&fname))) return ret; source_file = dcc_find_basename(source_file); if (source_file) { - strlcpy(my_state.file, source_file, sizeof my_state.file); + strlcpy(my_state->file, source_file, sizeof my_state->file); } if (host) { - strlcpy(my_state.host, host, sizeof my_state.host); + strlcpy(my_state->host, host, sizeof my_state->host); } if (gettimeofday(&tv, NULL) == -1) { rs_log_error("gettimeofday failed: %s", strerror(errno)); return EXIT_DISTCC_FAILED; } - my_state.curr_phase = state; + my_state->curr_phase = state; rs_trace("note state %d, file \"%s\", host \"%s\"", state, @@ -251,7 +257,36 @@ int dcc_note_state(enum dcc_phase state, } -void dcc_note_state_slot(int slot) +void dcc_note_state_slot(int slot, enum dcc_host target) +{ + if (direct_my_state(target)) + my_state->slot = slot; +} + + +/** + Point 'my_state' to the local or remote host state information, depending on target. + + Return 'my_state' pointer. +**/ +static struct dcc_task_state *direct_my_state(const enum dcc_host target) { - my_state.slot = slot; + switch (target) + { + case DCC_LOCAL: + my_state = &local_state; + break; + + case DCC_REMOTE: + my_state = &remote_state; + break; + + case DCC_UNKNOWN: + break; + } + + if (!my_state) + rs_log_error("my_state == NULL"); + + return my_state; } diff --git a/src/state.h b/src/state.h index 00a2371..d416857 100644 --- a/src/state.h +++ b/src/state.h @@ -46,10 +46,16 @@ enum dcc_phase { DCC_PHASE_DONE /**< MUST be last */ }; +enum dcc_host { + DCC_UNKNOWN, + DCC_LOCAL, + DCC_REMOTE +}; int dcc_note_state (enum dcc_phase state, const char *file, - const char *host); + const char *host, + enum dcc_host); void dcc_remove_state_file (void); @@ -83,7 +89,7 @@ struct dcc_task_state { const char *dcc_get_phase_name(enum dcc_phase); -void dcc_note_state_slot(int slot); +void dcc_note_state_slot(int slot, enum dcc_host target); #ifdef __cplusplus } diff --git a/src/where.c b/src/where.c index b0cd6be..6e4c5dd 100644 --- a/src/where.c +++ b/src/where.c @@ -124,7 +124,9 @@ static void dcc_lock_pause(void) unsigned pause_time = 1; - dcc_note_state(DCC_PHASE_BLOCKED, NULL, NULL); + /* This call to dcc_note_state() is made before the host is known, so it + does not make sense and does nothing useful as far as I can tell. */ + /* dcc_note_state(DCC_PHASE_BLOCKED, NULL, NULL, DCC_UNKNOWN); */ rs_trace("nothing available, sleeping %us...", pause_time); @@ -159,7 +161,7 @@ static int dcc_lock_one(struct dcc_hostdef *hostlist, if (ret == 0) { *buildhost = h; - dcc_note_state_slot(i_cpu); + dcc_note_state_slot(i_cpu, strcmp(h->hostname, "localhost") == 0 ? DCC_LOCAL : DCC_REMOTE); return 0; } else if (ret == EXIT_BUSY) { continue; @@ -192,6 +194,6 @@ int dcc_lock_local_cpp(int *cpu_lock_fd) int ret; struct dcc_hostdef *chosen; ret = dcc_lock_one(dcc_hostdef_local_cpp, &chosen, cpu_lock_fd); - dcc_note_state(DCC_PHASE_CPP, NULL, chosen->hostname); + dcc_note_state(DCC_PHASE_CPP, NULL, chosen->hostname, DCC_LOCAL); return ret; } -- cgit v1.2.1