Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 161244 | Differences between
and this patch

Collapse All | Expand All

(-)portage-utils-0.1.22.old/qlop.c (-47 / +109 lines)
Lines 288-306 Link Here
288
	fclose(fp);
288
	fclose(fp);
289
}
289
}
290
290
291
void show_current_emerge(void);
291
void show_current_emerge(const char *logfile);
292
#ifdef __QLOP_CURRENT__
292
#ifdef __QLOP_CURRENT__
293
void show_current_emerge(void)
293
void show_current_emerge(const char *logfile)
294
{
294
{
295
	FILE *fp;
295
	DIR *proc;
296
	DIR *proc;
296
	struct dirent *de;
297
	struct dirent *de;
297
	pid_t pid;
298
	pid_t pid;
298
	char buf[BUFSIZE], bufstat[300];
299
	char buf[2][BUFSIZE], path[50];
299
	char path[50];
300
	char *p;
300
	char *p, *q;
301
	unsigned long count, merge_time, elapsed_time = 0;
301
	unsigned long long start_time = 0;
302
	time_t start_date, t[2];
302
	double uptime_secs;
303
	depend_atom *pkg, *atom;
303
	time_t start_date;
304
304
305
	if ((proc = opendir("/proc")) == NULL) {
305
	if ((proc = opendir("/proc")) == NULL) {
306
		warnp("Could not open /proc");
306
		warnp("Could not open /proc");
Lines 314-371 Link Here
314
314
315
		/* portage renames the cmdline so the package name is first */
315
		/* portage renames the cmdline so the package name is first */
316
		snprintf(path, sizeof(path), "/proc/%i/cmdline", pid);
316
		snprintf(path, sizeof(path), "/proc/%i/cmdline", pid);
317
		if (!eat_file(path, buf, sizeof(buf)))
317
		if (!eat_file(path, buf[0], sizeof(buf[0])))
318
			continue;
318
			continue;
319
319
320
		if (buf[0] == '[' && (p = strchr(buf, ']')) != NULL && strstr(buf, "sandbox") != NULL) {
320
		if (buf[0][0] == '[' && (p = strchr(buf[0], ']')) != NULL && strstr(buf[0], "sandbox") != NULL) {
321
			/* try to fetch category from process env */
322
			snprintf(path, sizeof(path), "/proc/%i/environ", pid);
323
			if (eat_file(path, buf[1], sizeof(buf[1]))) {
324
				p = buf[1];
325
				while (strstr(p, "PORTAGE_BUILDDIR=") == NULL)
326
					p = strchr(p, '\0')+1;
327
				while (strchr(p, '/') != strrchr(p, '/'))
328
					p = strchr(p, '/')+1;
329
				if ((pkg = atom_explode(p)) == NULL)
330
					continue;
331
			}
332
			/* fallback to less acurate packagename if not allowed */
333
			else {
321
			*p = '\0';
334
			*p = '\0';
322
			p = buf+1;
335
				if ((pkg = atom_explode(buf[0]+1)) == NULL)
323
			q = p + strlen(p) + 1;
336
					continue;
337
			}
338
339
			start_date = t[0] = t[1] = 0UL;
340
			count = merge_time = 0;
341
		
342
			DBG("Searching for %s in %s\n", pkg->PN, logfile);
343
		
344
			if ((fp = fopen(logfile, "r")) == NULL) {
345
				warnp("Could not open logfile '%s'", logfile);
346
				return;
347
			}
348
		
349
			while ((fgets(buf[0], sizeof(buf[0]), fp)) != NULL) {
350
				if (strstr(buf[0], pkg->PN) == NULL)
351
					continue;
352
		
353
				if ((p = strchr(buf[0], '\n')) != NULL)
354
					*p = 0;
355
				if ((p = strchr(buf[0], ':')) == NULL)
356
					continue;
357
				*p = 0;
358
				t[0] = atol(buf[0]);
359
				strcpy(buf[1], p + 1);
360
				rmspace(buf[1]);
361
				if ((strncmp(buf[1], ">>> emerge (", 12)) == 0) {
362
					char matched = 0;
363
					if ((p = strchr(buf[1], ')')) == NULL)
364
						continue;
365
					*p = 0;
366
					strcpy(buf[0], p + 1);
367
					rmspace(buf[0]);
368
					if ((p = strchr(buf[0], ' ')) == NULL)
369
						continue;
370
					*p = 0;
371
					if ((atom = atom_explode(buf[0])) == NULL)
372
						continue;
373
		
374
					if (pkg->CATEGORY) {
375
						if ((strcmp(pkg->CATEGORY, atom->CATEGORY) == 0) && (strcmp(pkg->PN, atom->PN) == 0))
376
							matched = 1;
377
					} else if (strcmp(pkg->PN, atom->PN) == 0)
378
						matched = 1;
379
					
380
					if (matched) {
381
						start_date = t[0];
382
						while ((fgets(buf[0], sizeof(buf[0]), fp)) != NULL) {
383
							if ((p = strchr(buf[0], '\n')) != NULL)
384
								*p = 0;
385
							if ((p = strchr(buf[0], ':')) == NULL)
386
								continue;
387
							*p = 0;
388
							t[1] = atol(buf[0]);
389
							strcpy(buf[1], p + 1);
390
							rmspace(buf[1]);
391
							if (*buf[1] == '*')
392
								break;
393
							if ((strncmp(buf[1], "::: completed emerge (", 22)) == 0) {
394
								merge_time += (t[1] - t[0]);
395
								count++;
396
								break;
397
							}
398
						}
399
					}
400
					atom_implode(atom);
401
				}
402
			}
403
			fclose(fp);
324
404
325
			/* open the stat file to figure out how long we have been running */
405
			elapsed_time = time(0) - start_date;
326
			snprintf(path, sizeof(path), "/proc/%i/stat", pid);
406
			printf(	" %s*%s %s%s%s%s\n"
327
			if (!eat_file(path, bufstat, sizeof(bufstat)))
328
				continue;
329
330
			/* ripped from procps/proc/readproc.c */
331
			if ((q = strchr(bufstat, ')')) == NULL)
332
				continue;
333
			/* grab the start time */
334
			sscanf(q + 2,
335
				"%*c "
336
				"%*d %*d %*d %*d %*d "
337
				"%*u %*u %*u %*u %*u "
338
				"%*u %*u %*u %*u "
339
				"%*d %*d "
340
				"%*d "
341
				"%*d "
342
				"%Lu ",
343
				&start_time);
344
			/* get uptime */
345
			if (!eat_file("/proc/uptime", bufstat, sizeof(bufstat)))
346
				continue;
347
			sscanf(bufstat, "%lf", &uptime_secs);
348
349
			/* figure out when this thing started and then show it */
350
			start_date = time(0) - (uptime_secs - (start_time / HZ));
351
			printf(
352
				" %s*%s %s%s%s\n"
353
				"     started: %s%s%s\n"
407
				"     started: %s%s%s\n"
354
				"     elapsed: ", /*%s%llu%s seconds\n",*/
408
				"     elapsed: ",
355
				BOLD, NORM, BLUE, p, NORM,
409
				BOLD, NORM, BLUE, (pkg->CATEGORY ? strcat(pkg->CATEGORY, "/") : ""), pkg->P, NORM,
356
				GREEN, chop_ctime(start_date), NORM);
410
				GREEN, chop_ctime(start_date), NORM);
357
			print_seconds_for_earthlings(uptime_secs - (start_time / HZ));
411
			print_seconds_for_earthlings(elapsed_time);
358
			puts(NORM);
412
			printf("\n     ETA:     ");
413
			if (merge_time == 0)
414
				printf("Unknown");
415
			else if (merge_time / count < elapsed_time)
416
				printf("Sometime soon");
417
			else				
418
				print_seconds_for_earthlings(merge_time / count - elapsed_time);
419
			puts("");
420
			atom_implode(pkg);
359
		}
421
		}
360
	}
422
	}
361
423
362
	closedir(proc);
424
	closedir(proc);
363
425
364
	if (start_time == 0 && verbose)
426
	if (elapsed_time == 0 && verbose)
365
		puts("No emerge processes located");
427
		puts("No emerge processes located");
366
}
428
}
367
#else
429
#else
368
void show_current_emerge(void)
430
void show_current_emerge(const char *logfile)
369
{
431
{
370
	errf("not supported on your crapbox OS");
432
	errf("not supported on your crapbox OS");
371
}
433
}
Lines 416-422 Link Here
416
	else if (do_unlist)
478
	else if (do_unlist)
417
		show_emerge_history(QLOP_UNLIST, argc, argv, logfile);
479
		show_emerge_history(QLOP_UNLIST, argc, argv, logfile);
418
	if (do_current)
480
	if (do_current)
419
		show_current_emerge();
481
		show_current_emerge(logfile);
420
	if (do_sync)
482
	if (do_sync)
421
		show_sync_history(logfile);
483
		show_sync_history(logfile);
422
484

Return to bug 161244