SQLBOX_MSG_SET_DAT(3) Library Functions Manual SQLBOX_MSG_SET_DAT(3)

sqlbox_msg_set_datset message private data

library “sqlbox”

#include <stdint.h>
#include <sqlbox.h>

sqlbox_msg_set_dat(struct sqlbox *box, const void *dat, size_t sz);

Sets the ancillary data dat of size sz used by the logging functions assigned in struct sqlbox_msg, replacing whatever was passed to sqlbox_alloc(3). The data is copied out of dat, with the resulting allocation either freed during subsequent calls to () or in sqlbox_free(3).

The fields of struct sqlbox_msg are as follows:

Passed the message and dat. Messages are NUL-terminated but not newline terminated. The callback is run within the both the parent and protected child process when logging messages are emitted, so it should include any side effects that might affect the database. Callbacks may not assume to have any network or file-system resources available.
A short version of func useful for passing warnx(3) directly.
Auxiliary data passed to func.

The given binary data dat is of size sz. If passing strings, sz must include the NUL terminator. ~ Passing a size of 0 sets dat to NULL.

Returns non-zero on success or zero if communication with box fails or memory allocation fails.

If sqlbox_msg_set_dat() fails, box is no longer accessible beyond sqlbox_ping(3) and sqlbox_free(3).

Let a long-form function be as follows:

static void
func(const char *buf, void *arg)
  warnx("User %s: %s", (const char *)arg, buf);

This function may have its pointer manipulated as follows:

struct sqlbox *p;
struct sqlbox_cfg cfg;
const char *user;

memset(&cfg, 0, sizeof(struct sqlbox_cfg));
cfg.msg.func = func;
cfg.msg.dat = (char *)"-";

if ((p = sqlbox_alloc(&cfg)) == NULL)
  errx(EXIT_FAILURE, "sqlbox_alloc");
/* Now the prefix "-" is used. */
/* Get the username from somewhere... */
user = get_user();
if (!sqlbox_msg_set_dat(p, user, strlen(user) + 1))
  errx(EXIT_FAILURE, "sqlbox_msg_set_dat");
December 2, 2023 OpenBSD 7.4