From d2db6d8e92282de8ffb5293dd1445e3a2e549ed0 Mon Sep 17 00:00:00 2001 From: Paul Eggert 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 -#include -]]) - - # 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 -#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 . */ +#if defined __linux__ || 9 <= __ANDROID_API__ +# include +#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 #include -#if defined __linux__ || defined __ANDROID__ -# include -# include -#endif - #if HAVE_SYS_SYSCTL_H && !defined __minix # if HAVE_SYS_PARAM_H # include @@ -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 - -#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 - -#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; } /* An arbitrary limit on lock contents length. 8 K should be plenty -- 2.39.2