- wrapper: add optional <exec_dir> element in <task> elements;

specifies a directory to run app in.
    macro-substitute project dir for $PROJECT_DIR.
    From Carl Christensen, more or less


svn path=/trunk/boinc/; revision=23075
This commit is contained in:
David Anderson 2011-02-20 04:01:04 +00:00
parent 151ca04258
commit 7ae1e2357d
2 changed files with 100 additions and 65 deletions

View File

@ -928,3 +928,12 @@ David 18 Feb 2011
cs_notice.cpp,h cs_notice.cpp,h
gui_rpc_server.h gui_rpc_server.h
gui_rpc_server_ops.cpp gui_rpc_server_ops.cpp
David 19 Feb 2011
- wrapper: add optional <exec_dir> element in <task> elements;
specifies a directory to run app in.
macro-substitute project dir for $PROJECT_DIR.
From Carl Christensen, more or less
samples/wrapper/
wrapper.cpp

View File

@ -61,6 +61,8 @@ using std::string;
struct TASK { struct TASK {
string application; string application;
string exec_dir;
// optional execution directory; macro-substituted for $PROJECT_DIR
string stdin_filename; string stdin_filename;
string stdout_filename; string stdout_filename;
string stderr_filename; string stderr_filename;
@ -143,6 +145,22 @@ int TASK::parse(XML_PARSER& xp) {
return 0; return 0;
} }
else if (xp.parse_string(tag, "application", application)) continue; else if (xp.parse_string(tag, "application", application)) continue;
else if (xp.parse_str(tag, "exec_dir", buf, sizeof(buf))) {
while (1) {
char* p = strstr(buf, "$PROJECT_DIR");
if (!p) break;
strcpy(buf2, p+strlen("$PROJECT_DIR"));
if (strlen(aid.project_dir) > 0) {
strcpy(p, aid.project_dir);
} else {
strcpy(p, ".");
}
strcat(p, buf2);
}
exec_dir = buf;
//fprintf(stderr, "Found exec_dir = %s\n", exec_dir.c_str());
continue;
}
else if (xp.parse_string(tag, "stdin_filename", stdin_filename)) continue; else if (xp.parse_string(tag, "stdin_filename", stdin_filename)) continue;
else if (xp.parse_string(tag, "stdout_filename", stdout_filename)) continue; else if (xp.parse_string(tag, "stdout_filename", stdout_filename)) continue;
else if (xp.parse_string(tag, "stderr_filename", stderr_filename)) continue; else if (xp.parse_string(tag, "stderr_filename", stderr_filename)) continue;
@ -326,7 +344,7 @@ int TASK::run(int argct, char** argvt) {
TRUE, // bInheritHandles TRUE, // bInheritHandles
CREATE_NO_WINDOW|IDLE_PRIORITY_CLASS, CREATE_NO_WINDOW|IDLE_PRIORITY_CLASS,
NULL, NULL,
NULL, exec_dir.empty()?NULL:exec_dir.c_str(),
&startup_info, &startup_info,
&process_info &process_info
)) { )) {
@ -383,6 +401,14 @@ int TASK::run(int argct, char** argvt) {
strlcpy(arglist, command_line.c_str(), sizeof(arglist)); strlcpy(arglist, command_line.c_str(), sizeof(arglist));
argc = parse_command_line(arglist, argv+1); argc = parse_command_line(arglist, argv+1);
setpriority(PRIO_PROCESS, 0, PROCESS_IDLE_PRIORITY); setpriority(PRIO_PROCESS, 0, PROCESS_IDLE_PRIORITY);
if (!exec_dir.empty()) {
int retval = chdir(exec_dir.c_str());
#if 0
fprintf(stderr, "%s change to directory for task: %s\n",
retval ? "Failed to" : "Successful", exec_dir.c_str()
);
#endif
}
retval = execv(app_path, argv); retval = execv(app_path, argv);
perror("execv() failed: "); perror("execv() failed: ");
exit(ERR_EXEC); exit(ERR_EXEC);