33 #include <sys/socket.h> 35 #include <arpa/inet.h> 46 #include <sys/timerfd.h> 51 #include <linux/stat.h> 69 #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE) 70 #include "sd-daemon.h" 84 #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE 85 static uint32_t watchdog_trigger_interval;
101 printf(
"%s", version);
102 printf(
"Usage: dlt-daemon [options]\n");
103 printf(
"Options:\n");
104 printf(
" -d Daemonize\n");
105 printf(
" -h Usage\n");
106 printf(
" -c filename DLT daemon configuration file (Default: " CONFIGURATION_FILES_DIR
"/dlt.conf)\n");
107 printf(
" -t directory Directory for local fifo and user-pipes (Default: /tmp)\n");
108 printf(
" (Applications wanting to connect to a daemon using a\n");
109 printf(
" custom directory need to be started with the environment \n");
110 printf(
" variable DLT_PIPE_DIR set appropriately)\n");
111 printf(
" -p port port to monitor for incoming requests (Default: 3490)\n");
112 printf(
" (Applications wanting to connect to a daemon using a custom\n");
113 printf(
" port need to be started with the environment variable\n");
114 printf(
" DLT_DAEMON_TCP_PORT set appropriately)\n");
126 fprintf (stderr,
"Invalid parameter passed to option_handling()\n");
139 while ((c = getopt (argc, argv,
"hdc:t:p:")) != -1)
150 strncpy(daemon_local->
flags.
cvalue,optarg,NAME_MAX);
163 fprintf (stderr,
"Invalid port `%s' specified.\n", optarg);
175 if (optopt ==
'c' || optopt ==
't' || optopt ==
'p')
177 fprintf (stderr,
"Option -%c requires an argument.\n", optopt);
179 else if (isprint (optopt))
181 fprintf (stderr,
"Unknown option `-%c'.\n", optopt);
185 fprintf (stderr,
"Unknown option character `\\x%x'.\n",optopt);
193 fprintf (stderr,
"Invalid option, this should never occur!\n");
212 int value_length = 1024;
213 char line[value_length-1];
214 char token[value_length];
215 char value[value_length];
217 const char *filename;
264 filename = CONFIGURATION_FILES_DIR
"/dlt.conf";
266 pFile = fopen (filename,
"r");
273 if ( fgets (line , value_length - 1 , pFile) !=
NULL )
275 pch = strtok (line,
" =\r\n");
281 if(strcmp(pch,
"#")==0)
286 strncpy(token,pch,
sizeof(token) - 1);
287 token[
sizeof(token) - 1]=0;
291 strncpy(value,pch,
sizeof(value) - 1);
292 value[
sizeof(value) - 1]=0;
296 pch = strtok (
NULL,
" =\r\n");
299 if(token[0] && value[0])
302 if(strcmp(token,
"Verbose")==0)
307 else if(strcmp(token,
"PrintASCII")==0)
312 else if(strcmp(token,
"PrintHex")==0)
317 else if(strcmp(token,
"PrintHeadersOnly")==0)
322 else if(strcmp(token,
"SendSerialHeader")==0)
327 else if(strcmp(token,
"SendContextRegistration")==0)
332 else if(strcmp(token,
"SendContextRegistrationOption")==0)
337 else if(strcmp(token,
"SendMessageTime")==0)
342 else if(strcmp(token,
"RS232SyncSerialHeader")==0)
347 else if(strcmp(token,
"TCPSyncSerialHeader")==0)
352 else if(strcmp(token,
"RS232DeviceName")==0)
354 strncpy(daemon_local->
flags.
yvalue,value,NAME_MAX);
358 else if(strcmp(token,
"RS232Baudrate")==0)
360 strncpy(daemon_local->
flags.
bvalue,value,NAME_MAX);
364 else if(strcmp(token,
"ECUId")==0)
366 strncpy(daemon_local->
flags.
evalue,value,NAME_MAX);
370 else if(strcmp(token,
"PersistanceStoragePath")==0)
372 strncpy(daemon_local->
flags.
ivalue,value,NAME_MAX);
376 else if(strcmp(token,
"LoggingMode")==0)
381 else if(strcmp(token,
"LoggingLevel")==0)
386 else if(strcmp(token,
"LoggingFilename")==0)
392 else if(strcmp(token,
"TimeOutOnSend")==0)
397 else if(strcmp(token,
"RingbufferMinSize")==0)
401 else if(strcmp(token,
"RingbufferMaxSize")==0)
405 else if(strcmp(token,
"RingbufferStepSize")==0)
409 else if(strcmp(token,
"DaemonFIFOSize")==0)
413 else if(strcmp(token,
"SharedMemorySize")==0)
418 else if(strcmp(token,
"OfflineTraceDirectory")==0)
424 else if(strcmp(token,
"OfflineTraceFileSize")==0)
429 else if(strcmp(token,
"OfflineTraceMaxSize")==0)
434 else if(strcmp(token,
"OfflineTraceFileNameTimestampBased")==0)
439 else if(strcmp(token,
"SendECUSoftwareVersion")==0)
444 else if(strcmp(token,
"PathToECUSoftwareVersion")==0)
450 else if(strcmp(token,
"SendTimezone")==0)
455 else if(strcmp(token,
"OfflineLogstorageMaxDevices") == 0)
459 else if(strcmp(token,
"OfflineLogstorageDirPath") == 0)
465 else if(strcmp(token,
"OfflineLogstorageTimestamp") == 0)
473 else if(strcmp(token,
"OfflineLogstorageDelimiter") == 0)
476 if(ispunct((
char)value[0]))
481 else if(strcmp(token,
"OfflineLogstorageMaxCounter") == 0)
486 else if(strcmp(token,
"OfflineLogstorageCacheSize") == 0)
489 (
unsigned int)atoi(value);
493 else if(strcmp(token,
"ControlSocketPath") == 0)
504 else if(strcmp(token,
"GatewayMode")==0)
509 else if(strcmp(token,
"GatewayConfigFile")==0)
520 else if(strcmp(token,
"ContextLogLevel")==0)
522 int const intval = atoi(value);
526 printf(
"Option: %s=%s\n",token,value);
533 else if(strcmp(token,
"ContextTraceStatus")==0)
535 int const intval = atoi(value);
539 printf(
"Option: %s=%s\n",token,value);
546 else if(strcmp(token,
"ForceContextLogLevelAndTraceStatus")==0)
548 int const intval = atoi(value);
549 if ( (intval >= 0) && (intval <= 1))
552 printf(
"Option: %s=%s\n",token,value);
556 fprintf(stderr,
"Invalid value for ForceContextLogLevelAndTraceStatus: %i. Must be 0, 1\n", intval);
561 fprintf(stderr,
"Unknown option: %s=%s\n",token,value);
574 fprintf(stderr,
"Cannot open configuration file: %s\n",filename);
583 int main(
int argc,
char* argv[])
597 fprintf (stderr,
"option_handling() failed!\n");
606 fprintf (stderr,
"option_file_parser() failed!\n");
635 dlt_log(LOG_CRIT,
"Initialization of phase 1 failed!\n");
643 dlt_log(LOG_CRIT,
"Initialization of event handling failed!\n");
650 dlt_log(LOG_CRIT,
"Initialization of local connections failed!\n");
658 dlt_log(LOG_CRIT,
"Initialization of phase 2 failed!\n");
669 dlt_log(LOG_INFO,
"Setting up internal offline log storage failed!\n");
674 #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE 676 char* watchdogUSec = getenv(
"WATCHDOG_USEC");
677 int watchdogTimeoutSeconds = 0;
679 dlt_log(LOG_DEBUG,
"Systemd watchdog initialization\n");
682 watchdogTimeoutSeconds = atoi(watchdogUSec)/2000000;
684 watchdog_trigger_interval = watchdogTimeoutSeconds;
686 watchdogTimeoutSeconds,
687 watchdogTimeoutSeconds,
707 dlt_log(LOG_CRIT,
"Fail to create gateway\n");
729 while ((back >= 0) && (
g_exit >= 0))
742 dlt_log(LOG_NOTICE,
"Leaving DLT daemon\n");
754 if ((daemon==0) || (daemon_local==0))
756 dlt_log(LOG_ERR,
"Invalid function parameters used for function dlt_daemon_local_init_p1()\n");
760 #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE) 764 dlt_log(LOG_CRIT,
"System not booted with systemd!\n");
769 dlt_log(LOG_CRIT,
"sd_booted failed!\n");
774 dlt_log(LOG_INFO,
"System booted with systemd\n");
781 ret=mkdir(tmpFifo, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX );
782 if (ret==-1 && errno != EEXIST)
790 ret=chmod(tmpFifo, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH | S_ISGID | S_ISVTX );
807 dlt_log(LOG_ERR,
"Could not initialize file structure\n");
813 signal(SIGPIPE,SIG_IGN);
827 if ((daemon==0) || (daemon_local==0))
829 dlt_log(LOG_ERR,
"Invalid function parameters used for function dlt_daemon_local_init_p2()\n");
836 dlt_log(LOG_ERR,
"Could not initialize daemon data\n");
849 dlt_log(LOG_ERR,
"Could not initialize offline trace\n");
861 dlt_log(LOG_ERR,
"Could not initialize offline logstorage\n");
880 #ifdef DLT_SHM_ENABLE 884 dlt_log(LOG_ERR,
"Could not initialize shared memory\n");
892 dlt_log(LOG_ERR,
"Could not initialize message\n");
905 dlt_log(LOG_ERR,
"Could not initialize binary semaphore\n");
915 dlt_log(LOG_WARNING,
"Could not allocate memory for version string\n");
939 "Failed to open serial device %s\n",
965 "Failed to configure serial device %s (%s) \n",
975 dlt_log(LOG_DEBUG,
"Serial init done\n");
982 "Device is not a serial device, device = %s (%s) \n",
1010 ret=mkfifo(tmpFifo, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
1015 "FIFO user %s cannot be created (%s)!\n",
1018 dlt_log(LOG_WARNING, local_str);
1022 fd = open(tmpFifo, O_RDWR);
1027 "FIFO user %s cannot be opened (%s)!\n",
1030 dlt_log(LOG_WARNING, local_str);
1037 if (fcntl(fd, F_SETPIPE_SZ , daemon_local->
daemonFifoSize) == -1)
1045 if ((fifo_size = fcntl(fd, F_GETPIPE_SZ , 0)) == -1)
1075 if ((daemon ==
NULL) || (daemon_local ==
NULL))
1079 "%s: Invalid function parameters\n",
1088 dlt_log(LOG_ERR,
"Unable to initialize fifo.\n");
1101 dlt_log(LOG_ERR,
"Could not initialize main socket.\n");
1114 dlt_log(LOG_ERR,
"Could not initialize control socket.\n");
1121 dlt_log(LOG_ERR,
"Could not initialize daemon data\n");
1130 char *version =
NULL;
1143 dlt_log(LOG_NOTICE,
"Failed to open ECU Software version file.\n");
1150 if(fstat(fd, &s_buf) < 0)
1152 dlt_log(LOG_WARNING,
"Failed to stat ECU Software version file.\n");
1159 off_t size = s_buf.st_size;
1162 dlt_log(LOG_WARNING,
"Too large file for ECU version.\n");
1168 version = malloc(size + 1);
1171 dlt_log(LOG_WARNING,
"Cannot allocate memory for ECU version.\n");
1178 offset += fread(version + offset, 1, size, f);
1181 dlt_log(LOG_WARNING,
"Failed to read ECU Software version file.\n");
1188 dlt_log(LOG_WARNING,
"Too long file for ECU Software version info.\n");
1194 version[offset] =
'\0';
1204 if ((daemon==0) || (daemon_local==0))
1206 dlt_log(LOG_ERR,
"Invalid function parameters used for function dlt_daemon_local_cleanup()\n");
1225 #ifdef DLT_SHM_ENABLE 1266 char tmp[PATH_MAX + 1];
1282 dlt_log(LOG_CRIT,
"This case should never happen!");
1295 dlt_log(LOG_NOTICE,
"Daemon mode\n");
1301 dlt_log(LOG_CRIT,
"Unable to fork(), exiting DLT daemon\n");
1316 dlt_log(LOG_CRIT,
"setsid() failed, exiting DLT daemon\n");
1321 for (i=getdtablesize();i>=0;--i)
1327 i=open(
"/dev/null",O_RDWR);
1331 dlt_log(LOG_WARNING,
"Failed to direct stdout to /dev/null.\n");
1333 dlt_log(LOG_WARNING,
"Failed to direct stderr to /dev/null.\n");
1348 char dlt_daemon_lock_file[PATH_MAX + 1];
1350 dlt_daemon_lock_file[PATH_MAX] = 0;
1354 dlt_log(LOG_CRIT,
"Can't open lock file, exiting DLT daemon\n");
1357 if (lockf(lfp,F_TLOCK,0)<0)
1359 dlt_log(LOG_CRIT,
"Can't lock lock file, exiting DLT daemon\n");
1365 pid_len = strlen(
str);
1366 if(write(lfp,
str,pid_len) != pid_len)
1367 dlt_log(LOG_WARNING,
"Could not write pid to file in dlt_daemon_daemonize.\n");
1370 signal(SIGCHLD,SIG_IGN);
1371 signal(SIGTSTP,SIG_IGN);
1372 signal(SIGTTOU,SIG_IGN);
1373 signal(SIGTTIN,SIG_IGN);
1386 static uint8_t uiMsgCount = 0;
1387 DltStandardHeaderExtra *pStandardExtra;
1390 uint32_t uiExtraSize;
1405 msg.
headersize =
sizeof(DltStorageHeader) +
sizeof(DltStandardHeader) + uiExtraSize;
1408 pStandardExtra = (DltStandardHeaderExtra *)(msg.
headerbuffer +
sizeof(DltStorageHeader) +
sizeof(DltStandardHeader));
1422 uiSize = strlen(str) + 1;
1423 msg.
datasize =
sizeof(uint32_t) +
sizeof(uint16_t) + uiSize;
1429 dlt_log(LOG_WARNING,
"Can't allocate buffer for get log info message\n");
1434 memcpy((uint8_t *)(msg.
databuffer + msg.
datasize), (uint8_t *)(&uiType),
sizeof(uint32_t));
1436 memcpy((uint8_t *)(msg.
databuffer + msg.
datasize), (uint8_t *)(&uiSize),
sizeof(uint16_t));
1483 struct sockaddr cli;
1489 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (receiver ==
NULL))
1492 "Invalid function parameters used for function " 1493 "dlt_daemon_process_client_connect()\n");
1498 cli_size =
sizeof(cli);
1499 if ((in_sock = accept(receiver->
fd,&cli, &cli_size)) < 0)
1501 dlt_log(LOG_ERR,
"accept() failed!\n");
1512 struct timeval timeout_send;
1514 timeout_send.tv_usec = 0;
1515 if (setsockopt (in_sock,
1518 (
char *)&timeout_send,
1519 sizeof(timeout_send)) < 0)
1521 dlt_log(LOG_WARNING,
"setsockopt failed\n");
1530 dlt_log(LOG_ERR,
"Failed to register new client. \n");
1539 "New connection to client established, #connections: %d\n",
1576 dlt_log(LOG_DEBUG,
"Send ring-buffer to client\n");
1581 dlt_log(LOG_WARNING,
"Can't send contents of ringbuffer to clients\n");
1598 int bytes_to_be_removed=0;
1599 int must_close_socket = -1;
1603 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (receiver ==
NULL))
1606 "Invalid function parameters used for function " 1607 "dlt_daemon_process_client_messages()\n");
1612 if (must_close_socket < 0)
1624 (uint8_t*)receiver->
buf,
1630 if (0 < receiver->
fd &&
1636 &(daemon_local->
msg),
1642 sizeof(DltStorageHeader);
1655 "Can't remove bytes from receiver for sockets\n");
1664 "Can't move bytes to beginning of receiver buffer for sockets\n");
1668 if (must_close_socket == 0) {
1686 int bytes_to_be_removed=0;
1690 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (receiver ==
NULL))
1693 "Invalid function parameters used for function " 1694 "dlt_daemon_process_client_messages_serial()\n");
1701 "dlt_receiver_receive_fd() for messages from serial interface " 1708 (uint8_t*)receiver->
buf,
1719 &(daemon_local->
msg),
1723 dlt_log(LOG_WARNING,
"Can't process control messages\n");
1730 sizeof(DltStorageHeader);
1744 "Can't remove bytes from receiver for serial connection\n");
1753 "Can't move bytes to beginning of receiver buffer for serial " 1767 socklen_t ctrl_size;
1768 struct sockaddr_un ctrl;
1773 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (receiver ==
NULL))
1776 "Invalid function parameters used for function " 1777 "dlt_daemon_process_control_connect()\n");
1782 ctrl_size =
sizeof(ctrl);
1783 if ((in_sock = accept(receiver->
fd, &ctrl, &ctrl_size)) < 0)
1785 dlt_log(LOG_ERR,
"accept() on UNIX socket failed!\n");
1801 dlt_log(LOG_ERR,
"Failed to register new client. \n");
1809 "New connection to control client established\n");
1823 int bytes_to_be_removed=0;
1827 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (receiver ==
NULL))
1830 "Invalid function parameters used for function " 1831 "dlt_daemon_process_control_messages()\n");
1850 &(daemon_local->
msg),
1851 (uint8_t*)receiver->
buf,
1857 if (receiver->
fd > 0 &&
1861 daemon,daemon_local,
1862 &(daemon_local->
msg),
1868 sizeof(DltStorageHeader);
1882 "Can't remove bytes from receiver for sockets\n");
1890 dlt_log(LOG_WARNING,
"Can't move bytes to beginning of receiver buffer for sockets\n");
1903 DltUserHeader *userheader = (DltUserHeader*) (receiver->
buf);
1911 "Invalid user message type received: %d!\n",
1912 userheader->message);
1919 "Can't remove bytes from receiver for user messages\n");
1936 #ifdef DLT_SHM_ENABLE 1937 dlt_daemon_process_user_message_log_shm,
1945 dlt_daemon_process_user_message_not_sup
1955 int32_t min_size = (int32_t)
sizeof(DltUserHeader);
1956 DltUserHeader *userheader;
1960 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (receiver ==
NULL))
1963 "Invalid function parameters used for function " 1964 "dlt_daemon_process_user_messages()\n");
1972 "dlt_receiver_receive_fd() for user messages failed!\n");
1977 while ((receiver->
bytesRcvd >= min_size) && run_loop)
1982 userheader = (DltUserHeader *)(receiver->
buf + offset);
1985 (offset + min_size <= receiver->
bytesRcvd))
1989 userheader = (DltUserHeader *)(receiver->
buf + offset);
2027 "Can't move bytes to beginning of receiver buffer for user " 2040 uint32_t len =
sizeof(DltUserControlMsgBufferOverflow);
2042 DltUserControlMsgBufferOverflow userpayload;
2046 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (rec ==
NULL))
2050 "Invalid function parameters used for %s\n",
2071 userpayload.overflow_counter,
2088 if ((daemon==0) || (daemon_local==0))
2090 dlt_log(LOG_ERR,
"Invalid function parameters used for function dlt_daemon_process_user_message_overflow()\n");
2108 uint32_t len =
sizeof(DltUserControlMsgRegisterApplication);
2113 DltUserControlMsgRegisterApplication userapp;
2118 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (rec ==
NULL))
2122 "Invalid function parameters used for %s\n",
2129 memset(&userapp, 0,
sizeof(DltUserControlMsgRegisterApplication));
2143 len = userapp.description_length;
2147 dlt_log(LOG_WARNING,
"Application description exceeds limit\n");
2151 rec->
buf += to_remove +
sizeof(DltUserHeader);
2155 dlt_log(LOG_ERR,
"Unable to get application description\n");
2157 strncpy(description,
"Unknown",
sizeof(
"Unknown"));
2165 to_remove +=
sizeof(DltUserHeader) + len;
2172 dlt_log(LOG_WARNING,
"Can't remove bytes from receiver\n");
2185 if (application ==
NULL)
2189 "Can't add ApplicationID '%.4s' for PID %d\n",
2192 dlt_log(LOG_WARNING,local_str);
2199 "ApplicationID '%.4s' registered for PID %d, Description=%s\n",
2207 dlt_log(LOG_DEBUG, local_str);
2220 uint32_t len =
sizeof(DltUserControlMsgRegisterContext);
2221 DltUserControlMsgRegisterContext userctxt;
2225 DltServiceGetLogInfoRequest *req =
NULL;
2232 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (rec ==
NULL))
2236 "Invalid function parameters used for %s\n",
2243 memset(&userctxt, 0,
sizeof(DltUserControlMsgRegisterContext));
2257 len = userctxt.description_length;
2262 dlt_log(LOG_WARNING,
"Context description exceeds limit\n");
2266 rec->
buf += to_remove +
sizeof(DltUserHeader);
2270 dlt_log(LOG_ERR,
"Unable to get context description\n");
2272 strncpy(description,
"Unknown",
sizeof(
"Unknown"));
2280 to_remove +=
sizeof(DltUserHeader) + len;
2287 dlt_log(LOG_WARNING,
"Can't remove bytes from receiver\n");
2293 if (application == 0)
2297 "ApID '%.4s' not found for new ContextID '%.4s' in %s\n",
2301 dlt_log(LOG_WARNING, local_str);
2340 userctxt.trace_status,
2341 userctxt.log_level_pos,
2350 "Can't add ContextID '%.4s' for ApID '%.4s'\n in %s",
2354 dlt_log(LOG_WARNING, local_str);
2361 "ContextID '%.4s' registered for ApID '%.4s', Description=%s\n",
2366 dlt_log(LOG_DEBUG, local_str);
2388 dlt_log(LOG_WARNING,
"Can't initialize message");
2392 msg.
datasize =
sizeof(DltServiceGetLogInfoRequest);
2404 dlt_log(LOG_WARNING,
"Can't allocate buffer for get log info message\n");
2408 req = (DltServiceGetLogInfoRequest*) msg.
databuffer;
2426 dlt_vlog(LOG_WARNING,
"Can't send current log level as response to %s for (%.4s;%.4s)\n",
2441 uint32_t len =
sizeof(DltUserControlMsgUnregisterApplication);
2442 DltUserControlMsgUnregisterApplication userapp;
2450 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (rec ==
NULL))
2454 "Invalid function parameters used for %s\n",
2490 context = &(daemon->
contexts[offset_base+i]);
2498 "Can't delete CtID '%.4s' for ApID '%.4s' in %s\n",
2502 dlt_log(LOG_WARNING, local_str);
2513 "Can't delete ApID '%.4s' in %s\n",
2516 dlt_log(LOG_WARNING, local_str);
2523 "Unregistered ApID '%.4s'\n",
2529 dlt_log(LOG_DEBUG, local_str);
2543 uint32_t len =
sizeof(DltUserControlMsgUnregisterContext);
2544 DltUserControlMsgUnregisterContext userctxt;
2549 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (rec ==
NULL))
2553 "Invalid function parameters used for %s\n",
2581 "Can't delete CtID '%.4s' for ApID '%.4s' in %s\n",
2585 dlt_log(LOG_WARNING, local_str);
2592 "Unregistered CtID '%.4s' for ApID '%.4s'\n",
2599 dlt_log(LOG_DEBUG, local_str);
2624 int bytes_to_be_removed;
2630 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (rec ==
NULL))
2632 dlt_log(LOG_ERR,
"Invalid function parameters used for function dlt_daemon_process_user_message_log()\n");
2637 (
unsigned char*)rec->
buf +
sizeof(DltUserHeader),
2652 dlt_log(LOG_DEBUG,
"Can't read messages from receiver\n");
2665 dlt_log(LOG_WARNING,
"Can't set message extra parameters in process user message log\n");
2678 dlt_log(LOG_WARNING,
"Can't set storage header in process user message log\n");
2686 dlt_log(LOG_WARNING,
"Can't set storage header in process user message log\n");
2697 dlt_log(LOG_WARNING,
"dlt_message_print_hex() failed!\n");
2704 dlt_log(LOG_WARNING,
"dlt_message_print_ascii() failed!\n");
2711 dlt_log(LOG_WARNING,
"dlt_message_print_header() failed!\n");
2740 bytes_to_be_removed = daemon_local->
msg.
headersize+daemon_local->
msg.
datasize-
sizeof(DltStorageHeader)+
sizeof(DltUserHeader);
2748 dlt_log(LOG_WARNING,
"Can't remove bytes from receiver\n");
2755 #ifdef DLT_SHM_ENABLE 2756 #define DLT_SHM_RCV_BUFFER_SIZE 10000 2757 int dlt_daemon_process_user_message_log_shm(
DltDaemon *daemon,
2763 int j,sent,third_value;
2765 uint8_t *rcv_buffer =
NULL;
2767 uint32_t len =
sizeof(DltUserHeader);
2768 DltUserHeader userheader;
2774 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (rec ==
NULL))
2778 "Invalid function parameters used for %s\n",
2785 rcv_buffer = calloc(1, DLT_SHM_RCV_BUFFER_SIZE);
2791 "No memory to allocate receiver buffer in %s.\n",
2799 memset(&userheader, 0, len);
2813 DLT_SHM_RCV_BUFFER_SIZE);
2819 dlt_log(LOG_WARNING,
"Can't read messages from shm\n");
2831 dlt_log(LOG_WARNING,
"Can't set message extra parameters in process user message log\n");
2845 dlt_log(LOG_WARNING,
"Can't set storage header in process user message log\n");
2854 dlt_log(LOG_WARNING,
"Can't set storage header in process user message log\n");
2865 dlt_log(LOG_WARNING,
"dlt_message_print_hex() failed!\n");
2872 dlt_log(LOG_WARNING,
"dlt_message_print_ascii() failed!\n");
2879 dlt_log(LOG_WARNING,
"dlt_message_print_header() failed!\n");
2913 #undef DLT_SHM_RCV_BUFFER_SIZE 2922 uint32_t len =
sizeof(DltUserControlMsgAppLogLevelTraceStatus);
2923 DltUserControlMsgAppLogLevelTraceStatus userctxt;
2927 int8_t old_log_level, old_trace_status;
2931 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (rec ==
NULL))
2935 "Invalid function parameters used for %s\n",
2942 memset(&userctxt, 0, len);
2969 context = &(daemon->
contexts[offset_base+i]);
2973 context->
log_level = userctxt.log_level;
2997 DltUserControlMsgLogMode userctxt;
2998 uint32_t len =
sizeof(DltUserControlMsgLogMode);
3002 if ((daemon==0) || (daemon_local==0))
3004 dlt_log(LOG_ERR,
"Invalid function parameters used for function dlt_daemon_process_log_mode()\n");
3008 memset(&userctxt, 0, len);
3019 daemon->
mode = userctxt.log_mode;
3033 uint32_t len =
sizeof(DltUserControlMsgLogMode);
3034 DltUserControlMsgLogMode userctxt;
3037 if ((daemon ==
NULL) || (daemon_local ==
NULL) || (rec ==
NULL))
3041 "Invalid function parameters used for %s\n",
3048 memset(&userctxt, 0, len);
3066 #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE 3072 if ((daemon==0) || (daemon_local==0))
3074 dlt_log(LOG_ERR,
"Invalid function parameters used for function dlt_daemon_send_ringbuffer_to_client()\n");
3084 #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE 3085 if(sd_notify(0,
"WATCHDOG=1") < 0)
3087 dlt_log(LOG_WARNING,
"Could not reset systemd watchdog\n");
3093 #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE 3094 if ((
dlt_uptime() - curr_time) / 10000 >= watchdog_trigger_interval)
3096 if(sd_notify(0,
"WATCHDOG=1") < 0)
3098 dlt_log(LOG_WARNING,
"Could not reset systemd watchdog\n");
3125 #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE 3135 #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE 3136 [DLT_TIMER_SYSTEMD] =
"Systemd watchdog",
3148 struct itimerspec l_timer_spec;
3149 char *timer_name =
NULL;
3158 if(daemon_local ==
NULL)
3164 if(period_sec > 0) {
3166 local_fd = timerfd_create(CLOCK_MONOTONIC, 0);
3171 "<%s> timerfd_create failed: %s\n",
3177 l_timer_spec.it_interval.tv_sec = period_sec;
3178 l_timer_spec.it_interval.tv_nsec = 0;
3179 l_timer_spec.it_value.tv_sec = starts_in;
3180 l_timer_spec.it_value.tv_nsec = 0;
3182 if( timerfd_settime(local_fd, 0, &l_timer_spec,
NULL) < 0)
3186 "<%s> timerfd_settime failed: %s\n",
3196 snprintf(
str,
sizeof(
str),
"<%s> not set: period=0\n", timer_name);
3208 "<%s> initialized with %d timer\n",
3226 if((daemon_local ==
NULL)|| (daemon ==
NULL))
3228 dlt_log(LOG_ERR,
"dlt_daemon_close_socket: Invalid input parmeters\n");
int create_timer_fd(DltDaemonLocal *daemon_local, int period_sec, int starts_in, DltTimers timer_id)
static char dlt_timer_conn_types[DLT_TIMER_UNKNOWN+1]
int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose)
#define DLT_RCV_SKIP_HEADER
int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext *context, int verbose)
int dlt_daemon_process_user_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
int dlt_receiver_receive_socket(DltReceiver *receiver)
#define PRINT_FUNCTION_VERBOSE(_verbose)
int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
#define DLT_DAEMON_DESCSIZE
DltReturnValue dlt_offline_trace_free(DltOfflineTrace *trace)
int dlt_shm_copy(DltShm *buf, unsigned char *data, int max_size)
int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon, int fd, int verbose)
#define DLT_DAEMON_ERROR_BUFFER_FULL
int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
int dlt_event_handler_unregister_connection(DltEventHandler *evhdl, DltDaemonLocal *daemon_local, int fd)
Unregisters a connection from the event handler and destroys it.
int8_t found_serialheader
DltReturnValue dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose)
DltStorageHeader * storageheader
int dlt_daemon_local_ecu_version_init(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
unsigned long RingbufferMaxSize
#define DLT_CONNECTION_STATUS_CONNECTED
int dlt_daemon_process_control_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
#define DLT_DAEMON_DEFAULT_CTRL_SOCK_PATH
#define DLT_HTYP_PROTOCOL_VERSION1
void dlt_set_id(char *id, const char *text)
DltDaemonApplication * applications
int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
void dlt_event_handler_cleanup_connections(DltEventHandler *ev)
Destroy the connection list.
int dlt_receiver_check_and_get(DltReceiver *receiver, void *dest, unsigned int to_get, unsigned int flags)
static int dlt_daemon_init_fifo(DltDaemonLocal *daemon_local)
int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
DltLogStorage * storage_handle
int dlt_daemon_logstorage_get_loglevel(DltDaemon *daemon, int max_device, char *apid, char *ctid)
DltDaemonContext * dlt_daemon_context_add(DltDaemon *daemon, char *apid, char *ctid, int8_t log_level, int8_t trace_status, int log_level_pos, int user_handle, char *description, int verbose)
DltReturnValue dlt_shm_free_server(DltShm *buf)
#define DLT_MESSAGE_ERROR_OK
char daemonFifoName[NAME_MAX+1]
#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp)
unsigned long daemonFifoSize
unsigned int offlineLogstorageMaxCounterIdx
#define DLT_DAEMON_TEXTSIZE
char offlineLogstorageDelimiter
#define DLT_DAEMON_LOCK_FILE
DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size)
#define DLT_SERVICE_ID_GET_LOG_INFO
#define DLT_DAEMON_LOCK_FILE_PERM
#define DLT_DAEMON_ERROR_OK
DltReturnValue dlt_log(int prio, char *s)
int dlt_user_check_userheader(DltUserHeader *userheader)
int dlt_daemon_control_message_marker(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
char loggingFilename[DLT_DAEMON_FLAG_MAX]
#define DLT_DAEMON_ERROR_UNKNOWN
int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
int dlt_daemon_process_user_message_marker(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
int dlt_receiver_receive_fd(DltReceiver *receiver)
DltBuffer client_ringbuffer
int sendECUSoftwareVersion
DltReturnValue dlt_message_init(DltMessage *msg, int verbose)
int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver)
DltExtendedHeader * extendedheader
int dlt_daemon_send_message_overflow(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
DltReturnValue dlt_offline_trace_write(DltOfflineTrace *trace, unsigned char *data1, int size1, unsigned char *data2, int size2, unsigned char *data3, int size3)
DltReturnValue dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose)
void dlt_daemon_signal_handler(int sig)
int main(int argc, char *argv[])
DltOfflineTrace offlineTrace
void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose)
char offlineTraceDirectory[DLT_DAEMON_FLAG_MAX]
#define DLT_USER_MESSAGE_NOT_SUPPORTED
DltDaemonContext * contexts
static int dlt_daemon_init_serial(DltDaemonLocal *daemon_local)
int dlt_buffer_copy(DltBuffer *buf, unsigned char *data, int max_size)
#define DLT_DAEMON_RINGBUFFER_STEP_SIZE
DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose)
static char data[kDataSize]
#define DLT_MSIN_MTIN_SHIFT
DltDaemonApplication * dlt_daemon_application_add(DltDaemon *daemon, char *apid, pid_t pid, char *description, int verbose)
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
int dlt_daemon_socket_open(int *sock, unsigned int servPort)
int dlt_daemon_free(DltDaemon *daemon, int verbose)
int dlt_daemon_close_socket(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
#define DLT_IS_HTYP_UEH(htyp)
int dlt_daemon_user_send_log_state(DltDaemon *daemon, DltDaemonApplication *app, int verbose)
unsigned long RingbufferStepSize
int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *application, int verbose)
int dlt_mkdir_recursive(const char *dir)
int(* dlt_daemon_process_user_message_func)(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
void dlt_daemon_change_state(DltDaemon *daemon, DltDaemonState newState)
void dlt_daemon_logstorage_set_logstorage_cache_size(unsigned int size)
uint32_t dlt_uptime(void)
static char dlt_timer_names[DLT_TIMER_UNKNOWN+1][32]
int dlt_daemon_configuration_save(DltDaemon *daemon, const char *filename, int verbose)
int dlt_daemon_client_send_all(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
Send out message to all the clients.
void dlt_log_set_filename(const char *filename)
int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
#define DLT_CONNECTION_STATUS_DISCONNECTED
char gatewayConfigFile[DLT_DAEMON_FLAG_MAX]
#define DLT_DAEMON_ECU_ID
int dlt_daemon_control_message_unregister_context(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, char *apid, char *ctid, char *comid, int verbose)
int dlt_daemon_client_send(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, void *storage_header, int storage_header_size, void *data1, int size1, void *data2, int size2, int verbose)
const char dltSerialHeader[DLT_ID_SIZE]
int dlt_daemon_process_client_messages_serial(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
int dlt_daemon_init(DltDaemon *daemon, unsigned long RingbufferMinSize, unsigned long RingbufferMaxSize, unsigned long RingbufferStepSize, const char *runtime_directory, int InitialContextLogLevel, int InitialContextTraceStatus, int ForceLLTS, int verbose)
void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
#define DLT_MSG_IS_CONTROL_REQUEST(MSG)
int offlineLogstorageTimestamp
uint8_t headerbuffer[sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]
int enforceContextLLAndTS
int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
DltDaemonApplication * dlt_daemon_application_find(DltDaemon *daemon, char *apid, int verbose)
char userPipesDir[NAME_MAX+1]
#define DLT_DAEMON_SEND_TO_ALL
#define DLT_IS_HTYP_WEID(htyp)
int dlt_buffer_remove(DltBuffer *buf)
#define DLT_TYPE_INFO_STRG
int dlt_buffer_get_message_count(DltBuffer *buf)
DltStandardHeaderExtra headerextra
char ctrlSockPath[DLT_DAEMON_FLAG_MAX]
DltReturnValue dlt_file_init(DltFile *file, int verbose)
int dlt_shm_init_server(DltShm *buf, int key, int size)
unsigned int overflow_counter
#define DLT_GATEWAY_CONFIG_PATH
int dlt_daemon_control_message_connection_info(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, uint8_t state, char *comid, int verbose)
char offlineLogstorageDirPath[DLT_MOUNT_PATH_MAX]
char dltFifoBaseDir[PATH_MAX+1]
#define DLT_MSIN_MSTP_SHIFT
int dlt_gateway_init(DltDaemonLocal *daemon_local, int verbose)
int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
DltReturnValue dlt_file_free(DltFile *file, int verbose)
DltReturnValue dlt_setup_serial(int fd, speed_t speed)
int dlt_daemon_process_control_messages(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
DltStandardHeader * standardheader
int dlt_daemon_user_send_log_level(DltDaemon *daemon, DltDaemonContext *context, int verbose)
DltReturnValue dlt_message_free(DltMessage *msg, int verbose)
int autoResponseGetLogInfoOption
speed_t dlt_convert_serial_speed(int baudrate)
static int dlt_daemon_process_user_message_not_sup(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
int offlineLogstorageMaxDevices
int option_handling(DltDaemonLocal *daemon_local, int argc, char *argv[])
int dlt_daemon_unix_socket_open(int *sock, char *sock_path)
int dlt_daemon_process_user_message_register_application(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
static dlt_daemon_process_user_message_func process_user_func[DLT_USER_MESSAGE_NOT_SUPPORTED]
int option_file_parser(DltDaemonLocal *daemon_local)
int offlineTraceFilenameTimestampBased
void dlt_get_version(char *buf, size_t size)
char pathToECUSoftwareVersion[DLT_DAEMON_FLAG_MAX]
#define DLT_DAEMON_RINGBUFFER_MIN_SIZE
#define DLT_DAEMON_RCVBUFSIZE
char runtime_configuration[PATH_MAX+1]
void dlt_log_set_level(int level)
int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *rec, int verbose)
unsigned int offlineLogstorageMaxCounter
unsigned int offlineLogstorageCacheSize
int dlt_daemon_logstorage_setup_internal_storage(DltDaemon *daemon, char *path, int verbose)
int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_local, DltReceiver *receiver, int verbose)
#define DLT_DAEMON_FLAG_MAX
#define DLT_MESSAGE_ERROR_SIZE
static char str[DLT_DAEMON_TEXTBUFSIZE]
int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon, int fd, int verbose)
void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose)
int dlt_shm_remove(DltShm *buf)
void dlt_daemon_daemonize(int verbose)
int dlt_daemon_logstorage_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
#define DLT_DAEMON_TCP_PORT
char * context_description
#define DLT_USER_MESSAGE_LOG_SHM
int dlt_daemon_prepare_event_handling(DltEventHandler *ev)
Prepare the event handler.
#define DLT_USER_TRACE_STATUS_NOT_SET
int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
#define DLT_DAEMON_TEXTBUFSIZE
#define DLT_USER_LOG_LEVEL_NOT_SET
int dlt_daemon_local_connection_init(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
DltReturnValue dlt_vlog(int prio, const char *format,...)
#define DLT_DAEMON_RINGBUFFER_MAX_SIZE
DltReturnValue dlt_offline_trace_init(DltOfflineTrace *trace, const char *directory, int fileSize, int maxSize, int filenameTimestampBased)
#define DLT_DAEMON_SERIAL_DEFAULT_BAUDRATE
int dlt_connection_create(DltDaemonLocal *daemon_local, DltEventHandler *evh, int fd, int mask, DltConnectionType type)
Creates a connection and registers it to the DltEventHandler.
int dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, unsigned int overflow_counter, char *apid, int verbose)
static int dlt_daemon_log_internal(DltDaemon *daemon, DltDaemonLocal *daemon_local, char *str, int verbose)
DltDaemonContext * dlt_daemon_context_find(DltDaemon *daemon, char *apid, char *ctid, int verbose)
unsigned long RingbufferMinSize
void dlt_log_init(int mode)
#define DLT_DAEMON_SEND_FORCE
char * application_description
int dlt_daemon_handle_event(DltEventHandler *pEvent, DltDaemon *daemon, DltDaemonLocal *daemon_local)
Catch and process incoming events.
#define DLT_GATEWAY_TIMER_INTERVAL