From 508924df3cd5c7633a7d81cea0e8dadd869efc49 Mon Sep 17 00:00:00 2001 From: Duc Date: Fri, 22 Oct 2021 12:21:43 +0900 Subject: [PATCH] enabled changing log filename --- execute.c | 8 +++++++- main.c | 9 ++++++++- main.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/execute.c b/execute.c index 778ec7e..73550e5 100755 --- a/execute.c +++ b/execute.c @@ -137,13 +137,19 @@ static void run_gzip(int fd_out, int fd_in) { } static void run_child(int fd_send_filename, const char* tmpdir) { - char outfname[] = "/ts-out.XXXXXX"; + char *outfname; char errfname[sizeof outfname + 2]; /* .e */ int namesize; int outfd; int err; struct timeval starttv; + if (command_line.logfile) { + outfname = malloc(1 + strlen(command_line.logfile) + strlen(".XXXXXX") + 1); + sprintf(outfname, "/%s.XXXXXX", command_line.logfile); + } else + outfname = "/ts-out.XXXXXX"; + if (command_line.store_output) { /* Prepare path */ int lname; diff --git a/main.c b/main.c index 3525b8c..2be6e69 100755 --- a/main.c +++ b/main.c @@ -50,6 +50,7 @@ static void default_command_line() { command_line.require_elevel = 0; command_line.gpus = 0; command_line.wait_free_gpus = 1; + command_line.logfile = 0; } void get_command(int index, int argc, char **argv) { @@ -114,7 +115,7 @@ void parse_opts(int argc, char **argv) { /* Parse options */ while (1) { - c = getopt_long(argc, argv, ":RTVhKzClnfmBEr:a:F:t:c:o:p:w:k:u:s:U:qi:N:L:dS:D:G:W:g:", + c = getopt_long(argc, argv, ":RTVhKzClnfmBEr:a:F:t:c:o:p:w:k:u:s:U:qi:N:L:dS:D:G:W:g:O:", longOptions, &optionIdx); if (c == -1) @@ -181,6 +182,9 @@ void parse_opts(int argc, char **argv) { command_line.request = c_SHOW_OUTPUT_FILE; command_line.jobid = atoi(optarg); break; + case 'O': + command_line.logfile = optarg; + break; case 'n': command_line.store_output = 0; break; @@ -449,6 +453,8 @@ static void print_help(const char *cmd) { printf(" --full_cmd || -F [id] show full command. Of the last added, if not specified.\n"); printf(" --count_running || -R return the number of running jobs\n"); printf(" --last_queue_id || -q show the job ID of the last added.\n"); + printf(" --get_logdir get the path containing log files.\n"); + printf(" --set_logdir set the path containing log files.\n"); printf("Long option adding jobs:\n"); printf(" --gpus || -G [num] number of GPUs required by the job (1 default).\n"); printf(" --gpu_indices || -g the job will be on these GPU indices without checking whether they are free.\n"); @@ -475,6 +481,7 @@ static void print_help(const char *cmd) { printf(" -B in case of full clients on the server, quit instead of waiting.\n"); printf(" -n don't store the output of the command.\n"); printf(" -E Keep stderr apart, in a name like the output file, but adding '.e'.\n"); + printf(" -O Set name of the log file (without any path).\n"); printf(" -z gzip the stored output (if not -n).\n"); printf(" -f don't fork into background.\n"); printf(" -m send the output by e-mail (uses sendmail).\n"); diff --git a/main.h b/main.h index b7eacd1..7ddd07c 100755 --- a/main.h +++ b/main.h @@ -119,6 +119,7 @@ struct CommandLine { int *gpu_nums; int wait_free_gpus; int gpu_wait_time; + char *logfile; }; enum Process_type {