According to covscan, vfork() may lead to a deadlock in the parent
process. It suggests to use posix_spawn() instead. Since the latter
combines vfork() and exec() calls, use it for xtables_insmod().
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
#include <fcntl.h>
#include <inttypes.h>
#include <netdb.h>
+#include <spawn.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
char *buf = NULL;
char *argv[4];
int status;
+ pid_t pid;
/* If they don't explicitly set it, read out of kernel */
if (!modprobe) {
*/
fflush(stdout);
- switch (vfork()) {
- case 0:
- execv(argv[0], argv);
-
- /* not usually reached */
- _exit(1);
- case -1:
+ if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL)) {
free(buf);
return -1;
-
- default: /* parent */
- wait(&status);
+ } else {
+ waitpid(pid, &status, 0);
}
free(buf);