diff options
author | Ronny Chevalier <chevalier.ronny@gmail.com> | 2015-04-10 19:10:00 +0200 |
---|---|---|
committer | Ronny Chevalier <chevalier.ronny@gmail.com> | 2015-04-10 23:54:49 +0200 |
commit | 0b452006de98294d1690f045f6ea2f7f6630ec3b (patch) | |
tree | 852bde2d8fd7dac434636bd25a276b5cf0eece9f /src/shared/process-util.h | |
parent | 6482f6269c87d2249e52e889a63adbdd50f2d691 (diff) |
shared: add process-util.[ch]
Diffstat (limited to 'src/shared/process-util.h')
-rw-r--r-- | src/shared/process-util.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/shared/process-util.h b/src/shared/process-util.h new file mode 100644 index 0000000000..07431d043b --- /dev/null +++ b/src/shared/process-util.h @@ -0,0 +1,65 @@ +#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_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); +int get_process_uid(pid_t pid, uid_t *uid); +int get_process_gid(pid_t pid, gid_t *gid); +int get_process_capeff(pid_t pid, char **capeff); +int get_process_cwd(pid_t pid, char **cwd); +int get_process_root(pid_t pid, char **root); +int get_process_environ(pid_t pid, char **environ); + +int wait_for_terminate(pid_t pid, siginfo_t *status); +int wait_for_terminate_and_warn(const char *name, pid_t pid, bool check_exit_code); + +int kill_and_sigcont(pid_t pid, int sig); +pid_t get_parent_of_pid(pid_t pid, pid_t *ppid); +void rename_process(const char name[8]); +int is_kernel_thread(pid_t pid); +int getenv_for_pid(pid_t pid, const char *field, char **_value); + +bool pid_is_alive(pid_t pid); +bool pid_is_unwaited(pid_t pid); |