pg_top icon indicating copy to clipboard operation
pg_top copied to clipboard

pg_top inside a LXC container (unprivileged on ProxMox)

Open hvisage opened this issue 6 years ago • 4 comments

The error is a segmentation fault, looking at strace and ltrace we see the permission and array check error:

strace:

open("5401/io", O_RDONLY) = 4 read(4, 0x7ffd4c67c360, 4095) = -1 EACCES (Permission denied) close(4) = 0 --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x2} --- +++ killed by SIGSEGV +++ Segmentation fault

ltrace:

[pid 25433] open("5401/io", 0, 07332762347) = 4 [pid 25433] read(4 <no return ...> error: maximum array length seems negative , "5401/io", 4095) = -1 [pid 25433] close(4) = 0 [pid 25433] strchr("5401/io", ':') = nil [pid 25433] strchr("\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"..., '\n' <no return ...> [pid 25433] --- SIGSEGV (Segmentation fault) --- [pid 25433] +++ killed by SIGSEGV +++

hvisage avatar Dec 13 '18 18:12 hvisage

Looks like /proc/*/io is not always readable. Will have to handle that properly...

markwkm avatar Jan 02 '19 15:01 markwkm

Commit f6232a94 shows that -1 EACCES (Permission denied) should be handled:

	sprintf(buffer, "%d/io", proc->pid);
	fd = open(buffer, O_RDONLY);
	if (fd == -1)
	{
		/*
		 * CONFIG_TASK_IO_ACCOUNTING is not enabled in the Linux kernel or
		 * this version of Linux may not support collecting i/o statistics per
		 * pid.  Report 0's.
		 */
		proc->rchar = 0;
		proc->wchar = 0;
		proc->syscr = 0;
		proc->syscw = 0;
		proc->read_bytes = 0;
		proc->write_bytes = 0;
		proc->cancelled_write_bytes = 0;
		return;
	}
	len = read(fd, buffer, sizeof(buffer) - 1);
	close(fd);

I can't reproduce the segfaulting running lxc/lxd on Gentoo when I run pg_top as a user that does not have read access to io. I'm not sure which close() it would be segfaulting at. Is it still reproducible on the code tagged at 4.0.0-alpha1?

markwkm avatar Aug 28 '19 21:08 markwkm

I'm seeing this when running pg_top from the official docker image, and I install pgtop package using apt-get (3.7.0-18-gbbf1f12-3.pgdg90+1). I tried building 4.0+ from source but failed miserably 😢 . Here's what I did:

/# wget https://pg_top.gitlab.io/source/pg_top-4.0.0-alpha2.tar.xz
/# tar xf pg_top-4.0.0-alpha2.tar.xz
/# cd pg_top-4.0.0-alpha2
/pg_top-4.0.0-alpha2# apt install build-essential cmake libpq-dev libbsd-dev
/pg_top-4.0.0-alpha2# cmake CMakeLists.txt
-- machine - linux
-- arch - x86_64
-- pg_config --includedir - /usr/include/postgresql
-- pg_config --libdir - /usr/lib/x86_64-linux-gnu
-- Configuring done
-- Generating done
-- Build files have been written to: /pg_top-4.0.0-alpha2
/pg_top-4.0.0-alpha2# make install
Scanning dependencies of target pg_top
[  7%] Building C object CMakeFiles/pg_top.dir/commands.c.o
[ 14%] Linking C executable pg_top
CMakeFiles/pg_top.dir/display.c.o: In function `display_move':
display.c:(.text+0x2b5): undefined reference to `tgoto'
display.c:(.text+0x2cf): undefined reference to `tputs'
CMakeFiles/pg_top.dir/display.c.o: In function `display_write':
display.c:(.text+0x594): undefined reference to `tgoto'
display.c:(.text+0x5ae): undefined reference to `tputs'
CMakeFiles/pg_top.dir/display.c.o: In function `display_cte':
display.c:(.text+0x7cd): undefined reference to `tputs'
CMakeFiles/pg_top.dir/display.c.o: In function `u_endscreen':
display.c:(.text+0x1ecf): undefined reference to `tgoto'
display.c:(.text+0x1ee9): undefined reference to `tputs'
CMakeFiles/pg_top.dir/screen.c.o: In function `get_screensize':
screen.c:(.text+0x9d): undefined reference to `tgoto'
CMakeFiles/pg_top.dir/screen.c.o: In function `init_termcap':
screen.c:(.text+0x143): undefined reference to `tgetent'
screen.c:(.text+0x1b4): undefined reference to `tgetflag'
screen.c:(.text+0x1d0): undefined reference to `tgetnum'
screen.c:(.text+0x202): undefined reference to `tgetnum'
screen.c:(.text+0x23a): undefined reference to `tgetflag'
screen.c:(.text+0x268): undefined reference to `tgetstr'
screen.c:(.text+0x282): undefined reference to `tgetstr'
screen.c:(.text+0x2a8): undefined reference to `tgetstr'
screen.c:(.text+0x2da): undefined reference to `tgetstr'
screen.c:(.text+0x2f4): undefined reference to `tgetstr'
CMakeFiles/pg_top.dir/screen.c.o:screen.c:(.text+0x30e): more undefined references to `tgetstr' follow
CMakeFiles/pg_top.dir/screen.c.o: In function `init_termcap':
screen.c:(.text+0x394): undefined reference to `tgoto'
CMakeFiles/pg_top.dir/screen.c.o: In function `init_screen':
screen.c:(.text+0x4e1): undefined reference to `tputs'
CMakeFiles/pg_top.dir/screen.c.o: In function `end_screen':
screen.c:(.text+0x51d): undefined reference to `tputs'
screen.c:(.text+0x544): undefined reference to `tputs'
screen.c:(.text+0x57a): undefined reference to `tputs'
CMakeFiles/pg_top.dir/screen.c.o: In function `reinit_screen':
screen.c:(.text+0x5ff): undefined reference to `tputs'
CMakeFiles/pg_top.dir/screen.c.o:screen.c:(.text+0x640): more undefined references to `tputs' follow
collect2: error: ld returned 1 exit status
CMakeFiles/pg_top.dir/build.make:410: recipe for target 'pg_top' failed
make[2]: *** [pg_top] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/pg_top.dir/all' failed
make[1]: *** [CMakeFiles/pg_top.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

I'm obviously doing something wrong ... can this even compile as-is for debian, or does it need a patch? Is there a chance 4.0 alpha can hit next debian release?

asfaltboy avatar Oct 07 '19 17:10 asfaltboy

Yes, pg_top should be able to compile as-in on debian.

tputs is provided by curses. libncurses5-dev should take are of that one.

I'm not directly involved in any distro packaging. I'm afraid I'm not sure when packaging will be updated...

markwkm avatar Oct 16 '19 21:10 markwkm