systemd: merge branch systemd into master

Do another import, shortly before re-release.

There are no actual changes, but as always: to find out
that there are no changes requires large part of the work of
just doing the reimport.

Also, systemd import branch was rebased recently, that means
git-merge does not get this reimport right automatically (because
it thinks that the changes on master should be reverted). Hence,
this reimport required more care. Do it while there are few
changes.
This commit is contained in:
Thomas Haller 2019-11-29 13:06:05 +01:00
commit d345c4fd69
2 changed files with 45 additions and 11 deletions

View file

@ -86,3 +86,18 @@ static inline bool ERRNO_IS_RESOURCE(int r) {
ENFILE,
ENOMEM);
}
/* Three different errors for "operation/system call/ioctl not supported" */
static inline bool ERRNO_IS_NOT_SUPPORTED(int r) {
return IN_SET(abs(r),
EOPNOTSUPP,
ENOTTY,
ENOSYS);
}
/* Two different errors for access problems */
static inline bool ERRNO_IS_PRIVILEGE(int r) {
return IN_SET(abs(r),
EACCES,
EPERM);
}

View file

@ -25,8 +25,8 @@
#include "alloc-util.h"
#include "architecture.h"
#include "escape.h"
#include "env-util.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
@ -38,6 +38,7 @@
#include "missing_sched.h"
#include "missing_syscall.h"
#include "namespace-util.h"
#include "path-util.h"
#include "process-util.h"
#include "raw-clone.h"
#include "rlimit-util.h"
@ -57,13 +58,17 @@
#define COMM_MAX_LEN 128
static int get_process_state(pid_t pid) {
_cleanup_free_ char *line = NULL;
const char *p;
char state;
int r;
_cleanup_free_ char *line = NULL;
assert(pid >= 0);
/* Shortcut: if we are enquired about our own state, we are obviously running */
if (pid == 0 || pid == getpid_cached())
return (unsigned char) 'R';
p = procfs_file_alloca(pid, "stat");
r = read_one_line_file(p, &line);
@ -86,24 +91,35 @@ static int get_process_state(pid_t pid) {
int get_process_comm(pid_t pid, char **ret) {
_cleanup_free_ char *escaped = NULL, *comm = NULL;
const char *p;
int r;
assert(ret);
assert(pid >= 0);
if (pid == 0 || pid == getpid_cached()) {
comm = new0(char, TASK_COMM_LEN + 1); /* Must fit in 16 byte according to prctl(2) */
if (!comm)
return -ENOMEM;
if (prctl(PR_GET_NAME, comm) < 0)
return -errno;
} else {
const char *p;
p = procfs_file_alloca(pid, "comm");
/* Note that process names of kernel threads can be much longer than TASK_COMM_LEN */
r = read_one_line_file(p, &comm);
if (r == -ENOENT)
return -ESRCH;
if (r < 0)
return r;
}
escaped = new(char, COMM_MAX_LEN);
if (!escaped)
return -ENOMEM;
p = procfs_file_alloca(pid, "comm");
r = read_one_line_file(p, &comm);
if (r == -ENOENT)
return -ESRCH;
if (r < 0)
return r;
/* Escape unprintable characters, just in case, but don't grow the string beyond the underlying size */
cellescape(escaped, COMM_MAX_LEN, comm);
@ -506,6 +522,9 @@ int get_process_cwd(pid_t pid, char **cwd) {
assert(pid >= 0);
if (pid == 0 || pid == getpid_cached())
return safe_getcwd(cwd);
p = procfs_file_alloca(pid, "cwd");
return get_process_link_contents(p, cwd);