* Android NDK r26 and utmpx
[not found] <87v87ntq4m.fsf.ref@yahoo.com>
@ 2024-01-21 1:46 ` Po Lu
2024-01-21 3:04 ` Paul Eggert
2024-01-21 16:54 ` Bruno Haible
0 siblings, 2 replies; 6+ messages in thread
From: Po Lu @ 2024-01-21 1:46 UTC (permalink / raw)
To: bug-gnulib
utmpx.h is provided by this new release of the Android NDK, defining
functions as nonfunctional as utmp.h does.
The more pressing problem is that its presence suppresses the definition
of UTMP_NAME_FUNCTION when a program is built with an __ANDROID_API__
lower than 34, where the utmpx* series of functions were introduced,
because the conditional for HAVE_UTMPX_H in readutmp.h does not search
for a `utmpname' function if `utmpxname' is unavailable, with the result
that get_android_boot_time is never invoked. Here are the relevant
portions of config.log:
configure:9462: checking for utmpx.h
configure:9462: /opt/android/ndk/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android22-clang -c -O2 -g3 -Werror=implicit-function-declaration conftest.c >&5
configure:9462: $? = 0
configure:9462: result: yes
configure:16416: /opt/android/ndk/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android22-clang -o conftest -O2 -g3 -Werror=implicit-function-declaration conftest.c >&5
ld.lld: error: undefined symbol: utmpxname
>>> referenced by conftest.c:116
>>> /tmp/conftest-c4f4cf.o:(main)
>>> did you mean: utmpname
>>> defined in: /opt/android/ndk/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/22/libc.so
I will install a workaround in Emacs, but it ought to be fixed at the
source.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Android NDK r26 and utmpx
2024-01-21 1:46 ` Android NDK r26 and utmpx Po Lu
@ 2024-01-21 3:04 ` Paul Eggert
2024-01-21 3:38 ` Po Lu
2024-01-21 16:54 ` Bruno Haible
1 sibling, 1 reply; 6+ messages in thread
From: Paul Eggert @ 2024-01-21 3:04 UTC (permalink / raw)
To: Po Lu; +Cc: bug-gnulib
[-- Attachment #1: Type: text/plain, Size: 271 bytes --]
Thanks for reporting that. Would something like the attached Gnulib
patch fix the Android issue?
This patch assumes that readutmp-like functions have never worked on
Android (always report nothing); is that the case?
I haven't installed this, or tested it on Android.
[-- Attachment #2: 0001-readutmp-port-to-Android-NDK-r26.patch --]
[-- Type: text/x-patch, Size: 4793 bytes --]
From 60aa07c1ccd5aa18a9f87997a51acc8507515ef1 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 20 Jan 2024 19:01:12 -0800
Subject: [PATCH] readutmp: port to Android NDK r26
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lib/readutmp.c (read_utmp_from_file) [__ANDROID__]:
Don’t bother trying to read from a real file, as this
has never worked with Android and the useless code
stops working on Android NDK r26.
---
ChangeLog | 8 ++++++++
lib/readutmp.c | 48 ++++++++++++++++++++++++------------------------
2 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d8d2a13d9e..4533eaceb2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-01-20 Paul Eggert <eggert@cs.ucla.edu>
+
+ readutmp: port to Android NDK r26
+ * lib/readutmp.c (read_utmp_from_file) [__ANDROID__]:
+ Don’t bother trying to read from a real file, as this
+ has never worked with Android and the useless code
+ stops working on Android NDK r26.
+
2024-01-19 Bruno Haible <bruno@clisp.org>
fenv-environment: Fix for NetBSD/powerpc.
diff --git a/lib/readutmp.c b/lib/readutmp.c
index ae2e3ae8c6..59074d68c1 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -330,7 +330,27 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
# if READUTMP_USE_SYSTEMD || HAVE_UTMPX_H || HAVE_UTMP_H
-# if defined UTMP_NAME_FUNCTION /* glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, IRIX, Solaris, Cygwin, Android */
+# ifdef __ANDROID__
+ /* On Android, there is no /var, and normal processes don't have access
+ to system files. Therefore use the kernel's uptime counter, although
+ it produces wrong values after the date has been bumped in the running
+ system. */
+ if ((options & (READ_UTMP_USER_PROCESS | READ_UTMP_NO_BOOT_TIME)) == 0
+ && strcmp (file, UTMP_FILE) == 0
+ && !have_boot_time (a))
+ {
+ struct timespec boot_time;
+ if (get_android_boot_time (&boot_time) >= 0)
+ a = add_utmp (a, options,
+ "reboot", strlen ("reboot"),
+ "", 0,
+ "", 0,
+ "", 0,
+ 0, BOOT_TIME, boot_time, 0, 0, 0);
+ }
+
+# elif defined UTMP_NAME_FUNCTION
+ /* glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, IRIX, Solaris, Cygwin */
/* Ignore the return value for now.
Solaris' utmpname returns 1 upon success -- which is contrary
@@ -340,7 +360,7 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
SET_UTMP_ENT ();
-# if (defined __linux__ && !defined __ANDROID__) || defined __minix
+# if defined __linux__ || defined __minix
bool file_is_utmp = (strcmp (file, UTMP_FILE) == 0);
/* Timestamp of the "runlevel" entry, if any. */
struct timespec runlevel_ts = {0};
@@ -390,7 +410,7 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
#endif
UT_EXIT_E_TERMINATION (ut), UT_EXIT_E_EXIT (ut)
);
-# if defined __linux__ && !defined __ANDROID__
+# ifdef __linux__
if (file_is_utmp
&& memcmp (UT_USER (ut), "runlevel", strlen ("runlevel") + 1) == 0
&& memcmp (ut->ut_line, "~", strlen ("~") + 1) == 0)
@@ -406,7 +426,7 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
END_UTMP_ENT ();
-# if defined __linux__ && !defined __ANDROID__
+# ifdef __linux__
/* On Alpine Linux, UTMP_FILE is not filled. It is always empty.
So, fake a BOOT_TIME entry, by getting the time stamp of a file that
gets touched only during the boot process.
@@ -449,26 +469,6 @@ read_utmp_from_file (char const *file, idx_t *n_entries, STRUCT_UTMP **utmp_buf,
}
# endif
-# if defined __ANDROID__
- /* On Android, there is no /var, and normal processes don't have access
- to system files. Therefore use the kernel's uptime counter, although
- it produces wrong values after the date has been bumped in the running
- system. */
- if ((options & (READ_UTMP_USER_PROCESS | READ_UTMP_NO_BOOT_TIME)) == 0
- && strcmp (file, UTMP_FILE) == 0
- && !have_boot_time (a))
- {
- struct timespec boot_time;
- if (get_android_boot_time (&boot_time) >= 0)
- a = add_utmp (a, options,
- "reboot", strlen ("reboot"),
- "", 0,
- "", 0,
- "", 0,
- 0, BOOT_TIME, boot_time, 0, 0, 0);
- }
-# endif
-
# if defined __minix
/* On Minix, during boot,
1. an entry gets written into /var/run/utmp, with ut_type = BOOT_TIME,
--
2.40.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: Android NDK r26 and utmpx
2024-01-21 3:04 ` Paul Eggert
@ 2024-01-21 3:38 ` Po Lu
2024-01-21 4:04 ` Paul Eggert
0 siblings, 1 reply; 6+ messages in thread
From: Po Lu @ 2024-01-21 3:38 UTC (permalink / raw)
To: Paul Eggert; +Cc: bug-gnulib
Paul Eggert <eggert@cs.ucla.edu> writes:
> Thanks for reporting that. Would something like the attached Gnulib
> patch fix the Android issue?
>
> This patch assumes that readutmp-like functions have never worked on
> Android (always report nothing); is that the case?
That is true, but the problem affects the boot-time module rather than
readutmp, which Emacs doesn't import. And in the words of Bruno, a
functional utmp(x) might appear in Android someday, which binaries
compiled today should take advantage of wherever available.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Android NDK r26 and utmpx
2024-01-21 3:38 ` Po Lu
@ 2024-01-21 4:04 ` Paul Eggert
2024-01-21 5:11 ` Po Lu
0 siblings, 1 reply; 6+ messages in thread
From: Paul Eggert @ 2024-01-21 4:04 UTC (permalink / raw)
To: Po Lu; +Cc: bug-gnulib
[-- Attachment #1: Type: text/plain, Size: 441 bytes --]
On 2024-01-20 19:38, Po Lu wrote:
> the problem affects the boot-time module rather than
> readutmp, which Emacs doesn't import. And in the words of Bruno, a
> functional utmp(x) might appear in Android someday, which binaries
> compiled today should take advantage of wherever available.
Oh, I see I was barking up the wrong tree. How about the attached patch
instead? Again, it's not installed into Gnulib and is not tested on Android.
[-- Attachment #2: 0001-boot-time-port-to-Android-SDK-r26.patch --]
[-- Type: text/x-patch, Size: 2686 bytes --]
From 5b48472effc4174d8c25bd46736fe7236ef36aae Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 20 Jan 2024 20:03:25 -0800
Subject: [PATCH] boot-time: port to Android SDK r26
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lib/boot-time.c (get_boot_time_uncached) [__ANDROID__]: Don’t
assume UTMP_NAME_FUNCTION is defined. Problem reported by Po Lu in:
https://lists.gnu.org/r/bug-gnulib/2024-01/msg00063.html
---
ChangeLog | 7 +++++++
lib/boot-time.c | 19 +++++++++----------
2 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d8d2a13d9e..80144c14dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-01-20 Paul Eggert <eggert@cs.ucla.edu>
+
+ boot-time: port to Android SDK r26
+ * lib/boot-time.c (get_boot_time_uncached) [__ANDROID__]: Don’t
+ assume UTMP_NAME_FUNCTION is defined. Problem reported by Po Lu in:
+ https://lists.gnu.org/r/bug-gnulib/2024-01/msg00063.html
+
2024-01-19 Bruno Haible <bruno@clisp.org>
fenv-environment: Fix for NetBSD/powerpc.
diff --git a/lib/boot-time.c b/lib/boot-time.c
index c1171e8024..c9dff8de4e 100644
--- a/lib/boot-time.c
+++ b/lib/boot-time.c
@@ -82,7 +82,7 @@ get_boot_time_uncached (struct timespec *p_boot_time)
/* Try to find the boot time in the /var/run/utmp file. */
-# if defined UTMP_NAME_FUNCTION /* glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, IRIX, Solaris, Cygwin, Android */
+# if defined UTMP_NAME_FUNCTION /* glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, IRIX, Solaris, Cygwin, Android pre-r26 */
/* Ignore the return value for now.
Solaris' utmpname returns 1 upon success -- which is contrary
@@ -147,14 +147,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,
@@ -167,7 +159,7 @@ get_boot_time_uncached (struct timespec *p_boot_time)
found_boot_time = runlevel_ts;
# endif
-# else /* HP-UX, Haiku */
+# elif !defined __ANDROID__ /* HP-UX, Haiku */
FILE *f = fopen (UTMP_FILE, "re");
@@ -228,6 +220,13 @@ get_boot_time_uncached (struct timespec *p_boot_time)
}
# endif
+# if defined __ANDROID__
+ if (found_boot_time.tv_sec == 0)
+ {
+ get_android_boot_time (&found_boot_time);
+ }
+#endif
+
# if defined __HAIKU__
if (found_boot_time.tv_sec == 0)
{
--
2.40.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: Android NDK r26 and utmpx
2024-01-21 4:04 ` Paul Eggert
@ 2024-01-21 5:11 ` Po Lu
0 siblings, 0 replies; 6+ messages in thread
From: Po Lu @ 2024-01-21 5:11 UTC (permalink / raw)
To: Paul Eggert; +Cc: bug-gnulib
Paul Eggert <eggert@cs.ucla.edu> writes:
> On 2024-01-20 19:38, Po Lu wrote:
>> the problem affects the boot-time module rather than
>> readutmp, which Emacs doesn't import. And in the words of Bruno, a
>> functional utmp(x) might appear in Android someday, which binaries
>> compiled today should take advantage of wherever available.
>
> Oh, I see I was barking up the wrong tree. How about the attached
> patch instead? Again, it's not installed into Gnulib and is not tested
> on Android.
I haven't tested this yet, but something tells me that the proper course
of action is to guarantee that the code which worked under NDK r25 is
enabled under r26, in the sense of falling back to the HAVE_UTMP_H
conditional (in readutmp.h) if functions inside utmpx.h can't be linked
against.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Android NDK r26 and utmpx
2024-01-21 1:46 ` Android NDK r26 and utmpx Po Lu
2024-01-21 3:04 ` Paul Eggert
@ 2024-01-21 16:54 ` Bruno Haible
1 sibling, 0 replies; 6+ messages in thread
From: Bruno Haible @ 2024-01-21 16:54 UTC (permalink / raw)
To: bug-gnulib; +Cc: Po Lu
Hi Po Lu,
> utmpx.h is provided by this new release of the Android NDK, defining
> functions as nonfunctional as utmp.h does.
So, HAVE_UTMPX_H now is 1.
And utmpname exists but utmpxname does not exist. Therefore UTMP_NAME_FUNCTION
is no longer defined.
> The more pressing problem is that its presence suppresses the definition
> of UTMP_NAME_FUNCTION when a program is built with an __ANDROID_API__
> lower than 34, where the utmpx* series of functions were introduced,
> because the conditional for HAVE_UTMPX_H in readutmp.h does not search
> for a `utmpname' function if `utmpxname' is unavailable, with the result
> that get_android_boot_time is never invoked. Here are the relevant
> portions of config.log:
>
> configure:9462: checking for utmpx.h
> configure:9462: /opt/android/ndk/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android22-clang -c -O2 -g3 -Werror=implicit-function-declaration conftest.c >&5
> configure:9462: $? = 0
> configure:9462: result: yes
>
> configure:16416: /opt/android/ndk/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android22-clang -o conftest -O2 -g3 -Werror=implicit-function-declaration conftest.c >&5
> ld.lld: error: undefined symbol: utmpxname
> >>> referenced by conftest.c:116
> >>> /tmp/conftest-c4f4cf.o:(main)
> >>> did you mean: utmpname
> >>> defined in: /opt/android/ndk/android-ndk-r26/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/22/libc.so
>
> I will install a workaround in Emacs, but it ought to be fixed at the
> source.
This patch should fix it, in the simplest possible way. Committing it.
2024-01-21 Bruno Haible <bruno@clisp.org>
readutmp, boot-time: Port to Android NDK r26.
Reported by Po Lu <luangruo@yahoo.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-01/msg00063.html>.
* lib/readutmp.h: Update comments.
(UTMP_NAME_FUNCTION): Define as a no-op for Android with HAVE_UTMPX_H.
diff --git a/lib/readutmp.h b/lib/readutmp.h
index b62eb3beaa..dcfd44dbbc 100644
--- a/lib/readutmp.h
+++ b/lib/readutmp.h
@@ -114,21 +114,21 @@ enum { UT_HOST_SIZE = -1 };
Field Type Platforms
---------- ------ ---------
- ⎡ ut_user char[] glibc, musl, macOS, FreeBSD, AIX, HP-UX, IRIX, Solaris, Cygwin
+ ⎡ ut_user char[] glibc, musl, macOS, FreeBSD, AIX, HP-UX, IRIX, Solaris, Cygwin, Android
⎣ ut_name char[] NetBSD, Minix
- ut_id char[] glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin
- ut_line char[] glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin
- ut_pid pid_t glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin
- ut_type short glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin
- ⎡ ut_tv struct glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin
+ ut_id char[] glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin, Android
+ ut_line char[] glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin, Android
+ ut_pid pid_t glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin, Android
+ ut_type short glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin, Android
+ ⎡ ut_tv struct glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin, Android
⎢ { tv_sec; tv_usec; }
⎣ ut_time time_t Cygwin
- ut_host char[] glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin
- ut_exit struct glibc, musl, NetBSD, Minix, HP-UX, IRIX, Solaris
+ ut_host char[] glibc, musl, macOS, FreeBSD, NetBSD, Minix, AIX, HP-UX, IRIX, Solaris, Cygwin, Android
+ ut_exit struct glibc, musl, NetBSD, Minix, HP-UX, IRIX, Solaris, Android
{ e_termination; e_exit; }
- ut_session [long] int glibc, musl, NetBSD, Minix, IRIX, Solaris
+ ut_session [long] int glibc, musl, NetBSD, Minix, IRIX, Solaris, Android
⎡ ut_addr [long] int HP-UX, Cygwin
- ⎢ ut_addr_v6 [u]int[4] glibc, musl
+ ⎢ ut_addr_v6 [u]int[4] glibc, musl, Android
⎣ ut_ss struct sockaddr_storage NetBSD, Minix
*/
@@ -177,6 +177,10 @@ struct utmpx32
# define UTMP_NAME_FUNCTION utmpxname
# elif defined UTXDB_ACTIVE /* FreeBSD */
# define UTMP_NAME_FUNCTION(x) setutxdb (UTXDB_ACTIVE, x)
+# elif defined __ANDROID__ /* Android */
+/* As of Android NDK r26, the getutxent, setutxent functions are no-ops.
+ Therefore we can ignore the file name. */
+# define UTMP_NAME_FUNCTION(x) ((void) (x))
# endif
#elif HAVE_UTMP_H
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-01-21 16:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <87v87ntq4m.fsf.ref@yahoo.com>
2024-01-21 1:46 ` Android NDK r26 and utmpx Po Lu
2024-01-21 3:04 ` Paul Eggert
2024-01-21 3:38 ` Po Lu
2024-01-21 4:04 ` Paul Eggert
2024-01-21 5:11 ` Po Lu
2024-01-21 16:54 ` Bruno Haible
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).