Bug 1460338

Summary: guestfs_shutdown hangs if main process sets signal handlers
Product: [Community] Virtualization Tools Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED UPSTREAM QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: ptoscano, rbalakri
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-06-13 15:45:16 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
lvm_guestfs.c
none
Debugging output none

Description Richard W.M. Jones 2017-06-09 18:12:06 UTC
Created attachment 1286485 [details]
lvm_guestfs.c

Description of problem:

(Reported by wtfuzz on IRC)

The attached program fails, but only when an LVM volume
group is open in the main process (using lvm2app).

It seems as if lvm2app fiddles with signal handlers, and
those are inherited by the forked qemu process, preventing
it from seeing the SIGTERM signal that we later send.  So
guestfs_shutdown hangs.

See attached example code and debug.

Version-Release number of selected component (if applicable):

libguestfs 1.32.7 (from Debian)

How reproducible:

100% when lvm_vg_open has been called in the main process.

Comment 1 Richard W.M. Jones 2017-06-09 18:12:36 UTC
Created attachment 1286486 [details]
Debugging output

Comment 2 Richard W.M. Jones 2017-06-09 22:12:47 UTC
From the reporter:

21:25 < wtfuzz> rwmjones: I can confirm that setting up SIGTERM in a sigset_t, and doing a sigprocmask(SIG_UNBLOCK, &mask, NULL) after lvm_vg_open() fixes my issue

Comment 3 Richard W.M. Jones 2017-06-10 17:25:14 UTC
I was able to reproduce this easily with upstream by adjusting
one of the example programs to include this code in main():

  guestfs_set_backend (g, "direct");
  sigemptyset (&set);
  sigaddset (&set, SIGTERM);
  sigprocmask (SIG_BLOCK, &set, NULL);

Note this only affects the 'direct' backend.

Comment 4 Richard W.M. Jones 2017-06-10 17:33:38 UTC
Patch posted upstream:

https://www.redhat.com/archives/libguestfs/2017-June/msg00061.html