From: Pavel Pisa Date: Sun, 2 Apr 2023 09:32:41 +0000 (+0200) Subject: vac_canping: make code more portable to embedded systems. X-Git-Url: https://rtime.felk.cvut.cz/gitweb/canping.git/commitdiff_plain/847d85b2aea7ef6725aff02ba3b0e8fff2fc823a vac_canping: make code more portable to embedded systems. error function is GNU extension. fork is not available on NuttX and RTEMS. Signed-off-by: Pavel Pisa --- diff --git a/src/canping.c b/src/canping.c index b265e89..39322b8 100644 --- a/src/canping.c +++ b/src/canping.c @@ -13,7 +13,7 @@ along with this program. If not, see . Copyright 2005 Michal Sojka - Copyright 2005 Pavel Pisa + Copyright 2005-2023 Pavel Pisa */ #include diff --git a/src/vca_canping.c b/src/vca_canping.c index 348d641..87c3fd3 100644 --- a/src/vca_canping.c +++ b/src/vca_canping.c @@ -3,7 +3,7 @@ /* */ /* LibVCA - Versatile CAN/CANopen API library */ /* Copyright (C) 2005-2009 Michal Sojka, DCE FEE CTU Prague */ -/* Copyright (C) 2006-2009 Pavel Pisa */ +/* Copyright (C) 2006-2023 Pavel Pisa */ /* */ /* LibVCA is free software; you can redistribute it and/or modify it */ /* under terms of the GNU General Public License as published by the */ @@ -33,7 +33,19 @@ #include #include #include +#ifndef OMK_FOR_TARGET #include +#define error_with_status error +#else /*OMK_FOR_TARGET*/ +#include +static inline void error_with_status (int __status, int __errnum, const char *__format, ...) +{ + va_list ap; + va_start (ap, __format); + vfprintf (stderr, __format, ap); + va_end (ap); +} +#endif /* TODO: Handle the case where there are more canping slaves running * on one CAN bus. */ @@ -60,7 +72,12 @@ int sched_rtprio; #define dbg(level, fmt, arg...) do { if (level <= DEBUG) { printf("candping: " fmt, ## arg); } } while (0) #endif +#if !defined(OMK_FOR_TARGET) || defined(ERESTART) #define NOT_INTERRUPTED_SYSCALL (errno != EINTR && errno != ERESTART) +#else /*OMK_FOR_TARGET*/ +#define NOT_INTERRUPTED_SYSCALL (errno != EINTR) +#endif /*OMK_FOR_TARGET*/ + #define IS_FINISH_FLAG() (finish_flag) /* Exit codes */ @@ -281,7 +298,7 @@ void *master_thread(void *arg) if (option_save_all_times) { td->times = malloc(sizeof(*td->times)*option_count); if (!td->times) - error(1, errno, "malloc times"); + error_with_status(1, errno, "malloc times"); } /* Prepare data structures for the select syscall. */ @@ -634,7 +651,9 @@ int parse_options(int argc, char *argv[]) { int c; +#ifndef OMK_FOR_TARGET opterr = 0; +#endif /*OMK_FOR_TARGET*/ while ((c = getopt (argc, argv, "bc:d:e:g:hi:l:m:n:os:t:vw:yrR:")) != -1) switch (c) { @@ -808,7 +827,9 @@ int main(int argc, char *argv[]) if(sched_policy != SCHED_OTHER) { if(set_sched_policy_and_prio(sched_policy, sched_rtprio) <0) exit(EXIT_BAD_PARAM); +#if !defined(OMK_FOR_TARGET) || (defined(MCL_CURRENT) && defined(MCL_FUTURE)) mlockall(MCL_CURRENT | MCL_FUTURE); +#endif /*OMK_FOR_TARGET*/ } #endif @@ -838,17 +859,19 @@ int main(int argc, char *argv[]) sem_t *child_ready; int fork_ret = 0; if ((child_ready = sem_open("canping", O_CREAT)) == NULL) - error(1, errno, "sem_open"); + error_with_status(1, errno, "sem_open"); +#ifndef OMK_FOR_TARGET if (option_background) { /* Go to background when everything is ready */ fork_ret = fork(); if (fork_ret < 0) - error(1, errno, "Cannot go to background"); + error_with_status(1, errno, "Cannot go to background"); if (fork_ret == 0) { int devnull = open("/dev/null", O_WRONLY); dup2(devnull, 1); } } +#endif /*OMK_FOR_TARGET*/ if (fork_ret == 0) { /* Child */