Line data Source code
1 : /**
2 : * Copyright (C) 2013 - 2018 Advanced Driver Information Technology.
3 : * This code is developed by Advanced Driver Information Technology.
4 : * Copyright of Advanced Driver Information Technology, Bosch and DENSO.
5 : *
6 : * DLT offline log storage functionality source file.
7 : *
8 : * \copyright
9 : * This Source Code Form is subject to the terms of the
10 : * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
11 : * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 : *
13 : *
14 : * \author Syed Hameed <shameed@jp.adit-jv.com> ADIT 2013 - 2015
15 : * \author Christoph Lipka <clipka@jp.adit-jv.com> ADIT 2015
16 : *
17 : * \file: dlt_daemon_offline_logstorage.c
18 : * For further information see http://www.covesa.org/.
19 : */
20 :
21 : #include <stdio.h>
22 : #include <stdlib.h>
23 : #include <string.h>
24 : #include <syslog.h>
25 :
26 : #include "dlt_daemon_offline_logstorage.h"
27 : #include "dlt_daemon_offline_logstorage_internal.h"
28 : #include "dlt_gateway_types.h"
29 : #include "dlt_gateway.h"
30 :
31 : /**
32 : * dlt_logstorage_split_ecuid
33 : *
34 : * Split keys with ECU ID alone
35 : *
36 : * @param key Key
37 : * @param len Key length
38 : * @param ecuid ECU ID from key stored here
39 : * @param apid Application ID as .* stored here
40 : * @param ctid Context id as .* stored here
41 : * @return 0 on success -1 on error
42 : */
43 0 : DLT_STATIC DltReturnValue dlt_logstorage_split_ecuid(char *key,
44 : int len,
45 : char *ecuid,
46 : char *apid,
47 : char *ctid)
48 : {
49 0 : if ((len > (DLT_ID_SIZE + 2)) || (len < 2))
50 : return DLT_RETURN_ERROR;
51 :
52 0 : memcpy(ecuid, key, (len - 2));
53 : memcpy(apid, ".*", 2);
54 : memcpy(ctid, ".*", 2);
55 :
56 0 : return DLT_RETURN_OK;
57 : }
58 :
59 : unsigned int g_logstorage_cache_max;
60 : /**
61 : * dlt_logstorage_split_ctid
62 : *
63 : * Split keys with Context ID alone
64 : *
65 : * @param key Key
66 : * @param len Key length
67 : * @param apid Application ID as .* stored here
68 : * @param ctid Context id from key stored here
69 : * @return 0 on success -1 on error
70 : */
71 0 : DLT_STATIC DltReturnValue dlt_logstorage_split_ctid(char *key,
72 : int len,
73 : char *apid,
74 : char *ctid)
75 : {
76 0 : if ((len > (DLT_ID_SIZE + 2)) || (len < 1))
77 : return DLT_RETURN_ERROR;
78 :
79 0 : strncpy(ctid, (key + 2), (len - 1));
80 : memcpy(apid, ".*", 2);
81 :
82 0 : return DLT_RETURN_OK;
83 : }
84 :
85 : /**
86 : * dlt_logstorage_split_apid
87 : *
88 : * Split keys with Application ID alone
89 : *
90 : * @param key Key
91 : * @param len Key length
92 : * @param apid Application ID from key is stored here
93 : * @param ctid Context id as .* stored here
94 : * @return 0 on success -1 on error
95 : */
96 1 : DLT_STATIC DltReturnValue dlt_logstorage_split_apid(char *key,
97 : int len,
98 : char *apid,
99 : char *ctid)
100 : {
101 1 : if ((len > (DLT_ID_SIZE + 2)) || (len < 2))
102 : return DLT_RETURN_ERROR;
103 :
104 1 : strncpy(apid, key + 1, (len - 2));
105 : memcpy(ctid, ".*", 2);
106 :
107 1 : return DLT_RETURN_OK;
108 : }
109 :
110 : /**
111 : * dlt_logstorage_split_apid_ctid
112 : *
113 : * Split keys with Application ID and Context ID
114 : *
115 : * @param key Key
116 : * @param len Key length
117 : * @param apid Application ID from key is stored here
118 : * @param ctid CContext id from key is stored here
119 : * @return 0 on success -1 on error
120 : */
121 1 : DLT_STATIC DltReturnValue dlt_logstorage_split_apid_ctid(char *key,
122 : int len,
123 : char *apid,
124 : char *ctid)
125 : {
126 : char *tok = NULL;
127 :
128 1 : if (len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)
129 : return DLT_RETURN_ERROR;
130 :
131 : /* copy apid and ctid */
132 1 : tok = strtok(key, ":");
133 :
134 1 : if (tok != NULL)
135 : strncpy(apid, tok, DLT_ID_SIZE);
136 : else
137 : return DLT_RETURN_ERROR;
138 :
139 1 : tok = strtok(NULL, ":");
140 :
141 1 : if (tok != NULL)
142 : strncpy(ctid, tok, DLT_ID_SIZE);
143 : else
144 : return DLT_RETURN_ERROR;
145 :
146 1 : return DLT_RETURN_OK;
147 : }
148 :
149 : /**
150 : * dlt_logstorage_split_ecuid_apid
151 : *
152 : * Split keys with ECU ID and Application ID
153 : *
154 : * @param key Key
155 : * @param len Key length
156 : * @param ecuid ECU ID from key stored here
157 : * @param apid Application ID from key is stored here
158 : * @param ctid Context id as .* stored here
159 : * @return 0 on success -1 on error
160 : */
161 1 : DLT_STATIC DltReturnValue dlt_logstorage_split_ecuid_apid(char *key,
162 : int len,
163 : char *ecuid,
164 : char *apid,
165 : char *ctid)
166 : {
167 : char *tok = NULL;
168 :
169 1 : if (len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)
170 : return DLT_RETURN_ERROR;
171 :
172 : /* copy apid and ctid */
173 1 : tok = strtok(key, ":");
174 :
175 1 : if (tok != NULL)
176 : strncpy(ecuid, tok, DLT_ID_SIZE);
177 : else
178 : return DLT_RETURN_ERROR;
179 :
180 1 : tok = strtok(NULL, ":");
181 :
182 1 : if (tok != NULL)
183 : strncpy(apid, tok, DLT_ID_SIZE);
184 : else
185 : return DLT_RETURN_ERROR;
186 :
187 : memcpy(ctid, ".*", 2);
188 :
189 1 : return DLT_RETURN_OK;
190 : }
191 :
192 : /**
193 : * dlt_logstorage_split_multi
194 : *
195 : * Prepares keys with application ID alone, will use ecuid if provided
196 : * (ecuid\:apid\:\:) or (\:apid\:\:)
197 : *
198 : * @param key Prepared key stored here
199 : * @param len Key length
200 : * @param ecuid ECU ID
201 : * @param apid Application ID
202 : * @param ctid Context ID
203 : * @return None
204 : */
205 34 : DLT_STATIC DltReturnValue dlt_logstorage_split_multi(char *key,
206 : int len,
207 : char *ecuid,
208 : char *apid,
209 : char *ctid)
210 : {
211 : char *tok = NULL;
212 :
213 34 : if (len > DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)
214 : return DLT_RETURN_ERROR;
215 :
216 34 : tok = strtok(key, ":");
217 :
218 34 : if (tok == NULL)
219 : return DLT_RETURN_ERROR;
220 :
221 34 : len = strlen(tok);
222 :
223 34 : if (key[len + 1] == ':') {
224 : strncpy(ecuid, tok, DLT_ID_SIZE);
225 :
226 0 : tok = strtok(NULL, ":");
227 :
228 0 : if (tok != NULL)
229 : strncpy(ctid, tok, DLT_ID_SIZE);
230 :
231 : memcpy(apid, ".*", 2);
232 : }
233 : else {
234 : strncpy(ecuid, tok, DLT_ID_SIZE);
235 34 : tok = strtok(NULL, ":");
236 :
237 34 : if (tok != NULL)
238 : strncpy(apid, tok, DLT_ID_SIZE);
239 :
240 34 : tok = strtok(NULL, ":");
241 :
242 34 : if (tok != NULL)
243 : strncpy(ctid, tok, DLT_ID_SIZE);
244 : }
245 :
246 : return DLT_RETURN_OK;
247 : }
248 :
249 : /**
250 : * dlt_logstorage_split_key
251 : *
252 : * Split a given key into apid and ctid.
253 : * If APID\: - apid = APID and ctid = .*
254 : * If \:CTID - ctid = CTID and apid = .*
255 : * Else apid = APID and ctid = CTID
256 : *
257 : * @param key Given key of filter hash map
258 : * @param apid Application id
259 : * @param ctid Context id
260 : * @param ecuid ECU id
261 : * @return 0 on success, -1 on error
262 : */
263 42 : DLT_STATIC DltReturnValue dlt_logstorage_split_key(char *key, char *apid,
264 : char *ctid, char *ecuid)
265 : {
266 : int len = 0;
267 : char *sep = NULL;
268 :
269 42 : if ((key == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL))
270 : return DLT_RETURN_WRONG_PARAMETER;
271 :
272 37 : len = strlen(key);
273 :
274 37 : sep = strchr (key, ':');
275 :
276 37 : if (sep == NULL)
277 : return DLT_RETURN_WRONG_PARAMETER;
278 :
279 : /* key is ecuid only ecuid::*/
280 37 : if ((key[len - 1] == ':') && (key[len - 2] == ':'))
281 0 : return dlt_logstorage_split_ecuid(key, len, ecuid, apid, ctid);
282 : /* key is context id only ::apid*/
283 37 : else if ((key[0] == ':') && (key[1] == ':'))
284 0 : return dlt_logstorage_split_ctid(key, len, apid, ctid);
285 : /* key is application id only :apid: */
286 37 : else if ((key[0] == ':') && (key[len - 1] == ':'))
287 1 : return dlt_logstorage_split_apid(key, len, apid, ctid);
288 : /* key is :apid:ctid */
289 36 : else if ((key[0] == ':') && (key[len - 1] != ':'))
290 1 : return dlt_logstorage_split_apid_ctid(key, len, apid, ctid);
291 : /* key is ecuid:apid: */
292 35 : else if ((key[0] != ':') && (key[len - 1] == ':'))
293 1 : return dlt_logstorage_split_ecuid_apid(key, len, ecuid, apid, ctid);
294 : /* key is either ecuid::ctid or ecuid:apid:ctid */
295 : else
296 34 : return dlt_logstorage_split_multi(key, len, ecuid, apid, ctid);
297 : }
298 :
299 : /**
300 : * Forward SET_LOG_LEVEL request to passive node
301 : *
302 : * @param daemon_local pointer to DltDaemonLocal structure
303 : * @param apid Application ID
304 : * @param ctid Context ID
305 : * @param ecuid ECU ID
306 : * @param loglevel requested log level
307 : * @param verbose verbosity flag
308 : */
309 0 : DLT_STATIC DltReturnValue dlt_daemon_logstorage_update_passive_node_context(
310 : DltDaemonLocal *daemon_local,
311 : char *apid,
312 : char *ctid,
313 : char *ecuid,
314 : int loglevel,
315 : int verbose)
316 : {
317 0 : DltServiceSetLogLevel req = { 0 };
318 0 : DltPassiveControlMessage ctrl = { 0 };
319 : DltGatewayConnection *con = NULL;
320 :
321 0 : PRINT_FUNCTION_VERBOSE(verbose);
322 :
323 0 : if ((daemon_local == NULL) || (apid == NULL) || (ctid == NULL) || (ecuid == NULL) ||
324 0 : (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) {
325 0 : dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__);
326 0 : return DLT_RETURN_WRONG_PARAMETER;
327 : }
328 :
329 0 : con = dlt_gateway_get_connection(&daemon_local->pGateway, ecuid, verbose);
330 :
331 0 : if (con == NULL) {
332 0 : dlt_vlog(LOG_ERR,
333 : "Failed to fond connection to passive node %s\n",
334 : ecuid);
335 0 : return DLT_RETURN_ERROR;
336 : }
337 :
338 0 : ctrl.id = DLT_SERVICE_ID_SET_LOG_LEVEL;
339 0 : ctrl.type = CONTROL_MESSAGE_ON_DEMAND;
340 :
341 0 : dlt_set_id(req.apid, apid);
342 0 : dlt_set_id(req.ctid, ctid);
343 :
344 0 : req.log_level = loglevel;
345 :
346 0 : if (dlt_gateway_send_control_message(con, &ctrl, (void *)&req, verbose) != 0) {
347 0 : dlt_vlog(LOG_ERR,
348 : "Failed to forward SET_LOG_LEVEL message to passive node %s\n",
349 : ecuid);
350 :
351 0 : return DLT_RETURN_ERROR;
352 : }
353 :
354 : return DLT_RETURN_OK;
355 : }
356 :
357 : /**
358 : * dlt_daemon_logstorage_send_log_level
359 : *
360 : * Send new log level for the provided context, if ecuid is not daemon ecuid
361 : * update log level of passive node
362 : *
363 : * @param daemon DltDaemon structure
364 : * @param daemon_local DltDaemonLocal structure
365 : * @param context DltDaemonContext structure
366 : * @param ecuid ECU id
367 : * @param loglevel log level to be set to context
368 : * @param verbose If set to true verbose information is printed out
369 : * @return 0 on success, -1 on error
370 : */
371 2 : DLT_STATIC DltReturnValue dlt_daemon_logstorage_send_log_level(DltDaemon *daemon,
372 : DltDaemonLocal *daemon_local,
373 : DltDaemonContext *context,
374 : char *ecuid,
375 : int loglevel,
376 : int verbose)
377 : {
378 : int old_log_level = -1;
379 : int ll = DLT_LOG_DEFAULT;
380 :
381 2 : if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) ||
382 2 : (context == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) {
383 0 : dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__);
384 0 : return DLT_RETURN_WRONG_PARAMETER;
385 : }
386 :
387 2 : if (strncmp(ecuid, daemon->ecuid, DLT_ID_SIZE) == 0) {
388 2 : old_log_level = context->storage_log_level;
389 :
390 2 : context->storage_log_level = DLT_OFFLINE_LOGSTORAGE_MAX(loglevel,
391 : context->storage_log_level);
392 :
393 2 : if (context->storage_log_level > old_log_level) {
394 2 : if (dlt_daemon_user_send_log_level(daemon, context, verbose) == -1) {
395 0 : dlt_log(LOG_ERR, "Unable to update log level\n");
396 0 : return DLT_RETURN_ERROR;
397 : }
398 : }
399 : }
400 : else {
401 :
402 0 : old_log_level = context->log_level;
403 :
404 0 : ll = DLT_OFFLINE_LOGSTORAGE_MAX(loglevel, context->log_level);
405 :
406 0 : if (ll > old_log_level)
407 0 : return dlt_daemon_logstorage_update_passive_node_context(daemon_local,
408 0 : context->apid,
409 0 : context->ctid,
410 : ecuid,
411 : ll,
412 : verbose);
413 : }
414 :
415 : return DLT_RETURN_OK;
416 : }
417 :
418 : /**
419 : * dlt_daemon_logstorage_reset_log_level
420 : *
421 : * The log levels are reset if log level provided is -1 (not sent to
422 : * application in this case). Reset and sent to application if current log level
423 : * provided is 0.
424 : *
425 : * @param daemon DltDaemon structure
426 : * @param daemon_local DltDaemonLocal structure
427 : * @param context DltDaemonContext structure
428 : * @param ecuid ECU ID
429 : * @param loglevel log level to be set to context
430 : * @param verbose If set to true verbose information is printed out
431 : * @return 0 on success, -1 on error
432 : */
433 1 : DLT_STATIC DltReturnValue dlt_daemon_logstorage_reset_log_level(DltDaemon *daemon,
434 : DltDaemonLocal *daemon_local,
435 : DltDaemonContext *context,
436 : char *ecuid,
437 : int loglevel,
438 : int verbose)
439 : {
440 1 : if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) ||
441 1 : (context == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) {
442 0 : dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__);
443 0 : return DLT_RETURN_WRONG_PARAMETER;
444 : }
445 :
446 : /* Set storage level to -1, to clear log levels */
447 1 : context->storage_log_level = DLT_LOG_DEFAULT;
448 :
449 1 : if (loglevel == DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL) {
450 1 : if (strncmp(ecuid, daemon->ecuid, DLT_ID_SIZE) == 0) {
451 1 : if (dlt_daemon_user_send_log_level(daemon,
452 : context,
453 : verbose) == DLT_RETURN_ERROR) {
454 0 : dlt_log(LOG_ERR, "Unable to update log level\n");
455 0 : return DLT_RETURN_ERROR;
456 : }
457 : }
458 : else { /* forward set log level to passive node */
459 0 : return dlt_daemon_logstorage_update_passive_node_context(daemon_local,
460 0 : context->apid,
461 0 : context->ctid,
462 : ecuid,
463 : DLT_LOG_DEFAULT,
464 : verbose);
465 : }
466 : }
467 :
468 : return DLT_RETURN_OK;
469 : }
470 :
471 : /**
472 : * dlt_daemon_logstorage_force_reset_level
473 : *
474 : * Force resetting of log level since have no data provided by passive node.
475 : *
476 : * @param daemon DltDaemon structure
477 : * @param daemon_local DltDaemonLocal structure
478 : * @param apid Application ID
479 : * @param ctid Context ID
480 : * @param ecuid ECU ID
481 : * @param loglevel log level to be set to context
482 : * @param verbose If set to true verbose information is printed out
483 : * @return 0 on success, -1 on error
484 : */
485 0 : DLT_STATIC DltReturnValue dlt_daemon_logstorage_force_reset_level(DltDaemon *daemon,
486 : DltDaemonLocal *daemon_local,
487 : char *apid,
488 : char *ctid,
489 : char *ecuid,
490 : int loglevel,
491 : int verbose)
492 : {
493 : int ll = DLT_LOG_DEFAULT;
494 : int num = 0;
495 : int i = 0;
496 0 : DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 };
497 :
498 0 : if ((daemon == NULL) || (daemon_local == NULL) || (ecuid == NULL) ||
499 0 : (apid == NULL) || (ctid == NULL) || (loglevel > DLT_LOG_VERBOSE) || (loglevel < DLT_LOG_DEFAULT)) {
500 0 : dlt_vlog(LOG_ERR, "%s: Wrong parameter\n", __func__);
501 0 : return DLT_RETURN_WRONG_PARAMETER;
502 : }
503 :
504 0 : for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) {
505 0 : num = dlt_logstorage_get_config(&(daemon->storage_handle[i]), config, apid, ctid, ecuid);
506 :
507 0 : if (num > 0)
508 : break; /* found config */
509 : }
510 :
511 0 : if ((num == 0) || (config[0] == NULL)) {
512 0 : dlt_vlog(LOG_ERR,
513 : "%s: No information about APID: %s, CTID: %s, ECU: %s in Logstorage configuration\n",
514 : __func__, apid, ctid, ecuid);
515 0 : return DLT_RETURN_ERROR;
516 : }
517 :
518 0 : if (loglevel == DLT_DAEMON_LOGSTORAGE_RESET_SEND_LOGLEVEL)
519 0 : ll = config[0]->reset_log_level;
520 : else
521 0 : ll = config[0]->log_level;
522 :
523 0 : return dlt_daemon_logstorage_update_passive_node_context(daemon_local, apid,
524 : ctid, ecuid, ll, verbose);
525 :
526 : }
527 :
528 : /**
529 : * dlt_logstorage_update_all_contexts
530 : *
531 : * Update log level of all contexts of the application by updating the daemon
532 : * internal table. The compare flags (cmp_flag) indicates if Id has to be
533 : * compared with application id or Context id of the daemon internal table.
534 : * The log levels are reset if current log level provided is -1 (not sent to
535 : * application in this case). Reset and sent to application if current log level
536 : * provided is 0.
537 : *
538 : * @param daemon DltDaemon structure
539 : * @param daemon_local DltDaemonLocal structure
540 : * @param id application id or context id
541 : * @param curr_log_level log level to be set to context
542 : * @param cmp_flag compare flag
543 : * @param ecuid ecu id where application runs
544 : * @param verbose If set to true verbose information is printed out
545 : * @return 0 on success, -1 on error
546 : */
547 4 : DltReturnValue dlt_logstorage_update_all_contexts(DltDaemon *daemon,
548 : DltDaemonLocal *daemon_local,
549 : char *id,
550 : int curr_log_level,
551 : int cmp_flag,
552 : char *ecuid,
553 : int verbose)
554 : {
555 : DltDaemonRegisteredUsers *user_list = NULL;
556 : int i = 0;
557 4 : char tmp_id[DLT_ID_SIZE + 1] = { '\0' };
558 :
559 4 : if ((daemon == NULL) || (daemon_local == NULL) || (id == NULL) ||
560 3 : (ecuid == NULL) || (cmp_flag <= DLT_DAEMON_LOGSTORAGE_CMP_MIN) ||
561 : (cmp_flag >= DLT_DAEMON_LOGSTORAGE_CMP_MAX)) {
562 1 : dlt_vlog(LOG_ERR, "Wrong parameter in function %s\n", __func__);
563 1 : return DLT_RETURN_WRONG_PARAMETER;
564 : }
565 :
566 3 : user_list = dlt_daemon_find_users_list(daemon, ecuid, verbose);
567 :
568 3 : if (user_list == NULL)
569 : return DLT_RETURN_ERROR;
570 :
571 3 : for (i = 0; i < user_list->num_contexts; i++) {
572 0 : if (cmp_flag == DLT_DAEMON_LOGSTORAGE_CMP_APID)
573 0 : dlt_set_id(tmp_id, user_list->contexts[i].apid);
574 0 : else if (cmp_flag == DLT_DAEMON_LOGSTORAGE_CMP_CTID)
575 0 : dlt_set_id(tmp_id, user_list->contexts[i].ctid);
576 : else
577 : /* this is for the case when both apid and ctid are wildcard */
578 0 : dlt_set_id(tmp_id, ".*");
579 :
580 0 : if (strncmp(id, tmp_id, DLT_ID_SIZE) == 0) {
581 0 : if (curr_log_level > 0)
582 0 : dlt_daemon_logstorage_send_log_level(daemon,
583 : daemon_local,
584 0 : &user_list->contexts[i],
585 : ecuid,
586 : curr_log_level,
587 : verbose);
588 : else /* The request is to reset log levels */
589 0 : dlt_daemon_logstorage_reset_log_level(daemon,
590 : daemon_local,
591 0 : &user_list->contexts[i],
592 : ecuid,
593 : curr_log_level,
594 : verbose);
595 : }
596 : }
597 :
598 : return DLT_RETURN_OK;
599 : }
600 :
601 : /**
602 : * dlt_logstorage_update_context
603 : *
604 : * Update log level of a context by updating the daemon internal table
605 : * The log levels are reset if current log level provided is -1 (not sent to
606 : * application in this case)
607 : * Reset and sent to application if current log level provided is 0
608 : *
609 : * @param daemon DltDaemon structure
610 : * @param daemon_local DltDaemonLocal structure
611 : * @param apid application id
612 : * @param ctid context id
613 : * @param ecuid ecu id
614 : * @param curr_log_level log level to be set to context
615 : * @param verbose If set to true verbose information is printed out
616 : * @return 0 on success, -1 on error
617 : */
618 38 : DltReturnValue dlt_logstorage_update_context(DltDaemon *daemon,
619 : DltDaemonLocal *daemon_local,
620 : char *apid,
621 : char *ctid,
622 : char *ecuid,
623 : int curr_log_level,
624 : int verbose)
625 : {
626 : DltDaemonContext *context = NULL;
627 :
628 38 : if ((daemon == NULL) || (daemon_local == NULL) || (apid == NULL)
629 37 : || (ctid == NULL) || (ecuid == NULL)) {
630 1 : dlt_vlog(LOG_ERR, "Wrong parameter in function %s\n", __func__);
631 1 : return DLT_RETURN_WRONG_PARAMETER;
632 : }
633 :
634 37 : context = dlt_daemon_context_find(daemon, apid, ctid, ecuid, verbose);
635 :
636 37 : if (context != NULL) {
637 3 : if (curr_log_level > 0)
638 2 : return dlt_daemon_logstorage_send_log_level(daemon,
639 : daemon_local,
640 : context,
641 : ecuid,
642 : curr_log_level,
643 : verbose);
644 : else /* The request is to reset log levels */
645 1 : return dlt_daemon_logstorage_reset_log_level(daemon,
646 : daemon_local,
647 : context,
648 : ecuid,
649 : curr_log_level,
650 : verbose);
651 : }
652 : else {
653 34 : if (strncmp(ecuid, daemon->ecuid, DLT_ID_SIZE) != 0) {
654 : /* we intentionally have no data provided by passive node. */
655 : /* We blindly send the log level or reset log level */
656 0 : return dlt_daemon_logstorage_force_reset_level(daemon,
657 : daemon_local,
658 : apid,
659 : ctid,
660 : ecuid,
661 : curr_log_level,
662 : verbose);
663 : }
664 : else {
665 34 : dlt_vlog(LOG_WARNING,
666 : "%s: No information about APID: %s, CTID: %s, ECU: %s\n",
667 : __func__,
668 : apid,
669 : ctid,
670 : ecuid);
671 34 : return DLT_RETURN_ERROR;
672 :
673 : }
674 : }
675 :
676 : return DLT_RETURN_OK;
677 : }
678 :
679 : /**
680 : * dlt_logstorage_update_context_loglevel
681 : *
682 : * Update all contexts or particular context depending provided key
683 : *
684 : * @param daemon Pointer to DLT Daemon structure
685 : * @param daemon_local Pointer to DLT Daemon Local structure
686 : * @param key Filter key stored in Hash Map
687 : * @param curr_log_level log level to be set to context
688 : * @param verbose If set to true verbose information is printed out
689 : * @return 0 on success, -1 on error
690 : */
691 37 : DltReturnValue dlt_logstorage_update_context_loglevel(DltDaemon *daemon,
692 : DltDaemonLocal *daemon_local,
693 : char *key,
694 : int curr_log_level,
695 : int verbose)
696 : {
697 : int cmp_flag = 0;
698 37 : char apid[DLT_ID_SIZE + 1] = { '\0' };
699 37 : char ctid[DLT_ID_SIZE + 1] = { '\0' };
700 37 : char ecuid[DLT_ID_SIZE + 1] = { '\0' };
701 :
702 37 : PRINT_FUNCTION_VERBOSE(verbose);
703 :
704 37 : if ((daemon == NULL) || (daemon_local == NULL) || (key == NULL))
705 : return DLT_RETURN_WRONG_PARAMETER;
706 :
707 36 : if (dlt_logstorage_split_key(key, apid, ctid, ecuid) != 0) {
708 0 : dlt_log(LOG_ERR,
709 : "Error while updating application log levels (split key)\n");
710 0 : return DLT_RETURN_ERROR;
711 : }
712 :
713 36 : if (ecuid[0] == '\0') /* ECU id was not specified in filter configuration */
714 2 : dlt_set_id(ecuid, daemon->ecuid);
715 :
716 : /* check wildcard for both apid and ctid first of all */
717 36 : if (strcmp(ctid, ".*") == 0 && strcmp(apid, ".*") == 0) {
718 : cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_ECID;
719 :
720 0 : if (dlt_logstorage_update_all_contexts(daemon,
721 : daemon_local,
722 : apid,
723 : curr_log_level,
724 : cmp_flag,
725 : ecuid,
726 : verbose) != 0)
727 0 : return DLT_RETURN_ERROR;
728 : }
729 36 : else if (strcmp(ctid, ".*") == 0) {
730 : cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_APID;
731 :
732 1 : if (dlt_logstorage_update_all_contexts(daemon,
733 : daemon_local,
734 : apid,
735 : curr_log_level,
736 : cmp_flag,
737 : ecuid,
738 : verbose) != 0)
739 0 : return DLT_RETURN_ERROR;
740 : }
741 : /* wildcard for application id, find all contexts with context id */
742 35 : else if (strcmp(apid, ".*") == 0)
743 : {
744 : cmp_flag = DLT_DAEMON_LOGSTORAGE_CMP_CTID;
745 :
746 0 : if (dlt_logstorage_update_all_contexts(daemon,
747 : daemon_local,
748 : ctid,
749 : curr_log_level,
750 : cmp_flag,
751 : ecuid,
752 : verbose) != 0)
753 0 : return DLT_RETURN_ERROR;
754 : }
755 : /* In case of given application id, context id pair, call available context
756 : * find function */
757 35 : else if (dlt_logstorage_update_context(daemon,
758 : daemon_local,
759 : apid,
760 : ctid,
761 : ecuid,
762 : curr_log_level,
763 : verbose) != 0)
764 : {
765 34 : return DLT_RETURN_ERROR;
766 : }
767 :
768 : return DLT_RETURN_OK;
769 : }
770 :
771 : /**
772 : * dlt_daemon_logstorage_reset_application_loglevel
773 : *
774 : * Reset storage log level of all running applications
775 : * 2 steps for resetting
776 : * 1. Setup storage_loglevel of all contexts configured for the requested device
777 : * to -1
778 : * 2. Re-run update log level for all other configured devices
779 : *
780 : * @param daemon Pointer to DLT Daemon structure
781 : * @param daemon_local Pointer to DLT Daemon local structure
782 : * @param dev_num Number of attached DLT Logstorage device
783 : * @param max_device Maximum storage devices setup by the daemon
784 : * @param verbose If set to true verbose information is printed out
785 : */
786 2 : void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon,
787 : DltDaemonLocal *daemon_local,
788 : int dev_num,
789 : int max_device,
790 : int verbose)
791 : {
792 : DltLogStorage *handle = NULL;
793 : DltLogStorageFilterList **tmp = NULL;
794 : int i = 0;
795 2 : char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { '\0' };
796 : unsigned int status;
797 : int log_level = 0;
798 :
799 2 : PRINT_FUNCTION_VERBOSE(verbose);
800 :
801 2 : if ((daemon == NULL) || (daemon_local == NULL) ||
802 1 : (daemon->storage_handle == NULL) || (dev_num < 0)) {
803 2 : dlt_vlog(LOG_ERR,
804 : "Invalid function parameters used for %s\n",
805 : __func__);
806 2 : return;
807 : }
808 :
809 0 : handle = &(daemon->storage_handle[dev_num]);
810 :
811 0 : if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) ||
812 0 : (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE))
813 : return;
814 :
815 : /* for all filters (keys) check if application context are already running
816 : * and log level need to be reset*/
817 0 : tmp = &(handle->config_list);
818 0 : while (*(tmp) != NULL)
819 : {
820 0 : for (i = 0; i < (*tmp)->num_keys; i++)
821 : {
822 : memset(key, 0, sizeof(key));
823 :
824 0 : strncpy(key, ((*tmp)->key_list
825 0 : + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)),
826 : DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN);
827 :
828 : /* dlt-daemon wants to reset loglevel if
829 : * a logstorage device is disconnected.
830 : */
831 : log_level = DLT_DAEMON_LOGSTORAGE_RESET_LOGLEVEL;
832 :
833 0 : dlt_logstorage_update_context_loglevel(
834 : daemon,
835 : daemon_local,
836 : key,
837 : log_level,
838 : verbose);
839 : }
840 0 : tmp = &(*tmp)->next;
841 : }
842 :
843 : /* Re-run update log level for all other configured devices */
844 0 : for (i = 0; i < max_device; i++) {
845 0 : status = daemon->storage_handle[i].config_status;
846 :
847 0 : if (i == dev_num)
848 0 : continue;
849 :
850 0 : if (status == DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE)
851 0 : dlt_daemon_logstorage_update_application_loglevel(daemon,
852 : daemon_local,
853 : i,
854 : verbose);
855 : }
856 :
857 : return;
858 : }
859 :
860 : /**
861 : * dlt_daemon_logstorage_update_application_loglevel
862 : *
863 : * Update log level of all running applications with new filter configuration
864 : * available due to newly attached DltLogstorage device. The log level is only
865 : * updated when the current application log level is less than the log level
866 : * obtained from the storage configuration file
867 : *
868 : * @param daemon Pointer to DLT Daemon structure
869 : * @param daemon_local Pointer to DLT Daemon local structure
870 : * @param dev_num Number of attached DLT Logstorage device
871 : * @param verbose If set to true verbose information is printed out
872 : */
873 10 : void dlt_daemon_logstorage_update_application_loglevel(DltDaemon *daemon,
874 : DltDaemonLocal *daemon_local,
875 : int dev_num,
876 : int verbose)
877 : {
878 : DltLogStorage *handle = NULL;
879 : DltLogStorageFilterList **tmp = NULL;
880 10 : char key[DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN + 1] = { '\0' };
881 : int i = 0;
882 : int log_level = 0;
883 :
884 10 : PRINT_FUNCTION_VERBOSE(verbose);
885 :
886 10 : if ((daemon == NULL) || (daemon_local == NULL) || (dev_num < 0))
887 : {
888 1 : dlt_vlog(LOG_ERR,
889 : "Invalid function parameters used for %s\n",
890 : __func__);
891 1 : return;
892 : }
893 :
894 9 : handle = &(daemon->storage_handle[dev_num]);
895 :
896 9 : if ((handle->connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) ||
897 9 : (handle->config_status != DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE))
898 : return;
899 :
900 : /* for all filters (keys) check if application or context already running
901 : * and log level need to be updated*/
902 9 : tmp = &(handle->config_list);
903 44 : while (*(tmp) != NULL)
904 : {
905 70 : for (i = 0; i < (*tmp)->num_keys; i++)
906 : {
907 : memset(key, 0, sizeof(key));
908 :
909 35 : strncpy(key, ((*tmp)->key_list
910 35 : + (i * DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN)),
911 : DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN);
912 :
913 : /* Obtain storage configuration data */
914 35 : log_level = dlt_logstorage_get_loglevel_by_key(handle, key);
915 35 : if (log_level < 0)
916 : {
917 0 : dlt_log(LOG_ERR, "Failed to get log level by key \n");
918 0 : return;
919 : }
920 :
921 : /* Update context log level with storage configuration log level */
922 35 : dlt_logstorage_update_context_loglevel(daemon,
923 : daemon_local,
924 : key,
925 : log_level,
926 : verbose);
927 : }
928 35 : tmp = &(*tmp)->next;
929 : }
930 :
931 : return;
932 : }
933 :
934 : /**
935 : * dlt_daemon_logstorage_get_loglevel
936 : *
937 : * Obtain log level as a union of all configured storage devices and filters for
938 : * the provided application id and context id
939 : *
940 : * @param daemon Pointer to DLT Daemon structure
941 : * @param max_device Maximum storage devices setup by the daemon
942 : * @param apid Application ID
943 : * @param ctid Context ID
944 : * @return Log level on success, -1 on error
945 : */
946 35 : int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon,
947 : int max_device,
948 : char *apid,
949 : char *ctid)
950 : {
951 35 : DltLogStorageFilterConfig *config[DLT_CONFIG_FILE_SECTIONS_MAX] = { 0 };
952 : int i = 0;
953 : int j = 0;
954 : int8_t storage_loglevel = -1;
955 : int8_t configured_loglevel = -1;
956 : int num_config = 0;
957 :
958 35 : if ((daemon == NULL) || (max_device == 0) || (apid == NULL) || (ctid == NULL))
959 : return DLT_RETURN_WRONG_PARAMETER;
960 :
961 68 : for (i = 0; i < max_device; i++)
962 34 : if (daemon->storage_handle[i].config_status ==
963 : DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) {
964 34 : num_config = dlt_logstorage_get_config(&(daemon->storage_handle[i]),
965 : config,
966 : apid,
967 : ctid,
968 34 : daemon->ecuid);
969 :
970 34 : if (num_config == 0) {
971 1 : dlt_log(LOG_DEBUG, "No valid filter configuration found\n");
972 1 : continue;
973 : }
974 :
975 66 : for (j = 0; j < num_config; j++)
976 : {
977 33 : if (config[j] == NULL)
978 0 : continue;
979 :
980 : /* If logstorage configuration do not contain file name,
981 : * then it is non verbose control filter, so return level as in this filter */
982 33 : if (config[j]->file_name == NULL) {
983 0 : storage_loglevel = config[j]->log_level;
984 0 : break;
985 : }
986 :
987 33 : configured_loglevel = config[j]->log_level;
988 33 : storage_loglevel = DLT_OFFLINE_LOGSTORAGE_MAX(
989 : configured_loglevel,
990 : storage_loglevel);
991 : }
992 : }
993 :
994 34 : return storage_loglevel;
995 : }
996 :
997 : /**
998 : * dlt_daemon_logstorage_write
999 : *
1000 : * Write log message to all attached storage device. If the called
1001 : * dlt_logstorage_write function is not able to write to the device, DltDaemon
1002 : * will disconnect this device.
1003 : *
1004 : * @param daemon Pointer to Dlt Daemon structure
1005 : * @param user_config DltDaemon configuration
1006 : * @param data1 message header buffer
1007 : * @param size1 message header buffer size
1008 : * @param data2 message extended header buffer
1009 : * @param size2 message extended header size
1010 : * @param data3 message data buffer
1011 : * @param size3 message data size
1012 : * @return 0 on success, -1 on error, 1 on disable network routing
1013 : */
1014 5841 : int dlt_daemon_logstorage_write(DltDaemon *daemon,
1015 : DltDaemonFlags *user_config,
1016 : unsigned char *data1,
1017 : int size1,
1018 : unsigned char *data2,
1019 : int size2,
1020 : unsigned char *data3,
1021 : int size3)
1022 : {
1023 : int i = 0;
1024 : int ret = 0;
1025 : DltLogStorageUserConfig file_config;
1026 :
1027 5841 : if ((daemon == NULL) || (user_config == NULL) ||
1028 5840 : (user_config->offlineLogstorageMaxDevices <= 0) || (data1 == NULL) ||
1029 5840 : (data2 == NULL) || (data3 == NULL)) {
1030 1 : dlt_vlog(LOG_DEBUG,
1031 : "%s: message type is not LOG. Skip storing.\n",
1032 : __func__);
1033 1 : return -1;
1034 : /* Log Level changed callback */
1035 : }
1036 :
1037 : /* Copy user configuration */
1038 5840 : file_config.logfile_timestamp = user_config->offlineLogstorageTimestamp;
1039 5840 : file_config.logfile_delimiter = user_config->offlineLogstorageDelimiter;
1040 5840 : file_config.logfile_maxcounter = user_config->offlineLogstorageMaxCounter;
1041 5840 : file_config.logfile_optional_counter = user_config->offlineLogstorageOptionalCounter;
1042 5840 : file_config.logfile_counteridxlen =
1043 5840 : user_config->offlineLogstorageMaxCounterIdx;
1044 :
1045 11680 : for (i = 0; i < user_config->offlineLogstorageMaxDevices; i++) {
1046 5840 : if (daemon->storage_handle[i].config_status ==
1047 : DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE) {
1048 5840 : int disable_nw = 0;
1049 5840 : if ((ret = dlt_logstorage_write(&(daemon->storage_handle[i]),
1050 : &file_config,
1051 : data1,
1052 : size1,
1053 : data2,
1054 : size2,
1055 : data3,
1056 : size3,
1057 : &disable_nw)) < 0) {
1058 0 : dlt_log(LOG_ERR,
1059 : "dlt_daemon_logstorage_write: failed. "
1060 : "Disable storage device\n");
1061 : /* DLT_OFFLINE_LOGSTORAGE_MAX_ERRORS happened,
1062 : * therefore remove logstorage device */
1063 0 : dlt_logstorage_device_disconnected(
1064 0 : &(daemon->storage_handle[i]),
1065 : DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT);
1066 : }
1067 5840 : if (i == 0) {
1068 5840 : if (disable_nw == 1) {
1069 : ret = 1;
1070 : }
1071 : } else {
1072 0 : dlt_vlog(LOG_WARNING,
1073 : "%s: DisableNetwork is not supported for more than one device yet\n",
1074 : __func__);
1075 : }
1076 : }
1077 : }
1078 :
1079 : return ret;
1080 : }
1081 :
1082 : /**
1083 : * dlt_daemon_logstorage_setup_internal_storage
1084 : *
1085 : * Setup user defined path as offline log storage device
1086 : *
1087 : * @param daemon Pointer to Dlt Daemon structure
1088 : * @param daemon_local Pointer to Dlt Daemon local structure
1089 : * @param path User configured internal storage path
1090 : * @param verbose If set to true verbose information is printed out
1091 : * @return 0 on sucess, -1 otherwise
1092 : */
1093 8 : int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon,
1094 : DltDaemonLocal *daemon_local,
1095 : char *path,
1096 : int verbose)
1097 : {
1098 : int ret = 0;
1099 :
1100 8 : PRINT_FUNCTION_VERBOSE(verbose);
1101 :
1102 8 : if ((path == NULL) || (daemon == NULL))
1103 : return DLT_RETURN_WRONG_PARAMETER;
1104 :
1105 : /* connect internal storage device */
1106 : /* Device index always used as 0 as it is setup on DLT daemon startup */
1107 7 : ret = dlt_logstorage_device_connected(&(daemon->storage_handle[0]), path);
1108 :
1109 7 : if (ret != 0) {
1110 0 : dlt_vlog(LOG_ERR, "%s: Device connect failed\n", __func__);
1111 0 : return DLT_RETURN_ERROR;
1112 : }
1113 :
1114 : /* check if log level of running application need an update */
1115 7 : dlt_daemon_logstorage_update_application_loglevel(daemon,
1116 : daemon_local,
1117 : 0,
1118 : verbose);
1119 :
1120 7 : if (daemon->storage_handle[0].maintain_logstorage_loglevel !=
1121 : DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF) {
1122 0 : daemon->maintain_logstorage_loglevel =
1123 : daemon->storage_handle[0].maintain_logstorage_loglevel;
1124 :
1125 0 : dlt_vlog(LOG_DEBUG, "[%s] Startup with maintain loglevel: [%d]\n",
1126 : __func__,
1127 : daemon->storage_handle[0].maintain_logstorage_loglevel);
1128 : }
1129 :
1130 : return ret;
1131 : }
1132 :
1133 10 : void dlt_daemon_logstorage_set_logstorage_cache_size(unsigned int size)
1134 : {
1135 : /* store given [KB] size in [Bytes] */
1136 10 : g_logstorage_cache_max = size * 1024;
1137 10 : }
1138 :
1139 8 : int dlt_daemon_logstorage_cleanup(DltDaemon *daemon,
1140 : DltDaemonLocal *daemon_local,
1141 : int verbose)
1142 : {
1143 : int i = 0;
1144 :
1145 8 : PRINT_FUNCTION_VERBOSE(verbose);
1146 :
1147 8 : if ((daemon == NULL) || (daemon_local == NULL) || (daemon->storage_handle == NULL))
1148 : return DLT_RETURN_WRONG_PARAMETER;
1149 :
1150 14 : for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
1151 : /* call disconnect on all currently connected devices */
1152 7 : if (daemon->storage_handle[i].connection_type ==
1153 : DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
1154 : {
1155 6 : (&daemon->storage_handle[i])->uconfig.logfile_counteridxlen =
1156 6 : daemon_local->flags.offlineLogstorageMaxCounterIdx;
1157 6 : (&daemon->storage_handle[i])->uconfig.logfile_delimiter =
1158 6 : daemon_local->flags.offlineLogstorageDelimiter;
1159 6 : (&daemon->storage_handle[i])->uconfig.logfile_maxcounter =
1160 6 : daemon_local->flags.offlineLogstorageMaxCounter;
1161 6 : (&daemon->storage_handle[i])->uconfig.logfile_timestamp =
1162 6 : daemon_local->flags.offlineLogstorageTimestamp;
1163 6 : (&daemon->storage_handle[i])->uconfig.logfile_optional_counter =
1164 6 : daemon_local->flags.offlineLogstorageOptionalCounter;
1165 :
1166 6 : dlt_logstorage_device_disconnected(
1167 : &daemon->storage_handle[i],
1168 : DLT_LOGSTORAGE_SYNC_ON_DAEMON_EXIT);
1169 : }
1170 :
1171 : return 0;
1172 : }
1173 :
1174 4 : int dlt_daemon_logstorage_sync_cache(DltDaemon *daemon,
1175 : DltDaemonLocal *daemon_local,
1176 : char *mnt_point,
1177 : int verbose)
1178 : {
1179 : int i = 0;
1180 : DltLogStorage *handle = NULL;
1181 :
1182 4 : PRINT_FUNCTION_VERBOSE(verbose);
1183 :
1184 4 : if ((daemon == NULL) || (daemon_local == NULL) || (mnt_point == NULL))
1185 : return DLT_RETURN_WRONG_PARAMETER;
1186 :
1187 3 : if (strlen(mnt_point) > 0) { /* mount point is given */
1188 3 : handle = dlt_daemon_logstorage_get_device(daemon,
1189 : daemon_local,
1190 : mnt_point,
1191 : verbose);
1192 :
1193 3 : if (handle == NULL) {
1194 : return DLT_RETURN_ERROR;
1195 : }
1196 : else {
1197 3 : handle->uconfig.logfile_counteridxlen =
1198 3 : daemon_local->flags.offlineLogstorageMaxCounterIdx;
1199 3 : handle->uconfig.logfile_delimiter =
1200 3 : daemon_local->flags.offlineLogstorageDelimiter;
1201 3 : handle->uconfig.logfile_maxcounter =
1202 3 : daemon_local->flags.offlineLogstorageMaxCounter;
1203 3 : handle->uconfig.logfile_timestamp =
1204 3 : daemon_local->flags.offlineLogstorageTimestamp;
1205 3 : handle->uconfig.logfile_optional_counter =
1206 3 : daemon_local->flags.offlineLogstorageOptionalCounter;
1207 :
1208 3 : if (dlt_logstorage_sync_caches(handle) != 0)
1209 0 : return DLT_RETURN_ERROR;
1210 : }
1211 : }
1212 : else { /* sync caches for all connected logstorage devices */
1213 :
1214 0 : for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++)
1215 0 : if (daemon->storage_handle[i].connection_type ==
1216 : DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) {
1217 0 : daemon->storage_handle[i].uconfig.logfile_counteridxlen =
1218 0 : daemon_local->flags.offlineLogstorageMaxCounterIdx;
1219 0 : daemon->storage_handle[i].uconfig.logfile_delimiter =
1220 0 : daemon_local->flags.offlineLogstorageDelimiter;
1221 0 : daemon->storage_handle[i].uconfig.logfile_maxcounter =
1222 0 : daemon_local->flags.offlineLogstorageMaxCounter;
1223 0 : daemon->storage_handle[i].uconfig.logfile_timestamp =
1224 0 : daemon_local->flags.offlineLogstorageTimestamp;
1225 0 : daemon->storage_handle[i].uconfig.logfile_optional_counter =
1226 0 : daemon_local->flags.offlineLogstorageOptionalCounter;
1227 :
1228 0 : if (dlt_logstorage_sync_caches(&daemon->storage_handle[i]) != 0)
1229 : return DLT_RETURN_ERROR;
1230 : }
1231 : }
1232 :
1233 : return 0;
1234 : }
1235 :
1236 5 : DltLogStorage *dlt_daemon_logstorage_get_device(DltDaemon *daemon,
1237 : DltDaemonLocal *daemon_local,
1238 : char *mnt_point,
1239 : int verbose)
1240 : {
1241 : int i = 0;
1242 : int len = 0;
1243 : int len1 = 0;
1244 : int len2 = 0;
1245 :
1246 5 : PRINT_FUNCTION_VERBOSE(verbose);
1247 :
1248 5 : if ((daemon == NULL) || (daemon_local == NULL) || (mnt_point == NULL))
1249 : return NULL;
1250 :
1251 4 : len1 = strlen(mnt_point);
1252 :
1253 4 : for (i = 0; i < daemon_local->flags.offlineLogstorageMaxDevices; i++) {
1254 4 : len2 = strlen(daemon->storage_handle[i].device_mount_point);
1255 :
1256 : /* Check if the requested device path is already used as log storage
1257 : * device. Check for strlen first, to avoid comparison errors when
1258 : * final '/' is given or not */
1259 4 : len = len1 > len2 ? len2 : len1;
1260 :
1261 4 : if (strncmp(daemon->storage_handle[i].device_mount_point, mnt_point, len) == 0)
1262 4 : return &daemon->storage_handle[i];
1263 : }
1264 :
1265 : return NULL;
1266 : }
|