Lely core libraries 2.3.4
|
This file is part of the utilities library; it contains the daemon function definitions. More...
#include "util.h"
#include <lely/libc/threads.h>
#include <lely/util/daemon.h>
#include <lely/util/diag.h>
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <poll.h>
#include <sys/stat.h>
#include <unistd.h>
Go to the source code of this file.
Functions | |
int | daemon_start (const char *name, int(*init)(int, char **), void(*main)(void), void(*fini)(void), int argc, char *argv[]) |
Executes the supplied function as a POSIX daemon or Windows service. More... | |
int | daemon_signal (int sig) |
Sends a signal to a daemon, triggering the execution of the daemon handler. More... | |
int | daemon_status (int status) |
Sets the current daemon status (one of DAEMON_START, DAEMON_STOP, DAEMON_PAUSE or DAEMON_CONTINUE). More... | |
int | daemon_stop (void) |
Sends the stop signal to the daemon handler. More... | |
int | daemon_reload (void) |
Sends the reload signal to the daemon handler. More... | |
int | daemon_pause (void) |
Sends the pause signal to the daemon handler. More... | |
int | daemon_continue (void) |
Sends the continue signal to the daemon handler. More... | |
void | daemon_get_handler (daemon_handler_t **phandler, void **phandle) |
Retrieves current daemon handler and handle argument. More... | |
void | daemon_set_handler (daemon_handler_t *handler, void *handle) |
Sets the current daemon handler and its (optional) handle argument. More... | |
void | default_daemon_handler (int sig, void *handle) |
The default daemon_signal() handler. More... | |
This file is part of the utilities library; it contains the daemon function definitions.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Definition in file daemon.c.
int daemon_start | ( | const char * | name, |
int(*)(int, char **) | init, | ||
void(*)(void) | main, | ||
void(*)(void) | fini, | ||
int | argc, | ||
char * | argv[] | ||
) |
Executes the supplied function as a POSIX daemon or Windows service.
This function MUST be called only once, before any threads have been created or any files, sockets, etc. have been opened. On successful execution, this function does not return until the daemon terminates.
This function registers daemon_diag_handler() and daemon_diag_at_handler() as the diagnostic message handlers for any code running as a daemon (this includes init on Windows, but not on other platforms).
name | a pointer to the name of the daemon. Depending on the platform, the name is used for diagnostic or registration purposes. |
init | a pointer to the initialization function executed before main (can be NULL). |
main | a pointer to the function to be executed as a daemon. |
fini | a pointer to the finalization function executed after main (can be NULL). |
argc | the number of arguments in argv (unused on Windows as the daemon receives its arguments directly from the Service Control Manager). |
argv | an array of pointers to arguments to init (unused on Windows). The array MUST be NULL-terminated, i.e., argv[argc] == NULL . |
int daemon_signal | ( | int | sig | ) |
int daemon_status | ( | int | status | ) |
Sets the current daemon status (one of DAEMON_START, DAEMON_STOP, DAEMON_PAUSE or DAEMON_CONTINUE).
It is the responsibility of the user to update the status in a timely manner after receiving a start, stop, pause or continue signal.
int daemon_stop | ( | void | ) |
Sends the stop signal to the daemon handler.
This function is equivalent to daemon_signal(DAEMON_STOP)
. It is the responsibility of the user to invoke daemon_status(DAEMON_STOP)
once the daemon is stopped.
int daemon_reload | ( | void | ) |
Sends the reload signal to the daemon handler.
This function is equivalent to daemon_signal(DAEMON_RELOAD)
. The user does not need to invoke daemon_status() to acknowledge execution of the reload operation.
int daemon_pause | ( | void | ) |
Sends the pause signal to the daemon handler.
This function is equivalent to daemon_signal(DAEMON_PAUSE)
. It is the responsibility of the user to invoke daemon_status(DAEMON_PAUSE)
once the daemon is paused.
int daemon_continue | ( | void | ) |
Sends the continue signal to the daemon handler.
This function is equivalent to daemon_signal(DAEMON_CONTINUE)
. It is the responsibility of the user to invoke daemon_status(DAEMON_CONTINUE)
once the daemon continues its normal operation.
void daemon_get_handler | ( | daemon_handler_t ** | phandler, |
void ** | phandle | ||
) |
Retrieves current daemon handler and handle argument.
phandler | the address at which to store a pointer to the current daemon handler (can be NULL). |
phandle | the address at which to store a pointer to the handle argument of the current daemon handler (can be NULL). |
void daemon_set_handler | ( | daemon_handler_t * | handler, |
void * | handle | ||
) |
Sets the current daemon handler and its (optional) handle argument.
The handler is invoked asynchronously (in a separate thread) after the reception of a signal.
void default_daemon_handler | ( | int | sig, |
void * | handle | ||
) |
The default daemon_signal() handler.