/usr/share/doc/libconfuse-dev/examples/reread.c is in libconfuse-dev 2.7-4ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include "confuse.h"
#include <string.h>
#include <signal.h>
#include <unistd.h>
cfg_t *cfg = 0;
const char *config_filename = "./reread.conf";
void read_config(void)
{
cfg_opt_t arg_opts[] = {
CFG_STR("value", "default", CFGF_NONE),
CFG_END()
};
cfg_opt_t opts[] = {
CFG_INT("delay", 3, CFGF_NONE),
CFG_STR("message", "This is a message", CFGF_NONE),
CFG_SEC("argument", arg_opts, CFGF_MULTI | CFGF_TITLE),
CFG_END()
};
int ret;
char *buf = "" \
" delay = 3\n" \
"# message = \"asdfasfasfd tersf\"\n" \
" argument one { value = 1 }\n" \
" argument two { value=foo}\n";
cfg_free(cfg);
cfg = cfg_init(opts, 0);
ret = cfg_parse_buf(cfg, buf);
ret = cfg_parse(cfg, config_filename);
}
void sighandler(int sig)
{
read_config();
signal(SIGHUP, sighandler);
}
static int loop = 1;
void usr1handler(int sig)
{
loop = 0;
}
int main(void)
{
unsigned int i;
read_config();
signal(SIGHUP, sighandler);
signal(SIGUSR1, usr1handler);
while(loop)
{
printf("Message: %s", cfg_getstr(cfg, "message"));
for(i = 0; i < cfg_size(cfg, "argument"); i++)
{
cfg_t *arg = cfg_getnsec(cfg, "argument", i);
printf(", %s", cfg_getstr(arg, "value"));
}
printf("\n");
sleep(cfg_getint(cfg, "delay"));
}
cfg_free(cfg);
cfg = 0;
return 0;
}
|