diff options
author | Michal Privoznik <mprivozn@redhat.com> | 2019-04-30 11:17:22 +0200 |
---|---|---|
committer | Michal Privoznik <mprivozn@redhat.com> | 2019-05-17 16:01:11 +0200 |
commit | 5cdd5d380bab5f6f7207e0ffd0c1322a8281feca (patch) | |
tree | d5e4ecf18a590d1dde22239565ea14b400a53358 /tests/commandtest.c | |
parent | e5df4edefa6b6b9db2ef620a1f16a901afda0274 (diff) | |
download | libvirt-5cdd5d380bab5f6f7207e0ffd0c1322a8281feca.tar.gz |
lib: Avoid double close when passing FDs with virCommandPassFD()
If an FD is passed into a child using:
virCommandPassFD(cmd, fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
then the parent should refrain from touching @fd thereafter. This
is even documented in virCommandPassFD() comment. The reason is
that either at virCommandRun()/virCommandRunAsync() or
virCommandFree() time the @fd will be closed. Closing it earlier,
e.g. right after virCommandPassFD() call might result in
undesired results. Another thread might open a file and receive
the same FD which is then unexpectedly closed by virCommandFree()
or virCommandRun().
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Diffstat (limited to 'tests/commandtest.c')
-rw-r--r-- | tests/commandtest.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tests/commandtest.c b/tests/commandtest.c index 816a70860f..146cc4c1bf 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -1024,6 +1024,7 @@ static int test24(const void *unused ATTRIBUTE_UNUSED) virCommandDaemonize(cmd); virCommandPassFD(cmd, newfd2, VIR_COMMAND_PASS_FD_CLOSE_PARENT); virCommandPassFD(cmd, newfd3, VIR_COMMAND_PASS_FD_CLOSE_PARENT); + newfd2 = newfd3 = -1; virCommandPassListenFDs(cmd); if (virCommandRun(cmd, NULL) < 0) { @@ -1053,7 +1054,6 @@ static int test24(const void *unused ATTRIBUTE_UNUSED) VIR_FREE(prefix); virCommandFree(cmd); VIR_FORCE_CLOSE(newfd1); - /* coverity[double_close] */ VIR_FORCE_CLOSE(newfd2); VIR_FORCE_CLOSE(newfd3); return ret; |