Added test for gettid()

Sat, 04 May 2024 17:37:47 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 04 May 2024 17:37:47 +0200
changeset 726
8289078ff7be
parent 725
b15a2ae7bea7
child 727
78744b7e6021

Added test for gettid()

config.h.in file | annotate | diff | comparison | revisions
configure file | annotate | diff | comparison | revisions
configure.ac file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
--- a/config.h.in	Sat May 04 15:43:37 2024 +0200
+++ b/config.h.in	Sat May 04 17:37:47 2024 +0200
@@ -39,6 +39,9 @@
 #define SEND_PORT       6554
 
 
+/* Do not use wrapper gettid() */
+#undef HAVE_GETTID
+
 /* Compile experimental code (may not be present) */
 #undef USE_EXPERIMENT
 
--- a/configure	Sat May 04 15:43:37 2024 +0200
+++ b/configure	Sat May 04 17:37:47 2024 +0200
@@ -1679,6 +1679,52 @@
   eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
 } # ac_fn_c_check_header_compile
+
+# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
+# ---------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_c_check_decl ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  as_decl_name=`echo $2|sed 's/ *(.*//'`
+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+  (void) $as_decl_use;
+#else
+  (void) $as_decl_name;
+#endif
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_decl
 cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
@@ -3049,6 +3095,7 @@
 
 
 
+
 #
 # Libraries for mbsePi-apps
 #
@@ -3747,6 +3794,27 @@
 fi
 LIBS="$LIBS -lm"
 
+ac_fn_c_check_decl "$LINENO" "gettid" "ac_cv_have_decl_gettid" "$ac_includes_default"
+if test "x$ac_cv_have_decl_gettid" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_GETTID $ac_have_decl
+_ACEOF
+if test $ac_have_decl = 1; then :
+  result=yes
+else
+  result=no
+fi
+
+if test "$result" = "yes"; then
+  $as_echo "#define HAVE_GETTID 1" >>confdefs.h
+
+fi
+
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for xmlParseFile in -lxml2" >&5
 $as_echo_n "checking for xmlParseFile in -lxml2... " >&6; }
--- a/configure.ac	Sat May 04 15:43:37 2024 +0200
+++ b/configure.ac	Sat May 04 17:37:47 2024 +0200
@@ -29,6 +29,7 @@
 AC_CHECK_PROG(INSTALL, install, install)
 AC_CHECK_PROG(TAR, tar, tar)
 
+
 #
 # Libraries for mbsePi-apps
 #
@@ -92,6 +93,11 @@
 fi
 LIBS="$LIBS -lm"
 
+AC_CHECK_DECLS(gettid,result=yes,result=no)
+if test "$result" = "yes"; then
+  AC_DEFINE(HAVE_GETTID)
+fi
+
 
 AC_CHECK_LIB(xml2,xmlParseFile,result=yes,result=no)
 if test "$result" = "yes"; then
--- a/thermferm/thermferm.c	Sat May 04 15:43:37 2024 +0200
+++ b/thermferm/thermferm.c	Sat May 04 17:37:47 2024 +0200
@@ -118,6 +118,16 @@
 extern char		*state;
 
 
+#ifndef HAVE_GETTID
+/*
+ * Wrapper for older systems
+ */
+pid_t gettid(void)
+{
+    return (pid_t)syscall(__NR_gettid);
+}
+#endif
+
 
 void help(void)
 {
--- a/thermferm/thermferm.h	Sat May 04 15:43:37 2024 +0200
+++ b/thermferm/thermferm.h	Sat May 04 17:37:47 2024 +0200
@@ -20,6 +20,7 @@
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <sys/syscall.h>
 #include <sys/un.h>
 #include <sys/utsname.h>
 #include <ifaddrs.h>
@@ -54,6 +55,12 @@
 
 #endif
 
+
+#ifndef HAVE_GETTID
+pid_t gettid(void);
+#endif
+
+
 /*
  * Thread locks
  */

mercurial