Skip to content

Commit

Permalink
Merge pull request #6467 from garlick/use_size_t
Browse files Browse the repository at this point in the history
libflux: update API to use size_t where appropriate
  • Loading branch information
grondo authored Dec 11, 2024
2 parents cb2b6f3 + 174a1d4 commit 8ee6a97
Show file tree
Hide file tree
Showing 71 changed files with 642 additions and 385 deletions.
4 changes: 2 additions & 2 deletions doc/man3/flux_event_decode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SYNOPSIS
int flux_event_decode_raw (const flux_msg_t *msg,
const char **topic,
const void **data,
int *len);
size_t *len);
int flux_event_unpack (const flux_msg_t *msg,
const char **topic,
Expand All @@ -29,7 +29,7 @@ SYNOPSIS
flux_msg_t *flux_event_encode_raw (const char *topic,
const void *data,
int len);
size_t len);
flux_msg_t *flux_event_pack (const char *topic,
const char *fmt,
Expand Down
2 changes: 1 addition & 1 deletion doc/man3/flux_event_publish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SYNOPSIS
const char *topic,
int flags,
const void *data,
int len);
size_t len);
int flux_event_publish_get_seq (flux_future_t *f, int *seq);
Expand Down
2 changes: 1 addition & 1 deletion doc/man3/flux_kvs_lookup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SYNOPSIS
int flux_kvs_lookup_get_raw (flux_future_t *f,
const void **data
int *len);
size_t *len);
int flux_kvs_lookup_get_dir (flux_future_t *f,
const flux_kvsdir_t **dir);
Expand Down
2 changes: 1 addition & 1 deletion doc/man3/flux_kvs_txn_create.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SYNOPSIS
int flags,
const char *key,
const void *data,
int len);
size_t len);
int flux_kvs_txn_put_treeobj (flux_kvs_txn_t *txn,
int flags,
Expand Down
2 changes: 1 addition & 1 deletion doc/man3/flux_request_decode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SYNOPSIS
int flux_request_decode_raw (const flux_msg_t *msg,
const char **topic,
const void **data,
int *len);
size_t *len);
Link with :command:`-lflux-core`.

Expand Down
2 changes: 1 addition & 1 deletion doc/man3/flux_request_encode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SYNOPSIS
flux_msg_t *flux_request_encode_raw (const char *topic,
void *data,
int len);
size_t len);
Link with :command:`-lflux-core`.

Expand Down
2 changes: 1 addition & 1 deletion doc/man3/flux_respond.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SYNOPSIS
int flux_respond_raw (flux_t *h,
const flux_msg_t *request,
const void *data,
int length);
size_t length);
int flux_respond_error (flux_t *h,
const flux_msg_t *request,
Expand Down
2 changes: 1 addition & 1 deletion doc/man3/flux_response_decode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SYNOPSIS
int flux_response_decode_raw (const flux_msg_t *msg,
const char **topic,
const void **data,
int *len);
size_t *len);
int flux_response_decode_error (const flux_msg_t *msg,
const char *errstr);
Expand Down
4 changes: 2 additions & 2 deletions doc/man3/flux_rpc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SYNOPSIS
flux_future_t *flux_rpc_raw (flux_t *h,
const char *topic,
const void *data,
int len,
size_t len,
uint32_t nodeid,
int flags);
Expand All @@ -42,7 +42,7 @@ SYNOPSIS
int flux_rpc_get_raw (flux_future_t *f,
const void **data,
int *len);
size_t *len);
uint32_t flux_rpc_get_matchtag (flux_future_t *f);
Expand Down
133 changes: 92 additions & 41 deletions src/broker/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,18 @@ static int attr_set_log (const char *name, const char *val, void *arg)
int level = strtol (val, NULL, 10);
if (logbuf_set_forward_level (logbuf, level) < 0)
goto done;
} else if (streq (name, "log-critical-level")) {
}
else if (streq (name, "log-critical-level")) {
int level = strtol (val, NULL, 10);
if (logbuf_set_critical_level (logbuf, level) < 0)
goto done;
} else if (streq (name, "log-stderr-level")) {
}
else if (streq (name, "log-stderr-level")) {
int level = strtol (val, NULL, 10);
if (logbuf_set_stderr_level (logbuf, level) < 0)
goto done;
} else if (streq (name, "log-stderr-mode")) {
}
else if (streq (name, "log-stderr-mode")) {
if (streq (val, "leader"))
logbuf->stderr_mode = MODE_LEADER;
else if (streq (val, "local"))
Expand All @@ -303,18 +306,22 @@ static int attr_set_log (const char *name, const char *val, void *arg)
errno = EINVAL;
goto done;
}
} else if (streq (name, "log-ring-size")) {
}
else if (streq (name, "log-ring-size")) {
int size = strtol (val, NULL, 10);
if (logbuf_set_ring_size (logbuf, size) < 0)
goto done;
} else if (streq (name, "log-filename")) {
}
else if (streq (name, "log-filename")) {
if (logbuf_set_filename (logbuf, val) < 0)
goto done;
} else if (streq (name, "log-level")) {
}
else if (streq (name, "log-level")) {
int level = strtol (val, NULL, 10);
if (logbuf_set_level (logbuf, level) < 0)
goto done;
} else {
}
else {
errno = ENOENT;
goto done;
}
Expand All @@ -331,32 +338,61 @@ static int logbuf_register_attrs (logbuf_t *logbuf, attr_t *attrs)
* Only allowed to be set on rank 0 (ignore initial value on rank > 0).
*/
if (logbuf->rank == 0) {
if (attr_add_active (attrs, "log-filename", 0,
attr_get_log, attr_set_log, logbuf) < 0)
if (attr_add_active (attrs,
"log-filename",
0,
attr_get_log,
attr_set_log,
logbuf) < 0)
goto done;
} else {
}
else {
(void)attr_delete (attrs, "log-filename", true);
if (attr_add (attrs, "log-filename", NULL, ATTR_IMMUTABLE) < 0)
goto done;
}

if (attr_add_active (attrs, "log-stderr-level", 0,
attr_get_log, attr_set_log, logbuf) < 0)
if (attr_add_active (attrs,
"log-stderr-level",
0,
attr_get_log,
attr_set_log,
logbuf) < 0)
goto done;
if (attr_add_active (attrs, "log-stderr-mode", 0,
attr_get_log, attr_set_log, logbuf) < 0)
if (attr_add_active (attrs,
"log-stderr-mode",
0,
attr_get_log,
attr_set_log,
logbuf) < 0)
goto done;
if (attr_add_active (attrs, "log-level", 0,
attr_get_log, attr_set_log, logbuf) < 0)
if (attr_add_active (attrs,
"log-level",
0,
attr_get_log,
attr_set_log,
logbuf) < 0)
goto done;
if (attr_add_active (attrs, "log-forward-level", 0,
attr_get_log, attr_set_log, logbuf) < 0)
if (attr_add_active (attrs,
"log-forward-level",
0,
attr_get_log,
attr_set_log,
logbuf) < 0)
goto done;
if (attr_add_active (attrs, "log-critical-level", 0,
attr_get_log, attr_set_log, logbuf) < 0)
if (attr_add_active (attrs,
"log-critical-level",
0,
attr_get_log,
attr_set_log,
logbuf) < 0)
goto done;
if (attr_add_active (attrs, "log-ring-size", 0,
attr_get_log, attr_set_log, logbuf) < 0)
if (attr_add_active (attrs,
"log-ring-size",
0,
attr_get_log,
attr_set_log,
logbuf) < 0)
goto done;
rc = 0;
done:
Expand All @@ -366,8 +402,12 @@ static int logbuf_register_attrs (logbuf_t *logbuf, attr_t *attrs)
static int logbuf_forward (logbuf_t *logbuf, const char *buf, int len)
{
flux_future_t *f;
if (!(f = flux_rpc_raw (logbuf->h, "log.append", buf, len,
FLUX_NODEID_UPSTREAM, FLUX_RPC_NORESPONSE)))
if (!(f = flux_rpc_raw (logbuf->h,
"log.append",
buf,
len,
FLUX_NODEID_UPSTREAM,
FLUX_RPC_NORESPONSE)))
return -1;
flux_future_destroy (f);
return 0;
Expand Down Expand Up @@ -398,7 +438,8 @@ static void log_fp (FILE *fp, int flags, const char *buf, int len)
{
struct stdlog_header hdr;
const char *msg;
int msglen, severity;
size_t msglen;
int severity;
uint32_t nodeid;

if (fp) {
Expand All @@ -408,11 +449,13 @@ static void log_fp (FILE *fp, int flags, const char *buf, int len)
nodeid = strtoul (hdr.hostname, NULL, 10);
severity = STDLOG_SEVERITY (hdr.pri);
log_timestamp (fp, &hdr, flags);
fprintf (fp, "%s.%s[%" PRIu32 "]: %.*s\n",
fprintf (fp,
"%s.%s[%" PRIu32 "]: %.*s\n",
hdr.appname,
stdlog_severity_to_string (severity),
nodeid,
msglen, msg);
(int)msglen,
msg);
}
}
fflush (fp);
Expand All @@ -438,8 +481,8 @@ static int logbuf_append (logbuf_t *logbuf, const char *buf, int len)
rc = -1;
}
if (severity <= logbuf->critical_level
|| (severity <= logbuf->stderr_level
&& logbuf->stderr_mode == MODE_LOCAL)) {
|| (severity <= logbuf->stderr_level
&& logbuf->stderr_mode == MODE_LOCAL)) {
int flags = 0;
if (logbuf->stderr_mode == MODE_LOCAL)
flags |= LOG_NO_TIMESTAMP; // avoid dup in syslog journal
Expand All @@ -450,15 +493,17 @@ static int logbuf_append (logbuf_t *logbuf, const char *buf, int len)
if (severity <= logbuf->forward_level) {
if (logbuf->rank == 0) {
log_fp (logbuf->f, 0, buf, len);
} else {
}
else {
if (logbuf_forward (logbuf, buf, len) < 0)
rc = -1;
}
}
if (!logged_stderr && severity <= logbuf->stderr_level
&& logbuf->stderr_mode == MODE_LEADER
&& logbuf->rank == 0) {
log_fp (stderr, 0, buf, len);
if (!logged_stderr
&& severity <= logbuf->stderr_level
&& logbuf->stderr_mode == MODE_LEADER
&& logbuf->rank == 0) {
log_fp (stderr, 0, buf, len);
}
return rc;
}
Expand All @@ -475,13 +520,15 @@ static void logbuf_append_redirect (const char *buf, int len, void *arg)

/* N.B. log requests have no response.
*/
static void append_request_cb (flux_t *h, flux_msg_handler_t *mh,
const flux_msg_t *msg, void *arg)
static void append_request_cb (flux_t *h,
flux_msg_handler_t *mh,
const flux_msg_t *msg,
void *arg)
{
logbuf_t *logbuf = arg;
uint32_t matchtag;
const char *buf;
int len;
size_t len;

if (flux_msg_get_matchtag (msg, &matchtag) < 0) {
log_msg ("%s: malformed log request", __FUNCTION__);
Expand All @@ -503,8 +550,10 @@ static void append_request_cb (flux_t *h, flux_msg_handler_t *mh,
}
}

static void clear_request_cb (flux_t *h, flux_msg_handler_t *mh,
const flux_msg_t *msg, void *arg)
static void clear_request_cb (flux_t *h,
flux_msg_handler_t *mh,
const flux_msg_t *msg,
void *arg)
{
logbuf_t *logbuf = arg;

Expand All @@ -513,8 +562,10 @@ static void clear_request_cb (flux_t *h, flux_msg_handler_t *mh,
return;
}

static void dmesg_request_cb (flux_t *h, flux_msg_handler_t *mh,
const flux_msg_t *msg, void *arg)
static void dmesg_request_cb (flux_t *h,
flux_msg_handler_t *mh,
const flux_msg_t *msg,
void *arg)
{
logbuf_t *logbuf = arg;
struct logbuf_entry *e;
Expand Down
4 changes: 2 additions & 2 deletions src/broker/shutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int forward_logbuf (flux_t *h,
{
struct stdlog_header hdr;
const char *txt;
int txtlen;
size_t txtlen;
char buf[FLUX_MAX_LOGBUF];
int loglevel;

Expand All @@ -86,7 +86,7 @@ static int forward_logbuf (flux_t *h,
hdr.appname,
stdlog_severity_to_string (STDLOG_SEVERITY (hdr.pri)),
strtoul (hdr.hostname, NULL, 10),
txtlen,
(int)txtlen,
txt) >= sizeof (buf))
return 0;
return flux_respond_pack (h, request, "{s:s}", "log", buf);
Expand Down
6 changes: 4 additions & 2 deletions src/broker/test/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@ void diag_logger (const char *buf, int len, void *arg)
{
struct stdlog_header hdr;
const char *msg;
int msglen, severity;
size_t msglen;
int severity;
char *s;

if (stdlog_decode (buf, len, &hdr, NULL, NULL, &msg, &msglen) < 0)
Expand All @@ -692,7 +693,8 @@ void diag_logger (const char *buf, int len, void *arg)
if (asprintf (&s,
"%s: %.*s\n",
stdlog_severity_to_string (severity),
msglen, msg) < 0)
(int)msglen,
msg) < 0)
BAIL_OUT ("asprintf failed");
diag (s);
if (zlist_append (logs, s) < 0)
Expand Down
Loading

0 comments on commit 8ee6a97

Please sign in to comment.