diff --git a/client.c b/client.c index f4a8b32..6531b85 100644 --- a/client.c +++ b/client.c @@ -698,3 +698,37 @@ void c_get_count_running() { /* This will never be reached */ return; } + +void c_show_label() +{ + struct msg m; + int res; + char *string = 0; + + /* Send the request */ + m.type = GET_LABEL; + m.u.jobid = command_line.jobid; + send_msg(server_socket, &m); + + /* Receive the answer */ + res = recv_msg(server_socket, &m); + if(res != sizeof(m)) + error("Error in get_label"); + + switch(m.type) + { + case LIST_LINE: + string = (char *) malloc(m.u.size); + res = recv_bytes(server_socket, string, m.u.size); + if(res != m.u.size) + error("Error in get_label - line size"); + + printf("%s", string); + return; + default: + warning("Wrong internal message in get_label"); + } + + /* This will never be reached */ + return; +} diff --git a/jobs.c b/jobs.c index 1ab6864..354a9de 100644 --- a/jobs.c +++ b/jobs.c @@ -178,7 +178,7 @@ void s_count_running_jobs(int s) struct Job *p; struct msg m; - /* Show Queued or Running jobs */ + /* Count running jobs */ p = firstjob; while(p != 0) { @@ -194,6 +194,48 @@ void s_count_running_jobs(int s) send_msg(s, &m); } +void s_get_label(int s, int jobid) +{ + struct Job *p = 0; + char *label; + + if (jobid == -1) + { + /* Find the last job added */ + p = firstjob; + + if (p != 0) + while (p->next != 0) + p = p->next; + + /* Look in finished jobs if needed */ + if (p == 0) + { + p = first_finished_job; + if (p != 0) + while (p->next != 0) + p = p->next; + } + + } + else + { + p = get_job(jobid); + } + + if (p == 0) + { + char tmp[50]; + sprintf(tmp, "Job %i not finished or not running.\n", jobid); + send_list_line(s, tmp); + return; + } + + label = (char *) malloc(strlen(p->label) + 1); + sprintf(label, "%s\n", p->label); + send_list_line(s, label); +} + void s_mark_job_running(int jobid) { struct Job *p; diff --git a/main.c b/main.c index c3898bd..c7afafd 100644 --- a/main.c +++ b/main.c @@ -84,7 +84,7 @@ void parse_opts(int argc, char **argv) /* Parse options */ while(1) { - c = getopt(argc, argv, ":RVhKgClnfmBEr:t:c:o:p:w:k:u:s:U:i:N:L:dS:D:"); + c = getopt(argc, argv, ":RVhKgClnfmBEr:a:t:c:o:p:w:k:u:s:U:i:N:L:dS:D:"); if (c == -1) break; @@ -150,6 +150,10 @@ void parse_opts(int argc, char **argv) command_line.request = c_INFO; command_line.jobid = atoi(optarg); break; + case 'a': + command_line.request = c_GET_LABEL; + command_line.jobid = atoi(optarg); + break; case 'N': command_line.num_slots = atoi(optarg); if (command_line.num_slots < 0) @@ -260,6 +264,10 @@ void parse_opts(int argc, char **argv) case 'S': command_line.request = c_GET_MAX_SLOTS; break; + case 'a': + command_line.request = c_GET_LABEL; + command_line.jobid = -1; + break; default: fprintf(stderr, "Option %c missing argument.\n", optopt); @@ -361,6 +369,7 @@ static void print_help(const char *cmd) printf(" -o [id] show the output file. Of last job run, if not specified.\n"); printf(" -i [id] show job information. Of last job run, if not specified.\n"); printf(" -s [id] show the job state. Of the last added, if not specified.\n"); + printf(" -a [id] show the job label. Of the last added, if not specified.\n"); printf(" -r [id] remove a job. The last added, if not specified.\n"); printf(" -w [id] wait for a job. The last added, if not specified.\n"); printf(" -k [id] send SIGTERM to the job process group. The last run, if not specified.\n"); @@ -427,7 +436,7 @@ int main(int argc, char **argv) switch(command_line.request) { case c_SHOW_VERSION: - print_version(argv[0]); + print_version(); break; case c_SHOW_HELP: print_help(argv[0]); @@ -502,6 +511,11 @@ int main(int argc, char **argv) error("The command %i needs the server", command_line.request); c_show_info(); break; + case c_GET_LABEL: + if (!command_line.need_server) + error("The command %i needs the server", command_line.request); + c_show_label(); + break; case c_REMOVEJOB: if (!command_line.need_server) error("The command %i needs the server", command_line.request); diff --git a/main.h b/main.h index a63b00c..2c7239e 100644 --- a/main.h +++ b/main.h @@ -42,7 +42,8 @@ enum msg_types GET_VERSION, VERSION, NEWJOB_NOK, - COUNT_RUNNING + COUNT_RUNNING, + GET_LABEL }; enum Request @@ -66,7 +67,8 @@ enum Request c_SET_MAX_SLOTS, c_GET_MAX_SLOTS, c_KILL_JOB, - c_COUNT_RUNNING + c_COUNT_RUNNING, + c_GET_LABEL }; struct Command_line { @@ -156,6 +158,7 @@ struct msg int max_slots; int version; int count_running; + char *label; } u; }; @@ -225,6 +228,7 @@ void c_send_max_slots(int max_slots); void c_get_max_slots(); void c_check_version(); void c_get_count_running(); +void c_show_label(); /* jobs.c */ void s_list(int s); @@ -256,6 +260,7 @@ void s_get_max_slots(int s); int job_is_running(int jobid); int job_is_holding_client(int jobid); int wake_hold_client(); +void s_get_label(int s, int jobid); /* server.c */ void server_main(int notify_fd, char *_path); diff --git a/server.c b/server.c index 71b610d..7156ccc 100644 --- a/server.c +++ b/server.c @@ -421,6 +421,9 @@ static enum Break close(s); remove_connection(index); break; + case GET_LABEL: + s_get_label(s, m.u.jobid); + break; case ENDJOB: job_finished(&m.u.result, client_cs[index].jobid); /* For the dependencies */