--- qlop.c.old 2010-03-13 10:02:27.189479059 +0100 +++ qlop.c 2010-03-13 10:09:37.492821028 +0100 @@ -88,11 +88,12 @@ { FILE *fp; char cat[126], buf[2][BUFSIZ]; - char *pkg, *p; + char *pkg, *p, *q; char ep[BUFSIZ]; unsigned long count, merge_time; time_t t[2]; depend_atom *atom; + unsigned int parallel_emerge; t[0] = t[1] = 0UL; count = merge_time = 0; @@ -148,6 +149,7 @@ matched = 1; if (matched) { + parallel_emerge = 0; while ((fgets(buf[0], sizeof(buf[0]), fp)) != NULL) { if ((p = strchr(buf[0], '\n')) != NULL) *p = 0; @@ -157,6 +159,44 @@ t[1] = atol(buf[0]); strcpy(buf[1], p + 1); rmspace(buf[1]); + + if ((strncmp(buf[1], "Started emerge on:", 18)) == 0) + { + /* a parallel emerge was launched */ + parallel_emerge++; + continue; + } + + if ((strncmp(buf[1], "*** terminating.", 16)) == 0) + { + if(parallel_emerge > 0) + { + /* a parallel emerge has finished */ + parallel_emerge--; + continue; + } + else /* the main emerge was stopped */ + break; + } + + /* pay attention to malformed log files (when the end of an emerge process + is not indicated by the line '*** terminating'). We assume than the log is + malformed when we find a parallel emerge process which is trying to + emerge the same package */ + if ((strncmp(buf[1], ">>> emerge (", 12)) == 0 && parallel_emerge > 0) + { + if ((p = strchr(buf[1], ')')) == NULL || (q = strchr(ep, ')')) == NULL) + continue; + + if (!strcmp(p,q)) + { + parallel_emerge--; + /* update the main emerge reference data */ + snprintf(ep, BUFSIZ, "completed %s", &buf[1][4]); + continue; + } + } + if ((strncmp(&buf[1][4], ep, BUFSIZ)) == 0) { if (!average) { strcpy(buf[1], "");