all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Po Lu <luangruo@yahoo.com>
Cc: Bruno Haible <bruno@clisp.org>,
	bug-gnulib@gnu.org, Emacs Development <Emacs-devel@gnu.org>
Subject: Re: boot-time: straighten code
Date: Sat, 12 Aug 2023 23:35:04 -0700	[thread overview]
Message-ID: <5ee6768b-9af7-313f-3119-93b0a994acbf@cs.ucla.edu> (raw)
In-Reply-To: <87v8djoc6n.fsf@yahoo.com>

[-- Attachment #1: Type: text/plain, Size: 1224 bytes --]

On 2023-08-12 20:26, Po Lu wrote:

> In file included from boot-time.c:54:0:
> boot-time-aux.h: In function 'get_linux_uptime':
> boot-time-aux.h:70:3: error: implicit declaration of function 'sysinfo' [-Werror=implicit-function-declaration]
>     if (sysinfo (&info) >= 0)
>     ^
> boot-time.c: In function 'get_boot_time_uncached':
> boot-time.c:111:26: error: 'BOOT_TIME' undeclared (first use in this function)
>         if (ut->ut_type == BOOT_TIME)
>                            ^
> boot-time.c:111:26: note: each undeclared identifier is reported only once for each function it appears in
> boot-time.c:126:3: error: implicit declaration of function 'endutent' [-Werror=implicit-function-declaration]
>     END_UTMP_ENT ();
>     ^
> cc1: some warnings being treated as errors

Thanks for reporting that. As I understand it, the utmp/utmpx functions 
are a losing cause on Android since they never return anything. If so, 
it's simpler to bypass these functions on that platform. Also, Gnulib 
should bypass sysinfo unless it's available. Please try the attached 
patch, which I haven't installed onto Emacs master on Savannah. I've 
tested it only on Ubuntu 23.04.

If this patch works we can propagate it to Gnulib.

[-- Attachment #2: 0001-Temp-patch-for-Android.patch --]
[-- Type: text/x-patch, Size: 6598 bytes --]

From d2db6d8e92282de8ffb5293dd1445e3a2e549ed0 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 12 Aug 2023 23:20:12 -0700
Subject: [PATCH] Temp patch for Android

---
 configure.ac        | 19 -------------------
 lib/boot-time-aux.h | 10 ++++++++++
 lib/boot-time.c     | 26 +++++++++-----------------
 src/conf_post.h     | 34 ----------------------------------
 src/filelock.c      | 14 +++++---------
 5 files changed, 24 insertions(+), 79 deletions(-)

diff --git a/configure.ac b/configure.ac
index 46836073aa0..0234a82b92f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2710,25 +2710,6 @@ AC_DEFUN
 
     # Check for some functions not always present in the NDK.
     AC_CHECK_DECLS([android_get_device_api_level])
-    AC_CHECK_DECLS([endutent, sysinfo], [], [],
-      [[
-#include <sys/sysinfo.h>
-#include <utmp.h>
-]])
-
-    # Establish if BOOT_TIME is defined in utmp.h.
-    AC_CACHE_CHECK([if utmp.h defines BOOT_TIME],
-      [emacs_cv_utmp_h_defines_boot_time],
-      [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
-#include <utmp.h>
-#ifndef BOOT_TIME
-BOOT_TIME not defined
-#endif /* BOOT_TIME */
-]], [[]])], [emacs_cv_utmp_h_defines_boot_time=yes],
-      [emacs_cv_utmp_h_defines_boot_time=no])])
-    AS_IF([test x"$emacs_cv_utmp_h_defines_boot_time" = xyes],
-      [AC_DEFINE([UTMP_H_DEFINES_BOOT_TIME], [1],
-        [Define to 1 if building for Android and utmp.h declares BOOT_TIME])])
 
     # Say this build is really for Android.
     REALLY_ANDROID=yes])])
diff --git a/lib/boot-time-aux.h b/lib/boot-time-aux.h
index 348611fc85c..e782ca6eac6 100644
--- a/lib/boot-time-aux.h
+++ b/lib/boot-time-aux.h
@@ -16,6 +16,14 @@
 
 /* Written by Bruno Haible <bruno@clisp.org>.  */
 
+#if defined __linux__ || 9 <= __ANDROID_API__
+# include <sys/sysinfo.h>
+#endif
+#if 9 <= __ANDROID_API__
+/* Absent from some NDK versions, but present in API level 9+.  */
+extern int sysinfo (struct sysinfo *);
+#endif
+
 #define SIZEOF(a) (sizeof(a)/sizeof(a[0]))
 
 #if defined __linux__ || defined __ANDROID__
@@ -65,6 +73,7 @@ get_linux_uptime (struct timespec *p_uptime)
     }
 # endif
 
+# if defined __linux__ || 9 <= __ANDROID_API__
   /* The sysinfo call returns the uptime with a resolution of 1 sec only.  */
   struct sysinfo info;
   if (sysinfo (&info) >= 0)
@@ -73,6 +82,7 @@ get_linux_uptime (struct timespec *p_uptime)
       p_uptime->tv_nsec = 0;
       return 0;
     }
+# endif
 
   return -1;
 }
diff --git a/lib/boot-time.c b/lib/boot-time.c
index d813bfa5825..331711238bc 100644
--- a/lib/boot-time.c
+++ b/lib/boot-time.c
@@ -27,11 +27,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#if defined __linux__ || defined __ANDROID__
-# include <sys/sysinfo.h>
-# include <time.h>
-#endif
-
 #if HAVE_SYS_SYSCTL_H && !defined __minix
 # if HAVE_SYS_PARAM_H
 #  include <sys/param.h>
@@ -76,7 +71,12 @@ get_boot_time_uncached (struct timespec *p_boot_time)
 {
   struct timespec found_boot_time = {0};
 
-# if (HAVE_UTMPX_H ? HAVE_STRUCT_UTMPX_UT_TYPE : HAVE_STRUCT_UTMP_UT_TYPE)
+# ifdef __ANDROID__
+
+  /* Workaround for Android:  */
+  get_android_boot_time (&found_boot_time);
+
+# elif (HAVE_UTMPX_H ? HAVE_STRUCT_UTMPX_UT_TYPE : HAVE_STRUCT_UTMP_UT_TYPE)
 
   /* Try to find the boot time in the /var/run/utmp file.  */
 
@@ -90,7 +90,7 @@ get_boot_time_uncached (struct timespec *p_boot_time)
 
   SET_UTMP_ENT ();
 
-#   if (defined __linux__ && !defined __ANDROID__) || defined __minix
+#   if defined __linux__ || defined __minix
   /* Timestamp of the "runlevel" entry, if any.  */
   struct timespec runlevel_ts = {0};
 #   endif
@@ -111,7 +111,7 @@ get_boot_time_uncached (struct timespec *p_boot_time)
       if (ut->ut_type == BOOT_TIME)
         found_boot_time = ts;
 
-#   if defined __linux__ && !defined __ANDROID__
+#   ifdef __linux__
       if (memcmp (UT_USER (ut), "runlevel", strlen ("runlevel") + 1) == 0
           && memcmp (ut->ut_line, "~", strlen ("~") + 1) == 0)
         runlevel_ts = ts;
@@ -125,7 +125,7 @@ get_boot_time_uncached (struct timespec *p_boot_time)
 
   END_UTMP_ENT ();
 
-#   if defined __linux__ && !defined __ANDROID__
+#   ifdef __linux__
   /* On Raspbian, which runs on hardware without a real-time clock, during boot,
        1. the clock gets set to 1970-01-01 00:00:00,
        2. an entry gets written into /var/run/utmp, with ut_type = BOOT_TIME,
@@ -145,14 +145,6 @@ get_boot_time_uncached (struct timespec *p_boot_time)
     }
 #   endif
 
-#   if defined __ANDROID__
-  if (found_boot_time.tv_sec == 0)
-    {
-      /* Workaround for Android:  */
-      get_android_boot_time (&found_boot_time);
-    }
-#   endif
-
 #   if defined __minix
   /* On Minix, during boot,
        1. an entry gets written into /var/run/utmp, with ut_type = BOOT_TIME,
diff --git a/src/conf_post.h b/src/conf_post.h
index 5f18e5ae4bb..f31e012dc6e 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -471,37 +471,3 @@ #define VFORK() vfork ()
 #undef MB_CUR_MAX
 #define MB_CUR_MAX REPLACEMENT_MB_CUR_MAX
 #endif /* REPLACEMENT_MB_CUR_MAX */
-
-#ifdef __ANDROID__
-
-/* The Android NDK r10b omits the function `endutent' that is actually
-   defined in the C library and used by Gnulib.  Define a prototype
-   for it here.  */
-
-#if !HAVE_DECL_ENDUTENT
-extern void endutent (void);
-#endif /* !HAVE_DECL_ENDUTENT */
-
-/* Now define substitutes for BOOT_TIME if necessary.  */
-
-#ifndef UTMP_H_DEFINES_BOOT_TIME
-#include <utmp.h>
-
-#define BOOT_TIME 2
-#endif /* !UTMP_H_DEFINES_BOOT_TIME */
-
-/* sysinfo is also absent from some versions of the NDK, yet is
-   present on API level 9 and above.  */
-
-#if !HAVE_DECL_SYSINFO
-#include <sys/sysinfo.h>
-
-#if __ANDROID_API__ >= 9
-extern int sysinfo (struct sysinfo *info);
-#else /* __ANDROID_API__ < 8 */
-/* Gnulib uses this function unconditionally.  */
-#define sysinfo(ignored) ((void) ignored, (errno = ENOSYS), -1)
-#endif /* __ANDROID_API >= 9 */
-#endif /* !HAVE_DECL_SYSINFO */
-
-#endif /* __ANDROID__ */
diff --git a/src/filelock.c b/src/filelock.c
index f3075b93322..92be20ad8a0 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -118,16 +118,12 @@ get_boot_sec (void)
   if (will_dump_p ())
     return 0;
 
+  struct timespec boot_time;
+  boot_time.tv_sec = 0;
 #ifndef MSDOS
-  {
-    struct timespec boot_time;
-    boot_time.tv_sec = 0;
-    get_boot_time (&boot_time);
-    return boot_time.tv_sec;
-  }
-#else /* MSDOS */
-  return 0;
-#endif /* MSDOS */
+  get_boot_time (&boot_time);
+#endif
+  return boot_time.tv_sec;
 }
 \f
 /* An arbitrary limit on lock contents length.  8 K should be plenty
-- 
2.39.2


  reply	other threads:[~2023-08-13  6:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4536176.VaOIPsP7d9@nimes>
2023-08-13  2:49 ` boot-time: straighten code Paul Eggert
2023-08-13  3:26   ` Po Lu
2023-08-13  6:35     ` Paul Eggert [this message]
2023-08-13 13:45     ` Bruno Haible
2023-08-13 14:16     ` Bruno Haible
2023-08-13 14:36     ` Bruno Haible
2023-08-13 23:44       ` Po Lu
2023-08-13 23:59         ` Bruno Haible
2023-08-14  1:07           ` Po Lu
2023-08-14  2:14             ` Corwin Brust
2023-08-15 19:57               ` Windows port binaries Bruno Haible
2023-08-16  6:45                 ` Po Lu
2023-08-16 11:36                 ` Eli Zaretskii
2023-08-17 14:01                   ` Bruno Haible
2023-08-17 14:14                     ` Eli Zaretskii
2023-08-14  8:02   ` boot-time: straighten code Andreas Schwab
2023-08-14  9:15     ` Bruno Haible
2023-08-14  9:20       ` Andreas Schwab
2023-08-14 10:19         ` Bruno Haible
2023-08-14 10:33           ` Andreas Schwab
2023-08-14 13:51             ` Bruno Haible
2023-08-15 23:03               ` Paul Eggert
2023-08-15 21:12   ` Bruno Haible
2023-08-16 10:13     ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5ee6768b-9af7-313f-3119-93b0a994acbf@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=Emacs-devel@gnu.org \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=luangruo@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.