[PATCH v2 03/18] ptpd: Add conditional macros for RTEMS
Gabriel Moyano
gabriel.moyano at dlr.de
Mon Apr 17 07:59:16 UTC 2023
From: Chris Johns <chrisj at rtems.org>
---
rtemsbsd/ptpd/src/dep/constants_dep.h | 5 +++--
rtemsbsd/ptpd/src/dep/net.c | 7 ++++++-
rtemsbsd/ptpd/src/dep/ptpd_dep.h | 8 ++++++++
rtemsbsd/ptpd/src/dep/startup.c | 2 ++
rtemsbsd/ptpd/src/dep/sys.c | 7 ++++++-
5 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/rtemsbsd/ptpd/src/dep/constants_dep.h b/rtemsbsd/ptpd/src/dep/constants_dep.h
index ad0f39f6..2aaad49d 100644
--- a/rtemsbsd/ptpd/src/dep/constants_dep.h
+++ b/rtemsbsd/ptpd/src/dep/constants_dep.h
@@ -16,7 +16,8 @@
/* platform dependent */
#if !defined(linux) && !defined(__NetBSD__) && !defined(__FreeBSD__) && \
- !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__sun) && !defined(__QNXNTO__)
+ !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__sun) && !defined(__QNXNTO__) && \
+ !defined(__rtems__)
#error PTPD hasn't been ported to this OS - should be possible \
if it's POSIX compatible, if you succeed, report it to ptpd-devel at sourceforge.net
#endif
@@ -34,7 +35,7 @@ if it's POSIX compatible, if you succeed, report it to ptpd-devel at sourceforge.ne
#define octet ether_addr_octet
#endif /* linux */
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__sun) || defined(__QNXNTO__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__sun) || defined(__QNXNTO__) || defined(__rtems__)
# include <sys/types.h>
# include <sys/socket.h>
#ifdef HAVE_SYS_SOCKIO_H
diff --git a/rtemsbsd/ptpd/src/dep/net.c b/rtemsbsd/ptpd/src/dep/net.c
index 7e185728..86db9b83 100644
--- a/rtemsbsd/ptpd/src/dep/net.c
+++ b/rtemsbsd/ptpd/src/dep/net.c
@@ -1208,7 +1208,12 @@ netInit(NetPath * netPath, RunTimeOpts * rtOpts, PtpClock * ptpClock)
*/
if(rtOpts->ipMode == IPMODE_UNICAST ||
- rtOpts->ignore_daemon_lock) {
+#ifdef __rtems__
+ FALSE
+#else
+ rtOpts->ignore_daemon_lock
+#endif
+ ) {
addr.sin_addr = netPath->interfaceAddr;
} else {
addr.sin_addr.s_addr = htonl(INADDR_ANY);
diff --git a/rtemsbsd/ptpd/src/dep/ptpd_dep.h b/rtemsbsd/ptpd/src/dep/ptpd_dep.h
index 10663afb..e0bcdf11 100644
--- a/rtemsbsd/ptpd/src/dep/ptpd_dep.h
+++ b/rtemsbsd/ptpd/src/dep/ptpd_dep.h
@@ -14,6 +14,10 @@
#define PTPD_DBGV
#endif
+#ifdef __rtems__
+#include <errno.h>
+#endif /* __rtems__ */
+
/** \name System messages*/
/**\{*/
@@ -31,7 +35,11 @@
#define ALERT(x, ...) logMessage(LOG_ALERT, x, ##__VA_ARGS__)
#define CRITICAL(x, ...) logMessage(LOG_CRIT, x, ##__VA_ARGS__)
#define ERROR(x, ...) logMessage(LOG_ERR, x, ##__VA_ARGS__)
+#ifdef __rtems__
+#define PERROR(x, ...) logMessage(LOG_ERR, x " (strerror: %s)\n", ##__VA_ARGS__, strerror(errno))
+#else /* __rtems__ */
#define PERROR(x, ...) logMessage(LOG_ERR, x " (strerror: %m)\n", ##__VA_ARGS__)
+#endif /* __rtems__ */
#define WARNING(x, ...) logMessage(LOG_WARNING, x, ##__VA_ARGS__)
#define NOTIFY(x, ...) logMessage(LOG_NOTICE, x, ##__VA_ARGS__)
#define NOTICE(x, ...) logMessage(LOG_NOTICE, x, ##__VA_ARGS__)
diff --git a/rtemsbsd/ptpd/src/dep/startup.c b/rtemsbsd/ptpd/src/dep/startup.c
index a9011736..97231d99 100644
--- a/rtemsbsd/ptpd/src/dep/startup.c
+++ b/rtemsbsd/ptpd/src/dep/startup.c
@@ -679,7 +679,9 @@ ptpdStartup(int argc, char **argv, Integer16 * ret, RunTimeOpts * rtOpts)
* this was not the case for log files. This adds consistency
* and allows to use FILE* vs. fds everywhere
*/
+#ifndef __rtems__
umask(~DEFAULT_FILE_PERMS);
+#endif /* __rtems__ */
/* get some entropy in... */
getTime(&tmpTime);
diff --git a/rtemsbsd/ptpd/src/dep/sys.c b/rtemsbsd/ptpd/src/dep/sys.c
index 31553b84..bf459a62 100644
--- a/rtemsbsd/ptpd/src/dep/sys.c
+++ b/rtemsbsd/ptpd/src/dep/sys.c
@@ -390,8 +390,13 @@ int writeMessage(FILE* destination, uint32_t *lastHash, int priority, const char
gettimeofday(&now, 0);
strftime(time_str, MAXTIMESTR, "%F %X", localtime((time_t*)&now.tv_sec));
fprintf(destination, "%s.%06d ", time_str, (int)now.tv_usec );
+#ifndef __rtems__
fprintf(destination,PTPD_PROGNAME"[%d].%s (%-9s ",
(int)getpid(), startupInProgress ? "startup" : rtOpts.ifaceName,
+#else /* __rtems__ */
+ fprintf(destination,PTPD_PROGNAME"[%08x].%s (%-9s ",
+ rtems_task_self(), startupInProgress ? "startup" : rtOpts.ifaceName,
+#endif /* __rtems__ */
priority == LOG_EMERG ? "emergency)" :
priority == LOG_ALERT ? "alert)" :
priority == LOG_CRIT ? "critical)" :
@@ -2627,7 +2632,7 @@ int setCpuAffinity(int cpu) {
#endif
-#ifdef HAVE_SYS_CPUSET_H
+#if defined(HAVE_SYS_CPUSET_H) && !defined(__rtems__)
cpuset_t mask;
CPU_ZERO(&mask);
if(cpu >= 0) {
--
2.25.1
More information about the devel
mailing list