[systemd-devel] [PATCH] core: fix detection of dead process.

Yuxuan Shui yshuiv7 at gmail.com
Fri Feb 14 10:37:39 PST 2014


Sorry, I sent the wrong patch
2014-2-15 上午2:34于 "Yuxuan Shui" <yshuiv7 at gmail.com>写道:

> Commit 5ba6985b moves the UNIT_VTABLE(u)->sigchld_event before systemd
> actually reap the zombie. Which leads to service_load_pid_file accept
> zombie as a valid pid.
> ---
>  src/core/service.c |  3 +++
>  src/shared/util.c  | 24 ++++++++++++++++++++++++
>  src/shared/util.h  |  1 +
>  3 files changed, 28 insertions(+)
>
> diff --git a/src/core/service.c b/src/core/service.c
> index 5129784..64a0670 100644
> --- a/src/core/service.c
> +++ b/src/core/service.c
> @@ -1376,6 +1376,9 @@ static int service_load_pid_file(Service *s, bool
> may_warn) {
>                  return -ESRCH;
>          }
>
> +        if ('Z' == get_process_state(pid))
> +                return -ESRCH;
> +
>          if (s->main_pid_known) {
>                  if (pid == s->main_pid)
>                          return 0;
> diff --git a/src/shared/util.c b/src/shared/util.c
> index 3482b9b..6c3cf6c 100644
> --- a/src/shared/util.c
> +++ b/src/shared/util.c
> @@ -513,6 +513,30 @@ char *truncate_nl(char *s) {
>          return s;
>  }
>
> +char get_process_state(pid_t pid) {
> +        const char *p;
> +        int r;
> +
> +        assert(name);
> +        assert(pid >= 0);
> +
> +        p = procfs_file_alloca(pid, "stat");
> +        r = read_one_line_file(p, &line);
> +        if (r < 0)
> +                return r;
> +
> +        p = strrchr(line, ')');
> +        if (!p)
> +                return -EIO;
> +
> +        p++;
> +
> +        if (sscanf(p, " %c", &state) != 1)
> +                return -EIO;
> +
> +        return state;
> +}
> +
>  int get_process_comm(pid_t pid, char **name) {
>          const char *p;
>          int r;
> diff --git a/src/shared/util.h b/src/shared/util.h
> index 9aea3a4..8dede1f 100644
> --- a/src/shared/util.h
> +++ b/src/shared/util.h
> @@ -238,6 +238,7 @@ char *file_in_same_dir(const char *path, const char
> *filename);
>
>  int rmdir_parents(const char *path, const char *stop);
>
> +char get_process_state(pid_t pid);
>  int get_process_comm(pid_t pid, char **name);
>  int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback,
> char **line);
>  int get_process_exe(pid_t pid, char **name);
> --
> 1.8.5.4
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20140215/ae6db64a/attachment.html>


More information about the systemd-devel mailing list