Hi,
The following patch change the system(3) call in swapctl(8) to
vfork(2)+exec(2).
swapctl use it for invoking mount_nfs(8) when fstab contains option for
swapping to NFS files.
Comments ? OK ?
--
Sebastien Marie
Index: swapctl.c
===================================================================
RCS file: /cvs/src/sbin/swapctl/swapctl.c,v
retrieving revision 1.20
diff -u -p -r1.20 swapctl.c
--- swapctl.c 18 Apr 2015 18:28:37 -0000 1.20
+++ swapctl.c 13 Aug 2015 11:58:12 -0000
@@ -52,6 +52,7 @@
#include <sys/stat.h>
#include <sys/swap.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <err.h>
@@ -366,8 +367,9 @@ do_fstab(void)
priority = pri;
if ((s = strstr(fp->fs_mntops, NFSMNTPT)) != NULL) {
- char *t, cmd[sizeof(PATH_MOUNT)+PATH_MAX+1+PATH_MAX+1];
- int l;
+ char *t;
+ pid_t pid;
+ int status;
/*
* Skip this song and dance if we're only
@@ -391,11 +393,18 @@ do_fstab(void)
free((char *)spec);
continue;
}
- l = snprintf(cmd, sizeof(cmd), "%s %s %s",
- PATH_MOUNT, fp->fs_spec, spec);
- if (l == -1 || l >= sizeof(cmd))
- errx(1, "path too long");
- if (system(cmd) != 0) {
+
+ switch (pid = vfork()) {
+ case -1: /* error */
+ err(1, "vfork");
+ case 0:
+ execl(PATH_MOUNT, PATH_MOUNT, fp->fs_spec, spec,
+ NULL);
+ err(1, "execl");
+ }
+ if (waitpid(pid, &status, 0) < 0)
+ err(1, "waitpid");
+ if (status != 0) {
warnx("%s: mount failed", fp->fs_spec);
free((char *)spec);
continue;