Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/network/leaseshelper.c | 2 +-
src/util/virpidfile.c | 51 ++++++++++++++++++++++++--------------
src/util/virpidfile.h | 1 +
3 files changed, 34 insertions(+), 20 deletions(-)
diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c
index b1ce313e6a..9ee42045d9 100644
--- a/src/network/leaseshelper.c
+++ b/src/network/leaseshelper.c
@@ -159,7 +159,7 @@ main(int argc, char **argv)
pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
/* Try to claim the pidfile, exiting if we can't */
- if ((pid_file_fd = virPidFileAcquirePathFull(pid_file, true, getpid())) < 0) {
+ if ((pid_file_fd = virPidFileAcquirePathFull(pid_file, true, false, getpid())) <
0) {
fprintf(stderr,
_("Unable to acquire PID file: %s\n errno=%d"),
pid_file, errno);
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index 252100cdc3..05d19100c6 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -364,6 +364,7 @@ int virPidFileDelete(const char *dir,
int virPidFileAcquirePathFull(const char *path,
bool waitForLock,
+ bool quiet,
pid_t pid)
{
int fd = -1;
@@ -375,32 +376,40 @@ int virPidFileAcquirePathFull(const char *path,
while (1) {
struct stat a, b;
if ((fd = open(path, O_WRONLY|O_CREAT, 0644)) < 0) {
- virReportSystemError(errno,
- _("Failed to open pid file '%s'"),
- path);
+ if (!quiet) {
+ virReportSystemError(errno,
+ _("Failed to open pid file
'%s'"),
+ path);
+ }
return -1;
}
if (virSetCloseExec(fd) < 0) {
- virReportSystemError(errno,
- _("Failed to set close-on-exec flag
'%s'"),
- path);
+ if (!quiet) {
+ virReportSystemError(errno,
+ _("Failed to set close-on-exec flag
'%s'"),
+ path);
+ }
VIR_FORCE_CLOSE(fd);
return -1;
}
if (fstat(fd, &b) < 0) {
- virReportSystemError(errno,
- _("Unable to check status of pid file
'%s'"),
- path);
+ if (!quiet) {
+ virReportSystemError(errno,
+ _("Unable to check status of pid file
'%s'"),
+ path);
+ }
VIR_FORCE_CLOSE(fd);
return -1;
}
if (virFileLock(fd, false, 0, 1, waitForLock) < 0) {
- virReportSystemError(errno,
- _("Failed to acquire pid file '%s'"),
- path);
+ if (!quiet) {
+ virReportSystemError(errno,
+ _("Failed to acquire pid file
'%s'"),
+ path);
+ }
VIR_FORCE_CLOSE(fd);
return -1;
}
@@ -427,17 +436,21 @@ int virPidFileAcquirePathFull(const char *path,
g_snprintf(pidstr, sizeof(pidstr), "%lld", (long long) pid);
if (ftruncate(fd, 0) < 0) {
- virReportSystemError(errno,
- _("Failed to truncate pid file '%s'"),
- path);
+ if (!quiet) {
+ virReportSystemError(errno,
+ _("Failed to truncate pid file
'%s'"),
+ path);
+ }
VIR_FORCE_CLOSE(fd);
return -1;
}
if (safewrite(fd, pidstr, strlen(pidstr)) < 0) {
- virReportSystemError(errno,
- _("Failed to write to pid file '%s'"),
- path);
+ if (!quiet) {
+ virReportSystemError(errno,
+ _("Failed to write to pid file
'%s'"),
+ path);
+ }
VIR_FORCE_CLOSE(fd);
}
@@ -448,7 +461,7 @@ int virPidFileAcquirePathFull(const char *path,
int virPidFileAcquirePath(const char *path,
pid_t pid)
{
- return virPidFileAcquirePathFull(path, false, pid);
+ return virPidFileAcquirePathFull(path, false, false, pid);
}
diff --git a/src/util/virpidfile.h b/src/util/virpidfile.h
index 6db0fb843f..5d31f02702 100644
--- a/src/util/virpidfile.h
+++ b/src/util/virpidfile.h
@@ -58,6 +58,7 @@ int virPidFileDelete(const char *dir,
int virPidFileAcquirePathFull(const char *path,
bool waitForLock,
+ bool quiet,
pid_t pid) G_GNUC_WARN_UNUSED_RESULT;
int virPidFileAcquirePath(const char *path,
pid_t pid) G_GNUC_WARN_UNUSED_RESULT;
--
2.39.2