56 #define pr_fmt(fmt) "Logstorage control: "fmt 66 #include <sys/epoll.h> 68 #include "sd-daemon.h" 76 #define EPOLL_MAX_EVENTS 10 77 #define EPOLL_TIME_OUT 500 79 #define DLT_LOGSTORAGE_CTRL_EXIT 1 111 pr_error(
"Signal %d received, exiting.", signo);
123 int signals[] = { SIGINT, SIGQUIT, SIGTERM, 0 };
130 for (i = 0 ; signals[i] ; i++)
132 memset(&sa, 0,
sizeof(sa));
135 if (sigaction(signals[i], &sa,
NULL) < 0)
137 pr_error(
"Failed to install signal %u handler. Error: %s\n",
138 signals[i], strerror(errno));
143 #define MAX_RESPONSE_LENGTH 32 159 if (data ==
NULL || payload ==
NULL)
173 if (strncmp(data, resp_ok, strlen(resp_ok)) == 0)
178 pr_verbose(
"Response received: '%s'\n", data);
179 pr_verbose(
"Response expected: '%s'\n", resp_ok);
197 struct epoll_event event;
201 pr_error(
"Wrong parameter to add event (%d %p)\n", fd, cb);
205 pr_verbose(
"Setting up the event handler with (%d, %p).\n", fd, cb);
208 event.events = EPOLLIN | EPOLLET;
210 return epoll_ctl(
efd, EPOLL_CTL_ADD, fd, &event);
222 struct epoll_event *events;
227 events = calloc(10,
sizeof(
struct epoll_event));
231 pr_error(
"No memory available for events.\n");
239 pr_error(
"epoll_wait error: %s\n", strerror(errno));
252 for (i = 0 ; i < n ; i++)
254 int (*callback)() = events[i].
data.ptr;
256 if (!(events[i].events & (EPOLLIN | EPOLLET)))
258 pr_error(
"Error while polling. Event received: 0x%x\n",
263 pr_error(
"Now closing fd and exiting.\n");
264 close(events[i].
data.fd);
272 pr_error(
"Callback not found, exiting.\n");
278 pr_verbose(
"Got new event, calling %p.\n", callback);
282 pr_error(
"Error while calling the callback, exiting.\n");
308 efd = epoll_create1(0);
312 pr_error(
"epoll_create error: %s\n", strerror(errno));
321 pr_error(
"Failed to initialize connection with the daemon.\n");
332 pr_verbose(
"Initializing event generator.\n");
336 pr_error(
"Failed to initialize handler.\n");
344 pr_error(
"epoll_ctl error: %s\n", strerror(errno));
376 pr_error(
"No '%s' file available at: %s\n",
393 pr_error(
"Failed to initialize connection with the daemon.\n");
398 pr_verbose(
"event type is [%d]\t device path is [%s]\n",
414 printf(
"Usage: dlt-logstorage-ctrl [options]\n");
415 printf(
"Send a trigger to DLT daemon to connect/disconnect" 416 "a certain logstorage device\n");
418 printf(
"Options:\n");
419 printf(
" -c --command Connection type: connect = 1, disconnect = 0\n");
420 printf(
" -d[prop] --daemonize=prop Run as daemon: prop = use proprietary handler\n");
421 printf(
" 'prop' may be replaced by any meaningful word\n");
422 printf(
" If prop is not specified, udev will be used\n");
424 printf(
" -h --help Usage\n");
425 printf(
" -p --path Mount point path\n");
426 printf(
" -s[path] --snapshot=path Sync Logstorage cache\n");
427 printf(
" Don't use -s together with -d and -c\n");
428 printf(
" -t Specify connection timeout (Default: %ds)\n",
430 printf(
" -v --verbose Set verbose flag (Default:%d)\n",
get_verbosity());
434 {
"command", required_argument, 0,
'c'},
435 {
"daemonize", optional_argument, 0,
'd'},
436 {
"ecuid", required_argument, 0,
'e'},
437 {
"help", no_argument, 0,
'h'},
438 {
"path", required_argument, 0,
'p'},
439 {
"snapshot", optional_argument, 0,
's'},
440 {
"timeout", required_argument, 0,
't'},
441 {
"verbose", no_argument, 0,
'v'},
459 while ((c = getopt_long(argc,
472 pr_error(
"Mount path '%s' too long\n", optarg);
496 pr_error(
"Mount path '%s' too long\n", optarg);
510 pr_error(
"Option -%c requires an argument.\n", optopt);
517 pr_error(
"Unknown option -%c.\n", optopt);
521 pr_error(
"Unknown option character \\x%x.\n", optopt);
527 pr_error(
"Try %s -h for more information.\n", argv[0]);
535 pr_error(
"Sync caches not available in daemon mode\n");
551 int main(
int argc,
char *argv[])
573 pr_error(
"Message failed to be send. Please check DLT config.\n");
581 if (sd_notify(0,
"READY=1") <= 0)
583 pr_verbose(
"SD notify failed, manually daemonizing.\n");
590 pr_error(
"Failed to daemonize: %s\n", strerror(errno));
#define DLT_LOGSTORAGE_CTRL_EXIT
int dlt_logstorage_get_handler_fd(void)
void set_default_path(char *path)
static void catch_signal(int signo)
Signal handler.
void set_verbosity(int v)
static void install_signal_handler(void)
Install a handler for some signals.
#define MAX_RESPONSE_LENGTH
static int dlt_logstorage_ctrl_single_request()
Send a single command to DLT daemon and wait for response.
#define DLT_SERVICE_ID_OFFLINE_LOGSTORAGE
DltLogstorageHandler get_handler_type(void)
int dlt_control_deinit(void)
Control communication clean-up.
int dlt_logstorage_check_config_file(char *mnt_point)
Search for config file in given mount point.
void * dlt_logstorage_get_handler_cb(void)
#define DLT_MOUNT_PATH_MAX
static int parse_args(int argc, char *argv[])
Parses the application arguments.
void set_handler_type(char *type)
char * get_default_path(void)
static char data[kDataSize]
int dlt_logstorage_must_exit(void)
Check if the application must exit.
static int dlt_logstorage_ctrl_setup_event_loop(void)
Start event loop and receive messages from DLT.
static int analyze_response(char *data, void *payload, int len)
Analyze the daemon answer to a request.
static struct option long_options[]
void set_default_event_type(long type)
static void usage(void)
Print out the application help.
int main(int argc, char *argv[])
Entry point.
#define pr_error(fmt,...)
int get_default_event_type(void)
int dlt_logstorage_send_event(int type, char *mount_point)
Send a logstorage event to DLT.
#define pr_verbose(fmt,...)
int dlt_control_init(int(*response_analyzer)(char *, void *, int), char *ecuid, int verbosity)
Control communication initialization.
int dlt_logstorage_deinit_handler(void)
Clean-up the handler based on configuration.
#define DLT_CTRL_DEFAULT_ECUID
int dlt_logstorage_init_handler(void)
Initialized the handler based on configuration.
void dlt_logstorage_exit(void)
Triggers the application exit.
static int dlt_logstorage_ctrl_execute_event_loop(int efd)
Main execution loop.
int dlt_logstorage_check_directory_permission(char *mnt_point)
Check if given mount point is writable.
static int dlt_logstorage_ctrl_add_event(int fd, void *cb)
Add a new event to watch to the epoll instance.
void set_ecuid(char *ecuid)