int virPidFileAcquirePathFull(const char *path,
bool waitForLock,
+ bool quiet,
pid_t pid)
{
int fd = -1;
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;
}
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);
}
int virPidFileAcquirePath(const char *path,
pid_t pid)
{
- return virPidFileAcquirePathFull(path, false, pid);
+ return virPidFileAcquirePathFull(path, false, false, pid);
}