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/qlop.c.old (-71 / +134 lines)
Lines 295-313 Link Here
295
	fclose(fp);
295
	fclose(fp);
296
}
296
}
297
297
298
void show_current_emerge(void);
298
void print_current_emerge(const char *logfile, const depend_atom *pkg);
299
#if defined(__linux__) || defined(__FreeBSD__)
300
void print_current_emerge(const char *logfile, const depend_atom *pkg)
301
{
302
	FILE *fp;
303
	char buf[2][BUFSIZE];
304
	char *p;
305
	unsigned long count, merge_time, elapsed_time = 0;
306
	time_t start_date, t[2];
307
	depend_atom *atom;
308
309
	start_date = t[0] = t[1] = 0UL;
310
	count = merge_time = 0;
311
312
	DBG("Searching for %s in %s\n", pkg->PN, logfile);
313
314
	if ((fp = fopen(logfile, "r")) == NULL) {
315
		warnp("Could not open logfile '%s'", logfile);
316
		return;
317
	}
318
319
	while ((fgets(buf[0], sizeof(buf[0]), fp)) != NULL) {
320
		if (strstr(buf[0], pkg->PN) == NULL)
321
			continue;
322
323
		if ((p = strchr(buf[0], '\n')) != NULL)
324
			*p = 0;
325
		if ((p = strchr(buf[0], ':')) == NULL)
326
			continue;
327
		*p = 0;
328
		t[0] = atol(buf[0]);
329
		strcpy(buf[1], p + 1);
330
		rmspace(buf[1]);
331
		if ((strncmp(buf[1], ">>> emerge (", 12)) == 0) {
332
			char matched = 0;
333
			if ((p = strchr(buf[1], ')')) == NULL)
334
				continue;
335
			*p = 0;
336
			strcpy(buf[0], p + 1);
337
			rmspace(buf[0]);
338
			if ((p = strchr(buf[0], ' ')) == NULL)
339
				continue;
340
			*p = 0;
341
			if ((atom = atom_explode(buf[0])) == NULL)
342
				continue;
343
344
			if (pkg->CATEGORY) {
345
				if ((strcmp(pkg->CATEGORY, atom->CATEGORY) == 0) && (strcmp(pkg->PN, atom->PN) == 0))
346
					matched = 1;
347
			} else if (strcmp(pkg->PN, atom->PN) == 0)
348
				matched = 1;
349
350
			if (matched) {
351
				start_date = t[0];
352
				while ((fgets(buf[0], sizeof(buf[0]), fp)) != NULL) {
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[1] = atol(buf[0]);
359
					strcpy(buf[1], p + 1);
360
					rmspace(buf[1]);
361
					if (*buf[1] == '*')
362
						break;
363
					if ((strncmp(buf[1], "::: completed emerge (", 22)) == 0) {
364
						merge_time += (t[1] - t[0]);
365
						count++;
366
						break;
367
					}
368
				}
369
			}
370
			atom_implode(atom);
371
		}
372
	}
373
	fclose(fp);
374
375
	elapsed_time = time(0) - start_date;
376
	printf(	" %s*%s %s%s%s%s\n"
377
			"     started: %s%s%s\n"
378
			"     elapsed: ",
379
	BOLD, NORM, BLUE, (pkg->CATEGORY ? strcat(pkg->CATEGORY, "/") : ""), pkg->P, NORM,
380
	GREEN, chop_ctime(start_date), NORM);
381
	print_seconds_for_earthlings(elapsed_time);
382
	printf("\n     ETA:     ");
383
	if (merge_time == 0)
384
		printf("Unknown");
385
	else if (merge_time / count < elapsed_time)
386
		printf("Sometime soon");
387
	else
388
		print_seconds_for_earthlings(merge_time / count - elapsed_time);
389
	puts("");
390
}
391
#else
392
void print_current_emerge(const char *logfile, const depend_atom *pkg)
393
{
394
	errf("not supported on your crapbox OS");
395
}
396
#endif
397
398
void show_current_emerge(const char *logfile);
299
#ifdef __linux__
399
#ifdef __linux__
300
void show_current_emerge(void)
400
void show_current_emerge(const char *logfile)
301
{
401
{
302
	DIR *proc;
402
	DIR *proc;
303
	struct dirent *de;
403
	struct dirent *de;
304
	pid_t pid;
404
	pid_t pid;
305
	char buf[BUFSIZE], bufstat[300];
405
	char buf[2][BUFSIZE], path[50];
306
	char path[50];
406
	char *p;
307
	char *p, *q;
407
	depend_atom *atom;
308
	unsigned long long start_time = 0;
309
	double uptime_secs;
310
	time_t start_date;
311
408
312
	if ((proc = opendir("/proc")) == NULL) {
409
	if ((proc = opendir("/proc")) == NULL) {
313
		warnp("Could not open /proc");
410
		warnp("Could not open /proc");
Lines 321-384 Link Here
321
418
322
		/* portage renames the cmdline so the package name is first */
419
		/* portage renames the cmdline so the package name is first */
323
		snprintf(path, sizeof(path), "/proc/%i/cmdline", pid);
420
		snprintf(path, sizeof(path), "/proc/%i/cmdline", pid);
324
		if (!eat_file(path, buf, sizeof(buf)))
421
		if (!eat_file(path, buf[0], sizeof(buf[0])))
325
			continue;
422
			continue;
326
423
327
		if (buf[0] == '[' && (p = strchr(buf, ']')) != NULL && strstr(buf, "sandbox") != NULL) {
424
		if (buf[0][0] == '[' && (p = strchr(buf[0], ']')) != NULL && strstr(buf[0], "sandbox") != NULL) {
425
			/* try to fetch category from process env */
426
			snprintf(path, sizeof(path), "/proc/%i/environ", pid);
427
			if (eat_file(path, buf[1], sizeof(buf[1]))) {
428
				p = buf[1];
429
				while (strstr(p, "PORTAGE_BUILDDIR=") == NULL)
430
					p = strchr(p, '\0')+1;
431
				while (strchr(p, '/') != strrchr(p, '/'))
432
					p = strchr(p, '/')+1;
433
				if ((atom = atom_explode(p)) == NULL)
434
					continue;
435
			}
436
			/* fallback to packagename if not allowed */
437
			else {
328
			*p = '\0';
438
			*p = '\0';
329
			p = buf+1;
439
				if ((atom = atom_explode(buf[0]+1)) == NULL)
330
			q = p + strlen(p) + 1;
440
					continue;
331
441
			}
332
			/* open the stat file to figure out how long we have been running */
442
			print_current_emerge(logfile, atom);
333
			snprintf(path, sizeof(path), "/proc/%i/stat", pid);
443
			atom_implode(atom);
334
			if (!eat_file(path, bufstat, sizeof(bufstat)))
335
				continue;
336
337
			/* ripped from procps/proc/readproc.c */
338
			if ((q = strchr(bufstat, ')')) == NULL)
339
				continue;
340
			/* grab the start time */
341
			sscanf(q + 2,
342
				"%*c "
343
				"%*d %*d %*d %*d %*d "
344
				"%*u %*u %*u %*u %*u "
345
				"%*u %*u %*u %*u "
346
				"%*d %*d "
347
				"%*d "
348
				"%*d "
349
				"%Lu ",
350
				&start_time);
351
			/* get uptime */
352
			if (!eat_file("/proc/uptime", bufstat, sizeof(bufstat)))
353
				continue;
354
			sscanf(bufstat, "%lf", &uptime_secs);
355
356
			/* figure out when this thing started and then show it */
357
			start_date = time(0) - (uptime_secs - (start_time / HZ));
358
			printf(
359
				" %s*%s %s%s%s\n"
360
				"     started: %s%s%s\n"
361
				"     elapsed: ", /*%s%llu%s seconds\n",*/
362
				BOLD, NORM, BLUE, p, NORM,
363
				GREEN, chop_ctime(start_date), NORM);
364
			print_seconds_for_earthlings(uptime_secs - (start_time / HZ));
365
			puts(NORM);
366
		}
444
		}
367
	}
445
	}
368
446
369
	closedir(proc);
447
	closedir(proc);
370
371
	if (start_time == 0 && verbose)
372
		puts("No emerge processes located");
373
}
448
}
374
#elif defined(__FreeBSD__)
449
#elif defined(__FreeBSD__)
375
void show_current_emerge(void)
450
void show_current_emerge(const char *logfile)
376
{
451
{
377
	kvm_t *kd = NULL;
452
	kvm_t *kd = NULL;
378
	struct kinfo_proc *ip;
453
	struct kinfo_proc *ip;
379
	int i; int total_processes;
454
	int i, total_processes;
380
	char *p, *q;
455
	char *p;
381
	time_t start_date = 0;
456
	depend_atom *atom;
382
457
383
	if (! (kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY, "kvm_open"))) {
458
	if (! (kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY, "kvm_open"))) {
384
		warnp("Could not open kvm: %s", kvm_geterr(kd));
459
		warnp("Could not open kvm: %s", kvm_geterr(kd));
Lines 403-428 Link Here
403
		}
478
		}
404
479
405
		*p = '\0';
480
		*p = '\0';
406
		p = buf+1;
481
		atom = atom_explode(buf+1);
407
		q = p + strlen(p) + 1;
482
		print_current_emerge(logfile, atom);
408
483
		atom_implode(atom);
409
		printf(
410
			" %s*%s %s%s%s\n"
411
			"     started: %s%s%s\n"
412
			"     elapsed: ", /*%s%llu%s seconds\n",*/
413
			BOLD, NORM, BLUE, p, NORM,
414
			GREEN, chop_ctime(ip[i].ki_start.tv_sec), NORM);
415
		print_seconds_for_earthlings(time(0) - ip[i].ki_start.tv_sec);
416
		puts(NORM);
417
418
		free(buf);
484
		free(buf);
419
	}
485
	}
420
421
	if (start_date == 0 && verbose)
422
		puts("No emerge processes located");
423
}
486
}
424
#else
487
#else
425
void show_current_emerge(void)
488
void show_current_emerge(const char *logfile)
426
{
489
{
427
	errf("not supported on your crapbox OS");
490
	errf("not supported on your crapbox OS");
428
}
491
}
Lines 473-479 Link Here
473
	else if (do_unlist)
536
	else if (do_unlist)
474
		show_emerge_history(QLOP_UNLIST, argc, argv, logfile);
537
		show_emerge_history(QLOP_UNLIST, argc, argv, logfile);
475
	if (do_current)
538
	if (do_current)
476
		show_current_emerge();
539
		show_current_emerge(logfile);
477
	if (do_sync)
540
	if (do_sync)
478
		show_sync_history(logfile);
541
		show_sync_history(logfile);
479
542

Return to bug 161244