diff options
| author | Karel Zak <kzak@redhat.com> | 2021-09-07 17:38:31 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2021-10-06 11:01:54 +0200 |
| commit | 0bac02dafb7037376bb277f8c8c65ece69e2a6a1 (patch) | |
| tree | b22a88a4cf7d7a3b565a71784dd37ea7f2c8834d /misc-utils/kill.c | |
| parent | c0f40fe5ad91261f0b84d530faee150a14b0ce90 (diff) | |
| download | util-linux-0bac02dafb7037376bb277f8c8c65ece69e2a6a1.tar.gz | |
kill: use lib/procfs.c
Diffstat (limited to 'misc-utils/kill.c')
| -rw-r--r-- | misc-utils/kill.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/misc-utils/kill.c b/misc-utils/kill.c index c70c385070..f557aacaab 100644 --- a/misc-utils/kill.c +++ b/misc-utils/kill.c @@ -55,11 +55,13 @@ #include "closestream.h" #include "nls.h" #include "pidfd-utils.h" -#include "procutils.h" +#include "procfs.h" +#include "pathnames.h" #include "signames.h" #include "strutils.h" #include "ttyutils.h" #include "xalloc.h" +#include "fileutils.h" /* partial success, otherwise we return regular EXIT_{SUCCESS,FAILURE} */ #define KILL_EXIT_SOMEOK 64 @@ -472,23 +474,31 @@ int main(int argc, char **argv) nerrs++; ct++; } else { - struct proc_processes *ps = proc_open_processes(); int found = 0; + struct dirent *d; + DIR *dir = opendir(_PATH_PROC); + uid_t uid = !ctl.check_all ? getuid() : 0; - if (!ps) + if (!dir) continue; - if (!ctl.check_all) - proc_processes_filter_by_uid(ps, getuid()); - proc_processes_filter_by_name(ps, ctl.arg); - while (proc_next_pid(ps, &ctl.pid) == 0) { + while ((d = xreaddir(dir))) { + if (!ctl.check_all && + !procfs_dirent_match_uid(dir, d, uid)) + continue; + if (ctl.arg && + !procfs_dirent_match_name(dir, d, ctl.arg)) + continue; + if (procfs_dirent_get_pid(d, &ctl.pid) != 0) + continue; + if (kill_verbose(&ctl) != 0) nerrs++; ct++; found = 1; } - proc_close_processes(ps); + closedir(dir); if (!found) { nerrs++, ct++; warnx(_("cannot find process \"%s\""), ctl.arg); |
