Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Sun, 04 Oct 2020 12:33:21
Message-Id: 1601814720.8b01bccbd469e034736f4d88f595a61e6ef6f7b4.grobian@gentoo
1 commit: 8b01bccbd469e034736f4d88f595a61e6ef6f7b4
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Sun Oct 4 12:32:00 2020 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Sun Oct 4 12:32:00 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8b01bccb
7
8 qlop: treat either terminating or exiting or both as a termination of Portage
9
10 It seems Portage is very inconsistent sometimes terminating, sometimes
11 exiting, most of the time exiting and terminating. Deal with it.
12
13 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
14
15 qlop.c | 49 +++++++++++++++++++++++++++----------------------
16 1 file changed, 27 insertions(+), 22 deletions(-)
17
18 diff --git a/qlop.c b/qlop.c
19 index dce46f2..a5d8678 100644
20 --- a/qlop.c
21 +++ b/qlop.c
22 @@ -374,6 +374,7 @@ static int do_emerge_log(
23 time_t tlast = tbegin;
24 time_t tstart_emerge = 0;
25 time_t last_merge = 0;
26 + time_t last_exit = 0;
27 time_t sync_start = 0;
28 time_t sync_time = 0;
29 size_t sync_cnt = 0;
30 @@ -392,6 +393,7 @@ static int do_emerge_log(
31 char afmt[BUFSIZ];
32 struct pkg_match *pkg;
33 struct pkg_match *pkgw;
34 +#define strpfx(X, Y) strncmp(X, Y, sizeof(Y) - 1)
35
36 /* support relative path in here and now, when using ROOT, stick to
37 * it, turning relative into a moot point */
38 @@ -420,14 +422,14 @@ static int do_emerge_log(
39 continue;
40
41 if (flags->show_lastmerge) {
42 - if (strncmp(p, " *** emerge ", 13) == 0)
43 + if (strpfx(p, " *** emerge ") == 0)
44 tstart_emerge = tstart;
45 if (!all_atoms)
46 continue;
47 }
48
49 atom = NULL;
50 - if (strncmp(p, " >>> emerge ", 13) == 0 &&
51 + if (strpfx(p, " >>> emerge ") == 0 &&
52 (q = strchr(p + 13, ')')) != NULL)
53 {
54 p = q + 2;
55 @@ -436,8 +438,8 @@ static int do_emerge_log(
56 *q = '\0';
57 atom = atom_explode(p);
58 }
59 - } else if (strncmp(p, " === Unmerging... (", 20) == 0 ||
60 - strncmp(p, " === Unmerging... (", 19) == 0)
61 + } else if (strpfx(p, " === Unmerging... (") == 0 ||
62 + strpfx(p, " === Unmerging... (") == 0)
63 {
64 if (p[1] == ' ')
65 p++;
66 @@ -493,17 +495,23 @@ static int do_emerge_log(
67 continue;
68 *p++ = '\0';
69
70 + tstart = atol(buf);
71 +
72 /* keeping track of parallel merges needs to be done before
73 * applying dates, for a subset of the log might show emerge
74 * finished without knowledge of another instance */
75 if (flags->do_running &&
76 - (strncmp(p, " *** emerge ", 13) == 0 ||
77 - strncmp(p, " *** terminating.", 18) == 0))
78 + (strpfx(p, " *** emerge ") == 0 ||
79 + strpfx(p, " *** exiting ") == 0 ||
80 + strpfx(p, " *** terminating.") == 0))
81 {
82 if (p[7] == 'm') {
83 parallel_emerge++;
84 } else if (parallel_emerge > 0) {
85 - parallel_emerge--;
86 + if (p[7] != 'e' || tstart != last_exit)
87 + parallel_emerge--;
88 + if (p[7] == 'x')
89 + last_exit = tstart;
90 }
91
92 /* for bug #687508, this cannot be in the else if case
93 @@ -531,7 +539,6 @@ static int do_emerge_log(
94 }
95 }
96
97 - tstart = atol(buf);
98 if (tstart < tlast)
99 continue;
100 tlast = tstart;
101 @@ -539,15 +546,14 @@ static int do_emerge_log(
102 continue;
103
104 /* are we interested in this line? */
105 - if (flags->show_emerge && verbose && (
106 - strncmp(p, " *** emerge ", 13) == 0))
107 + if (flags->show_emerge && verbose && (strpfx(p, " *** emerge ") == 0))
108 {
109 char shortopts[8]; /* must hold as many opts converted below */
110 int numopts = 0;
111
112 printf("%semerge%s", DKBLUE, NORM);
113 for (p += 13; (q = strtok(p, " \n")) != NULL; p = NULL) {
114 - if (strncmp(q, "--", 2) == 0) {
115 + if (strpfx(q, "--") == 0) {
116 /* portage seems to normalise options given into
117 * their long forms always; I don't want to keep a
118 * mapping table to short forms here, but it's
119 @@ -596,7 +602,7 @@ static int do_emerge_log(
120 continue;
121 }
122
123 - if (strncmp(q, "--", 2) == 0) {
124 + if (strpfx(q, "--") == 0) {
125 printf(" %s%s%s", GREEN, q, NORM);
126 } else if (strcmp(q, "@world") == 0 ||
127 strcmp(q, "@system") == 0)
128 @@ -622,7 +628,7 @@ static int do_emerge_log(
129 }
130 printf("\n");
131 } else if (flags->do_sync && (
132 - strncmp(p, " === Sync completed ", 20) == 0 ||
133 + strpfx(p, " === Sync completed ") == 0 ||
134 strcmp(p, " === sync\n") == 0))
135 {
136 /* sync start or stop, we have nothing to detect parallel
137 @@ -636,7 +642,7 @@ static int do_emerge_log(
138 elapsed = tstart - sync_start;
139
140 p += 20;
141 - if (strncmp(p, "for ", 4) == 0) {
142 + if (strpfx(p, "for ") == 0) {
143 p += 4;
144 } else { /* "with " */
145 p += 5;
146 @@ -670,8 +676,8 @@ static int do_emerge_log(
147 sync_start = 0; /* reset */
148 }
149 } else if (flags->do_merge && (
150 - strncmp(p, " >>> emerge (", 14) == 0 ||
151 - strncmp(p, " ::: completed emerge (", 24) == 0))
152 + strpfx(p, " >>> emerge (") == 0 ||
153 + strpfx(p, " ::: completed emerge (") == 0))
154 {
155 /* merge start/stop (including potential unmerge of old pkg) */
156 if (p[3] == '>') { /* >>> emerge */
157 @@ -810,11 +816,11 @@ static int do_emerge_log(
158 }
159 } else if (
160 (flags->do_unmerge &&
161 - strncmp(p, " === Unmerging... (", 19) == 0) ||
162 + strpfx(p, " === Unmerging... (") == 0) ||
163 (flags->do_autoclean &&
164 - strncmp(p, " === Unmerging... (", 20) == 0) ||
165 + strpfx(p, " === Unmerging... (") == 0) ||
166 ((flags->do_unmerge || flags->do_autoclean) &&
167 - strncmp(p, " >>> unmerge success: ", 23) == 0))
168 + strpfx(p, " >>> unmerge success: ") == 0))
169 {
170 /* unmerge action */
171 if (p[2] == '=') {
172 @@ -1230,7 +1236,7 @@ static array_t *probe_proc(array_t *atoms)
173 if (eat_file(npath, &cmdline, &cmdlinesize)) {
174 if (cmdlinesize > 0 && cmdline[0] == '[' &&
175 (p = strchr(cmdline, ']')) != NULL &&
176 - strncmp(p, "] sandbox", sizeof("] sandbox") - 1) == 0)
177 + strpfx(p, "] sandbox") == 0)
178 {
179 *p = '\0';
180 atom = atom_explode(cmdline + 1);
181 @@ -1268,8 +1274,7 @@ static array_t *probe_proc(array_t *atoms)
182 if ((size_t)rpathlen > sizeof(".log.gz") &&
183 (p = strrchr(rpath, '.')) != NULL &&
184 p - (sizeof(".log") - 1) > rpath &&
185 - strncmp(p - (sizeof(".log") - 1), ".log",
186 - sizeof(".log") - 1) == 0)
187 + strpfx(p - (sizeof(".log") - 1), ".log") == 0)
188 {
189 *p = '\0';
190 rpathlen -= rpath - p;