Skip to content

Commit

Permalink
enabled changing log filename
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Nov 4, 2021
1 parent e01cafc commit 508924d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 <id,...> the job will be on these GPU indices without checking whether they are free.\n");
Expand All @@ -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");
Expand Down
1 change: 1 addition & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ struct CommandLine {
int *gpu_nums;
int wait_free_gpus;
int gpu_wait_time;
char *logfile;
};

enum Process_type {
Expand Down

0 comments on commit 508924d

Please sign in to comment.