'\" -*- coding: UTF-8 -*- .if \n(.g .ds T< \\FC .if \n(.g .ds T> \\F[\n[.fam]] .de URL \\$2 \(la\\$1\(ra\\$3 .. .if \n(.g .mso www.tmac .TH sg_init 3 2019-10-03 libstatgrab "" .SH NAME sg_init, sg_snapshot, sg_shutdown, sg_drop_privileges \- initialise libstatgrab .SH SYNOPSIS 'nh .nf \*(T<#include \*(T> .fi .sp 1 .PP .fi .ad l \*(T \kx .if (\nx>(\n(.l/2)) .nr x (\n(.l/5) 'in \n(.iu+\nxu \*(T<(const char *\fIproperties_pfx\fR, const char *\fIenv_name\fR, const char *\fIargv0\fR);\*(T> 'in \n(.iu-\nxu .ad b .PP .fi .ad l \*(T \kx .if (\nx>(\n(.l/2)) .nr x (\n(.l/5) 'in \n(.iu+\nxu \*(T<(int \fIignore_init_errors\fR);\*(T> 'in \n(.iu-\nxu .ad b .PP .fi .ad l \*(T \kx .if (\nx>(\n(.l/2)) .nr x (\n(.l/5) 'in \n(.iu+\nxu \*(T<(void);\*(T> 'in \n(.iu-\nxu .ad b .PP .fi .ad l \*(T \kx .if (\nx>(\n(.l/2)) .nr x (\n(.l/5) 'in \n(.iu+\nxu \*(T<(void);\*(T> 'in \n(.iu-\nxu .ad b .PP .fi .ad l \*(T \kx .if (\nx>(\n(.l/2)) .nr x (\n(.l/5) 'in \n(.iu+\nxu \*(T<(void);\*(T> 'in \n(.iu-\nxu .ad b 'hy .SH DESCRIPTION \*(T<\fBsg_init\fR\*(T>() either initialises the statgrab library and sets the initialisation counter to 1, if not already done, or increases the initialisation counter. If called for the first time (in fact: if called when the initialisation counter is 0), the constructor (initialisation routine) of each registered component is invoked, some global variables are initialised, requested mutual exclusion semaphores are initialised and so on. \*(T<\fBsg_init\fR\*(T>() is protected by the mutex named "statgrab". .PP \*(T<\fBsg_log_init\fR\*(T>() allows some application-individual logging configuration. It's intended for projects with several applications or commands which might have different appenders. Mind that \*(T<\fBsg_log_init\fR\*(T> must be called before \*(T<\fBsg_init\fR\*(T>, but after your application initialized logging framework. .PP \*(T<\fBsg_snapshot\fR\*(T>() is Win32 only and will probably disappear. .PP \*(T<\fBsg_shutdown\fR\*(T>() decrements the initialisation counter. If the counter reaches zero, components' destructors are called, mutual exclusion semaphores (except "statgrab") are destroyed etc. \*(T<\fBsg_shutdown\fR\*(T>() is protected by the mutex named "statgrab". .PP \*(T<\fBsg_drop_privileges\fR\*(T>() drops elevated privileges. .SH "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. .SH EXAMPLE Typical initialization/deinitialization sequence when using with log4cplus: .nf \*(T< 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; } \*(T> .fi .SH "SEE ALSO" \fBstatgrab\fR(3) .SH WEBSITE \(lahttps://libstatgrab.org/\(ra