Skip to content

Commit 49f27d8

Browse files
authored
Merge pull request #6394 from BOINC/dpa_wsl_wrapper3
WSL wrapper enhancements
2 parents 34f9721 + 896edd2 commit 49f27d8

File tree

7 files changed

+99
-36
lines changed

7 files changed

+99
-36
lines changed

samples/docker_wrapper/docker_wrapper.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ DOCKER_CONN docker_conn;
193193
vector<string> app_args;
194194
DOCKER_TYPE docker_type;
195195

196-
// parse job config file
196+
// parse job config file (job.toml)
197197
//
198198
int parse_config_file() {
199199
// defaults
@@ -684,7 +684,16 @@ int main(int argc, char** argv) {
684684
options.check_heartbeat = true;
685685
options.handle_process_control = true;
686686
boinc_init_options(&options);
687+
688+
// don't write to stderr before this; it won't go to stderr.txt
689+
690+
// parse job.toml
687691
retval = parse_config_file();
692+
if (retval) {
693+
fprintf(stderr, "can't parse config file\n");
694+
exit(1);
695+
}
696+
688697
if (boinc_is_standalone()) {
689698
config.verbose = VERBOSE_STD;
690699
strcpy(image_name, "boinc");
@@ -697,10 +706,6 @@ int main(int argc, char** argv) {
697706
get_container_name();
698707
}
699708

700-
if (retval) {
701-
fprintf(stderr, "can't parse config file\n");
702-
exit(1);
703-
}
704709
if (config.verbose) config.print();
705710

706711
if (sporadic) {

samples/wsl_wrapper/main.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /bin/bash
2+
3+
# Shim for running worker with wsl_wrapper or docker_wrapper.
4+
# Resolves exec/in/out filenames, and passes cmdline args to worker.
5+
6+
resolve () {
7+
sed 's/<soft_link>//; s/<\/soft_link>//' $1 | tr -d '\r\n'
8+
}
9+
10+
$(resolve worker) $@ $(resolve in) $(resolve out)

samples/wsl_wrapper/wsl_wrapper.cpp

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
// wsl_wrapper: wrapper for WSL apps on Windows.
1919
//
20-
// cmdline options:
20+
// wsl_wrapper [options] arg1 arg2
21+
// arg1 arg2 ... are passed to the main program on cmdline
22+
// options:
2123
//
2224
// --main_prog X name of main program (default "main")
23-
// --pass_thru args additional cmdline arg for main program
2425
// --os_name_regex use only distros w/ matching OS name
2526
// --os_version_regex
2627
// --min_libc_version MMmm e.g. 235 means 2.35
@@ -34,11 +35,11 @@
3435
// and relays this to the client.
3536

3637
// implementation:
37-
// We use two WSL_CMDs (connections into the WSL container):
38-
// one to run the app, get its process group ID,
38+
// We use two WSL_CMDs (connections to shells the WSL container):
39+
// app_wc: run the app, get its process group ID,
3940
// and capture its stdout and stderr
40-
// another to run a shell for monitoring and control operations (ps, kill)
41-
// (this has less overhead than creating a shell per op)
41+
// ctl_wc: monitoring and control operations (ps, kill)
42+
// this has less overhead than creating a shell per op
4243
//
4344
// Typically, the app has a control script as well as an executable.
4445
// This might be written in bash or perl,
@@ -57,6 +58,7 @@
5758

5859
#include <cstdio>
5960
#include <string>
61+
#include <vector>
6062

6163
#include "boinc_win.h"
6264
#include "util.h"
@@ -65,6 +67,7 @@
6567
#include "app_ipc.h"
6668

6769
using std::string;
70+
using std::vector;
6871

6972
WSL_CMD app_wc;
7073
WSL_CMD ctl_wc;
@@ -110,8 +113,8 @@ int launch(const char* distro, const char* cmd) {
110113
retval = read_from_pipe(app_wc.out_read, app_wc.proc_handle, reply, CMD_TIMEOUT, "\n");
111114
if (retval) return error("app read_from_pipe", retval);
112115
pgid = atoi(reply.c_str());
116+
fprintf(stderr, "launch reply: [%s]\n", reply.c_str());
113117
if (verbose) {
114-
fprintf(stderr, "launch reply: [%s]\n", reply.c_str());
115118
fprintf(stderr, "pgid: %d\n", pgid);
116119
}
117120
running = true;
@@ -223,36 +226,48 @@ void poll_client_msgs() {
223226
}
224227
}
225228

229+
// copy app_wc to our stderr;
230+
// called when job finishes
231+
//
232+
void copy_output() {
233+
string reply;
234+
read_from_pipe(
235+
app_wc.out_read, app_wc.proc_handle, reply, CMD_TIMEOUT, NULL
236+
);
237+
fprintf(stderr, "output from container:\n%s\n", reply.c_str());
238+
}
239+
226240
int main(int argc, char** argv) {
227-
const char *os_name_regexp=".*", *os_version_regexp=".*", *pass_thru=NULL;
241+
const char *os_name_regexp=".*", *os_version_regexp=".*";
228242
const char *main_prog = "main";
229243
int min_libc_version = 0;
244+
vector<string> app_args;
245+
246+
// do this before writing to stderr, else the messages will be lost
247+
//
248+
BOINC_OPTIONS options;
249+
memset(&options, 0, sizeof(options));
250+
options.main_program = true;
251+
options.check_heartbeat = true;
252+
options.handle_process_control = true;
253+
boinc_init_options(&options);
254+
230255
for (int i=1; i<argc; i++) {
231256
if (!strcmp(argv[i], "--os_name_regexp")) {
232257
os_name_regexp = argv[++i];
233258
} else if (!strcmp(argv[i], "--os_version_regexp")) {
234259
os_version_regexp = argv[++i];
235-
} else if (!strcmp(argv[i], "--pass_thru")) {
236-
pass_thru = argv[++i];
237260
} else if (!strcmp(argv[i], "--min_libc_version")) {
238261
min_libc_version = atoi(argv[++i]);
239262
} else if (!strcmp(argv[i], "--verbose")) {
240263
verbose = true;
241264
} else if (!strcmp(argv[i], "--main_prog")) {
242265
main_prog = argv[++i];
243266
} else {
244-
fprintf(stderr, "unknown option %s\n", argv[i]);
245-
exit(1);
267+
app_args.push_back(argv[i]);
246268
}
247269
}
248270

249-
BOINC_OPTIONS options;
250-
memset(&options, 0, sizeof(options));
251-
options.main_program = true;
252-
options.check_heartbeat = true;
253-
options.handle_process_control = true;
254-
boinc_init_options(&options);
255-
256271
string distro_name;
257272
if (boinc_is_standalone()) {
258273
SetCurrentDirectoryA("C:/ProgramData/BOINC/slots/test");
@@ -271,9 +286,9 @@ int main(int argc, char** argv) {
271286

272287
string main_cmd = "./";
273288
main_cmd += main_prog;
274-
if (pass_thru){
289+
for (string s: app_args) {
275290
main_cmd += " ";
276-
main_cmd += pass_thru;
291+
main_cmd += s;
277292
}
278293
if (launch(distro_name.c_str(), main_cmd.c_str())) {
279294
fprintf(stderr, "launch failed\n");
@@ -287,10 +302,12 @@ int main(int argc, char** argv) {
287302
switch (poll_app(ru)) {
288303
case JOB_FAIL:
289304
fprintf(stderr, "job failed\n");
305+
copy_output();
290306
boinc_finish(1);
291307
goto done;
292308
case JOB_SUCCESS:
293309
fprintf(stderr, "job succeeded\n");
310+
copy_output();
294311
boinc_finish(0);
295312
goto done;
296313
}

tools/process_input_template.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,10 @@ static int process_file_info(
397397
return 0;
398398
}
399399

400-
// parse the <workunit> elements, which includes file refs and job params
400+
// Process the <workunit> section of an input template.
401+
// Copy resource usage and replication params to 'wu'.
402+
// Append XML (the workunit's xml_doc) to 'out'.
403+
// Add the given command line and additional XML.
401404
//
402405
static int process_workunit(
403406
XML_PARSER& xp, WORKUNIT& wu, string& out,

tools/submit_job

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@
33

44
// submit a job and show the WU name
55
//
6-
// usage: submit_job [options] appname [infile ...]
7-
// options:
8-
// --templates in out: specify in/out template files
9-
// --verbose
10-
// --target_user ID
11-
//
12-
// If the app uses a sample assimilator,
6+
7+
function usage() {
8+
return "
9+
usage: submit_job [options] appname [infile ...]
10+
options:
11+
--templates in out specify in/out template files
12+
--verbose
13+
--target_user ID
14+
--command_line "X" cmdline args to program
15+
";
16+
}
17+
18+
// Note: to pass cmdline args to some apps you may need e.g.
19+
// bin/submit_job --command_line "--pass_thru \"--nsecs 17\"" worker infile
20+
// ... but this doesn't work with csh; use bash instead
21+
22+
// This is basically create_work with nicer syntax, and it stages files.
23+
// Note: if the app uses a sample assimilator,
1324
// you can use query_job to query the job status and see output files.
1425

1526
$appname = null;
@@ -18,6 +29,7 @@ $output_template = null;
1829
$infiles = [];
1930
$verbose = false;
2031
$target_user = null;
32+
$command_line = null;
2133

2234
for ($i=1; $i<$argc; $i++) {
2335
if ($argv[$i] == '--templates') {
@@ -27,6 +39,8 @@ for ($i=1; $i<$argc; $i++) {
2739
$verbose = true;
2840
} else if ($argv[$i] == '--target_user') {
2941
$target_user = $argv[++$i];
42+
} else if ($argv[$i] == '--command_line') {
43+
$command_line = $argv[++$i];
3044
} else if (!$appname) {
3145
$appname = $argv[$i];
3246
} else {
@@ -35,7 +49,7 @@ for ($i=1; $i<$argc; $i++) {
3549
}
3650

3751
if (!$appname) {
38-
die("usage: demo_submit [--template fname] [--dir dir] appname [infile ...]\n");
52+
die(usage());
3953
}
4054

4155
chdir("html/ops");
@@ -96,6 +110,11 @@ if ($output_template) {
96110
if ($target_user) {
97111
$x .= " --target_user $target_user";
98112
}
113+
if ($command_line) {
114+
$command_line = str_replace('"', '\"', $command_line);
115+
$x .= sprintf('--command_line "%s"', $command_line);
116+
}
117+
99118
$cmd = sprintf('bin/create_work --appname %s --wu_name %s %s %s',
100119
$appname, $wu_name, $x, implode(' ', $fnames)
101120
);

version.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
// worker version number
3030
#define WORKER_RELEASE 5
3131

32-
// dockerwrapper version number
32+
// wsl_wrapper
33+
#define WSL_WRAPPER_RELEASE 4
34+
35+
// docker_wrapper version number
3336
#define DOCKERWRAPPER_RELEASE 6
3437

3538
// client version number as string

win_build/wsl_wrapper.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
<CharacterSet>MultiByte</CharacterSet>
1010
</PropertyGroup>
1111
<Import Project="boinc.props" />
12+
<PropertyGroup>
13+
<PlatformSuffix Condition="'$(Platform)'=='x64'">x86_64</PlatformSuffix>
14+
<PlatformSuffix Condition="'$(Platform)'=='ARM64'">ARM64</PlatformSuffix>
15+
<TargetVersion>4</TargetVersion>
16+
<TargetName>$(ProjectName)_$(TargetVersion)_windows_$(PlatformSuffix)</TargetName>
17+
</PropertyGroup>
1218
<ItemDefinitionGroup>
1319
<ClCompile>
1420
<AdditionalIncludeDirectories>.;..;../api;../lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

0 commit comments

Comments
 (0)