Skip to content

Commit

Permalink
Do away with num_jobs (it is implicitly the length of the array)
Browse files Browse the repository at this point in the history
  • Loading branch information
bstee615 committed Sep 30, 2022
1 parent cba84dc commit 39b7d2e
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,23 +475,14 @@ void s_list(int s) {
}
}
else if (list_format == JSON) {
cJSON *wrapper_object = cJSON_CreateObject();
if (wrapper_object == NULL)
{
error("Error initializing JSON wrapper object.");
goto end;
}

cJSON *jobs = cJSON_CreateArray();
if (jobs == NULL)
{
error("Error initializing JSON array.");
goto end;
}
debug("made JSON array");

/* Serialize Queued or Running jobs */
int num_jobs = 0;
p = firstjob;
while (p != 0) {
if (p->state != HOLDING_CLIENT) {
Expand All @@ -501,7 +492,6 @@ void s_list(int s) {
}
}
p = p->next;
num_jobs ++;
}

/* Serialize Finished jobs */
Expand All @@ -512,20 +502,9 @@ void s_list(int s) {
goto end;
}
p = p->next;
num_jobs ++;
}

cJSON *num_jobs_obj = cJSON_CreateNumber(num_jobs);
if (num_jobs_obj == NULL)
{
error("Error initializing JSON object for job count.");
goto end;
}
cJSON_AddItemToObject(wrapper_object, "num_jobs", num_jobs_obj);

cJSON_AddItemToObject(wrapper_object, "jobs", jobs);

buffer = cJSON_Print(wrapper_object);
buffer = cJSON_Print(jobs);
if (buffer == NULL)
{
error("Error converting jobs to JSON.");
Expand Down

0 comments on commit 39b7d2e

Please sign in to comment.