zia::api::handler::ECode ModPhpHandler::operator()(zia::api::http::ITransaction & transac, std::istream & is, std::ostream & os) { if (this->_map == NULL) return zia::api::handler::ServerError; const std::string& path = transac.getRequest().getPath(); int p[2]; if (pipe(p) == -1) { std::cerr << "Pipe failed" << std::endl; return zia::api::handler::ServerError; } std::string extens; if (path.rfind(".") != std::string::npos) extens = path.substr(path.rfind(".") + 1); zia::api::IConfig::ValueMap* maptest = (zia::api::IConfig::ValueMap*)(_map); zia::api::IConfig::ValueMap::iterator it2 = maptest->begin(); zia::api::IConfig::ValueMap::const_iterator conf = this->_map->begin(); if (conf == this->_map->end()) return zia::api::handler::Decline; std::multimap<std::string, std::string>::const_iterator it = conf->second.find(extens); for (;it != conf->second.end() && it->first != extens; ++it); if (it == conf->second.end()) return zia::api::handler::Decline; int res = fork(); if (res == -1) { std::cerr << "Fork failed" << std::endl; return zia::api::handler::ServerError; } if (res == 0) { inChild(p, it->second.data(),transac.getRequest().getUri(), transac, is); exit(-1); } else { int status; res = fork(); if (res == -1) { std::cerr << "Fork has failed" << std::endl; return zia::api::handler::ServerError; } if (res == 0) { inParent(p, os, is); waitpid(res, &status, 0); exit(status); } else { waitpid(res, &status, 0); if (status == 0) return zia::api::handler::Ok; //exit(status); } } return zia::api::handler::ServerError; }
int main(int argc, char **argv) { int ch; int nChildren = 0; static char *progname = "**UNSET**"; /* * Parse the command line arguments. */ progname = argv[0]; for (;;) { ch = getopt_long(argc, argv, "c::ghnp", options, NULL); if (ch == -1) break; switch (ch) { case 'c': if (optarg) nChildren = atoi(optarg); else nChildren = 1; break; case 'g': showPgids = 1; break; case 'h': usage(progname); exit(0); case 'n': synchronize = 0; break; case 'p': showPpids = 1; break; default: printf("?? getopt returned character code 0x%02x ??\n", ch); exit(1); } } int count, childPid; initSignals(); if(nChildren==0) { writeLog("main is pause()'d for a signal", __func__); pause(); } else { for(count =0; count < nChildren; count++) childPid = fork(); if(childPid == 0) { inChild(count); } else { char* message = malloc(2048); snprintf(message, 2048, "parent forked a child. iSibling %d child process %d", count, childPid); writeLog(message, __func__); free(message); } } inParent(); exit(EXIT_SUCCESS); return 0; }