Re: [PATCH v3 1/3] virpidfile: Add virPidFileReadPathIfLocked func

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/2/22 17:28, Vasiliy Ulyanov wrote:
> The function will attempt to read a pid from @path, and store it in
> @pid. The @pid will only be set, however, if @path is locked by
> virFileLock() at byte 0 and the pid in @path is running.
> 
> Signed-off-by: Vasiliy Ulyanov <vulyanov@xxxxxxx>
> ---
>  src/libvirt_private.syms |  1 +
>  src/util/virpidfile.c    | 34 ++++++++++++++++++++++++++++++++++
>  src/util/virpidfile.h    |  2 ++
>  3 files changed, 37 insertions(+)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 9bc3d9530b..447ba9d82b 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -3070,6 +3070,7 @@ virPidFileRead;
>  virPidFileReadIfAlive;
>  virPidFileReadPath;
>  virPidFileReadPathIfAlive;
> +virPidFileReadPathIfLocked;
>  virPidFileRelease;
>  virPidFileReleasePath;
>  virPidFileWrite;
> diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
> index 7069f8343d..b8bb455e5e 100644
> --- a/src/util/virpidfile.c
> +++ b/src/util/virpidfile.c
> @@ -302,6 +302,40 @@ int virPidFileReadIfAlive(const char *dir,
>      return 0;
>  }
>  
> +/**
> + * virPidFileReadPathIfLocked:
> + * @path: path to pidfile
> + * @pid: variable to return pid in
> + *
> + * This will attempt to read a pid from @path, and store it
> + * in @pid. The @pid will only be set, however, if the
> + * pid in @path is running, and @path is locked by virFileLock()
> + * at byte 0. This adds protection against returning a stale pid.

I'd mention here virCommandSetPidFile(), but otherwise looking good.

Michal




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux