Skip to content

Commit

Permalink
added show full cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Nov 27, 2020
1 parent 8942f2d commit 2150ca3
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
30 changes: 30 additions & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,33 @@ void c_send_reminder() {
m.type = REMINDER;
send_msg(server_socket, &m);
}

void c_show_cmd() {
struct Msg m;
int res;
char *string = 0;

/* Send the request */
m.type = GET_CMD;
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 show_cmd");

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 show_cmd - line size");

printf("%s", string);
free(string);
return;
default:
warning("Wrong internal message in show_cmd");
}
}
36 changes: 36 additions & 0 deletions jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,42 @@ void s_get_label(int s, int jobid) {
send_list_line(s, label);
}

void s_send_cmd(int s, int jobid) {
struct Job *p = 0;
char *cmd;

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;
}
cmd = (char *) malloc(strlen(p->command) + 1);
sprintf(cmd, "%s\n", p->command);
send_list_line(s, cmd);
free(cmd);
}

void s_mark_job_running(int jobid) {
struct Job *p;
p = findjob(jobid);
Expand Down
18 changes: 16 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ static int get_two_jobs(const char *str, int *j1, int *j2) {
}

static struct option longOptions[] = {
{"get_label", no_argument, NULL, 'a'},
{"get_label", optional_argument, NULL, 'a'},
{"count_running", no_argument, NULL, 'R'},
{"last_queue_id", no_argument, NULL, 'q'},
{"gpus", required_argument, NULL, 'G'},
{"set_gpu_wait", required_argument, NULL, 0},
{"get_gpu_wait", no_argument, NULL, 0},
{"full_cmd", optional_argument, NULL, 'F'},
{NULL, 0, NULL, 0}
};

Expand All @@ -92,7 +93,7 @@ void parse_opts(int argc, char **argv) {

/* Parse options */
while (1) {
c = getopt_long(argc, argv, ":RTVhKgClnfmBEr:a:t:c:o:p:w:k:u:s:U:qi:N:L:dS:D:G:",
c = getopt_long(argc, argv, ":RTVhKgClnfmBEr:a:F:t:c:o:p:w:k:u:s:U:qi:N:L:dS:D:G:",
longOptions, &optionIdx);

if (c == -1)
Expand Down Expand Up @@ -187,6 +188,10 @@ void parse_opts(int argc, char **argv) {
command_line.request = c_GET_LABEL;
command_line.jobid = atoi(optarg);
break;
case 'F':
command_line.request = c_SHOW_CMD;
command_line.jobid = atoi(optarg);
break;
case 'N':
command_line.num_slots = atoi(optarg);
if (command_line.num_slots < 0)
Expand Down Expand Up @@ -297,6 +302,10 @@ void parse_opts(int argc, char **argv) {
command_line.request = c_GET_LABEL;
command_line.jobid = -1;
break;
case 'F':
command_line.request = c_SHOW_CMD;
command_line.jobid = -1;
break;
default:
fprintf(stderr, "Option %c missing argument.\n",
optopt);
Expand Down Expand Up @@ -547,6 +556,11 @@ int main(int argc, char **argv) {
error("The command %i needs the server", command_line.request);
c_show_label();
break;
case c_SHOW_CMD:
if (!command_line.need_server)
error("The command %i needs the server", command_line.request);
c_show_cmd();
break;
case c_REMOVEJOB:
if (!command_line.need_server)
error("The command %i needs the server", command_line.request);
Expand Down
10 changes: 8 additions & 2 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ enum msg_types {
KILL_ALL,
SET_GPU_WAIT_TIME,
GET_GPU_WAIT_TIME,
REMINDER
REMINDER,
GET_CMD
};

enum Request {
Expand Down Expand Up @@ -77,7 +78,8 @@ enum Request {
c_LAST_ID,
c_KILL_ALL,
c_SET_GPU_WAIT_TIME,
c_GET_GPU_WAIT_TIME
c_GET_GPU_WAIT_TIME,
c_SHOW_CMD
};

struct CommandLine {
Expand Down Expand Up @@ -275,6 +277,8 @@ void c_get_gpu_wait_time();

void c_send_reminder();

void c_show_cmd();

/* jobs.c */
void s_list(int s);

Expand Down Expand Up @@ -351,6 +355,8 @@ void dump_conns_struct(FILE *out);

void s_request_reminder_after(int time, int jobid);

void s_send_cmd(int s, int jobid);

/* server_start.c */
int try_connect(int s);

Expand Down
3 changes: 3 additions & 0 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ client_read(int index) {
case GET_LABEL:
s_get_label(s, m.u.jobid);
break;
case GET_CMD:
s_send_cmd(s, m.u.jobid);
break;
case ENDJOB:
job_finished(&m.u.result, client_cs[index].jobid);
/* For the dependencies */
Expand Down

0 comments on commit 2150ca3

Please sign in to comment.