Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge branch 'logrotate-support' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
lerwys committed May 25, 2018
2 parents b1903ef + da21cab commit 36eb72c
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.orig
*.bak
*.o
*tags

# Binaries
dev_mngr
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ LIBS = -lm -lzmq -lczmq -lmlm
# FIXME: make the project libraries easily interchangeable, specifying
# the lib only a single time
PROJECT_LIBS_NAME = liberrhand libconvc libhutils libdisptable libllio libhalcsclient \
libacqclient libbpmclient libsdbutils libsdbfs libpcidriver
libacqclient libbpmclient libsdbutils libsdbfs libpcidriver \
libpthread
PROJECT_LIBS = -lerrhand -lconvc -lhutils -ldisptable -lllio -lhalcsclient \
-lacqclient -lbpmclient -lsdbutils -lsdbfs -lpcidriver
-lacqclient -lbpmclient -lsdbutils -lsdbfs -lpcidriver \
-lpthread

# General library flags -L<libdir>
LFLAGS = -Lforeign/libsdbfs
Expand Down
4 changes: 2 additions & 2 deletions apps/halcsd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ model {
binaries.all {
cCompiler.define '__AFE_RFFE_V2__'

linker.args '-lczmq', '-lpcidriver', '-lmlm'
linker.args '-lczmq', '-lpcidriver', '-lmlm', '-lpthread'
}
}

Expand Down Expand Up @@ -64,7 +64,7 @@ model {
binaries.all {
cCompiler.define '__AFE_RFFE_V2__'

linker.args '-lczmq', '-lpcidriver', '-lmlm'
linker.args '-lczmq', '-lpcidriver', '-lmlm', '-lpthread'
}
}

Expand Down
13 changes: 13 additions & 0 deletions apps/halcsd/src/halcsd/c/halcsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ int main (int argc, char *argv[])
char *cfg_file = NULL;
int opt;

/* Block signals in all of the threads, if not otherwise stated */
static sigset_t signal_mask;
sigemptyset (&signal_mask);
sigaddset (&signal_mask, SIGUSR1);
sigaddset (&signal_mask, SIGUSR2);
sigaddset (&signal_mask, SIGHUP);
int rc = pthread_sigmask (SIG_BLOCK, &signal_mask, NULL);
if (rc != 0) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[halcsd] Could not block sigmask: %d\n", rc);
goto err_sigmask;
}

while ((opt = getopt_long (argc, argv, shortopt, long_options, NULL)) != -1) {
/* Get the user selected options */
switch (opt) {
Expand Down Expand Up @@ -645,6 +657,7 @@ int main (int argc, char *argv[])
zhashx_destroy (&devio_hints);
err_devio_hints_alloc:
err_cfg_not_found:
err_sigmask:
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[halcsd] Exiting ...\n");
return 0;
}
Expand Down
13 changes: 13 additions & 0 deletions apps/halcsd/src/halcsd_cfg/c/halcsd_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ int main (int argc, char *argv[])
char *log_filename = NULL;
int opt;

/* Block signals in all of the threads, if not otherwise stated */
static sigset_t signal_mask;
sigemptyset (&signal_mask);
sigaddset (&signal_mask, SIGUSR1);
sigaddset (&signal_mask, SIGUSR2);
sigaddset (&signal_mask, SIGHUP);
int rc = pthread_sigmask (SIG_BLOCK, &signal_mask, NULL);
if (rc != 0) {
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_FATAL, "[halcsd_cfg] Could not block sigmask: %d\n", rc);
goto err_sigmask;
}

while ((opt = getopt_long (argc, argv, shortopt, long_options, NULL)) != -1) {
/* Get the user selected options */
switch (opt) {
Expand Down Expand Up @@ -266,6 +278,7 @@ int main (int argc, char *argv[])
free (dev_type);
free (devio_type_str);
free (devio_work_dir);
err_sigmask:
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[halcsd_cfg] Exiting ...\n");
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions core/common/include/halcs_server_prelude.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sys/types.h>
#include <stdbool.h>
#include <getopt.h>
#include <signal.h>

/* zeroMQ libraries */
#include <zmq.h>
Expand Down
118 changes: 115 additions & 3 deletions core/dev_io/src/dev_io/c/dev_io_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#define DEVIO_MAX_DESTRUCT_MSG_TRIES 10
#define DEVIO_LINGER_TIME 100 /* in ms */

#define DEVIO_DFLT_MONITOR_INTERVAL 1000 /* /n ms */

struct _devio_t {
/* General information */
zactor_t **pipes_mgmt; /* Address nodes using this array of actors (Management PIPES) */
Expand Down Expand Up @@ -117,6 +119,11 @@ static devio_err_e _devio_engine_handle_socket (devio_t *devio, void *sock,
zloop_reader_fn handler);
static int _devio_handle_pipe_backend (zloop_t *loop, zsock_t *reader, void *args);

/* Handle monitors */
static int _devio_engine_set_monitor (devio_t *devio, size_t interval,
zloop_timer_fn monitor);
static devio_err_e _devio_engine_cancel_monitor (devio_t* devio, int identifier);

/* Utilities */
static zactor_t *_devio_get_pipe_from_smio_id (devio_t *self, uint32_t smio_id,
uint32_t inst_id);
Expand Down Expand Up @@ -178,6 +185,10 @@ devio_t * devio_new (char *name, uint32_t id, char *endpoint_dev,
assert (reg_ops);
assert (endpoint_broker);

/* Just satisfy compilers that complain for unused functions */
_devio_engine_set_monitor (NULL, 0, NULL);
_devio_engine_cancel_monitor (NULL, 0);

/* Set logfile available for all dev_mngr and dev_io instances.
* We accept NULL as a parameter, meaning to suppress all messages */
errhand_log_new (log_file_name, DEVIO_DFLT_LOG_MODE);
Expand Down Expand Up @@ -260,10 +271,12 @@ devio_t * devio_new (char *name, uint32_t id, char *endpoint_dev,
_devio_set_spawn_clhd_handler (self, &hutils_spawn_chld);

devio_err_e derr = devio_set_sig_handler (self, &devio_sigchld_handler);
ASSERT_TEST(derr==DEVIO_SUCCESS, "Error setting signal handlers", err_set_sig_handlers);
ASSERT_TEST(derr==DEVIO_SUCCESS, "Error setting SIGCHLD signal handlers",
err_set_sig_handlers);

derr = _devio_register_sig_handlers (self);
ASSERT_TEST(derr==DEVIO_SUCCESS, "Error registering setting up signal handlers", err_sig_handlers);
ASSERT_TEST(derr==DEVIO_SUCCESS, "Error registering setting up signal handlers",
err_sig_handlers);

/* Concatenate recv'ed name with a llio identifier */
size_t llio_name_len = sizeof (char)*(strlen(name)+strlen(LLIO_STR)+1);
Expand Down Expand Up @@ -554,6 +567,45 @@ static devio_err_e _devio_engine_handle_socket (devio_t *devio, void *sock,
return err;
}

/* From Malamute https://github.com/zeromq/malamute/blob/master/src/mlm_server_engine.inc
*
* Register monitor function that will be called at regular intervals
* by the server engine. Returns an identifier that can be used to cancel it. */

static int _devio_engine_set_monitor (devio_t *devio, size_t interval,
zloop_timer_fn monitor)
{
int err = -1;

if (devio) {
devio_t *self = (devio_t *) devio;
err = zloop_timer (self->loop, interval, 0, monitor, self);
ASSERT_TEST(err >= 0, "Could not register zloop_timer",
err_zloop_timer, -1);
}

err_zloop_timer:
return err;
}

/* From Malamute https://github.com/zeromq/malamute/blob/master/src/mlm_server_engine.inc
*
* Cancel the monitor function with the given identifier. */
static devio_err_e _devio_engine_cancel_monitor (devio_t* devio, int identifier)
{
int err = -1;

if (devio) {
devio_t *self = (devio_t *) devio;
err = zloop_timer_end (self->loop, identifier);
ASSERT_TEST(err >= 0, "Could not deregister zloop_timer",
err_zloop_timer, -1);
}

err_zloop_timer:
return err;
}

/************************************************************/
/********************** zloop handlers **********************/
/************************************************************/
Expand Down Expand Up @@ -832,6 +884,10 @@ static int _devio_handle_pipe_backend (zloop_t *loop, zsock_t *reader, void *arg
return 0;
}

/************************************************************/
/********************* zmonitor handlers ********************/
/************************************************************/

/************************************************************/
/********************** PIPE methods ************************/
/************************************************************/
Expand Down Expand Up @@ -1476,6 +1532,46 @@ static devio_err_e _devio_check_send_cfg_done (devio_t *self)
return err;
}

/* Signal actor to catch signals block by every other
* thread, but this one */
void signal_actor (zsock_t *pipe, void *args)
{
/* Initialize */
devio_t *self = (devio_t *) args;

/* Tell parent we are initializing */
zsock_signal (pipe, 0);

sigset_t sig_mask;
sigemptyset (&sig_mask);
sigaddset (&sig_mask, SIGUSR1);
sigaddset (&sig_mask, SIGUSR2);
sigaddset (&sig_mask, SIGHUP);

int sig_caught;

while (!zsys_interrupted) {
sigwait (&sig_mask, &sig_caught);
switch (sig_caught)
{
/* Reopen Logs */
case SIGUSR1:
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io] Caught SIGUSR1!\n");
errhand_reallog_destroy ();
errhand_log_new (self->log_file, DEVIO_DFLT_LOG_MODE);
break;
/* Undefined */
case SIGUSR2:
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io] Caught SIGUSR2!\n");
break;
/* Undefined */
case SIGHUP:
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_TRACE, "[dev_io] Caught SIGHUP!\n");
break;
}
}
}

/* Main devio loop implemented as actor */
void devio_loop (zsock_t *pipe, void *args)
{
Expand All @@ -1485,12 +1581,23 @@ void devio_loop (zsock_t *pipe, void *args)
devio_t *self = (devio_t *) args;
self->pipe = pipe;

/* Unblock signals for this thread only. We can't use the regular
* signal handlers as all thread will inherit and we want only
* this thread to treat them */
sigset_t signal_mask;
sigemptyset (&signal_mask);
pthread_sigmask (SIG_UNBLOCK, &signal_mask, NULL);

/* Tell parent we are initializing */
zsock_signal (pipe, 0);

/* Set-up server register commands handler */
_devio_engine_handle_socket (self, pipe, _devio_handle_pipe);

/* Initialize signal handlers for specific signals */
zactor_t *server = zactor_new (signal_actor, self);
UNUSED(server);

/* Run reactor until there's a termination signal */
zloop_start (self->loop);
}
Expand Down Expand Up @@ -1526,6 +1633,11 @@ llio_t *devio_get_llio (devio_t *self)
return self->llio;
}

/* Register signal handlers for specified signals. Bear in mind that you can't,
* by default register handlers for SIGINT/SIGTERM as they are automatically
* managed by CZMQ library. If needed, you can call zsys_handler_set () and CZMQ
* will disable its signal handling for those signals, but zctx_interrupt and
* zsys_interrupt will not work as expected anymore. */
devio_err_e devio_set_sig_handler (devio_t *self, devio_sig_handler_t *sig_handler)
{
assert (self);
Expand All @@ -1551,7 +1663,7 @@ static devio_err_e _devio_register_sig_handlers (devio_t *self)
int err = sigaction (sig_handler->signal, &act, NULL);
CHECK_ERR(err, DEVIO_ERR_SIGACTION);

DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_INFO, "[dev_mngr_core] registered signal %d\n",
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io_core] registered signal %d\n",
sig_handler->signal);

sig_handler = (devio_sig_handler_t *)
Expand Down
13 changes: 13 additions & 0 deletions core/dev_mngr/src/dev_mngr/c/dev_mngr.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ int main (int argc, char *argv[])
char *cfg_file = NULL;
int opt;

/* Block signals in all of the threads, if not otherwise stated */
static sigset_t signal_mask;
sigemptyset (&signal_mask);
sigaddset (&signal_mask, SIGUSR1);
sigaddset (&signal_mask, SIGUSR2);
sigaddset (&signal_mask, SIGHUP);
int rc = pthread_sigmask (SIG_BLOCK, &signal_mask, NULL);
if (rc != 0) {
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_FATAL, "[halcsd_cfg] Could not block sigmask: %d\n", rc);
goto err_sigmask;
}

while ((opt = getopt_long (argc, argv, shortopt, long_options, NULL)) != -1) {
/* Get the user selected options */
switch (opt) {
Expand Down Expand Up @@ -379,6 +391,7 @@ int main (int argc, char *argv[])
err_dmngr_hints_alloc:
free (cfg_file);
err_parse_cfg:
err_sigmask:
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_INFO, "[dev_mngr] Exiting ...\n");

return 0;
Expand Down
1 change: 1 addition & 0 deletions libs/errhand/include/errhand_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ int errhand_log_new (const char *log_file_name, const char *mode);
void errhand_log_file_destroy ();
int errhand_log_destroy ();
void errhand_log_print_zmq_msg (struct _zmsg_t *msg);
void errhand_reallog_destroy ();

/********************** Error handling macros **********************/

Expand Down
Loading

0 comments on commit 36eb72c

Please sign in to comment.