Skip to content

Commit c91456a

Browse files
committed
kill_all: use rc_exec()
1 parent db44980 commit c91456a

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

src/kill_all/kill_all.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "einfo.h"
3333
#include "rc.h"
34+
#include "rc_exec.h"
3435
#include "_usage.h"
3536
#include "helpers.h"
3637

@@ -51,33 +52,26 @@ const char *usagestring = NULL;
5152

5253
static int mount_proc(void)
5354
{
54-
pid_t pid;
5555
pid_t rc;
5656
int status;
57+
const char *argv[] = { "mount", "-t", "proc", "proc", "/proc", NULL };
58+
struct rc_exec_result res;
59+
struct rc_exec_args args = rc_exec_args_init(argv);
5760

5861
if (exists("/proc/version"))
5962
return 0;
60-
pid = fork();
61-
switch (pid) {
62-
case -1:
63-
syslog(LOG_ERR, "Unable to fork");
64-
return -1;
65-
break;
66-
case 0:
67-
/* attempt to mount /proc */
68-
execlp("mount", "mount", "-t", "proc", "proc", "/proc", NULL);
69-
syslog(LOG_ERR, "Unable to execute mount");
70-
exit(1);
71-
break;
72-
default:
73-
/* wait for child process */
74-
while ((rc = wait(&status)) != pid)
75-
if (rc < 0 && errno == ECHILD)
76-
break;
77-
if (rc != pid || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
78-
syslog(LOG_ERR, "mount returned non-zero exit status");
79-
break;
63+
64+
res = rc_exec(&args);
65+
if (res.pid < 0) {
66+
syslog(LOG_ERR, "Failed to execute mount");
67+
return -1;
8068
}
69+
while ((rc = wait(&status)) != res.pid)
70+
if (rc < 0 && errno == ECHILD)
71+
break;
72+
if (rc != res.pid || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
73+
syslog(LOG_ERR, "mount returned non-zero exit status");
74+
8175
if (!exists("/proc/version")) {
8276
syslog(LOG_ERR, "Could not mount /proc");
8377
return -1;

src/kill_all/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
if os == 'Linux'
22
executable('kill_all',
3-
['kill_all.c', usage_c, version_h],
3+
['kill_all.c', rc_exec_c, usage_c, version_h],
44
c_args : cc_branding_flags,
55
include_directories: [incdir, einfo_incdir, rc_incdir],
66
link_with: [libeinfo,librc],

0 commit comments

Comments
 (0)