From 3e0623ebc86a4e173dd98e4cd5256bb5bb5cbdea Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 26 Jan 2012 16:25:38 +0100 Subject: [PATCH] pidfile: Make checking binary path in virPidFileRead optional This patch changes behavior of virPidFileRead to enable passing NULL as path to the binary the pid file should be checked against to skip this check. This enables using this function for reading files that have same semantics as pid files, but belong to unknown processes. --- src/util/virpidfile.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 9c299673ae..83083c0993 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -193,6 +193,9 @@ int virPidFileRead(const char *dir, * resolves to @binpath. This adds protection against * recycling of previously reaped pids. * + * If @binpath is NULL the check for the executable path + * is skipped. + * * Returns -errno upon error, or zero on successful * reading of the pidfile. If the PID was not still * alive, zero will be returned, but @pid will be @@ -218,17 +221,19 @@ int virPidFileReadPathIfAlive(const char *path, } #endif - if (virAsprintf(&procpath, "/proc/%d/exe", *pid) < 0) { - *pid = -1; - return -1; + if (binpath) { + if (virAsprintf(&procpath, "/proc/%d/exe", *pid) < 0) { + *pid = -1; + return -1; + } + + if (virFileIsLink(procpath) && + virFileLinkPointsTo(procpath, binpath) == 0) + *pid = -1; + + VIR_FREE(procpath); } - if (virFileIsLink(procpath) && - virFileLinkPointsTo(procpath, binpath) == 0) - *pid = -1; - - VIR_FREE(procpath); - return 0; }