SQLBOX_ALLOC(3) | Library Functions Manual | SQLBOX_ALLOC(3) |
sqlbox_alloc
—
#include <stdint.h>
#include <sqlbox.h>
struct sqlbox *
sqlbox_alloc
(struct sqlbox_cfg
*cfg);
sqlbox_alloc
() performs the following
validity checks on cfg, if not
NULL
, before forking:
NULL
NULL
or empty stringsNULL
After successful return, a suggested idiom is for callers to reduce system resources to just the communciation socket with the context. This may be affected with pledge(2) if on OpenBSD.
It is usually followed by calls to sqlbox_open(3).
NULL
if
cfg is invalid, memory allocation failed, or the
fork(2) or socketpair(2) functions failed.
On success, the pointer must be freed with sqlbox_free(3).
struct sqlbox *p; struct sqlbox_cfg cfg; struct sqlbox_src srcs[] = { { .fname = (char *)":memory:", .mode = SQLBOX_SRC_RWC } }; memset(&cfg, 0, sizeof(struct sqlbox_cfg)); cfg.msg.func_short = warnx; cfg.srcs.srcs = srcs; cfg.srcs.srcsz = 1; if ((p = sqlbox_alloc(&cfg)) == NULL) errx(EXIT_FAILURE, "sqlbox_alloc"); /* Do work. */ sqlbox_free(p);
The following does the same, but with RBAC for the source. In this
example, arrays in struct sqlbox_role are not set to
NULL
if they have an associated length as in the
case of rolesz.
struct sqlbox *p; struct sqlbox_cfg cfg; struct sqlbox_role roles[] = { { .rolesz = 0, .stmtsz = 0, .srcs = (size_t[]){ 0 }, .srcsz = 1 } }; struct sqlbox_src srcs[] = { { .fname = (char *)":memory:", .mode = SQLBOX_SRC_RWC } }; memset(&cfg, 0, sizeof(struct sqlbox_cfg)); cfg.srcs.srcs = srcs; cfg.srcs.srcsz = 1; cfg.roles.roles = roles; cfg.roles.rolesz = 1; cfg.roles.defrole = 0; if ((p = sqlbox_alloc(&cfg)) == NULL) errx(EXIT_FAILURE, "sqlbox_alloc"); /* Do work. */ sqlbox_free(p);
November 8, 2019 | OpenBSD 6.5 |