35 #include "include/private.h"
43 static void framework_sig_handler(
int sig, siginfo_t *si,
void *unused) {
81 " Copyright (C) %i %s <%s>\n\n"
83 " This program comes with ABSOLUTELY NO WARRANTY\n"
84 " This is free software, and you are welcome to redistribute it\n"
85 " under certain conditions.\n\n", pname, year, dev, email, www);
105 }
else if (forkpid < 0) {
113 signal(SIGTSTP, SIG_IGN);
114 signal(SIGCHLD, SIG_IGN);
120 printf(
"Could not lock pid file Exiting\n");
121 while(framework_core_info) {
142 sprintf(pidstr,
"%i\n", (
int)mypid);
143 if (runfile && ((lck_fd = open(runfile, O_RDWR|O_CREAT, 0640)) > 0) && (!
flock(lck_fd, LOCK_EX | LOCK_NB))) {
144 if (write(lck_fd, pidstr, strlen(pidstr)) < 0) {
149 }
else if (runfile && lck_fd) {
162 static void configure_sigact(
struct sigaction *
sa) {
163 sa->sa_flags = SA_SIGINFO | SA_RESTART;
164 sigemptyset(&sa->sa_mask);
165 sa->sa_sigaction = framework_sig_handler;
166 sigaction(SIGINT, sa, NULL);
167 sigaction(SIGTERM, sa, NULL);
170 sigaction(SIGUSR1, sa, NULL);
171 sigaction(SIGUSR2, sa, NULL);
172 sigaction(SIGHUP, sa, NULL);
173 sigaction(SIGALRM, sa, NULL);
180 static void framework_free(
void *data) {
182 framework_core_info = NULL;
188 free((
char *)ci->
email);
191 free((
char *)ci->
www);
196 if (ci->
flock >= 0) {
200 if (ci->
flock >= 0) {
223 if (framework_core_info) {
225 framework_core_info = NULL;
228 if (!(core_info =
objalloc(
sizeof(*core_info), framework_free))) {
233 if (core_info && !(core_info->
sa = malloc(
sizeof(*core_info->
sa)))) {
250 framework_core_info = core_info;
285 printf(
"Could not lock pid file Exiting\n");
292 configure_sigact(framework_core_info->
sa);
297 ret = callback(argc, argv);
const char * email
Email address of copyright holder.
void(* syssighandler)(int, siginfo_t *, void *)
Callback to user supplied signal handler.
const char * progname
Detailed application name.
int objref(void *data)
Reference a object.
void framework_mkcore(char *progname, char *name, char *email, char *web, int year, char *runfile, int flags, syssighandler sigfunc)
Initilise application data structure and return a reference.
struct sigaction * sa
sigaction structure allocated on execution
const char * developer
Developer/Copyright holder.
void stopthreads(int join)
Signal manager to stop and cancel all running threads.
int flock
if there is a file locked this is the FD that will be unlocked and unlinked
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
const char * www
URL displayed (use full URL ie with http://)
void sslstartup(void)
Initialise SSL support this should be called at startup.
int framework_init(int argc, char *argv[], frameworkfunc callback)
Initilise the application daemonise and join the manager thread.
int flags
Application Options.
int lockpidfile(const char *runfile)
Lock the run file in the framework application info.
void unrefconfigfiles(void)
Empty out and unreference config files.
DTS Application library API Include file.
int(* frameworkfunc)(int, char **)
Framework callback function.
int thread_signal(int sig)
Handle signal if its for me.
Create lockfile on daemonize latter.
void seedrand(void)
Seed openssl random number generator.
Application framework data.
Dont print GNU copyright.
void daemonize()
Daemonise the application using fork/exit.
const char * runfile
File to write PID too and lock.
#define ALLOC_CONST(const_var, val)
Macro to assign values to char const.
void printgnu(const char *pname, int year, const char *dev, const char *email, const char *www)
Print a brief GNU copyright notice on console.
int objunref(void *data)
Drop reference held.
syssighandler sig_handler
Signal handler to pass signals too.
Allow application daemonization.