sg_init(3)
π NAME π
okay so this is sg_init(3) from libstatgrab, and the NAME squad is literally sg_init, sg_snapshot, sg_shutdown, and sg_drop_privileges β the whole vibe is initialise libstatgrab. also yep, sg_log_init shows up in the synopsis and description, bestie, keep scrolling π«Ά
β¨ SYNOPSIS β¨
#include <statgrab.h>
void sg_log_init (const char *properties_pfx, const char *env_name,
const char *argv0);
sg_error sg_init (int ignore_init_errors);
sg_error sg_snapshot (void);
sg_error sg_shutdown (void);
sg_error sg_drop_privileges (void);
π DESCRIPTION π
okay so sg_init() is the main character here: it either initialises the statgrab library and sets the initialisation counter to 1, if that hasnβt already happened, or it increases the initialisation counter. if itβs called for the first time (in fact: if itβs called when the initialisation counter is 0), the constructor (initialisation routine) of each registered component gets invoked, some global variables get initialised, requested mutual exclusion semaphores get initialised, and so on. sg_init() is protected by the mutex named "statgrab". no cap, thatβs the whole system π
sg_log_init() lets you do some application-individual logging configuration. itβs intended for projects with several applications or commands which might have different appenders. mind that sg_log_init must be called before sg_init, but after your application initialized logging framework. timing is everything, bestie β°
sg_snapshot() is Win32 only and will probably disappear. itβs giving legacy era, ngl π
sg_shutdown() decrements the initialisation counter. if the counter reaches zero, componentsβ destructors are called, mutual exclusion semaphores (except "statgrab") are destroyed etc. sg_shutdown() is protected by the mutex named "statgrab". clean exit energy, periodt β¨
sg_drop_privileges() drops elevated privileges. safety slay π‘οΈ
π«Ά RETURN VALUES π«Ά
all functions return a statgrab error code. either SG_ERROR_NONE when everything was ok, or the appropriate error code from an constructor/destructor. thatβs the whole return-value tea β
πΈ EXAMPLE πΈ
typical initialization/deinitialization sequence when using with log4cplus:
static void *l4cplus_initializer;
static void
cleanup_logging(void)
{
log4cplus_deinitialize(l4cplus_initializer);
}
int
main(int argc, char const *argv[])
{
l4cplus_initializer = log4cplus_initialize();
atexit((void (*)(void))cleanup_logging);
sg_log_init("saidar", "SAIDAR_LOG_PROPERTIES", argv[0]);
sg_init(1);
if(sg_drop_privileges() != 0) {
die("Failed to drop setuid/setgid privileges");
}
do_something();
sg_shutdown();
return 0;
}
π₯ SEE ALSO π₯
statgrab(3) β go read that next, bestie, itβs giving required reading π
π WEBSITE π
β¨https://libstatgrab.org/β© β the iconic little corner of the internet for this one π¦
π okay thatβs the whole sg_init(3) page, and it comes from libstatgrab, dated 2019-10-03 β mwah, go init responsibly and remember to drop those privileges π
π¦ where this page comes from
- alpine 3.24: libstatgrab-doc 0.92.1-r1 Β· LGPL-2.0-or-later
- arch rolling: libstatgrab 0.92.1-2 Β· LGPL AND GPL
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 43: libstatgrab-devel 1:0.92.1-14.fc43 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- fedora 44: libstatgrab-devel 1:0.92.1-15.fc44 Β· LGPL-2.1-or-later
- nixos 26.05: libstatgrab 0.92.1
- nixpkgs unstable: libstatgrab 0.92.1
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libstatgrab-devel 0.92.1-bp160.1.14 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms