Index: /home/jeremy/src/distcc-read-only/src/where.c =================================================================== --- /home/jeremy/src/distcc-read-only/src/where.c (revision 719) +++ /home/jeremy/src/distcc-read-only/src/where.c (working copy) @@ -124,7 +124,9 @@ 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 @@ 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 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; } Index: /home/jeremy/src/distcc-read-only/src/remote.c =================================================================== --- /home/jeremy/src/distcc-read-only/src/remote.c (revision 719) +++ /home/jeremy/src/distcc-read-only/src/remote.c (working copy) @@ -105,7 +105,7 @@ int ret; if (cpp_pid) { - dcc_note_state(DCC_PHASE_CPP, NULL, NULL); + dcc_note_state(DCC_PHASE_CPP, NULL, NULL, DCC_REMOTE); /* Wait for cpp to finish (if not already done), check the * result, then send the .i file */ @@ -216,7 +216,7 @@ 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 @@ } #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 @@ /* 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. */ Index: /home/jeremy/src/distcc-read-only/src/clirpc.c =================================================================== --- /home/jeremy/src/distcc-read-only/src/clirpc.c (revision 719) +++ /home/jeremy/src/distcc-read-only/src/clirpc.c (working copy) @@ -162,7 +162,7 @@ /* 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; Index: /home/jeremy/src/distcc-read-only/src/compile.c =================================================================== --- /home/jeremy/src/distcc-read-only/src/compile.c (revision 719) +++ /home/jeremy/src/distcc-read-only/src/compile.c (working copy) @@ -375,7 +375,7 @@ 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. */ Index: /home/jeremy/src/distcc-read-only/src/state.c =================================================================== --- /home/jeremy/src/distcc-read-only/src/state.c (revision 719) +++ /home/jeremy/src/distcc-read-only/src/state.c (working copy) @@ -43,9 +43,9 @@ 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; - /** * @file * @@ -182,7 +182,7 @@ /* 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 +199,45 @@ **/ 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(); + /* JWM: Set my_state to point to the relevant state information. Leave it unchanged if unknown. */ + if (target != DCC_UNKNOWN) + my_state = target == DCC_LOCAL ? &local_state : &remote_state; + + if (!my_state) + { + rs_log_error("my_state == NULL"); + 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 +262,13 @@ } -void dcc_note_state_slot(int slot) +void dcc_note_state_slot(int slot, enum dcc_host target) { - my_state.slot = slot; + if (target != DCC_UNKNOWN) + my_state = target == DCC_LOCAL ? &local_state : &remote_state; + + if (!my_state) + rs_log_error("my_state == NULL"); + else + my_state->slot = slot; } Index: /home/jeremy/src/distcc-read-only/src/state.h =================================================================== --- /home/jeremy/src/distcc-read-only/src/state.h (revision 719) +++ /home/jeremy/src/distcc-read-only/src/state.h (working copy) @@ -46,10 +46,16 @@ 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 @@ 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 }