aboutsummaryrefslogtreecommitdiff
path: root/qlop.c
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2019-12-27 21:38:44 +0100
committerFabian Groffen <grobian@gentoo.org>2019-12-27 21:38:44 +0100
commit1e5b2c8d3fb58335990e411af98498f249b54980 (patch)
tree6c62184a223b7216719a8faa6cb96cca349ef4a2 /qlop.c
parentqkeyword: apply profile masks to -S/-T results (diff)
downloadportage-utils-1e5b2c8d3fb58335990e411af98498f249b54980.tar.gz
portage-utils-1e5b2c8d3fb58335990e411af98498f249b54980.tar.bz2
portage-utils-1e5b2c8d3fb58335990e411af98498f249b54980.zip
qlop: some changes to -r (running) mode
- warn when qlop needs to defer to log heuristics (#701968) - print running packages most recent first - suppress identical running packages (#701392) - ignore batches in emerge.log that appear to be backwards in time Bug: https://bugs.gentoo.org/701968 Bug: https://bugs.gentoo.org/701392 Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Diffstat (limited to 'qlop.c')
-rw-r--r--qlop.c50
1 files changed, 43 insertions, 7 deletions
diff --git a/qlop.c b/qlop.c
index 7cc8f44d..634431a6 100644
--- a/qlop.c
+++ b/qlop.c
@@ -371,6 +371,7 @@ static int do_emerge_log(
char *p;
char *q;
time_t tstart = LONG_MAX;
+ time_t tlast = tbegin;
time_t tstart_emerge = 0;
time_t last_merge = 0;
time_t sync_start = 0;
@@ -531,6 +532,9 @@ static int do_emerge_log(
}
tstart = atol(buf);
+ if (tstart < tlast)
+ continue;
+ tlast = tstart;
if (tstart < tbegin || tstart > tend)
continue;
@@ -845,6 +849,7 @@ static int do_emerge_log(
fclose(fp);
if (flags->do_running) {
time_t cutofftime;
+ set *pkgs_seen = create_set();
tstart = time(NULL);
@@ -856,7 +861,8 @@ static int do_emerge_log(
/* can't report endtime for non-finished operations */
flags->do_endtime = 0;
- sync_time /= sync_cnt;
+ if (sync_time > 0)
+ sync_time /= sync_cnt;
if (sync_start >= cutofftime) {
elapsed = tstart - sync_start;
if (elapsed >= sync_time)
@@ -876,9 +882,10 @@ static int do_emerge_log(
fmt_elapsedtime(flags, sync_time - elapsed));
}
}
- array_for_each(merge_matches, i, pkgw) {
+ array_for_each_rev(merge_matches, i, pkgw) {
time_t maxtime = 0;
bool isMax = false;
+ bool notseen;
if (pkgw->tbegin < cutofftime)
continue;
@@ -886,6 +893,11 @@ static int do_emerge_log(
snprintf(afmt, sizeof(afmt), "%s/%s",
pkgw->atom->CATEGORY, pkgw->atom->PN);
+ /* eliminate dups, bug #701392 */
+ add_set_unique(afmt, pkgs_seen, &notseen);
+ if (!notseen)
+ continue;
+
elapsed = tstart - pkgw->tbegin;
pkg = get_set(afmt, merge_averages);
if (pkg != NULL) {
@@ -923,9 +935,11 @@ static int do_emerge_log(
maxtime > 0 && verbose ?
isMax ? " (longest run)" : " (average run)" : "");
}
+ clear_set(pkgs_seen);
array_for_each(unmerge_matches, i, pkgw) {
time_t maxtime = 0;
bool isMax = false;
+ bool notseen;
if (pkgw->tbegin < cutofftime)
continue;
@@ -933,6 +947,11 @@ static int do_emerge_log(
snprintf(afmt, sizeof(afmt), "%s/%s",
pkgw->atom->CATEGORY, pkgw->atom->PN);
+ /* eliminate dups, bug #701392 */
+ add_set_unique(afmt, pkgs_seen, &notseen);
+ if (!notseen)
+ continue;
+
elapsed = tstart - pkgw->tbegin;
pkg = get_set(afmt, unmerge_averages);
if (pkg != NULL) {
@@ -959,6 +978,7 @@ static int do_emerge_log(
maxtime > 0 && verbose ?
isMax ? " (longest run)" : " (average run)" : "");
}
+ free_set(pkgs_seen);
} else if (flags->do_average) {
size_t total_merges = 0;
size_t total_unmerges = 0;
@@ -1135,9 +1155,22 @@ static array_t *probe_proc(array_t *atoms)
scandir_free(procs, procslen);
} else {
/* flag /proc doesn't exist */
+ warn("/proc doesn't exist, running merges are based on heuristics");
return NULL;
}
+ if (array_cnt(ret_atoms) == 0) {
+ /* if we didn't find anything, this is either because nothing is
+ * running, or because we didn't have appropriate permissions --
+ * try to figure out which of the two is it (there is no good
+ * way) */
+ if (geteuid() != 0) {
+ warn("insufficient privileges for full /proc access, "
+ "running merges are based on heuristics");
+ return NULL;
+ }
+ }
+
if (array_cnt(atoms) > 0) {
size_t j;
depend_atom *atomr;
@@ -1351,12 +1384,15 @@ int qlop_main(int argc, char **argv)
}
if (m.do_running) {
- array_t *new_atoms = probe_proc(atoms);
+ array_t *new_atoms = NULL;
+
+ if (runningmode > 1) {
+ warn("running without /proc scanning, heuristics only");
+ } else {
+ new_atoms = probe_proc(atoms);
+ }
- if (runningmode > 1 || new_atoms == NULL) {
- warn("/proc not available, deducing running "
- "merges from emerge.log");
- } else if (array_cnt(new_atoms) == 0) {
+ if (new_atoms != NULL && array_cnt(new_atoms) == 0) {
/* proc supported, found nothing running */
start_time = LONG_MAX;
}