/********************************************************************* Restart the process with the same args. */ static void restart( /*====*/ int argc, char* argv[]) { (void) argc; #ifdef __WIN__ _execvp(argv[0], argv); #else execvp(argv[0], argv); #endif perror("execvp"); abort(); }
void perform(const std::string &command, const std::list<std::string> &arguments) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); if(!CreateProcess(NULL, "", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)){ //child process char *argv[arguments.size() + 2]; argv[0] = (char *)command.c_str(); argv[arguments.size() + 1] = 0; std::list<std::string>::const_iterator it = arguments.begin(); for (size_t i = 0; i < arguments.size(); i++) { argv[i + 1] = (char *)it->c_str(); it++; } int rv = _execvp(command.c_str(), argv); if (rv == -1) throw make_runtime_error("Unable to create new process: %s.", strerror(errno)); } else { // parent process throw make_runtime_error("CreateProcess failed (%d).\n", GetLastError() ); return; } // Wait until child process exits. WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); }
/* * Program entry point: set up arguments and invoke Java interpreter. */ int main( int argc, char *argv[] ) { int i; /* loop index variable */ char **args; /* array to store arguments to interpreter */ int n = 0; /* next index to fill in argument array */ /* allocate space for argument list */ args = (char **) /* allocate space for: */ malloc((1 /* executable name */ + NUM_VARS /* property definition for each variable */ + 1 /* class name */ + 1) /* terminating NULL */ * sizeof(*args)); if (args == NULL) { server_error("memory allocation failure"); return 1; } /* first argument: name of java interpreter */ args[n ++] = JAVA_NAME; /* next arguments: define CGI variables as properties to Java VM */ for (i = 0; i < NUM_VARS; ++ i) { char *name = var_names[i]; /* name of variable */ char *value; /* value of variable */ char *buffer; /* buffer to store argument string */ value = getenv(name); if (value == NULL) /* if variable undefined, */ value = ""; /* use empty string */ buffer = (char *) /* allocate space for: */ malloc((2 /* "-D" */ + strlen(name) /* variable name */ + 2 /* "=\"" */ + strlen(value) /* variable value */ + 2) /* "\"" and terminating '\0' */ * sizeof(*buffer)); if (buffer == NULL) { server_error("memory allocation failure"); return 1; } /* construct property definition parameter */ sprintf(buffer, "-D%s=\"%s\"", name, value); args[n ++] = buffer; /* add to argument list */ } /* last argument: name of class to execute */ args[n ++] = CLASS_NAME; args[n ++] = NULL; /* terminate argument list */ _execvp(JAVA_NAME, args); /* execute java interpreter */ /* if exec call returns, there was an error */ server_error("interpreter execution failure"); return 1; }
void CNelLauncherDlg::clickedConnect() { pbConnect->setEnabled(FALSE); TShardList shards = m_Connection.getShards(); nlinfo("a shard was double clicked. row selected: %d", tblShardList->currentRow()); if(tblShardList->currentRow() < 0) { QMessageBox::about(this, "Connect to Shard", "Please, select a shard and then press Connect button."); } pbConnect->setEnabled(FALSE); CShard shard = shards[tblShardList->currentRow()]; if(!shard.Online) { QMessageBox::about(this, "Connect to Shard", "You can't connect to an offline shard (error code 15)"); } // TODO implement the patching stuff. //if(!shard.Version.empty() && shard.Version != getVersion()) std::string cookie, addr; std::string res = m_Connection.selectShard(shard.ShardId, cookie, addr); if(res.empty()) { nlinfo("successfully connected to shard, launch client."); std::string rapp = ConfigFile.getVar("Application").asString(1); std::string dir = ConfigFile.getVar("Application").asString(2); std::vector<std::string> vargs; //const char *args[50]; vargs.push_back(rapp); vargs.push_back(cookie); vargs.push_back(addr); // Create the ArgV from a vector. uint nArgs = vargs.size(); char **buf = new char*[nArgs + 1]; for(uint i=0; i<nArgs; ++i) { buf[i] = new char(vargs[i].size() + 1); strcpy(buf[i], vargs[i].c_str()); //strcat(buf[i], '\0'); } buf[nArgs]=NULL; if(!dir.empty()) _chdir(dir.c_str()); if(_execvp(rapp.c_str(), buf) == -1) { QMessageBox::about(this, "Launch Client", "Can't execute the game (error code 17)"); pbConnect->setEnabled(TRUE); } else { for(uint i=0; i<nArgs; ++i) delete [] buf[i]; delete buf; exit(0); } } else { QMessageBox::about(this, "Connect to Shard", res.c_str()); pbConnect->setEnabled(TRUE); } }
int execvp(const char * path, char * const argv[]) { int (*_execvp) (const char *, char * const argv[]) = dlsym(RTLD_NEXT, "execvp"); char buf[PATH_MAX]; return _execvp(rewrite(path, buf), argv); }