Port Proced to Android

* configure.ac (HAVE_PROCFS): Define if opsys is `android'.

* src/android.c (android_set_task_name): New function.
(android_run_select_thread, android_run_debug_thread): Set the
name of the LWP for debugging purposes.

* src/process.c (create_process): Set F_SETPIPE_SZ on Android in
addition to GNU/Linux.

* src/sysdep.c (procfs_ttyname, system_process_attributes)
[__ANDROID__]: Enable procfs_ttyname on Android systems.
This commit is contained in:
Po Lu 2023-09-07 09:35:59 +08:00
parent 2416168310
commit 8b25edfbda
4 changed files with 55 additions and 8 deletions

View file

@ -6513,7 +6513,7 @@ case $opsys in
esac
case $opsys in
gnu-* | solaris | cygwin )
gnu-* | android | solaris | cygwin )
dnl FIXME Can't we test if this exists (eg /proc/$$)?
AC_DEFINE([HAVE_PROCFS], [1], [Define if you have the /proc filesystem.])
;;

View file

@ -282,6 +282,46 @@ static volatile sig_atomic_t android_pselect_interrupted;
#endif
/* Set the task name of the current task to NAME, a string at most 16
characters in length.
This name is displayed as that of the task (LWP)'s pthread in
GDB. */
static void
android_set_task_name (const char *name)
{
char proc_name[INT_STRLEN_BOUND (long)
+ sizeof "/proc/self/task//comm"];
int fd;
pid_t lwp;
size_t length;
lwp = gettid ();
sprintf (proc_name, "/proc/self/task/%ld/comm", (long) lwp);
fd = open (proc_name, O_WRONLY | O_TRUNC);
if (fd < 1)
goto failure;
length = strlen (name);
if (write (fd, name, MIN (16, length)) < 0)
goto failure;
close (fd);
return;
failure:
__android_log_print (ANDROID_LOG_WARN, __func__,
"Failed to set task name for LWP %ld: %s",
(long) lwp, strerror (errno));
/* Close the file descriptor if it is already set. */
if (fd >= 0)
close (fd);
}
static void *
android_run_select_thread (void *data)
{
@ -298,6 +338,9 @@ android_run_select_thread (void *data)
int sig;
#endif
/* Set the name of this thread's LWP for debugging purposes. */
android_set_task_name ("`android_select'");
#if __ANDROID_API__ < 16
/* A completely different implementation is used when building for
Android versions earlier than 16, because pselect with a signal
@ -797,6 +840,9 @@ android_run_debug_thread (void *data)
char *line;
size_t n;
/* Set the name of this thread's LWP for debugging purposes. */
android_set_task_name ("`android_debug'");
fd = (int) (intptr_t) data;
file = fdopen (fd, "r");

View file

@ -2206,9 +2206,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
inchannel = p->open_fd[READ_FROM_SUBPROCESS];
forkout = p->open_fd[SUBPROCESS_STDOUT];
#if defined(GNU_LINUX) && defined(F_SETPIPE_SZ)
#if (defined (GNU_LINUX) || defined __ANDROID__) \
&& defined (F_SETPIPE_SZ)
fcntl (inchannel, F_SETPIPE_SZ, read_process_output_max);
#endif
#endif /* (GNU_LINUX || __ANDROID__) && F_SETPIPE_SZ */
}
if (!NILP (p->stderrproc))

View file

@ -3452,7 +3452,7 @@ make_lisp_timeval (struct timeval t)
#endif
#if defined (GNU_LINUX) || defined (CYGWIN)
#if defined (GNU_LINUX) || defined (CYGWIN) || defined __ANDROID__
static Lisp_Object
time_from_jiffies (unsigned long long ticks, Lisp_Object hz, Lisp_Object form)
@ -3500,7 +3500,7 @@ get_up_time (void)
return up;
}
# ifdef GNU_LINUX
# if defined GNU_LINUX || defined __ANDROID__
#define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff)
#define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12))
@ -3546,7 +3546,7 @@ procfs_ttyname (int rdev)
unblock_input ();
return build_string (name);
}
# endif /* GNU_LINUX */
# endif /* GNU_LINUX || __ANDROID__ */
static uintmax_t
procfs_get_total_memory (void)
@ -3695,9 +3695,9 @@ system_process_attributes (Lisp_Object pid)
attrs = Fcons (Fcons (Qppid, INT_TO_INTEGER (ppid)), attrs);
attrs = Fcons (Fcons (Qpgrp, INT_TO_INTEGER (pgrp)), attrs);
attrs = Fcons (Fcons (Qsess, INT_TO_INTEGER (sess)), attrs);
# ifdef GNU_LINUX
# if defined GNU_LINUX || defined __ANDROID__
attrs = Fcons (Fcons (Qttname, procfs_ttyname (tty)), attrs);
# endif
# endif /* GNU_LINUX || __ANDROID__ */
attrs = Fcons (Fcons (Qtpgid, INT_TO_INTEGER (tpgid)), attrs);
attrs = Fcons (Fcons (Qminflt, INT_TO_INTEGER (minflt)), attrs);
attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (majflt)), attrs);