process-util: add pidref_is_kernel_thread()
This commit is contained in:
@@ -389,7 +389,7 @@ int namespace_get_leader(pid_t pid, NamespaceType type, pid_t *ret) {
|
||||
}
|
||||
}
|
||||
|
||||
int is_kernel_thread(pid_t pid) {
|
||||
int pid_is_kernel_thread(pid_t pid) {
|
||||
_cleanup_free_ char *line = NULL;
|
||||
unsigned long long flags;
|
||||
size_t l, i;
|
||||
@@ -447,6 +447,23 @@ int is_kernel_thread(pid_t pid) {
|
||||
return !!(flags & PF_KTHREAD);
|
||||
}
|
||||
|
||||
int pidref_is_kernel_thread(const PidRef *pid) {
|
||||
int result, r;
|
||||
|
||||
if (!pidref_is_set(pid))
|
||||
return -ESRCH;
|
||||
|
||||
result = pid_is_kernel_thread(pid->pid);
|
||||
if (result < 0)
|
||||
return result;
|
||||
|
||||
r = pidref_verify(pid); /* Verify that the PID wasn't reused since */
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int get_process_capeff(pid_t pid, char **ret) {
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
@@ -79,7 +79,8 @@ void sigkill_nowaitp(pid_t *pid);
|
||||
|
||||
int kill_and_sigcont(pid_t pid, int sig);
|
||||
|
||||
int is_kernel_thread(pid_t pid);
|
||||
int pid_is_kernel_thread(pid_t pid);
|
||||
int pidref_is_kernel_thread(const PidRef *pid);
|
||||
|
||||
int getenv_for_pid(pid_t pid, const char *field, char **_value);
|
||||
|
||||
|
||||
+1
-1
@@ -209,7 +209,7 @@ static int process(
|
||||
g->n_tasks = 0;
|
||||
while (cg_read_pid(f, &pid) > 0) {
|
||||
|
||||
if (arg_count == COUNT_USERSPACE_PROCESSES && is_kernel_thread(pid) > 0)
|
||||
if (arg_count == COUNT_USERSPACE_PROCESSES && pid_is_kernel_thread(pid) > 0)
|
||||
continue;
|
||||
|
||||
g->n_tasks++;
|
||||
|
||||
@@ -1295,7 +1295,7 @@ static int append_cgroup(sd_bus_message *reply, const char *p, Set *pids) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (is_kernel_thread(pid) > 0)
|
||||
if (pid_is_kernel_thread(pid) > 0)
|
||||
continue;
|
||||
|
||||
r = append_process(reply, p, pid, pids);
|
||||
|
||||
+1
-1
@@ -5953,7 +5953,7 @@ int unit_pid_attachable(Unit *u, PidRef *pid, sd_bus_error *error) {
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Process " PID_FMT " is a manager process, refusing.", pid->pid);
|
||||
|
||||
/* Don't even begin to bother with kernel threads */
|
||||
r = is_kernel_thread(pid->pid);
|
||||
r = pidref_is_kernel_thread(pid);
|
||||
if (r == -ESRCH)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_UNIX_PROCESS_ID_UNKNOWN, "Process with ID " PID_FMT " does not exist.", pid->pid);
|
||||
if (r < 0)
|
||||
|
||||
@@ -611,7 +611,7 @@ int cg_migrate(
|
||||
* them there. */
|
||||
if (cfrom &&
|
||||
empty_or_root(pfrom) &&
|
||||
is_kernel_thread(pid) > 0)
|
||||
pid_is_kernel_thread(pid) > 0)
|
||||
continue;
|
||||
|
||||
r = cg_attach(cto, pto, pid);
|
||||
|
||||
@@ -114,7 +114,7 @@ static int show_cgroup_one_by_path(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!(flags & OUTPUT_KERNEL_THREADS) && is_kernel_thread(pid) > 0)
|
||||
if (!(flags & OUTPUT_KERNEL_THREADS) && pid_is_kernel_thread(pid) > 0)
|
||||
continue;
|
||||
|
||||
if (!GREEDY_REALLOC(pids, n + 1))
|
||||
|
||||
@@ -77,7 +77,7 @@ static bool ignore_proc(pid_t pid, bool warn_rootfs) {
|
||||
return true;
|
||||
|
||||
/* Ignore kernel threads */
|
||||
r = is_kernel_thread(pid);
|
||||
r = pid_is_kernel_thread(pid);
|
||||
if (r != 0)
|
||||
return true; /* also ignore processes where we can't determine this */
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ TEST(proc) {
|
||||
if (r < 0)
|
||||
continue;
|
||||
|
||||
if (is_kernel_thread(pid))
|
||||
if (pid_is_kernel_thread(pid) != 0)
|
||||
continue;
|
||||
|
||||
cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &path);
|
||||
|
||||
@@ -76,7 +76,7 @@ static void test_get_process_comm_one(pid_t pid) {
|
||||
assert_se(e > 0);
|
||||
}
|
||||
|
||||
assert_se(is_kernel_thread(pid) == 0 || pid != 1);
|
||||
assert_se(pid_is_kernel_thread(pid) == 0 || pid != 1);
|
||||
|
||||
r = get_process_exe(pid, &f);
|
||||
assert_se(r >= 0 || r == -EACCES);
|
||||
|
||||
Reference in New Issue
Block a user