Skip to content

Commit 2d2cf72

Browse files
committed
flux-top: use idf58() convenience function
Problem: Several uses of flux_job_id_encode(3) in flux-top(1) could be replaced by the simpler idf58() convenience function. Replace usage of flux_job_id_encode(3) wtih idf58() where appropriate in flux-top(1) sources.
1 parent cdadca1 commit 2d2cf72

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

src/cmd/top/joblist_pane.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <jansson.h>
1919

2020
#include "src/common/libutil/fsd.h"
21+
#include "src/common/libjob/idf58.h"
2122
#include "ccan/str/str.h"
2223

2324
#include "top.h"
@@ -116,7 +117,7 @@ void joblist_pane_draw (struct joblist_pane *joblist)
116117

117118
json_array_foreach (joblist->jobs, index, job) {
118119
char *uri = NULL;
119-
char idstr[16];
120+
const char *idstr;
120121
char run[16] = "";
121122
flux_jobid_t id;
122123
int userid;
@@ -143,8 +144,7 @@ void joblist_pane_draw (struct joblist_pane *joblist)
143144
"uri", &uri) < 0)
144145
fatal (0, "error decoding a job record from job-list RPC");
145146

146-
if (flux_job_id_encode (id, "f58", idstr, sizeof (idstr)) < 0)
147-
fatal (errno, "error encoding jobid as F58");
147+
idstr = idf58 (id);
148148
(void)fsd_format_duration_ex (run, sizeof (run), fabs (now - t_run), 2);
149149
if (!(username = ucache_lookup (joblist->ucache, userid)))
150150
fatal (errno, "error looking up userid %d in ucache", (int)userid);
@@ -314,7 +314,6 @@ void joblist_pane_enter (struct joblist_pane *joblist)
314314
flux_jobid_t id;
315315
char *uri = NULL;
316316
char title [1024];
317-
char jobid [24];
318317
flux_error_t error;
319318

320319
json_t *job = get_current_job (joblist);
@@ -329,12 +328,11 @@ void joblist_pane_enter (struct joblist_pane *joblist)
329328
return;
330329
if (uri == NULL)
331330
return;
332-
if (flux_job_id_encode (id, "f58", jobid, sizeof (jobid)) < 0
333-
|| snprintf (title,
334-
sizeof(title),
335-
"%s/%s",
336-
joblist->top->title,
337-
jobid) > sizeof (title))
331+
if (snprintf (title,
332+
sizeof(title),
333+
"%s/%s",
334+
joblist->top->title,
335+
idf58 (id)) > sizeof (title))
338336
fatal (errno, "failed to build job title for job");
339337

340338
/* Lazily attempt to run top on jobid, but for now simply return to the

src/cmd/top/top.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "src/common/libutil/uri.h"
1919
#include "src/common/libutil/errprintf.h"
20+
#include "src/common/libjob/idf58.h"
2021
#include "ccan/str/str.h"
2122
#include "top.h"
2223

@@ -224,18 +225,8 @@ static flux_jobid_t get_jobid (flux_t *h)
224225

225226
static char * build_title (struct top *top, const char *title)
226227
{
227-
if (!title) {
228-
char jobid [24];
229-
title = "";
230-
if (top->id != FLUX_JOBID_ANY) {
231-
if (flux_job_id_encode (top->id,
232-
"f58",
233-
jobid,
234-
sizeof (jobid)) < 0)
235-
fatal (errno, "failed to build jobid");
236-
title = jobid;
237-
}
238-
}
228+
if (!title)
229+
title = idf58 (top->id);
239230
return strdup (title);
240231
}
241232

0 commit comments

Comments
 (0)