summaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
authorMichal Privoznik <mprivozn@redhat.com>2022-05-26 09:07:56 +0200
committerMichal Privoznik <mprivozn@redhat.com>2022-06-01 09:35:26 +0200
commitf3440055471058698042df06312b9dbdc75e1f4f (patch)
tree8f8e6b2206fdb7fd592e5254ab5f1405d00cb50c /src/ch
parent506210aab9d7a137a9c0cafdb9249d560eae8587 (diff)
downloadlibvirt-f3440055471058698042df06312b9dbdc75e1f4f.tar.gz
lib: Be consistent about vm->pid
The virDomainObj struct has @pid member where the domain's hypervisor PID is stored (e.g. QEMU/bhyve/libvirt_lxc/... PID). However, we are not consistent when it comes to shutoff state. Initially, because virDomainObjNew() uses g_new0() the @pid is initialized to 0. But when domain is shut off, some functions set it to -1 (virBhyveProcessStop, virCHProcessStop, qemuProcessStop, ..). In other places, the @pid is tested to be 0, on some other places it's tested for being negative and in the rest for being positive. To solve this inconsistency we can stick with either value, -1 or 0. I've chosen the latter as it's safer IMO. For instance if by mistake we'd kill(vm->pid, SIGTERM) we would kill ourselves instead of init's process group. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/ch_domain.c2
-rw-r--r--src/ch/ch_process.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c
index bb489a74e3..5ab526ba1b 100644
--- a/src/ch/ch_domain.c
+++ b/src/ch/ch_domain.c
@@ -405,7 +405,7 @@ virCHDomainGetMachineName(virDomainObj *vm)
virCHDriver *driver = priv->driver;
char *ret = NULL;
- if (vm->pid > 0) {
+ if (vm->pid != 0) {
ret = virSystemdGetMachineNameByPID(vm->pid);
if (!ret)
virResetLastError();
diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c
index 977082d585..4247902bcf 100644
--- a/src/ch/ch_process.c
+++ b/src/ch/ch_process.c
@@ -574,7 +574,7 @@ virCHProcessStop(virCHDriver *driver G_GNUC_UNUSED,
vm->def->name);
}
- vm->pid = -1;
+ vm->pid = 0;
vm->def->id = -1;
g_clear_pointer(&priv->machineName, g_free);