| 166 | } |
| 167 | |
| 168 | static void start_child(ACL_MASTER_SERV *serv) |
| 169 | { |
| 170 | const char *myname = "start_child"; |
| 171 | int n, i; |
| 172 | ACL_MASTER_NV *nv; |
| 173 | |
| 174 | if (serv->type != ACL_MASTER_SERV_TYPE_NONE) { |
| 175 | prepare_child_fds(serv); |
| 176 | } |
| 177 | |
| 178 | /* Redirect stdout to local file */ |
| 179 | if (serv->stdout_log) { |
| 180 | int oflags = O_APPEND | O_WRONLY | O_CREAT; |
| 181 | int fd = open(serv->stdout_log, oflags, 0600); |
| 182 | if (fd >= 0 && fd != 1) { |
| 183 | dup2(fd, 1); |
| 184 | close(fd); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | /* Redirect stderr to local file */ |
| 189 | if (serv->stderr_log) { |
| 190 | int oflags = O_APPEND | O_WRONLY | O_CREAT; |
| 191 | int fd = open(serv->stderr_log, oflags, 0600); |
| 192 | if (fd >= 0 && fd != 2) { |
| 193 | dup2(fd, 2); |
| 194 | close(fd); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | acl_vstring_sprintf(env_gen, "%s=%o", ACL_MASTER_GEN_NAME, |
| 199 | master_generation); |
| 200 | if (putenv(acl_vstring_str(env_gen)) < 0) { |
| 201 | acl_msg_fatal("%s: putenv: %s", myname, strerror(errno)); |
| 202 | } |
| 203 | |
| 204 | n = acl_array_size(serv->children_env); |
| 205 | for (i = 0; i < n; i++) { |
| 206 | nv = (ACL_MASTER_NV *) acl_array_index(serv->children_env, i); |
| 207 | if (nv == NULL) { |
| 208 | break; |
| 209 | } |
| 210 | setenv(nv->name, nv->value, 1); |
| 211 | } |
| 212 | |
| 213 | /* Begin to call the child process */ |
| 214 | if (acl_msg_verbose) { |
| 215 | acl_msg_info("%s: cmd = %s", myname, serv->path); |
| 216 | } |
| 217 | |
| 218 | /* Help app to change working directory */ |
| 219 | if (serv->home && *serv->home) { |
| 220 | if (chdir(serv->home) == -1) { |
| 221 | acl_msg_error("%s: chdir to %s error %s", |
| 222 | myname, serv->home, acl_last_serror()); |
| 223 | } else { |
| 224 | acl_msg_info("%s: %s chdir to %s ok", |
| 225 | myname, serv->path, serv->home); |
no test coverage detected
searching dependent graphs…