Re: [PATCH 3/5] Introduce functions for checking whether a pidfile is valid

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

 



On Fri, Aug 12, 2011 at 15:07:21 +0100, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
> 
> In some cases the caller of virPidFileRead might like extra checks
> to determine whether the pid just read is really the one they are
> expecting. This adds virPidFileReadIfAlive which will check whether
> the pid is still alive with kill(0, -1), and (on linux only) will
> look at /proc/$PID/path
...
> diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
> index 25c3272..c7adbfc 100644
> --- a/src/util/virpidfile.c
> +++ b/src/util/virpidfile.c
...
> +int virPidFileReadPathIfAlive(const char *path,
> +                              pid_t *pid,
> +                              const char *binpath)
> +{
> +    int rc;
> +    char *procpath = NULL;
> +
> +    rc = virPidFileReadPath(path, pid);
> +    if (rc < 0)
> +        return rc;
> +
> +    /* Check that it's still alive */
> +    if (kill(*pid, 0) < 0) {
> +        *pid = -1;
> +        return 0;
> +    }
> +
> +    if (virAsprintf(&procpath, "/proc/%d/exe", *pid) < 0) {
> +        *pid = -1;
> +        return 0;
> +    }
> +#ifdef __linux__
> +    if (virFileLinkPointsTo(procpath, binpath) == 0)
> +        *pid = -1;
> +#endif
> +   VIR_FREE(procpath);
   ^^^ three spaces here instead of four

Jirka

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]