From e38016d0171e5486ab541f818f75c83c1c7b1de0 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 4 Dec 2024 01:42:50 -0800 Subject: [PATCH] BUDA: add cmdline field to submission form. Specifies cmdline args for all jobs in batch; you can also specify per-job args, which come after. create_work: add logic to support the above; also fix bug involving pointers to stack vars (big no-no) --- html/user/buda_submit.php | 29 +++++++++++++++++++---------- lib/str_util.cpp | 5 +++++ tools/create_work.cpp | 21 +++++++++++++-------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/html/user/buda_submit.php b/html/user/buda_submit.php index 52a01d0b900..3a56969952b 100644 --- a/html/user/buda_submit.php +++ b/html/user/buda_submit.php @@ -41,16 +41,17 @@ function submit_form($user) { containing command-line arguments. Details. "; - $desc2 = "
- Write Docker commands and output to stderr (for debugging). - "; page_head("Submit jobs to $app ($variant)"); form_start('buda_submit.php'); form_input_hidden('action', 'submit'); form_input_hidden('app', $app); form_input_hidden('variant', $variant); form_select("Batch zip file $desc", 'batch_file', $sbitems_zip); - form_checkbox("Verbose Docker output? $desc2", 'wrapper_verbose'); + form_input_text('Command line arguments', 'cmdline'); + form_checkbox( + "Enabled debugging output
Write Docker commands and output to stderr.", + 'wrapper_verbose' + ); form_submit('OK'); form_end(); page_tail(); @@ -114,7 +115,8 @@ function parse_batch_dir($batch_dir, $variant_desc) { foreach(scandir("$batch_dir/$fname") as $f2) { if ($f2[0] == '.') continue; if ($f2 == 'cmdline') { - $cmdline = trim(file_get_contents("$batch_dir/$f2")); + $cmdline = trim(file_get_contents("$batch_dir/$fname/cmdline")); + continue; } if (!in_array($f2, $unshared_files)) { error_page("$fname/$f2 is not an input file name"); @@ -186,7 +188,8 @@ function stage_input_files($batch_dir, $batch_desc, $batch_id) { // Use --stdin, where each job is described by a line // function create_jobs( - $variant_desc, $batch_desc, $batch_id, $batch_dir_name, $wrapper_verbose + $variant_desc, $batch_desc, $batch_id, $batch_dir_name, + $wrapper_verbose, $cmdline ) { global $buda_app; @@ -211,15 +214,20 @@ function create_jobs( } $job_cmds .= "$job_cmd\n"; } - $cmd = sprintf( - 'cd ../..; bin/create_work --appname %s --batch %d --stdin --command_line "--dockerfile %s %s" --wu_template %s --result_template %s', - $buda_app->name, $batch_id, + $cw_cmdline = sprintf('"--dockerfile %s %s %s"', $variant_desc->dockerfile, $wrapper_verbose?'--verbose':'', + $cmdline + ); + $cmd = sprintf( + 'cd ../..; bin/create_work --appname %s --batch %d --stdin --command_line %s --wu_template %s --result_template %s', + $buda_app->name, $batch_id, + $cw_cmdline, "buda_batches/$batch_dir_name/template_in", "buda_batches/$batch_dir_name/template_out" ); $cmd .= sprintf(' > %s 2<&1', "buda_batches/errfile"); + $h = popen($cmd, "w"); if (!$h) error_page('create_work launch failed'); fwrite($h, $job_cmds); @@ -316,6 +324,7 @@ function handle_submit($user) { $batch_file = get_str('batch_file'); if (!is_valid_filename($batch_file)) die('bad arg'); $wrapper_verbose = get_str('wrapper_verbose', true); + $cmdline = get_str('cmdline'); $variant_dir = "../../buda_apps/$app/$variant"; $variant_desc = json_decode( @@ -341,7 +350,7 @@ function handle_submit($user) { create_jobs( $variant_desc, $batch_desc, $batch->id, $batch_dir_name, - $wrapper_verbose + $wrapper_verbose, $cmdline ); // mark batch as in progress diff --git a/lib/str_util.cpp b/lib/str_util.cpp index 58e92a5f35e..a1156fd1d1c 100644 --- a/lib/str_util.cpp +++ b/lib/str_util.cpp @@ -235,6 +235,11 @@ void nbytes_to_string(double nbytes, double total_bytes, char* str, int len) { // return an array of pointers to the null-terminated words. // Modifies the string arg. // Returns argc +// +// WARNING: the argv[] pointers are into the original string. +// If that goes away (stack) or is modified, +// the pointers are invalidated. + // TODO: use strtok here #define NOT_IN_TOKEN 0 diff --git a/tools/create_work.cpp b/tools/create_work.cpp index 3680943b675..e7162834bf1 100644 --- a/tools/create_work.cpp +++ b/tools/create_work.cpp @@ -26,6 +26,7 @@ // - to create multiple jobs, where per-job info is passed via stdin, // one line per job // available options here: +// --command_line X // --wu_name X // --wu_template F // --result_template F @@ -137,7 +138,7 @@ struct JOB_DESC { char result_template_file[256]; char result_template_path[MAXPATHLEN]; vector infiles; - char* command_line; + char command_line[1024]; bool assign_flag; bool assign_multi; int assign_id; @@ -145,7 +146,7 @@ struct JOB_DESC { JOB_DESC() { wu.clear(); - command_line = NULL; + strcpy(command_line, ""); assign_flag = false; assign_multi = false; strcpy(wu_template_file, ""); @@ -171,15 +172,19 @@ struct JOB_DESC { } void create(); - void parse_cmdline(int, char**); + void parse_stdin_line(int, char**); }; // parse additional job-specific info when using --stdin // -void JOB_DESC::parse_cmdline(int argc, char** argv) { +void JOB_DESC::parse_stdin_line(int argc, char** argv) { for (int i=0; i