From 20136d1af7dbf1d619499cc27e1c75e05368f3b6 Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Tue, 25 Mar 2014 13:24:52 +0100 Subject: Cygwin port: cygwin patch, signal handling patch and cppcheck and install lib dll to correct location on Windows. Originally from Mikko Rapeli . Signed-off-by: Alexander Wenzel --- src/daemon/dlt-daemon.c | 23 +++++++++++++++++------ src/daemon/dlt_daemon_client.c | 7 ++++++- src/daemon/dlt_daemon_socket.c | 6 +++++- src/lib/CMakeLists.txt | 1 + src/lib/dlt_user.c | 7 ++++++- src/shared/dlt_common.c | 2 +- src/system/dlt-system-filetransfer.c | 16 +++++++++++++--- src/system/dlt-system-watchdog.c | 4 ++-- 8 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 2fb9f2f..bb3b86e 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -77,10 +77,14 @@ #include #include +#ifdef linux #include +#endif #include #include +#ifdef linux #include +#endif #include "dlt_types.h" #include "dlt-daemon.h" @@ -500,8 +504,13 @@ int main(int argc, char* argv[]) daemon_local.read_fds = daemon_local.master; if (select(daemon_local.fdmax+1, &(daemon_local.read_fds), NULL, NULL, NULL) == -1) { - dlt_log(LOG_CRIT, "select() failed!\n"); - return -1 ; + int error = errno; + /* retry if SIGINT was received, else error out */ + if ( error != EINTR ) { + sprintf(str,"select() failed: %s\n", strerror(error) ); + dlt_log(LOG_CRIT, str); + return -1; + } } /* if */ /* run through the existing FIFO and sockets to check for events */ @@ -1027,8 +1036,8 @@ void dlt_daemon_signal_handler(int sig) case SIGQUIT: { /* finalize the server */ - //dlt_log("terminate signal catched"); - dlt_log(LOG_NOTICE, "Exiting DLT daemon\n"); + sprintf(str,"Exiting DLT daemon due to signal: %s\n", strsignal(sig) ); + dlt_log(LOG_NOTICE, str); /* Try to delete existing pipe, ignore result of unlink() */ unlink(DLT_USER_FIFO); @@ -1042,7 +1051,7 @@ void dlt_daemon_signal_handler(int sig) } default: { - /* This case should never occur */ + dlt_log(LOG_CRIT, "This case should never happen!"); break; } } /* switch */ @@ -2383,7 +2392,7 @@ int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daem int create_timer_fd(DltDaemonLocal *daemon_local, int period_sec, int starts_in, int* fd, const char* timer_name) { - int local_fd; + int local_fd = -1; struct itimerspec l_timer_spec; if(timer_name == NULL) @@ -2399,6 +2408,7 @@ int create_timer_fd(DltDaemonLocal *daemon_local, int period_sec, int starts_in, } if( period_sec > 0 ) { +#ifdef linux local_fd = timerfd_create(CLOCK_MONOTONIC, 0); if( local_fd < 0) { @@ -2417,6 +2427,7 @@ int create_timer_fd(DltDaemonLocal *daemon_local, int period_sec, int starts_in, dlt_log(DLT_LOG_ERROR, str); local_fd = -1; } +#endif } else { // timer not activated via the service file diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index a209975..30af665 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -63,10 +63,14 @@ #include #include +#ifdef linux #include +#endif #include #include +#ifdef linux #include +#endif #include "dlt_types.h" #include "dlt-daemon.h" @@ -1188,8 +1192,9 @@ int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLo time_t t = time(NULL); struct tm lt = {0}; localtime_r(&t, <); - +#if !defined(__CYGWIN__) resp->timezone = (int32_t) lt.tm_gmtoff; +#endif resp->isdst = (uint8_t) lt.tm_isdst; /* send message */ diff --git a/src/daemon/dlt_daemon_socket.c b/src/daemon/dlt_daemon_socket.c index 12f16a8..a4dbe9f 100644 --- a/src/daemon/dlt_daemon_socket.c +++ b/src/daemon/dlt_daemon_socket.c @@ -64,10 +64,14 @@ #include #include +#ifdef linux #include +#endif #include #include +#ifdef linux #include +#endif #include "dlt_types.h" #include "dlt-daemon.h" @@ -166,7 +170,7 @@ int dlt_daemon_socket_send(int sock,void* data1,int size1,void* data2,int size2, int dlt_daemon_socket_get_send_qeue_max_size(int sock) { int n = 0; - unsigned int m = sizeof(n); + socklen_t m = sizeof(n); getsockopt(sock,SOL_SOCKET,SO_SNDBUF,(void *)&n, &m); return n; diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index d64762b..6668793 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -22,6 +22,7 @@ target_link_libraries(dlt rt ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(dlt PROPERTIES VERSION ${DLT_VERSION} SOVERSION ${DLT_MAJOR_VERSION}) install(TARGETS dlt + RUNTIME DESTINATION bin LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR}/static COMPONENT base) diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index c3eb29d..3b23378 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -83,7 +83,9 @@ #include /* writev() */ #include +#ifdef linux #include +#endif #include "dlt_user.h" #include "dlt_user_shared.h" @@ -2214,8 +2216,9 @@ void dlt_user_trace_network_segmented_thread(void *unused) { /* Unused on purpose. */ (void) unused; - +#ifdef linux prctl(PR_SET_NAME, "dlt_segmented", 0, 0, 0); +#endif s_segmented_data *data; @@ -2751,7 +2754,9 @@ int dlt_disable_local_print(void) void dlt_user_receiverthread_function(__attribute__((unused)) void *ptr) { +#ifdef linux prctl(PR_SET_NAME, "dlt_receiver", 0, 0, 0); +#endif while (1) { /* Check for new messages from DLT daemon */ diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c index 8b94df7..589c50f 100755 --- a/src/shared/dlt_common.c +++ b/src/shared/dlt_common.c @@ -2943,7 +2943,7 @@ int dlt_setup_serial(int fd, speed_t speed) speed_t dlt_convert_serial_speed(int baudrate) { -#if !defined (__WIN32__) && !defined(_MSC_VER) +#if !defined (__WIN32__) && !defined(_MSC_VER) && !defined(__CYGWIN__) speed_t ret; switch (baudrate) diff --git a/src/system/dlt-system-filetransfer.c b/src/system/dlt-system-filetransfer.c index b75f614..273eb88 100644 --- a/src/system/dlt-system-filetransfer.c +++ b/src/system/dlt-system-filetransfer.c @@ -44,7 +44,9 @@ #include #include +#ifdef linux #include +#endif #include #include #include @@ -56,8 +58,10 @@ #include "dlt.h" #include "dlt_filetransfer.h" +#ifdef linux #define INOTIFY_SZ (sizeof(struct inotify_event)) #define INOTIFY_LEN (INOTIFY_SZ + NAME_MAX + 1) +#endif #define Z_CHUNK_SZ 1024*128 #define COMPRESS_EXTENSION ".gz" #define SUBDIR_COMPRESS ".tocompress" @@ -72,12 +76,14 @@ extern unsigned long getFileSerialNumber(const char* file, int *ok); DLT_IMPORT_CONTEXT(dltsystem); DLT_DECLARE_CONTEXT(filetransferContext) +#ifdef linux typedef struct { int handle; int fd[DLT_SYSTEM_LOG_DIRS_MAX]; } s_ft_inotify; s_ft_inotify ino; +#endif char *origin_name(char *src){ @@ -574,8 +580,9 @@ int init_filetransfer_dirs(FiletransferOptions const *opts) { DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, initializing inotify on directories.")); - ino.handle = inotify_init(); int i; +#ifdef linux + ino.handle = inotify_init(); if(ino.handle < 0) { @@ -583,6 +590,7 @@ int init_filetransfer_dirs(FiletransferOptions const *opts) DLT_STRING("Failed to initialize inotify in dlt-system file transfer.")); return -1; } +#endif for(i = 0;i < opts->Count;i++) { @@ -616,7 +624,7 @@ int init_filetransfer_dirs(FiletransferOptions const *opts) } free(subdirpath); - +#ifdef linux ino.fd[i] = inotify_add_watch(ino.handle, opts->Directory[i], IN_CLOSE_WRITE|IN_MOVED_TO); if(ino.fd[i] < 0) @@ -628,7 +636,7 @@ int init_filetransfer_dirs(FiletransferOptions const *opts) DLT_STRING(buf)); return -1; } - +#endif flush_dir(opts, i); @@ -638,6 +646,7 @@ int init_filetransfer_dirs(FiletransferOptions const *opts) int wait_for_files(FiletransferOptions const *opts) { +#ifdef linux DLT_LOG(dltsystem, DLT_LOG_DEBUG, DLT_STRING("dlt-system-filetransfer, waiting for files.")); static char buf[INOTIFY_LEN]; ssize_t len = read(ino.handle, buf, INOTIFY_LEN); @@ -679,6 +688,7 @@ int wait_for_files(FiletransferOptions const *opts) } i += INOTIFY_SZ + ie->len; } +#endif return 0; } diff --git a/src/system/dlt-system-watchdog.c b/src/system/dlt-system-watchdog.c index a45ef30..86b3346 100644 --- a/src/system/dlt-system-watchdog.c +++ b/src/system/dlt-system-watchdog.c @@ -152,7 +152,7 @@ void watchdog_thread(void *v_conf) // Calculate half of WATCHDOG_USEC in ns for timer tick notifiyPeriodNSec = watchdogTimeoutSeconds / 2 ; - sprintf(str,"systemd watchdog timeout: %i nsec - timer will be initialized: %i nsec\n", watchdogTimeoutSeconds, notifiyPeriodNSec ); + sprintf(str,"systemd watchdog timeout: %u nsec - timer will be initialized: %u nsec\n", watchdogTimeoutSeconds, notifiyPeriodNSec ); DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING(str)); if (make_periodic (notifiyPeriodNSec, &info) < 0 ) @@ -176,7 +176,7 @@ void watchdog_thread(void *v_conf) } else { - sprintf(str,"systemd watchdog timeout incorrect: %i\n", watchdogTimeoutSeconds); + sprintf(str,"systemd watchdog timeout incorrect: %u\n", watchdogTimeoutSeconds); DLT_LOG(watchdogContext, DLT_LOG_DEBUG,DLT_STRING(str)); } } -- cgit v1.2.1