/** * Read state. If loaded successfully, store a pointer to the newly * allocated structure into *ppl. */ static int dcc_mon_load_state(int fd, char *fullpath, struct dcc_task_state **ppl) { int ret; struct dcc_task_state *tl; tl = calloc(1, sizeof *tl); if (!tl) { rs_log_crit("failed to allocate dcc_task_state"); return EXIT_OUT_OF_MEMORY; } ret = dcc_mon_read_state(fd, fullpath, tl); if (ret) { dcc_task_state_free(tl); *ppl = NULL; return ret; } if (tl->curr_phase != DCC_PHASE_DONE) { ret = dcc_mon_check_orphans(tl); if (ret) { dcc_task_state_free(tl); *ppl = NULL; return ret; } } *ppl = tl; return ret; }
int main(int argc, char *argv[]) { struct dcc_task_state *list; int ret; float delay; char *end; dcc_set_trace_from_env(); if (argc == 1) delay = 0.0; else if (argc == 2) { delay = strtod(argv[1], &end); if (*end) { usage(); return 1; } } else { usage(); return 1; } /* We might be writing to e.g. a pipe that's being read by some * other program, so make sure we're always line buffered. */ setvbuf (stdout, NULL, _IOLBF, BUFSIZ); do { struct dcc_task_state *i; if ((ret = dcc_mon_poll(&list))) return ret; for (i = list; i; i = i->next) { #if 1 if (i->curr_phase == DCC_PHASE_DONE) continue; #endif /* Assume 80 cols = */ printf("%6ld %-10.10s %-30.30s %24.24s[%d]\n", (long) i->cpid, dcc_get_phase_name(i->curr_phase), i->file, i->host, i->slot); } printf("\n"); /* XXX: usleep() is probably not very portable */ usleep(delay * 1000000); dcc_task_state_free(list); } while (delay); return 0; }
/** * Callback when the timer triggers, causing a refresh. Loads the * current state from the state monitor and puts it into the table * model, which should then redraw itself. **/ static gint dcc_gnome_update_cb (gpointer UNUSED(view_void)) { struct dcc_task_state *task_list; if (dcc_mon_poll (&task_list)) { rs_log_warning("poll failed"); return TRUE; } dcc_update_store_from_tasks (task_list); dcc_task_state_free (task_list); return TRUE; /* please call again */ }