1134 |
1134 |
|
1135 |
1135 |
static int launch_script(const char *setup_script, const char *ifname, int fd)
|
1136 |
1136 |
{
|
|
1137 |
sigset_t oldmask, mask;
|
1137 |
1138 |
int pid, status;
|
1138 |
1139 |
char *args[3];
|
1139 |
1140 |
char **parg;
|
1140 |
1141 |
|
1141 |
|
/* try to launch network script */
|
1142 |
|
pid = fork();
|
1143 |
|
if (pid >= 0) {
|
1144 |
|
if (pid == 0) {
|
1145 |
|
int open_max = sysconf (_SC_OPEN_MAX), i;
|
1146 |
|
for (i = 0; i < open_max; i++)
|
1147 |
|
if (i != STDIN_FILENO &&
|
1148 |
|
i != STDOUT_FILENO &&
|
1149 |
|
i != STDERR_FILENO &&
|
1150 |
|
i != fd)
|
1151 |
|
close(i);
|
1152 |
|
|
1153 |
|
parg = args;
|
1154 |
|
*parg++ = (char *)setup_script;
|
1155 |
|
*parg++ = (char *)ifname;
|
1156 |
|
*parg++ = NULL;
|
1157 |
|
execv(setup_script, args);
|
1158 |
|
_exit(1);
|
1159 |
|
}
|
1160 |
|
while (waitpid(pid, &status, 0) != pid);
|
1161 |
|
if (!WIFEXITED(status) ||
|
1162 |
|
WEXITSTATUS(status) != 0) {
|
1163 |
|
fprintf(stderr, "%s: could not launch network script\n",
|
1164 |
|
setup_script);
|
1165 |
|
return -1;
|
|
1142 |
sigemptyset(&mask);
|
|
1143 |
sigaddset(&mask, SIGCHLD);
|
|
1144 |
sigprocmask(SIG_BLOCK, &mask, &oldmask);
|
|
1145 |
|
|
1146 |
/* try to launch network script */
|
|
1147 |
pid = fork();
|
|
1148 |
if (pid == 0) {
|
|
1149 |
int open_max = sysconf(_SC_OPEN_MAX), i;
|
|
1150 |
|
|
1151 |
for (i = 0; i < open_max; i++) {
|
|
1152 |
if (i != STDIN_FILENO &&
|
|
1153 |
i != STDOUT_FILENO &&
|
|
1154 |
i != STDERR_FILENO &&
|
|
1155 |
i != fd) {
|
|
1156 |
close(i);
|
1166 |
1157 |
}
|
1167 |
1158 |
}
|
1168 |
|
return 0;
|
|
1159 |
parg = args;
|
|
1160 |
*parg++ = (char *)setup_script;
|
|
1161 |
*parg++ = (char *)ifname;
|
|
1162 |
*parg++ = NULL;
|
|
1163 |
execv(setup_script, args);
|
|
1164 |
_exit(1);
|
|
1165 |
} else if (pid > 0) {
|
|
1166 |
while (waitpid(pid, &status, 0) != pid) {
|
|
1167 |
/* loop */
|
|
1168 |
}
|
|
1169 |
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
|
1170 |
|
|
1171 |
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
|
|
1172 |
return 0;
|
|
1173 |
}
|
|
1174 |
}
|
|
1175 |
fprintf(stderr, "%s: could not launch network script\n", setup_script);
|
|
1176 |
return -1;
|
1169 |
1177 |
}
|
1170 |
1178 |
|
1171 |
1179 |
static int net_tap_init(VLANState *vlan, const char *model,
|