[systemd-devel] [PATCH 2/4] util: add functions getting proc status, maps, limits, cgroup

Lennart Poettering lennart at poettering.net
Thu Nov 20 05:36:52 PST 2014


On Wed, 19.11.14 11:01, Jakub Filak (jfilak at redhat.com) wrote:

> ---
>  src/shared/util.c    | 13 +++++++++++++
>  src/shared/util.h    |  4 ++++
>  src/test/test-util.c | 17 +++++++++++++++++
>  3 files changed, 34 insertions(+)
> 
> diff --git a/src/shared/util.c b/src/shared/util.c
> index 0166052..d62d90c 100644
> --- a/src/shared/util.c
> +++ b/src/shared/util.c
> @@ -892,6 +892,19 @@ int get_process_root(pid_t pid, char **root) {
>          return get_process_link_contents(p, root);
>  }
>  
> +#define DEFINE_FN_GET_PROCESS_FULL_FILE(name) \
> +int get_process_##name(pid_t pid, char **name) { \
> +        const char *p; \
> +        assert(pid >= 0); \
> +        p = procfs_file_alloca(pid, #name); \
> +        return read_full_file(p, name, /*size*/NULL); \
> +}
> +
> +DEFINE_FN_GET_PROCESS_FULL_FILE(status)
> +DEFINE_FN_GET_PROCESS_FULL_FILE(maps)
> +DEFINE_FN_GET_PROCESS_FULL_FILE(limits)
> +DEFINE_FN_GET_PROCESS_FULL_FILE(cgroup)
> +

Please use functions instead of macros wherever that works. 

Maybe it is sufficient to just provide a single function for all four
cases that takes an extra argument for the file name to read?

Maybe:

        int get_process_proc_file(pid_t pid, const char *filename, char **ret)

Or so? Given that the files in question are generally just read and
passed on as is without processing them any further I think it is Ok
to just provide a single "bulk" call that covers all four cases
instead of four individual ones.

Hope that makes sense?

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list