mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
util: add quiet parameter to virPidFileAcquirePathFull
Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
d3d16f829b
commit
4479a307df
@ -159,7 +159,7 @@ main(int argc, char **argv)
|
|||||||
pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
|
pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
|
||||||
|
|
||||||
/* Try to claim the pidfile, exiting if we can't */
|
/* 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,
|
fprintf(stderr,
|
||||||
_("Unable to acquire PID file: %s\n errno=%d"),
|
_("Unable to acquire PID file: %s\n errno=%d"),
|
||||||
pid_file, errno);
|
pid_file, errno);
|
||||||
|
@ -364,6 +364,7 @@ int virPidFileDelete(const char *dir,
|
|||||||
|
|
||||||
int virPidFileAcquirePathFull(const char *path,
|
int virPidFileAcquirePathFull(const char *path,
|
||||||
bool waitForLock,
|
bool waitForLock,
|
||||||
|
bool quiet,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
@ -375,32 +376,40 @@ int virPidFileAcquirePathFull(const char *path,
|
|||||||
while (1) {
|
while (1) {
|
||||||
struct stat a, b;
|
struct stat a, b;
|
||||||
if ((fd = open(path, O_WRONLY|O_CREAT, 0644)) < 0) {
|
if ((fd = open(path, O_WRONLY|O_CREAT, 0644)) < 0) {
|
||||||
virReportSystemError(errno,
|
if (!quiet) {
|
||||||
_("Failed to open pid file '%s'"),
|
virReportSystemError(errno,
|
||||||
path);
|
_("Failed to open pid file '%s'"),
|
||||||
|
path);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSetCloseExec(fd) < 0) {
|
if (virSetCloseExec(fd) < 0) {
|
||||||
virReportSystemError(errno,
|
if (!quiet) {
|
||||||
_("Failed to set close-on-exec flag '%s'"),
|
virReportSystemError(errno,
|
||||||
path);
|
_("Failed to set close-on-exec flag '%s'"),
|
||||||
|
path);
|
||||||
|
}
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(fd, &b) < 0) {
|
if (fstat(fd, &b) < 0) {
|
||||||
virReportSystemError(errno,
|
if (!quiet) {
|
||||||
_("Unable to check status of pid file '%s'"),
|
virReportSystemError(errno,
|
||||||
path);
|
_("Unable to check status of pid file '%s'"),
|
||||||
|
path);
|
||||||
|
}
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileLock(fd, false, 0, 1, waitForLock) < 0) {
|
if (virFileLock(fd, false, 0, 1, waitForLock) < 0) {
|
||||||
virReportSystemError(errno,
|
if (!quiet) {
|
||||||
_("Failed to acquire pid file '%s'"),
|
virReportSystemError(errno,
|
||||||
path);
|
_("Failed to acquire pid file '%s'"),
|
||||||
|
path);
|
||||||
|
}
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -427,17 +436,21 @@ int virPidFileAcquirePathFull(const char *path,
|
|||||||
g_snprintf(pidstr, sizeof(pidstr), "%lld", (long long) pid);
|
g_snprintf(pidstr, sizeof(pidstr), "%lld", (long long) pid);
|
||||||
|
|
||||||
if (ftruncate(fd, 0) < 0) {
|
if (ftruncate(fd, 0) < 0) {
|
||||||
virReportSystemError(errno,
|
if (!quiet) {
|
||||||
_("Failed to truncate pid file '%s'"),
|
virReportSystemError(errno,
|
||||||
path);
|
_("Failed to truncate pid file '%s'"),
|
||||||
|
path);
|
||||||
|
}
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safewrite(fd, pidstr, strlen(pidstr)) < 0) {
|
if (safewrite(fd, pidstr, strlen(pidstr)) < 0) {
|
||||||
virReportSystemError(errno,
|
if (!quiet) {
|
||||||
_("Failed to write to pid file '%s'"),
|
virReportSystemError(errno,
|
||||||
path);
|
_("Failed to write to pid file '%s'"),
|
||||||
|
path);
|
||||||
|
}
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +461,7 @@ int virPidFileAcquirePathFull(const char *path,
|
|||||||
int virPidFileAcquirePath(const char *path,
|
int virPidFileAcquirePath(const char *path,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
return virPidFileAcquirePathFull(path, false, pid);
|
return virPidFileAcquirePathFull(path, false, false, pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ int virPidFileDelete(const char *dir,
|
|||||||
|
|
||||||
int virPidFileAcquirePathFull(const char *path,
|
int virPidFileAcquirePathFull(const char *path,
|
||||||
bool waitForLock,
|
bool waitForLock,
|
||||||
|
bool quiet,
|
||||||
pid_t pid) G_GNUC_WARN_UNUSED_RESULT;
|
pid_t pid) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
int virPidFileAcquirePath(const char *path,
|
int virPidFileAcquirePath(const char *path,
|
||||||
pid_t pid) G_GNUC_WARN_UNUSED_RESULT;
|
pid_t pid) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user