summaryrefslogtreecommitdiff
path: root/src/console
diff options
context:
space:
mode:
authorChristoph Lipka <clipka@jp.adit-jv.com>2016-03-16 16:05:53 +0900
committerGernot Wirschal <gernot.wirschal@bmw.de>2016-04-25 14:34:34 +0200
commitbc09757d465d4ee5728157dce4fed0f71841daa7 (patch)
treec65dbe20fe43dc36e480ca85b74b41aa812e5de2 /src/console
parentab443bc109f1d6a957fc5a85cd0efc566299bd4d (diff)
downloadDLT-daemon-bc09757d465d4ee5728157dce4fed0f71841daa7.tar.gz
Offline logstorage: On Demand triggering for syncing Logstorage cache and support long options
Signed-off-by: Christoph Lipka <clipka@jp.adit-jv.com> Change-Id: I2bac5e48a5d210b544a96fe96dc322f28ac472fe
Diffstat (limited to 'src/console')
-rw-r--r--src/console/logstorage/dlt-logstorage-common.c8
-rw-r--r--src/console/logstorage/dlt-logstorage-common.h1
-rw-r--r--src/console/logstorage/dlt-logstorage-ctrl.c84
3 files changed, 71 insertions, 22 deletions
diff --git a/src/console/logstorage/dlt-logstorage-common.c b/src/console/logstorage/dlt-logstorage-common.c
index 592da25..9f472d2 100644
--- a/src/console/logstorage/dlt-logstorage-common.c
+++ b/src/console/logstorage/dlt-logstorage-common.c
@@ -108,7 +108,7 @@ int get_default_event_type(void)
void set_default_event_type(long type)
{
- g_options.event_type = !!type;
+ g_options.event_type = type;
}
char *get_default_path(void)
@@ -119,7 +119,11 @@ char *get_default_path(void)
void set_default_path(char *path)
{
memset(g_options.device_path, 0, DLT_MOUNT_PATH_MAX);
- strncpy(g_options.device_path, path, DLT_MOUNT_PATH_MAX - 1);
+
+ if (path != NULL)
+ {
+ strncpy(g_options.device_path, path, DLT_MOUNT_PATH_MAX - 1);
+ }
}
/* Used by the handlers */
diff --git a/src/console/logstorage/dlt-logstorage-common.h b/src/console/logstorage/dlt-logstorage-common.h
index a1c0994..eaf5bd9 100644
--- a/src/console/logstorage/dlt-logstorage-common.h
+++ b/src/console/logstorage/dlt-logstorage-common.h
@@ -29,6 +29,7 @@
#define EVENT_UNMOUNTING 0
#define EVENT_MOUNTED 1
+#define EVENT_SYNC_CACHE 2
typedef enum
{
diff --git a/src/console/logstorage/dlt-logstorage-ctrl.c b/src/console/logstorage/dlt-logstorage-ctrl.c
index b213501..1e255b7 100644
--- a/src/console/logstorage/dlt-logstorage-ctrl.c
+++ b/src/console/logstorage/dlt-logstorage-ctrl.c
@@ -61,6 +61,7 @@
#include <stdlib.h>
#include <signal.h>
#include <string.h>
+#include <getopt.h>
#include <sys/epoll.h>
@@ -365,19 +366,24 @@ static int dlt_logstorage_ctrl_setup_event_loop(void)
static int dlt_logstorage_ctrl_single_request()
{
int ret = 0;
- /* Check if a 'CONF_NAME' file is present at the given path */
- if (!dlt_logstorage_check_config_file(get_default_path()))
- {
- pr_error("No '%s' file available at: %s\n",
- CONF_NAME,
- get_default_path());
- return -1;
- }
- if (!dlt_logstorage_check_directory_permission(get_default_path()))
+ /* in case sync all caches, an empty path is given */
+ if (get_default_event_type() != EVENT_SYNC_CACHE)
{
- pr_error("'%s' is not writable\n", get_default_path());
- return -1;
+ /* Check if a 'CONF_NAME' file is present at the given path */
+ if (!dlt_logstorage_check_config_file(get_default_path()))
+ {
+ pr_error("No '%s' file available at: %s\n",
+ CONF_NAME,
+ get_default_path());
+ return -1;
+ }
+
+ if (!dlt_logstorage_check_directory_permission(get_default_path()))
+ {
+ pr_error("'%s' is not writable\n", get_default_path());
+ return -1;
+ }
}
/* Initializing the communication with the daemon */
@@ -410,17 +416,32 @@ static void usage(void)
"a certain logstorage device\n");
printf("\n");
printf("Options:\n");
- printf(" -c Connection type: connect = 1, disconnect = 0\n");
- printf(" -d[prop] Run as daemon: prop = use proprietary handler\n");
- printf(" 'prop' may be replaced by any meaningful word\n");
- printf(" -e Set ECU ID (Default: %s)\n", DLT_CTRL_DEFAULT_ECUID);
- printf(" -h Usage\n");
- printf(" -p Mount point path\n");
- printf(" -t Specify connection timeout (Default: %ds)\n",
+ printf(" -c --command Connection type: connect = 1, disconnect = 0\n");
+ printf(" -d[prop] --daemonize=prop Run as daemon: prop = use proprietary handler\n");
+ printf(" 'prop' may be replaced by any meaningful word\n");
+ printf(" If prop is not specified, udev will be used\n");
+ printf(" -e --ecuid Set ECU ID (Default: %s)\n", DLT_CTRL_DEFAULT_ECUID);
+ printf(" -h --help Usage\n");
+ printf(" -p --path Mount point path\n");
+ printf(" -s[path] --snapshot=path Sync Logstorage cache\n");
+ printf(" Don't use -s together with -d and -c\n");
+ printf(" -t Specify connection timeout (Default: %ds)\n",
DLT_CTRL_TIMEOUT);
- printf(" -v Set verbose flag (Default:%d)\n", get_verbosity());
+ printf(" -v --verbose Set verbose flag (Default:%d)\n", get_verbosity());
}
+static struct option long_options[] = {
+ {"command", required_argument, 0, 'c'},
+ {"daemonize", optional_argument, 0, 'd'},
+ {"ecuid", required_argument, 0, 'e'},
+ {"help", no_argument, 0, 'h'},
+ {"path", required_argument, 0, 'p'},
+ {"snapshot", optional_argument, 0, 's'},
+ {"timeout", required_argument, 0, 't'},
+ {"verbose", no_argument, 0, 'v'},
+ {0, 0, 0, 0}
+};
+
/** @brief Parses the application arguments
*
* The arguments are parsed and saved in static structure for future use.
@@ -433,11 +454,27 @@ static void usage(void)
static int parse_args(int argc, char *argv[])
{
int c = -1;
+ int long_index = 0;
- while ((c = getopt(argc, argv, ":t:he:p:d::c:v")) != -1)
+ while ((c = getopt_long(argc,
+ argv,
+ ":s::t:he:p:d::c:v",
+ long_options,
+ &long_index)) != -1)
{
switch (c)
{
+ case 's':
+ set_default_event_type(EVENT_SYNC_CACHE);
+
+ if (optarg != NULL && strlen(optarg) >= DLT_MOUNT_PATH_MAX)
+ {
+ pr_error("Mount path '%s' too long\n", optarg);
+ return -1;
+ }
+
+ set_default_path(optarg);
+ break;
case 't':
set_timeout(strtol(optarg, NULL, 10));
break;
@@ -492,6 +529,13 @@ static int parse_args(int argc, char *argv[])
}
}
+ if (get_default_event_type() == EVENT_SYNC_CACHE &&
+ get_handler_type() != CTRL_NOHANDLER)
+ {
+ pr_error("Sync caches not available in daemon mode\n");
+ return -1;
+ }
+
return 0;
}