Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2092322

Summary: [QSD] pid file still exist after qsd process be killed when qsd run as daemonize
Product: Red Hat Enterprise Linux 9 Reporter: qing.wang <qinwang>
Component: qemu-kvmAssignee: Hanna Czenczek <hreitz>
qemu-kvm sub component: Storage QA Contact: qing.wang <qinwang>
Status: CLOSED CURRENTRELEASE Docs Contact:
Severity: low    
Priority: low CC: coli, jinzhao, juzhang, kwolf, lijin, qzhang, virt-maint, xuwei
Version: 9.1Keywords: Triaged
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-12-21 08:33:47 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description qing.wang 2022-06-01 09:34:17 UTC
Description of problem:
run qsd with pidfile and daemonize options. the pid file still exist after qsd process be killed.

Version-Release number of selected component (if applicable):
Red Hat Enterprise Linux release 9.1 Beta (Plow)
5.14.0-101.el9.x86_64
qemu-kvm-7.0.0-4.el9.x86_64
seabios-bin-1.16.0-3.el9.noarch
edk2-ovmf-20220221gitb24306f15d-2.el9.noarch
virtio-win-prewhql-0.1-221.iso


How reproducible:
100

Steps to Reproduce:
1.boot qsd with pidfile and daemonize options
qemu-storage-daemon \
--chardev socket,path=qmp.sock,server=on,wait=off,id=char1 \
--monitor chardev=char1 \
--pidfile qsd.pid \
--daemonize \

2.check the process
pgrep  -l -x -F qsd.pid|grep qemu-storage-da

3.kill process
kill  -SIGTERM $(<qsd.pid)

4.check the process
pgrep -l -x qemu-storage-da

5.check the pid file


Actual results:
pif file qsd.pid still exist on disk

Expected results:
This file should be deleted after qsd process quit.

Additional info:
It meet expected result if run without daemonize

Comment 2 Hanna Czenczek 2022-06-09 07:40:58 UTC
The problem is that daemonizing changes the current working directory to /, so the PID file cannot be removed if it was specified by relative path.  This is also true for qemu itself:

$ pwd
/tmp
$ qemu-system-x86_64 --daemonize --pidfile qemu.pid
$ kill $(cat qemu.pid)
$ ls -l qemu.pid
-rw------- 1 hreitz users 6  9. Jun 09:38 qemu.pid

We should probably always expand the PID file path to absolute paths internally.

Comment 3 qing.wang 2022-07-07 01:35:09 UTC
It still exist even using absolute paths on
Red Hat Enterprise Linux release 9.0 (Plow)
5.14.0-70.15.1.el9_0.x86_64
qemu-kvm-7.0.0-7.el9.x86_64
seabios-bin-1.15.0-1.el9.noarch
edk2-ovmf-20220126gitbb1bba3d77-3.el9.noarch




root@dell-per6515-03 /home $ qemu-storage-daemon --daemonize --pidfile /tmp/qemu.pid
root@dell-per6515-03 /home $  ps -e ww|grep qemu-storage-daemon|grep -v grep
 208762 ?        Sl     0:00 qemu-storage-daemon --daemonize --pidfile /tmp/qemu.pid
root@dell-per6515-03 /home $ kill -9 208762
root@dell-per6515-03 /home $ ls /tmp/qemu.pid 
/tmp/qemu.pid

Comment 4 Hanna Czenczek 2022-07-07 07:01:36 UTC
(In reply to qing.wang from comment #3)
> root@dell-per6515-03 /home $ qemu-storage-daemon --daemonize --pidfile
> /tmp/qemu.pid
> root@dell-per6515-03 /home $  ps -e ww|grep qemu-storage-daemon|grep -v grep
>  208762 ?        Sl     0:00 qemu-storage-daemon --daemonize --pidfile
> /tmp/qemu.pid
> root@dell-per6515-03 /home $ kill -9 208762

If you kill the process via SIGKILL, it has no chance to delete the PID file.  This should be the case with or without --daemonize.

The PID file can only be deleted if the process is terminated such that atexit() handlers run, e.g. via SIGTERM (as done in comment 0) or SIGINT.

Hanna

Comment 5 qing.wang 2022-07-11 07:58:41 UTC
verify on qemu-kvm-7.0.0-8.el9.x86_64:

1.qemu-storage-daemon --daemonize --pidfile /tmp/qemu.pid
2.kill  -SIGTERM $(cat /tmp/qemu.pid)
3. ps -e ww|grep qemu-storage-daemon|grep -v grep
4. ls /tmp/qemu.pid
ls: cannot access '/tmp/qemu.pid': No such file or director

It get expected result.
I suggest adding this to document or help message.