-
Notifications
You must be signed in to change notification settings - Fork 325
Expand file tree
/
Copy pathdlt-daemon.c
More file actions
4013 lines (3373 loc) · 142 KB
/
dlt-daemon.c
File metadata and controls
4013 lines (3373 loc) · 142 KB
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* SPDX license identifier: MPL-2.0
*
* Copyright (C) 2011-2015, BMW AG
*
* This file is part of COVESA Project DLT - Diagnostic Log and Trace.
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License (MPL), 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/.
*
* For further information see http://www.covesa.org/.
*/
/*!
* \author
* Alexander Wenzel <alexander.aw.wenzel@bmw.de>
* Markus Klein <Markus.Klein@esk.fraunhofer.de>
* Mikko Rapeli <mikko.rapeli@bmw.de>
*
* \copyright Copyright © 2011-2015 BMW AG. \n
* License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
*
* \file dlt-daemon.c
*/
#include <netdb.h>
#include <ctype.h>
#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), connect(), (), and recv() */
#include <sys/un.h>
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() and access */
#include <fcntl.h>
#include <signal.h>
#include <syslog.h>
#include <errno.h>
#include <pthread.h>
#include <grp.h>
#ifdef linux
# include <sys/timerfd.h>
#endif
#include <sys/stat.h>
#include <sys/time.h>
#include <libgen.h>
#if defined(linux) && defined(__NR_statx)
# include <linux/stat.h>
#endif
#ifdef DLT_DAEMON_VSOCK_IPC_ENABLE
# ifdef linux
# include <linux/vm_sockets.h>
# endif
# ifdef __QNX__
# include <vm_sockets.h>
# endif
#endif
#include "dlt_types.h"
#include "dlt-daemon.h"
#include "dlt-daemon_cfg.h"
#include "dlt_daemon_common_cfg.h"
#include "dlt_daemon_socket.h"
#include "dlt_daemon_unix_socket.h"
#include "dlt_daemon_serial.h"
#include "dlt_daemon_client.h"
#include "dlt_daemon_connection.h"
#include "dlt_daemon_event_handler.h"
#include "dlt_daemon_offline_logstorage.h"
#include "dlt_gateway.h"
#ifdef UDP_CONNECTION_SUPPORT
# include "dlt_daemon_udp_socket.h"
#endif
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
# include "sd-daemon.h"
#endif
/**
* \defgroup daemon DLT Daemon
* \addtogroup daemon
\{
*/
static int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, char *str, int verbose);
static int dlt_daemon_check_numeric_setting(char *token,
char *value,
unsigned long *data);
/* used in main event loop and signal handler */
int g_exit = 0;
int g_signo = 0;
/* used for value from conf file */
static int value_length = 1024;
static char dlt_timer_conn_types[DLT_TIMER_UNKNOWN + 1] = {
[DLT_TIMER_PACKET] = DLT_CONNECTION_ONE_S_TIMER,
[DLT_TIMER_ECU] = DLT_CONNECTION_SIXTY_S_TIMER,
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
[DLT_TIMER_SYSTEMD] = DLT_CONNECTION_SYSTEMD_TIMER,
#endif
[DLT_TIMER_GATEWAY] = DLT_CONNECTION_GATEWAY_TIMER,
[DLT_TIMER_UNKNOWN] = DLT_CONNECTION_TYPE_MAX
};
static char dlt_timer_names[DLT_TIMER_UNKNOWN + 1][32] = {
[DLT_TIMER_PACKET] = "Timing packet",
[DLT_TIMER_ECU] = "ECU version",
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
[DLT_TIMER_SYSTEMD] = "Systemd watchdog",
#endif
[DLT_TIMER_GATEWAY] = "Gateway",
[DLT_TIMER_UNKNOWN] = "Unknown timer"
};
#ifdef __QNX__
static int dlt_timer_pipes[DLT_TIMER_UNKNOWN][2] = {
/* [timer_id] = {read_pipe, write_pipe} */
[DLT_TIMER_PACKET] = {DLT_FD_INIT, DLT_FD_INIT},
[DLT_TIMER_ECU] = {DLT_FD_INIT, DLT_FD_INIT},
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
[DLT_TIMER_SYSTEMD] = {DLT_FD_INIT, DLT_FD_INIT},
#endif
[DLT_TIMER_GATEWAY] = {DLT_FD_INIT, DLT_FD_INIT}
};
static pthread_t timer_threads[DLT_TIMER_UNKNOWN] = {
[DLT_TIMER_PACKET] = 0,
[DLT_TIMER_ECU] = 0,
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
[DLT_TIMER_SYSTEMD] = 0,
#endif
[DLT_TIMER_GATEWAY] = 0
};
static DltDaemonPeriodicData *timer_data[DLT_TIMER_UNKNOWN] = {
[DLT_TIMER_PACKET] = NULL,
[DLT_TIMER_ECU] = NULL,
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
[DLT_TIMER_SYSTEMD] = NULL,
#endif
[DLT_TIMER_GATEWAY] = NULL
};
void close_pipes(int fds[2])
{
if (fds[0] > 0) {
close(fds[0]);
fds[0] = DLT_FD_INIT;
}
if (fds[1] > 0) {
close(fds[1]);
fds[1] = DLT_FD_INIT;
}
}
#endif // __QNX__
/**
* Print usage information of tool.
*/
void usage()
{
char version[DLT_DAEMON_TEXTBUFSIZE];
dlt_get_version(version, DLT_DAEMON_TEXTBUFSIZE);
/*printf("DLT logging daemon %s %s\n", _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE); */
/*printf("Compile options: %s %s %s %s",_DLT_SYSTEMD_ENABLE, _DLT_SYSTEMD_WATCHDOG_ENABLE, _DLT_TEST_ENABLE, _DLT_SHM_ENABLE); */
printf("%s", version);
printf("Usage: dlt-daemon [options]\n");
printf("Options:\n");
printf(" -d Daemonize\n");
printf(" -h Usage\n");
printf(" -c filename DLT daemon configuration file (Default: " CONFIGURATION_FILES_DIR "/dlt.conf)\n");
#ifdef DLT_DAEMON_USE_FIFO_IPC
printf(" -t directory Directory for local fifo and user-pipes (Default: /tmp)\n");
printf(" (Applications wanting to connect to a daemon using a\n");
printf(" custom directory need to be started with the environment \n");
printf(" variable DLT_PIPE_DIR set appropriately)\n");
#endif
#ifdef DLT_SHM_ENABLE
printf(" -s filename The file name to create the share memory (Default: /dlt-shm)\n");
printf(" (Applications wanting to connect to a daemon using a\n");
printf(" custom shm name need to be started with the environment \n");
printf(" variable DLT_SHM_NAME set appropriately)\n");
#endif
printf(" -p port port to monitor for incoming requests (Default: 3490)\n");
printf(" (Applications wanting to connect to a daemon using a custom\n");
printf(" port need to be started with the environment variable\n");
printf(" DLT_DAEMON_TCP_PORT set appropriately)\n");
#ifdef DLT_LOG_LEVEL_APP_CONFIG
printf(" -a filename The filename for load default app id log levels (Default: " CONFIGURATION_FILES_DIR "/dlt-log-levels.conf)\n");
#endif
#
} /* usage() */
/**
* Option handling
*/
int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
{
int c;
char options[255];
memset(options, 0, sizeof options);
const char *const default_options = "hdc:t:p:";
strcpy(options, default_options);
if (daemon_local == 0) {
fprintf (stderr, "Invalid parameter passed to option_handling()\n");
return -1;
}
/* Initialize flags */
memset(daemon_local, 0, sizeof(DltDaemonLocal));
/* default values */
daemon_local->flags.port = DLT_DAEMON_TCP_PORT;
#ifdef DLT_DAEMON_USE_FIFO_IPC
dlt_log_set_fifo_basedir(DLT_USER_IPC_PATH);
#endif
#ifdef DLT_SHM_ENABLE
strncpy(dltShmName, "/dlt-shm", NAME_MAX);
#endif
opterr = 0;
#ifdef DLT_SHM_ENABLE
strcpy(options + strlen(options), "s:");
#endif
#ifdef DLT_LOG_LEVEL_APP_CONFIG
strcpy(options + strlen(options), "a:");
#endif
while ((c = getopt(argc, argv, options)) != -1)
switch (c) {
case 'd':
{
daemon_local->flags.dflag = 1;
break;
}
case 'c':
{
strncpy(daemon_local->flags.cvalue, optarg, NAME_MAX);
break;
}
#ifdef DLT_LOG_LEVEL_APP_CONFIG
case 'a':
{
strncpy(daemon_local->flags.avalue, optarg, NAME_MAX);
break;
}
#endif
#ifdef DLT_DAEMON_USE_FIFO_IPC
case 't':
{
dlt_log_set_fifo_basedir(optarg);
break;
}
#endif
#ifdef DLT_SHM_ENABLE
case 's':
{
strncpy(dltShmName, optarg, NAME_MAX);
break;
}
#endif
case 'p':
{
daemon_local->flags.port = (unsigned int) atoi(optarg);
if (daemon_local->flags.port == 0) {
fprintf (stderr, "Invalid port `%s' specified.\n", optarg);
return -1;
}
break;
}
case 'h':
{
usage();
return -2; /* return no error */
}
case '?':
{
if ((optopt == 'c') || (optopt == 't') || (optopt == 'p')
#ifdef DLT_LOG_LEVEL_APP_CONFIG
|| (optopt == 'a')
#endif
)
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr, "Unknown option character `\\x%x'.\n", (uint32_t)optopt);
/* unknown or wrong option used, show usage information and terminate */
usage();
return -1;
}
default:
{
fprintf (stderr, "Invalid option, this should never occur!\n");
return -1;
}
}
/* switch() */
#ifdef DLT_DAEMON_USE_FIFO_IPC
snprintf(daemon_local->flags.userPipesDir, DLT_PATH_MAX,
"%s/dltpipes", dltFifoBaseDir);
snprintf(daemon_local->flags.daemonFifoName, DLT_PATH_MAX,
"%s/dlt", dltFifoBaseDir);
#endif
#ifdef DLT_SHM_ENABLE
strncpy(daemon_local->flags.dltShmName, dltShmName, NAME_MAX);
#endif
return 0;
} /* option_handling() */
/**
* Option file parser
*/
int option_file_parser(DltDaemonLocal *daemon_local)
{
FILE *pFile;
char line[value_length - 1];
char token[value_length];
char value[value_length];
char *pch;
const char *filename;
ssize_t n;
/* set default values for configuration */
daemon_local->flags.sharedMemorySize = DLT_SHM_SIZE;
daemon_local->flags.sendMessageTime = 0;
daemon_local->flags.offlineTraceDirectory[0] = 0;
daemon_local->flags.offlineTraceFileSize = 1000000;
daemon_local->flags.offlineTraceMaxSize = 4000000;
daemon_local->flags.offlineTraceFilenameTimestampBased = true;
daemon_local->flags.loggingMode = DLT_LOG_TO_CONSOLE;
daemon_local->flags.loggingLevel = LOG_INFO;
#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC
n = snprintf(daemon_local->flags.loggingFilename,
sizeof(daemon_local->flags.loggingFilename),
"%s/dlt.log", DLT_USER_IPC_PATH);
#else /* DLT_DAEMON_USE_FIFO_IPC */
n = snprintf(daemon_local->flags.loggingFilename,
sizeof(daemon_local->flags.loggingFilename),
"%s/dlt.log", dltFifoBaseDir);
#endif
if (n < 0 || (size_t)n > sizeof(daemon_local->flags.loggingFilename)) {
dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%ld) %s\n",
__func__, n, daemon_local->flags.loggingFilename);
}
daemon_local->flags.enableLoggingFileLimit = false;
daemon_local->flags.loggingFileSize = 250000;
daemon_local->flags.loggingFileMaxSize = 1000000;
daemon_local->timeoutOnSend = 4;
daemon_local->RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE;
daemon_local->RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE;
daemon_local->RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE;
daemon_local->daemonFifoSize = 0;
daemon_local->flags.sendECUSoftwareVersion = 0;
memset(daemon_local->flags.pathToECUSoftwareVersion, 0, sizeof(daemon_local->flags.pathToECUSoftwareVersion));
memset(daemon_local->flags.ecuSoftwareVersionFileField, 0, sizeof(daemon_local->flags.ecuSoftwareVersionFileField));
daemon_local->flags.sendTimezone = 0;
daemon_local->flags.offlineLogstorageMaxDevices = 0;
daemon_local->flags.offlineLogstorageDirPath[0] = 0;
daemon_local->flags.offlineLogstorageTimestamp = 1;
daemon_local->flags.offlineLogstorageDelimiter = '_';
daemon_local->flags.offlineLogstorageMaxCounter = UINT_MAX;
daemon_local->flags.offlineLogstorageMaxCounterIdx = 0;
daemon_local->flags.offlineLogstorageOptionalCounter = false;
daemon_local->flags.offlineLogstorageCacheSize = 30000; /* 30MB */
dlt_daemon_logstorage_set_logstorage_cache_size(
daemon_local->flags.offlineLogstorageCacheSize);
strncpy(daemon_local->flags.ctrlSockPath,
DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH,
sizeof(daemon_local->flags.ctrlSockPath));
#ifdef DLT_DAEMON_USE_UNIX_SOCKET_IPC
snprintf(daemon_local->flags.appSockPath, DLT_IPC_PATH_MAX, "%s/dlt", DLT_USER_IPC_PATH);
if (strlen(DLT_USER_IPC_PATH) > DLT_IPC_PATH_MAX)
fprintf(stderr, "Provided path too long...trimming it to path[%s]\n",
daemon_local->flags.appSockPath);
#else /* DLT_DAEMON_USE_FIFO_IPC */
memset(daemon_local->flags.daemonFifoGroup, 0, sizeof(daemon_local->flags.daemonFifoGroup));
#endif
daemon_local->flags.gatewayMode = 0;
strncpy(daemon_local->flags.gatewayConfigFile,
DLT_GATEWAY_CONFIG_PATH,
DLT_DAEMON_FLAG_MAX);
daemon_local->flags.autoResponseGetLogInfoOption = 7;
daemon_local->flags.contextLogLevel = DLT_LOG_INFO;
daemon_local->flags.contextTraceStatus = DLT_TRACE_STATUS_OFF;
daemon_local->flags.enforceContextLLAndTS = 0; /* default is off */
#ifdef UDP_CONNECTION_SUPPORT
daemon_local->UDPConnectionSetup = MULTICAST_CONNECTION_ENABLED;
strncpy(daemon_local->UDPMulticastIPAddress, MULTICASTIPADDRESS, MULTICASTIP_MAX_SIZE - 1);
daemon_local->UDPMulticastIPPort = MULTICASTIPPORT;
#endif
daemon_local->flags.ipNodes = NULL;
daemon_local->flags.injectionMode = 1;
/* open configuration file */
if (daemon_local->flags.cvalue[0])
filename = daemon_local->flags.cvalue;
else
filename = CONFIGURATION_FILES_DIR "/dlt.conf";
/*printf("Load configuration from file: %s\n",filename); */
pFile = fopen (filename, "r");
if (pFile != NULL) {
while (1) {
/* fetch line from configuration file */
if (fgets (line, value_length - 1, pFile) != NULL) {
pch = strtok (line, " =\r\n");
token[0] = 0;
value[0] = 0;
while (pch != NULL) {
if (strcmp(pch, "#") == 0)
break;
if (token[0] == 0) {
strncpy(token, pch, sizeof(token) - 1);
token[sizeof(token) - 1] = 0;
}
else {
strncpy(value, pch, sizeof(value) - 1);
value[sizeof(value) - 1] = 0;
break;
}
pch = strtok (NULL, " =\r\n");
}
if (token[0] && value[0]) {
/* parse arguments here */
if (strcmp(token, "Verbose") == 0) {
daemon_local->flags.vflag = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "PrintASCII") == 0)
{
daemon_local->flags.aflag = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "PrintHex") == 0)
{
daemon_local->flags.xflag = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "PrintHeadersOnly") == 0)
{
daemon_local->flags.sflag = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "SendSerialHeader") == 0)
{
daemon_local->flags.lflag = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "SendContextRegistration") == 0)
{
daemon_local->flags.rflag = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "SendContextRegistrationOption") == 0)
{
daemon_local->flags.autoResponseGetLogInfoOption = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "SendMessageTime") == 0)
{
daemon_local->flags.sendMessageTime = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "RS232SyncSerialHeader") == 0)
{
daemon_local->flags.mflag = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "TCPSyncSerialHeader") == 0)
{
daemon_local->flags.nflag = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "RS232DeviceName") == 0)
{
strncpy(daemon_local->flags.yvalue, value, NAME_MAX);
daemon_local->flags.yvalue[NAME_MAX] = 0;
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "RS232Baudrate") == 0)
{
strncpy(daemon_local->flags.bvalue, value, NAME_MAX);
daemon_local->flags.bvalue[NAME_MAX] = 0;
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "ECUId") == 0)
{
strncpy(daemon_local->flags.evalue, value, NAME_MAX);
daemon_local->flags.evalue[NAME_MAX] = 0;
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "PersistanceStoragePath") == 0)
{
strncpy(daemon_local->flags.ivalue, value, NAME_MAX);
daemon_local->flags.ivalue[NAME_MAX] = 0;
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "LoggingMode") == 0)
{
daemon_local->flags.loggingMode = (DltLoggingMode)atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "LoggingLevel") == 0)
{
daemon_local->flags.loggingLevel = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "LoggingFilename") == 0)
{
strncpy(daemon_local->flags.loggingFilename,
value,
sizeof(daemon_local->flags.loggingFilename) - 1);
daemon_local->flags.loggingFilename[sizeof(daemon_local->flags.loggingFilename) - 1] = 0;
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "EnableLoggingFileLimit") == 0)
{
daemon_local->flags.enableLoggingFileLimit = (bool)atoi(value);
}
else if (strcmp(token, "LoggingFileSize") == 0)
{
daemon_local->flags.loggingFileSize = atoi(value);
}
else if (strcmp(token, "LoggingFileMaxSize") == 0)
{
daemon_local->flags.loggingFileMaxSize = atoi(value);
}
else if (strcmp(token, "TimeOutOnSend") == 0)
{
daemon_local->timeoutOnSend = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "RingbufferMinSize") == 0)
{
if (dlt_daemon_check_numeric_setting(token,
value, &(daemon_local->RingbufferMinSize)) < 0) {
fclose (pFile);
return -1;
}
}
else if (strcmp(token, "RingbufferMaxSize") == 0)
{
if (dlt_daemon_check_numeric_setting(token,
value, &(daemon_local->RingbufferMaxSize)) < 0) {
fclose (pFile);
return -1;
}
}
else if (strcmp(token, "RingbufferStepSize") == 0)
{
if (dlt_daemon_check_numeric_setting(token,
value, &(daemon_local->RingbufferStepSize)) < 0) {
fclose (pFile);
return -1;
}
}
else if (strcmp(token, "SharedMemorySize") == 0)
{
daemon_local->flags.sharedMemorySize = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "OfflineTraceDirectory") == 0)
{
strncpy(daemon_local->flags.offlineTraceDirectory, value,
sizeof(daemon_local->flags.offlineTraceDirectory) - 1);
daemon_local->flags.offlineTraceDirectory[sizeof(daemon_local->flags.offlineTraceDirectory) -
1] = 0;
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "OfflineTraceFileSize") == 0)
{
daemon_local->flags.offlineTraceFileSize = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "OfflineTraceMaxSize") == 0)
{
daemon_local->flags.offlineTraceMaxSize = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "OfflineTraceFileNameTimestampBased") == 0)
{
daemon_local->flags.offlineTraceFilenameTimestampBased = (bool)atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "SendECUSoftwareVersion") == 0)
{
daemon_local->flags.sendECUSoftwareVersion = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "PathToECUSoftwareVersion") == 0)
{
strncpy(daemon_local->flags.pathToECUSoftwareVersion, value,
sizeof(daemon_local->flags.pathToECUSoftwareVersion) - 1);
daemon_local->flags.pathToECUSoftwareVersion[sizeof(daemon_local->flags.pathToECUSoftwareVersion)
- 1] = 0;
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "ECUSoftwareVersionFileField") == 0) {
strncpy(daemon_local->flags.ecuSoftwareVersionFileField, value,
sizeof(daemon_local->flags.ecuSoftwareVersionFileField) - 1);
daemon_local->flags.ecuSoftwareVersionFileField[sizeof(daemon_local->flags.ecuSoftwareVersionFileField)
- 1] = 0;
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "SendTimezone") == 0)
{
daemon_local->flags.sendTimezone = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "OfflineLogstorageMaxDevices") == 0)
{
daemon_local->flags.offlineLogstorageMaxDevices = (uint32_t) atoi(value);
}
else if (strcmp(token, "OfflineLogstorageDirPath") == 0)
{
strncpy(daemon_local->flags.offlineLogstorageDirPath,
value,
sizeof(daemon_local->flags.offlineLogstorageDirPath) - 1);
}
else if (strcmp(token, "OfflineLogstorageTimestamp") == 0)
{
/* Check if set to 0, default otherwise */
if (atoi(value) == 0)
daemon_local->flags.offlineLogstorageTimestamp = 0;
}
else if (strcmp(token, "OfflineLogstorageDelimiter") == 0)
{
/* Check if valid punctuation, default otherwise*/
if (ispunct((char)value[0]))
daemon_local->flags.offlineLogstorageDelimiter = (char)value[0];
}
else if (strcmp(token, "OfflineLogstorageMaxCounter") == 0)
{
daemon_local->flags.offlineLogstorageMaxCounter = (unsigned int) atoi(value);
daemon_local->flags.offlineLogstorageMaxCounterIdx = (unsigned int) strlen(value);
} else if (strcmp(token, "OfflineLogstorageOptionalIndex") == 0) {
daemon_local->flags.offlineLogstorageOptionalCounter = atoi(value);
}
else if (strcmp(token, "OfflineLogstorageCacheSize") == 0)
{
daemon_local->flags.offlineLogstorageCacheSize =
(unsigned int)atoi(value);
dlt_daemon_logstorage_set_logstorage_cache_size(
daemon_local->flags.offlineLogstorageCacheSize);
}
else if (strcmp(token, "ControlSocketPath") == 0)
{
memset(
daemon_local->flags.ctrlSockPath,
0,
DLT_DAEMON_FLAG_MAX);
strncpy(
daemon_local->flags.ctrlSockPath,
value,
DLT_DAEMON_FLAG_MAX - 1);
}
else if (strcmp(token, "GatewayMode") == 0)
{
daemon_local->flags.gatewayMode = atoi(value);
/*printf("Option: %s=%s\n",token,value); */
}
else if (strcmp(token, "GatewayConfigFile") == 0)
{
memset(
daemon_local->flags.gatewayConfigFile,
0,
DLT_DAEMON_FLAG_MAX);
strncpy(
daemon_local->flags.gatewayConfigFile,
value,
DLT_DAEMON_FLAG_MAX - 1);
}
else if (strcmp(token, "ContextLogLevel") == 0)
{
int const intval = atoi(value);
if ((intval >= DLT_LOG_OFF) && (intval <= DLT_LOG_VERBOSE)) {
daemon_local->flags.contextLogLevel = intval;
printf("Option: %s=%s\n", token, value);
}
else {
fprintf(stderr,
"Invalid value for ContextLogLevel: %i. Must be in range [%i..%i]\n",
intval,
DLT_LOG_OFF,
DLT_LOG_VERBOSE);
}
}
else if (strcmp(token, "ContextTraceStatus") == 0)
{
int const intval = atoi(value);
if ((intval >= DLT_TRACE_STATUS_OFF) && (intval <= DLT_TRACE_STATUS_ON)) {
daemon_local->flags.contextTraceStatus = intval;
printf("Option: %s=%s\n", token, value);
}
else {
fprintf(stderr,
"Invalid value for ContextTraceStatus: %i. Must be in range [%i..%i]\n",
intval,
DLT_TRACE_STATUS_OFF,
DLT_TRACE_STATUS_ON);
}
}
else if (strcmp(token, "ForceContextLogLevelAndTraceStatus") == 0)
{
int const intval = atoi(value);
if ((intval >= 0) && (intval <= 1)) {
daemon_local->flags.enforceContextLLAndTS = intval;
printf("Option: %s=%s\n", token, value);
}
else {
fprintf(stderr,
"Invalid value for ForceContextLogLevelAndTraceStatus: %i. Must be 0, 1\n",
intval);
}
}
#ifdef DLT_DAEMON_USE_FIFO_IPC
else if (strcmp(token, "DaemonFIFOSize") == 0)
{
if (dlt_daemon_check_numeric_setting(token,
value, &(daemon_local->daemonFifoSize)) < 0) {
fclose (pFile);
return -1;
}
#ifndef __linux__
printf("Option DaemonFIFOSize is set but only supported on Linux. Ignored.\n");
#endif
}
else if (strcmp(token, "DaemonFifoGroup") == 0)
{
strncpy(daemon_local->flags.daemonFifoGroup, value, NAME_MAX);
daemon_local->flags.daemonFifoGroup[NAME_MAX] = 0;
}
#endif
#ifdef UDP_CONNECTION_SUPPORT
else if (strcmp(token, "UDPConnectionSetup") == 0)
{
const long longval = strtol(value, NULL, 10);
if ((longval == MULTICAST_CONNECTION_DISABLED)
|| (longval == MULTICAST_CONNECTION_ENABLED)) {
daemon_local->UDPConnectionSetup = longval;
printf("Option: %s=%s\n", token, value);
}
else {
daemon_local->UDPConnectionSetup = MULTICAST_CONNECTION_DISABLED;
fprintf(stderr,
"Invalid value for UDPConnectionSetup set to default %ld\n",
longval);
}
}
else if (strcmp(token, "UDPMulticastIPAddress") == 0)
{
strncpy(daemon_local->UDPMulticastIPAddress, value,
MULTICASTIP_MAX_SIZE - 1);
}
else if (strcmp(token, "UDPMulticastIPPort") == 0)
{
daemon_local->UDPMulticastIPPort = strtol(value, NULL, 10);
}
#endif
else if (strcmp(token, "BindAddress") == 0)
{
DltBindAddress_t *newNode = NULL;
DltBindAddress_t *temp = NULL;
char *tok = strtok(value, ",;");
if (tok != NULL) {
daemon_local->flags.ipNodes = calloc(1, sizeof(DltBindAddress_t));
if (daemon_local->flags.ipNodes == NULL) {
dlt_vlog(LOG_ERR, "Could not allocate for IP list\n");
fclose(pFile);
return -1;
}
else {
strncpy(daemon_local->flags.ipNodes->ip,
tok,
sizeof(daemon_local->flags.ipNodes->ip) - 1);
daemon_local->flags.ipNodes->next = NULL;
temp = daemon_local->flags.ipNodes;
tok = strtok(NULL, ",;");
while (tok != NULL) {
newNode = calloc(1, sizeof(DltBindAddress_t));
if (newNode == NULL) {
dlt_vlog(LOG_ERR, "Could not allocate for IP list\n");
fclose(pFile);
return -1;
}
else {
strncpy(newNode->ip, tok, sizeof(newNode->ip) - 1);
}
temp->next = newNode;
temp = temp->next;
tok = strtok(NULL, ",;");
}
}
}
else {
dlt_vlog(LOG_WARNING, "BindAddress option is empty\n");
}
}
else if (strcmp(token, "InjectionMode") == 0) {
daemon_local->flags.injectionMode = atoi(value);
}
else {
fprintf(stderr, "Unknown option: %s=%s\n", token, value);
}
}
}
else {
break;
}
}
fclose (pFile);
}
else {
fprintf(stderr, "Cannot open configuration file: %s\n", filename);
}
return 0;
}
#ifdef DLT_LOG_LEVEL_APP_CONFIG
/**
* Load configuration file parser
*/
static int compare_app_id_conf(const void *lhs, const void *rhs)
{
return strncmp(((DltDaemonContextLogSettings *)lhs)->apid,
((DltDaemonContextLogSettings *)rhs)->apid, DLT_ID_SIZE);
}
int app_id_default_log_level_config_parser(DltDaemon *daemon,
DltDaemonLocal *daemon_local) {
FILE *pFile;
char line[value_length - 1];
char app_id_value[value_length];
char ctx_id_value[value_length];
DltLogLevelType log_level_value;
char *pch;
const char *filename;
/* open configuration file */
filename = daemon_local->flags.avalue[0]
? daemon_local->flags.avalue
: CONFIGURATION_FILES_DIR "/dlt-log-levels.conf";
pFile = fopen(filename, "r");
if (pFile == NULL) {
dlt_vlog(LOG_WARNING, "Cannot open app log level configuration%s\n", filename);
return -errno;
}
/* fetch lines from configuration file */
while (fgets(line, value_length - 1, pFile) != NULL) {
pch = strtok(line, " \t");
memset(app_id_value, 0, value_length);
memset(ctx_id_value, 0, value_length);
log_level_value = DLT_LOG_MAX;
/* ignore comments and new lines*/
if (strncmp(pch, "#", 1) == 0 || strncmp(pch, "\n", 1) == 0
|| strlen(pch) < 1)
continue;
strncpy(app_id_value, pch, sizeof(app_id_value) - 1);
app_id_value[sizeof(app_id_value) - 1] = 0;
if (strlen(app_id_value) == 0 || strlen(app_id_value) > DLT_ID_SIZE) {
if (app_id_value[strlen(app_id_value) - 1] == '\n') {
dlt_vlog(LOG_WARNING, "Missing log level for apid %s in log settings\n",
app_id_value);
} else {
dlt_vlog(LOG_WARNING,
"Invalid apid for log settings settings: app id: %s\n",
app_id_value);
}
continue;
}
char *pch_next1 = strtok(NULL, " \t");
char *pch_next2 = strtok(NULL, " \t");
char *log_level;
/* no context id given, log level is next token */
if (pch_next2 == NULL || pch_next2[0] == '#') {
log_level = pch_next1;
} else {
/* context id is given, log level is second to next token */
log_level = pch_next2;
/* next token is token id */
strncpy(ctx_id_value, pch_next1, sizeof(ctx_id_value) - 1);
if (strlen(ctx_id_value) == 0 || strlen(app_id_value) > DLT_ID_SIZE) {
dlt_vlog(LOG_WARNING,
"Invalid ctxid for log settings: app id: %s "
"(skipping line)\n",
app_id_value);
continue;
}
ctx_id_value[sizeof(ctx_id_value) - 1] = 0;
}
errno = 0;
log_level_value = strtol(log_level, NULL, 10);
if (errno != 0 || log_level_value >= DLT_LOG_MAX ||
log_level_value <= DLT_LOG_DEFAULT) {
dlt_vlog(LOG_WARNING,
"Invalid log level (%i), app id %s, conversion error: %s\n",
log_level_value, app_id_value, strerror(errno));
continue;
}
DltDaemonContextLogSettings *settings =
dlt_daemon_find_configured_app_id_ctx_id_settings(
daemon, app_id_value, NULL);
if (settings != NULL &&
strncmp(settings->ctid, ctx_id_value, DLT_ID_SIZE) == 0) {
if (strlen(ctx_id_value) > 0) {
dlt_vlog(LOG_WARNING,
"Appid %s with ctxid %s is already configured, skipping "
"duplicated entry\n",
app_id_value, ctx_id_value);
} else {
dlt_vlog(LOG_WARNING,
"Appid %s is already configured, skipping duplicated entry\n",
app_id_value);
}
continue;
}
/* allocate one more element in the trace load settings */
DltDaemonContextLogSettings *tmp =
realloc(daemon->app_id_log_level_settings,
(++daemon->num_app_id_log_level_settings) *
sizeof(DltDaemonContextLogSettings));
if (tmp == NULL) {
dlt_log(LOG_CRIT, "Failed to allocate memory for app load settings\n");
continue;
}
daemon->app_id_log_level_settings = tmp;
/* update newly created entry */
settings = &daemon->app_id_log_level_settings