summaryrefslogtreecommitdiff
path: root/src/daemon/dlt_daemon_offline_logstorage.c
blob: f6642bab9d1d9a286e854489e28e320493fa359b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
/**
* @licence app begin@
* Copyright (C) 2013 - 2015  Advanced Driver Information Technology.
* This code is developed by Advanced Driver Information Technology.
* Copyright of Advanced Driver Information Technology, Bosch and DENSO.
*
* DLT offline log storage functionality source file.
*
* \copyright
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*
* \author Syed Hameed <shameed@jp.adit-jv.com> ADIT 2013 - 2015
* \author Christoph Lipka <clipka@jp.adit-jv.com> ADIT 2015
*
* \file: dlt_daemon_offline_logstorage.c
* For further information see http://www.genivi.org/.
* @licence end@
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>

#include "dlt_daemon_offline_logstorage.h"


/**
 * dlt_logstorage_split_key
*
 * Split a given key into appid and ctxid.
 * If APID: - appid = APID and ctxid = .*
 * If :CTID - ctxid = CTID and appid = .*
 * Else appid = APID and ctxid = CTID
 *
 * @param key      Given key of filter hash map
 * @param appid    Application id
 * @param ctxid    Context id
 * @return         0 on success, -1 on error
 */
int dlt_logstorage_split_key(char *key, char *appid, char *ctxid)
{
    char *tok = NULL;
    int len = 0;
    int ret = 0;
    char *sep = NULL;

    if (key == NULL)
    {
        return -1;
    }

    len = strlen(key);

    sep = strchr (key, ':');
    if(sep == NULL)
    {
        return -1;
    }

    /* key is context id only */
    if(key[0] == ':')
    {
        if(len > (DLT_ID_SIZE+1))
            return -1;

        strncpy(ctxid,(key+1),(len-1));
        strncpy(appid, ".*",2);
    }
    /* key is application id only */
    else if (key[len-1] == ':')
    {
        if(len > (DLT_ID_SIZE+1))
            return -1;

        strncpy(appid,key,(len-1));
        strncpy(ctxid, ".*",2);
    }
    /* key is appid:ctxid */
    else
    {
        if(len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)
            return -1;

        /* copy appid and ctxid */
        tok = strtok(key, ":");
        if (tok != NULL)
            strncpy(appid,tok,DLT_ID_SIZE);
        else
            ret = -1;

        tok = strtok(NULL, ":");
        if (tok != NULL)
            strncpy(ctxid,tok,DLT_ID_SIZE);
        else
            ret = -1;
    }

    return ret;
}

/**
 * dlt_logstorage_update_all_contexts
 *
 * Update log level of all contexts of the application by updating the daemon internal table
 * The compare flags (cmp_flag) indicates if Id has to be compared with application ID
 * or Context id of the daemon internal table
 * The log levels are reset if current log level provided is -1 (not sent to application in this case)
 * Reset and sent to application if current log level provided is 0
 *
 * @param daemon            DltDaemon structure
 * @param id                application id or context id
 * @param curr_log_level    log level to be set to context
 * @param cmp_flag          compare flag (1 id is apid, 2 id is ctxid)
 * @param verbose           If set to true verbose information is printed out
 * @return                  0 on success, -1 on error
 */
int dlt_logstorage_update_all_contexts(DltDaemon *daemon, char *id, int curr_log_level, int cmp_flag, int verbose)
{
    int i = 0;
    char tmp_id[DLT_ID_SIZE+1];
    int old_log_level = -1;
    DltDaemonRegisteredUsers* user_list = NULL;

    if((daemon == 0) || (id == NULL))
        return -1;

    if((cmp_flag < 0 ) || (cmp_flag > 2 ))
        return -1;

    memset(tmp_id, 0, sizeof(tmp_id));

    user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
    if (user_list == NULL)
    {
        return -1;
    }

    for (i = 0 ; i < user_list->num_contexts ; i++)
    {
        if (cmp_flag == 1)
        {
            dlt_set_id(tmp_id, user_list->contexts[i].apid);
        }
        else
        {
            dlt_set_id(tmp_id, user_list->contexts[i].ctid);
        }

        if(strcmp(id, tmp_id) == 0)
        {
            if(curr_log_level > 0)
            {
                old_log_level = user_list->contexts[i].storage_log_level;

                user_list->contexts[i].storage_log_level =
                    DLT_OFFLINE_LOGSTORAGE_MAX(
                        curr_log_level,
                        user_list->contexts[i].storage_log_level);

                if (user_list->contexts[i].storage_log_level > old_log_level)
                {
                    if (dlt_daemon_user_send_log_level(daemon,
                                                       &user_list->contexts[i],
                                                       verbose) == -1)
                    {
                        dlt_log(LOG_ERR, "Unable to update loglevel\n");
                        return -1;
                    }
                }
            }
            else    /* The request is to reset log levels */
            {
                /* Set storage level to -1, to clear log levels */
                user_list->contexts[i].storage_log_level = -1;

                if(curr_log_level == DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL)
                {
                    if (dlt_daemon_user_send_log_level(daemon,
                                                       &user_list->contexts[i],
                                                       verbose) == -1)
                    {
                        dlt_log(LOG_ERR, "Unable to reset loglevel\n");
                        return -1;
                    }
                }

            }
        }
    }
    return 0;
}

/**
 * dlt_logstorage_update_context
 *
 * Update log level of a context by updating the daemon internal table
 * The log levels are reset if current log level provided is -1 (not sent to application in this case)
 * Reset and sent to application if current log level provided is 0
 *
 * @param daemon            DltDaemon structure
 * @param apid              application id
 * @param ctxid             context id
 * @param curr_log_level    log level to be set to context
 * @param verbose           If set to true verbose information is printed out
 * @return                  0 on success, -1 on error
 */
int dlt_logstorage_update_context(DltDaemon *daemon, char *apid, char *ctxid, int curr_log_level , int verbose)
{
    DltDaemonContext *context = NULL;
    int old_log_level = -1;

    if((daemon == 0) || (apid == NULL) || (ctxid == NULL))
        return -1;

    context = dlt_daemon_context_find(daemon, apid, ctxid, daemon->ecuid, verbose);

    if (context != NULL)
    {
        if(curr_log_level > 0)
        {
            old_log_level = context->storage_log_level;

            context->storage_log_level  = DLT_OFFLINE_LOGSTORAGE_MAX(curr_log_level, context->storage_log_level);
            if(context->storage_log_level > old_log_level)
            {
                if(dlt_daemon_user_send_log_level(daemon, context, verbose) == -1)
                {
                    dlt_log(LOG_ERR, "Unable to update loglevel\n");
                    return -1;
                }
            }
        }
        else
        {
            context->storage_log_level = -1;

            if(curr_log_level == DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL)
            {
                if(dlt_daemon_user_send_log_level(daemon, context, verbose) == -1)
                {
                    dlt_log(LOG_ERR, "Unable to update loglevel\n");
                    return -1;
                }
            }

        }
    }
    return 0;
}

/**
 * dlt_logstorage_update_context_loglevel
 *
 * Update all contexts or particular context depending provided key
 *
 * @param daemon            Pointer to DLT Daemon structure
 * @param key               Filter key stored in Hash Map
 * @param curr_log_level    log level to be set to context
 * @param verbose           If set to true verbose information is printed out
 * @return                  0 on success, -1 on error
 */
int dlt_logstorage_update_context_loglevel(DltDaemon *daemon, char *key, int curr_log_level , int verbose)
{

    int cmp_flag=0;
    char appid[DLT_ID_SIZE+1] = {'\0'};
    char ctxid[DLT_ID_SIZE+1] = {'\0'};

    PRINT_FUNCTION_VERBOSE(verbose);

    if((daemon == 0) || (key == NULL))
        return -1;

    memset(appid, 0, sizeof(appid));
    memset(ctxid, 0, sizeof(ctxid));

    if(dlt_logstorage_split_key(key, appid, ctxid) != 0)
    {
        dlt_log(LOG_ERR, "Error while updating application log levels (splt key)\n");
        return -1;
    }

    if(strcmp(ctxid, ".*") == 0) /* wildcard for context id, find all contexts of given application id */
    {
        cmp_flag = 1;

        if(dlt_logstorage_update_all_contexts(daemon, appid, curr_log_level, cmp_flag, verbose) != 0)
            return -1;
    }
    else if(strcmp(appid, ".*") == 0) /* wildcard for application id, find all contexts with context id */
    {
        cmp_flag = 2;

        if(dlt_logstorage_update_all_contexts(daemon, ctxid, curr_log_level, cmp_flag, verbose) != 0)
            return -1;
    }
    else /* In case of given application id, context id pair, call available context find function */
    {
         if(dlt_logstorage_update_context(daemon, appid, ctxid, curr_log_level, verbose) != 0)
            return -1;
    }
    return 0;
}

/**
 * dlt_daemon_logstorage_reset_application_loglevel
 *
 * Reset storage log level of all running applications
 * 2 steps for resetting
 * 1. Setup storage_loglevel of all contexts configured for the requested device to -1
 * 2. Re-run update log level for all other configured devices
 *
 * @param daemon        Pointer to DLT Daemon structure
 * @param dev_num       Number of attached DLT Logstorage device
 * @param max_device    Maximum storage devices setup by the daemon
 * @param verbose       If set to true verbose information is printed out
 */
void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, int dev_num, int max_device, int verbose)
{
    DltLogStorage *handle = NULL;
    int i = 0;
    char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = {'\0'};
    int num_device_configured = 0;

    PRINT_FUNCTION_VERBOSE(verbose);

    if((daemon == 0) || (dev_num < 0))
    {
        dlt_log(LOG_ERR, "Invalid function parameters used for dlt_daemon_logstorage_reset_application_loglevel\n");
        return;
    }

    handle = &(daemon->storage_handle[dev_num]);
    if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
            || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE))
    {
        return;
    }

    /* First, check number of devices configured */
    for(i = 0; i<max_device; i++)
    {
        if(daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
        {
            num_device_configured += 1;
        }
    }

    /* for all filters (keys) check if application context are already running and log level need to be reset*/
    for(i = 0; i < handle->num_filter_keys; i++)
    {
        memset(key, 0, sizeof(key));

        strncpy(key, (handle->filter_keys + i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN);

        if(num_device_configured == 1)
            /* Reset context log level  and send to application */
            dlt_logstorage_update_context_loglevel(daemon, key, DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL, verbose);
        else
            /* Reset context log level  do not send to application as other devices can have same configuration */
            dlt_logstorage_update_context_loglevel(daemon, key, DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL, verbose);
    }

    /* Re-run update log level for all other configured devices */
    for(i=0; i<max_device; i++)
    {
        if(i == dev_num)
            continue;

        if (daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
        {
            dlt_daemon_logstorage_update_application_loglevel(daemon, i, verbose);
        }
    }
    return;
}

/**
 * dlt_daemon_logstorage_update_application_loglevel
 *
 * Update log level of all running applications with new filter configuration available due
 * to newly attached DltLogstorage device. The log level is only updated when the current
 * application log level is less than the log level obtained from the storage configuration file
 *
 * @param daemon        Pointer to DLT Daemon structure
 * @param dev_num       Number of attached DLT Logstorage device
 * @param verbose       If set to true verbose information is printed out
 */
void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon, int dev_num, int verbose)
{
    DltLogStorage *handle = NULL;
    int i = 0;
    char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN] = {'\0'};


    PRINT_FUNCTION_VERBOSE(verbose);

    if((daemon == 0) || (dev_num < 0))
    {
        dlt_log(LOG_ERR, "Invalid function parameters used for dlt_daemon_logstorage_update_application_loglevel\n");
        return;
    }

    handle = &(daemon->storage_handle[dev_num]);
    if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
            || (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE))
    {
        return;
    }

    /* for all filters (keys) check if application or context already running and log level need to be updated*/
    for(i = 0; i < handle->num_filter_keys; i++)
    {
        int log_level = -1;

        memset(key, 0, sizeof(key));

        strncpy(key, (handle->filter_keys + i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN), DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN);

        /* Obtain storage configuration data */
        log_level = dlt_logstorage_get_loglevel_by_key(handle, key);
        if(log_level < 0)
        {
            dlt_log(LOG_ERR, "Failed to get log level by key \n");
           return;
        }

        /* Update context log level with storage configuration log level */
        dlt_logstorage_update_context_loglevel(daemon, key, log_level, verbose);
    }
    return;
}

/**
 * dlt_daemon_logstorage_get_loglevel
 *
 * Obtain log level as a union of all configured storage devices and filters for the
 * provided application id and context id
 *
 * @param daemon        Pointer to DLT Daemon structure
 * @param max_device    Maximum storage devices setup by the daemon
 * @param apid          Application ID
 * @param ctid          Context ID
 * @return              Log level on success, -1 on error
 */
int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, int max_device, char *apid, char *ctid)
{
    DltLogStorageConfigData **config = NULL;
    int i = 0;
    int j = 0;
    int8_t storage_loglevel = -1;
    int8_t retrvd_loglevel = -1;
    int num_config = 0;

    if((daemon == 0) || (max_device == 0) || (apid == NULL) || (ctid == NULL))
        return -1;

    for(i = 0; i<max_device; i++)
    {
        if (daemon->storage_handle[i].config_status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
        {
            config = dlt_logstorage_get_config(&(daemon->storage_handle[i]), apid, ctid, &num_config);
            if(config != NULL)
            {
                for(j = 0; j<num_config; j++)
                {
                    retrvd_loglevel = config[j]->log_level;
                    storage_loglevel = DLT_OFFLINE_LOGSTORAGE_MAX(retrvd_loglevel, storage_loglevel);
                }
                free(config);
            }
        }
    }
    return storage_loglevel;
}

/**
 * dlt_daemon_logstorage_write
 *
 * Write log message to all attached storage device. If the called dlt_logstorage_write function is not able
 * to write to the device, DltDaemon will disconnect this device.
 *
 * @param daemon        Pointer to Dlt Daemon structure
 * @param user_config   DltDaemon configuration
 * @param data1         message header buffer
 * @param size1         message header buffer size
 * @param data2         message extended header buffer
 * @param size2         message extended header size
 * @param data3         message data buffer
 * @param size3         message data size
 */
void dlt_daemon_logstorage_write(DltDaemon *daemon,
                                 DltDaemonFlags *user_config,
                                 unsigned char *data1,
                                 int size1,
                                 unsigned char *data2,
                                 int size2,
                                 unsigned char *data3,
                                 int size3)
{
    int i = 0;
    DltLogStorageUserConfig file_config;

    if (daemon == NULL || (user_config->offlineLogstorageMaxDevices <= 0)
        || data1 == NULL || data2 == NULL || data3 == NULL)
    {
        dlt_log(LOG_INFO,
                "dlt_daemon_logstorage_write: message type is not log. "
                "Skip storing.\n");
        return;
    }

    /* Copy user configuration */
    file_config.logfile_timestamp = user_config->offlineLogstorageTimestamp;
    file_config.logfile_delimiter = user_config->offlineLogstorageDelimiter;
    file_config.logfile_maxcounter = user_config->offlineLogstorageMaxCounter;
    file_config.logfile_counteridxlen =
            user_config->offlineLogstorageMaxCounterIdx;

    for (i = 0; i < user_config->offlineLogstorageMaxDevices; i++)
    {
        if (daemon->storage_handle[i].config_status ==
            DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
        {
            if (dlt_logstorage_write(&(daemon->storage_handle[i]),
                                     &file_config,
                                     data1,
                                     size1,
                                     data2,
                                     size2,
                                     data3,
                                     size3) != 0)
            {
                dlt_log(LOG_ERR,
                        "dlt_daemon_logstorage_write: failed. "
                        "Disable storage device\n");
                /* DLT_OFFLINE_LOGSTORAGE_MAX_WRITE_ERRORS happened,
                 * therefore remove logstorage device */
                dlt_logstorage_device_disconnected(
                        &(daemon->storage_handle[i]),
                        DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT);
            }
        }
    }
}

/**
 * dlt_daemon_logstorage_setup_internal_storage
 *
 * Setup user defined path as offline log storage device
 *
 * @param daemon        Pointer to Dlt Daemon structure
 * @param path          User configured internal storage path
 * @param verbose       If set to true verbose information is printed out
 */
int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, char *path, int verbose)
{
    int ret = 0;

    if((path == NULL) || (daemon == NULL))
    {
       return -1;
    }

    /* connect internal storage device */
    /* Device index always used as 0 as it is setup on DLT daemon startup */
    ret = dlt_logstorage_device_connected(&(daemon->storage_handle[0]), path);
    if(ret != 0)
    {
        dlt_log(LOG_ERR,"dlt_daemon_logstorage_setup_emmc_support : Device connect failed\n");
        return -1;
    }

    /* setup logstorage with config file settings */
    ret = dlt_logstorage_load_config(&(daemon->storage_handle[0]));
    if(ret != 0)
    {
        dlt_log(LOG_ERR,"dlt_daemon_logstorage_setup_emmc_support : Loading configuration file failed\n");
        return -1;
    }

    /* check if log level of running application need an update */
    dlt_daemon_logstorage_update_application_loglevel(daemon, 0, verbose);

    return ret;
}

void dlt_daemon_logstorage_set_logstorage_cache_size(unsigned int size)
{
    /* store given [KB] size in [Bytes] */
    g_logstorage_cache_max = size * 1000;
}

int dlt_daemon_logstorage_cleanup(DltDaemon *daemon,
                                  DltDaemonLocal *daemon_local,
                                  int verbose)
{
    int i = 0;

    PRINT_FUNCTION_VERBOSE(verbose);

    if (daemon == NULL || daemon_local == NULL)
    {
        return -1;
    }

    for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
    {
        /* call disconnect on all currently connected devices */
        if (daemon->storage_handle[i].connection_type ==
            DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
        {
            dlt_logstorage_device_disconnected(
                    &daemon->storage_handle[i],
                    DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT);
        }
    }

    return 0;
}

int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon,
                                     DltDaemonLocal *daemon_local,
                                     char *mnt_point,
                                     int verbose)
{
    int i = 0;
    DltLogStorage *handle = NULL;

    PRINT_FUNCTION_VERBOSE(verbose);

    if (daemon == NULL || mnt_point == NULL)
    {
        return -1;
    }

    if (strlen(mnt_point) > 0) /* mount point is given */
    {
        handle = dlt_daemon_logstorage_get_device(daemon,
                                                  daemon_local,
                                                  mnt_point,
                                                  verbose);
        if (handle == NULL)
        {
            return -1;
        }
        else
        {
            if (dlt_logstorage_sync_caches(handle) != 0)
            {
                return -1;
            }
        }
    }
    else /* sync caches for all connected logstorage devices */
    {
        for(i=0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
        {
            if (daemon->storage_handle[i].connection_type ==
                    DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
            {
                if (dlt_logstorage_sync_caches(&daemon->storage_handle[i]) != 0)
                {
                    return -1;
                }
            }
        }
    }

    return 0;
}

DltLogStorage *dlt_daemon_logstorage_get_device(DltDaemon *daemon,
                                                DltDaemonLocal *daemon_local,
                                                char *mnt_point,
                                                int verbose)
{
    int i = 0;
    int len1 = 0;
    int len2 = 0;

    PRINT_FUNCTION_VERBOSE(verbose);

    if (daemon == NULL || daemon_local == NULL || mnt_point == NULL)
    {
        return NULL;
    }

    len1 = strlen(mnt_point);

    for(i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
    {
        len2 = strlen(daemon->storage_handle[i].device_mount_point);

        /* Check if the requested device path is already used as log storage
         * device. Check for strlen first, to avoid comparison errors when
         * final '/' is given or not */
        if (strncmp(daemon->storage_handle[i].device_mount_point,
                    mnt_point,
                    len1 > len2 ? len2 : len1) == 0)
        {
            return &daemon->storage_handle[i];
        }
    }

    return NULL;
}