Skip to content

Commit

Permalink
added get label
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Oct 30, 2020
1 parent 8924dbc commit 4a4cebe
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 5 deletions.
34 changes: 34 additions & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
44 changes: 43 additions & 1 deletion jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ enum msg_types
GET_VERSION,
VERSION,
NEWJOB_NOK,
COUNT_RUNNING
COUNT_RUNNING,
GET_LABEL
};

enum Request
Expand All @@ -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 {
Expand Down Expand Up @@ -156,6 +158,7 @@ struct msg
int max_slots;
int version;
int count_running;
char *label;
} u;
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 4a4cebe

Please sign in to comment.