Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process-util: fix two bugs in get_process_cmdline() #3555

Merged
merged 1 commit into from
Jun 16, 2016

Conversation

poettering
Copy link
Member

@evverx
Copy link
Member

evverx commented Jun 16, 2016

oh, actually I didn't notice PID1 cmdline truncated to 8: '/usr...0' :)

sudo ./test-process-util works fine:

$ sudo ./test-process-util
PID1 comm: 'systemd'
PID1 cmdline: '/usr/lib/systemd/systemd --system --deserialize 17'
PID1 cmdline truncated to 8: '/usr...'
PID1 cmdline truncated to 1: ''
PID1 PPID: 0
PID1 exe: '/usr/lib/systemd/systemd'
PID1 UID: 0
PID1 GID: 0
PID1 strlen(environ): 0
PID1 $PATH: 'n/a'
PID12810 comm: 'test-process-ut'
PID12810 cmdline: './test-process-util'
PID12810 cmdline truncated to 8: './te...'
PID12810 cmdline truncated to 1: ''
PID12810 PPID: 12809
PID12810 exe: '/home/vagrant/systemd/test-process-util'
PID12810 UID: 0
PID12810 GID: 0
PID12810 strlen(environ): 1705
PID12810 $PATH: '/sbin:/bin:/usr/sbin:/usr/bin'
$ echo $?
0

But

$ sudo ./libtool --mode=execute valgrind -q --leak-check=full  --error-exitcode=55 --trace-children=yes ./test-process-util
PID1 comm: 'systemd'
PID1 cmdline: '/usr/lib/systemd/systemd --system --deserialize 17'
PID1 cmdline truncated to 8: '/usr...'
PID1 cmdline truncated to 1: ''
PID1 PPID: 0
PID1 exe: '/usr/lib/systemd/systemd'
PID1 UID: 0
PID1 GID: 0
PID1 strlen(environ): 0
PID1 $PATH: 'n/a'
PID14058 comm: 'memcheck-amd64-'
PID14058 cmdline: './test-process-util'
PID14058 cmdline truncated to 8: './te...'
PID14058 cmdline truncated to 1: ''
PID14058 PPID: 14057
PID14058 exe: '/home/vagrant/systemd/test-process-util'
PID14058 UID: 0
PID14058 GID: 0
PID14058 strlen(environ): 1880
PID14058 $PATH: '/sbin:/bin:/usr/sbin:/usr/bin'
Assertion 'get_process_cmdline(getpid(), 0, false, &line) == -ENOENT' failed at src/test/test-process-util.c:189, function test_get_process_cmdline_harder(). Aborting.
Assertion 'si.si_code == CLD_EXITED' failed at src/test/test-process-util.c:173, function test_get_process_cmdline_harder(). Aborting.
Aborted

(I'm not sure what's going on: get_process_cmdline(getpid(), 0, false, &line) returns 0, line contains ./test-process-util
Maybe, we can ignore this)

@evverx
Copy link
Member

evverx commented Jun 16, 2016

Hm,

23:58:15.979275 open("/tmp/valgrind_proc_16307_cmdline_53734e96", O_RDWR|O_CREAT|O_EXCL|O_TRUNC, 0600) = 3
23:58:15.979381 fcntl(3, F_DUPFD, 1024) = 1025
23:58:15.979396 close(3)                = 0
23:58:15.979408 fcntl(1025, F_SETFD, FD_CLOEXEC) = 0
23:58:15.979420 write(1025, "./test-process-util", 19) = 19
23:58:15.979441 write(1025, "\0", 1)    = 1
23:58:15.979456 unlink("/tmp/valgrind_proc_16307_cmdline_53734e96") = 0
...
[pid 16324] 23:58:17.680715 unshare(CLONE_NEWNS) = 0
...
[pid 16324] 23:58:17.683638 open("/tmp/test-cmdlinedkbRz2", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0600) = 3
...
[pid 16324] 23:58:17.684260 mount("/tmp/test-cmdlinedkbRz2", "/proc/self/cmdline", 0x14cef1, MS_BIND, NULL) = 0
...
[pid 16324] 23:58:17.686136 unlink("/tmp/test-cmdlinedkbRz2") = 0
...
[pid 16324] 23:58:17.686988 dup(1025)   = 4
[pid 16324] 23:58:17.687002 lseek(4, 0, SEEK_SET) = 0
[pid 16324] 23:58:17.687030 fstat(4, {st_dev=makedev(8, 1), st_ino=1449351, st_mode=S_IFREG|0600, st_nlink=0, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=20, st_atime=2016/06/15-23:58:17.292000000, st_mtime=2016/06/15-23:58:15.978000000, st_ctime=2016/06/15-23:58:15.978000000}) = 0
...
[pid 16324] 23:58:17.687193 read(4, "./test-process-util\0", 4096) = 20

@evverx
Copy link
Member

evverx commented Jun 16, 2016

Well, coregrind/pub_core_clientstate.h contains this comment:

/* A fd which refers to the fake /proc//cmdline in /tmp. The
idea is: make up the /proc//cmdline file the client would
expect to see if it was running natively. Copy into a file in
/tmp. When the client then does an open of /proc//cmdline or
/proc/self/cmdline, instead give it a file handle to the file in
/tmp. The problem of deleting said file when Valgrind exits is
neatly sidestepped by unlinking it as soon as it has been created,
but holding on to the file handle. That causes the kernel to keep
the file contents alive exactly until the process exits. */

So, this fail is ok:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

3 participants