]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/killall.c
util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]
[thirdparty/systemd.git] / src / core / killall.c
index 5a50ae6f045e5d024ec8434ee047a689abc97e03..dbfa90ebacb6f83565784bb99d8368e21d80ee43 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <sys/wait.h>
-#include <signal.h>
 #include <errno.h>
+#include <signal.h>
+#include <sys/wait.h>
 #include <unistd.h>
 
-#include "util.h"
-#include "def.h"
+#include "fd-util.h"
+#include "formats-util.h"
 #include "killall.h"
+#include "parse-util.h"
+#include "process-util.h"
 #include "set.h"
+#include "string-util.h"
+#include "terminal-util.h"
+#include "util.h"
 
 #define TIMEOUT_USEC (10 * USEC_PER_SEC)
 
@@ -106,7 +111,7 @@ static void wait_for_children(Set *pids, sigset_t *mask) {
                                 return;
                         }
 
-                        set_remove(pids, ULONG_TO_PTR(pid));
+                        (void) set_remove(pids, PID_TO_PTR(pid));
                 }
 
                 /* Now explicitly check who might be remaining, who
@@ -115,7 +120,7 @@ static void wait_for_children(Set *pids, sigset_t *mask) {
 
                         /* We misuse getpgid as a check whether a
                          * process still exists. */
-                        if (getpgid((pid_t) PTR_TO_ULONG(p)) >= 0)
+                        if (getpgid(PTR_TO_PID(p)) >= 0)
                                 continue;
 
                         if (errno != ESRCH)
@@ -156,6 +161,7 @@ static int killall(int sig, Set *pids, bool send_sighup) {
 
         while ((d = readdir(dir))) {
                 pid_t pid;
+                int r;
 
                 if (d->d_type != DT_DIR &&
                     d->d_type != DT_UNKNOWN)
@@ -175,8 +181,11 @@ static int killall(int sig, Set *pids, bool send_sighup) {
                 }
 
                 if (kill(pid, sig) >= 0) {
-                        if (pids)
-                                set_put(pids, ULONG_TO_PTR(pid));
+                        if (pids) {
+                                r = set_put(pids, PID_TO_PTR(pid));
+                                if (r < 0)
+                                        log_oom();
+                        }
                 } else if (errno != ENOENT)
                         log_warning_errno(errno, "Could not kill %d: %m", pid);