diff options
author | Ronny Chevalier <chevalier.ronny@gmail.com> | 2015-04-14 18:42:09 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2015-04-14 18:42:09 -0400 |
commit | 47fefe304092f07bf89c1fc3d0614da5b0dbee3d (patch) | |
tree | c6f1ff243a1e7dc3fcdabf8c3d8e29b15e477822 /src/shared/process-util.h | |
parent | 4b725bd2d38cbad1c490d22823f73c73ef3fc9df (diff) |
shared: add process-util.[ch]
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/process-util.h')
-rw-r--r-- | src/shared/process-util.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/shared/process-util.h b/src/shared/process-util.h new file mode 100644 index 0000000000..bb420ec06a --- /dev/null +++ b/src/shared/process-util.h @@ -0,0 +1,46 @@ +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <stdbool.h> +#include <sys/types.h> +#include <alloca.h> +#include <stdio.h> +#include <string.h> +#include <signal.h> + +#include "formats-util.h" + +#define procfs_file_alloca(pid, field) \ + ({ \ + pid_t _pid_ = (pid); \ + const char *_r_; \ + if (_pid_ == 0) { \ + _r_ = ("/proc/self/" field); \ + } else { \ + _r_ = alloca(strlen("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \ + sprintf((char*) _r_, "/proc/"PID_FMT"/" field, _pid_); \ + } \ + _r_; \ + }) + +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_environ(pid_t pid, char **environ); |