Skip to content

Commit c2104d4

Browse files
committed
libflux: fix rolemask display in flux_msg_fprint()
Problem: flux_msg_fprint() assumes rolemask contains only one role, but this is not necessarily true. Print a comma separated list of roles.
1 parent e1c2f55 commit c2104d4

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

src/common/libflux/message.c

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,26 +1247,39 @@ static void userid2str (uint32_t userid, char *buf, int buflen)
12471247
assert (n < buflen);
12481248
}
12491249

1250-
static void rolemask2str (uint32_t rolemask, char *buf, int buflen)
1250+
static int roletostr (uint32_t role, const char *sep, char *buf, int buflen)
12511251
{
12521252
int n;
1253-
switch (rolemask) {
1254-
case FLUX_ROLE_NONE:
1255-
n = snprintf (buf, buflen, "none");
1256-
break;
1257-
case FLUX_ROLE_OWNER:
1258-
n = snprintf (buf, buflen, "owner");
1259-
break;
1260-
case FLUX_ROLE_USER:
1261-
n = snprintf (buf, buflen, "user");
1262-
break;
1263-
case FLUX_ROLE_ALL:
1264-
n = snprintf (buf, buflen, "all");
1265-
break;
1266-
default:
1267-
n = snprintf (buf, buflen, "unknown");
1253+
if (role == FLUX_ROLE_OWNER)
1254+
n = snprintf (buf, buflen, "%sowner", sep);
1255+
else if (role == FLUX_ROLE_USER)
1256+
n = snprintf (buf, buflen, "%suser", sep);
1257+
else if (role == FLUX_ROLE_LOCAL)
1258+
n = snprintf (buf, buflen, "%slocal", sep);
1259+
else
1260+
n = snprintf (buf, buflen, "%s0x%x", sep, role);
1261+
if (n >= buflen)
1262+
n = buflen;
1263+
return n;
1264+
}
1265+
1266+
static void rolemask2str (uint32_t rolemask, char *buf, int buflen)
1267+
{
1268+
if (rolemask == FLUX_ROLE_NONE)
1269+
snprintf (buf, buflen, "none");
1270+
else if (rolemask == FLUX_ROLE_ALL)
1271+
snprintf (buf, buflen, "all");
1272+
else {
1273+
int offset = 0;
1274+
for (int i = 0; i < sizeof (rolemask)*8; i++) {
1275+
if (rolemask & 1<<i) {
1276+
offset += roletostr (rolemask & 1<<i,
1277+
offset > 0 ? "," : "",
1278+
buf + offset,
1279+
buflen - offset);
1280+
}
1281+
}
12681282
}
1269-
assert (n < buflen);
12701283
}
12711284

12721285
static void nodeid2str (uint32_t nodeid, char *buf, int buflen)

0 commit comments

Comments
 (0)