-static int run_script(const char *action)
-{
- pid_t pid;
- int r;
-
- bb_error_msg("executing '%s %s %s'", G.script_name, G.iface, action);
-
-#if 1
- pid = vfork();
- if (pid < 0) {
- bb_perror_msg("fork");
- return -1;
- }
-
- if (pid == 0) {
- /* child */
- execlp(G.script_name, G.script_name, G.iface, action, G.extra_arg, NULL);
- bb_perror_msg_and_die("can't execute '%s'", G.script_name);
- }
-
- /* parent */
- wait(&r);
- r = WEXITSTATUS(r);
-
- bb_error_msg("exit code: %u", r);
- return (option_mask32 & FLAG_IGNORE_RETVAL) ? 0 : r;
-
-#else /* insanity */
-
- struct fd_pair pipe_pair;
- char buf[256];
- int i = 0;
-
- xpiped_pair(pipe_pair);
-
- pid = vfork();
- if (pid < 0) {
- bb_perror_msg("fork");
- return -1;
- }
-
- /* child */
- if (pid == 0) {
- xmove_fd(pipe_pair.wr, 1);
- xdup2(1, 2);
- if (pipe_pair.rd > 2)
- close(pipe_pair.rd);
-
- // umask(0022); // Set up a sane umask
-
- execlp(G.script_name, G.script_name, G.iface, action, G.extra_arg, NULL);
- _exit(EXIT_FAILURE);
- }
-
- /* parent */
- close(pipe_pair.wr);
-
- while (1) {
- if (bb_got_signal && bb_got_signal != SIGCHLD) {
- bb_error_msg("killing child");
- kill(pid, SIGTERM);
- bb_got_signal = 0;
- break;
- }
-
- r = read(pipe_pair.rd, &buf[i], 1);
-
- if (buf[i] == '\n' || i == sizeof(buf)-2 || r != 1) {
- if (r == 1 && buf[i] != '\n')
- i++;
-
- buf[i] = '\0';
-
- if (i > 0)
- bb_error_msg("client: %s", buf);
-
- i = 0;
- } else {
- i++;
- }
-
- if (r != 1)
- break;
- }
-
- close(pipe_pair.rd);
-
- wait(&r);
-
- if (!WIFEXITED(r) || WEXITSTATUS(r) != 0) {
- bb_error_msg("program execution failed, return value is %i",
- WEXITSTATUS(r));
- return option_mask32 & FLAG_IGNORE_RETVAL ? 0 : WEXITSTATUS(r);
- }
- bb_error_msg("program executed successfully");
- return 0;
-#endif
-}
-
-static int network_ioctl(int request, void* data)
-{
- return ioctl(ioctl_fd, request, data);
-}