]> git.eshelyaron.com Git - emacs.git/commitdiff
Port Proced to Android
authorPo Lu <luangruo@yahoo.com>
Thu, 7 Sep 2023 01:35:59 +0000 (09:35 +0800)
committerPo Lu <luangruo@yahoo.com>
Thu, 7 Sep 2023 01:35:59 +0000 (09:35 +0800)
* 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.

configure.ac
src/android.c
src/process.c
src/sysdep.c

index f92339225b555a1f5872fa8414191f16b103608b..ee13b2e06590bef4a0e6ee8f1cda22f1ea23f0ee 100644 (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.])
   ;;
index b501a66b25d90a014408511e637bb01a581d42a4..76014cbcb3a4e22b83528aa2872136a3eeda1bf8 100644 (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");
 
index 08cb810ec136bdddef25ea8d05a7b9399b9cfffc..dbd677e59d73498c99e0a6162d8b7602a7951109 100644 (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))
index 52fbfbd1eb183b010578d23d4e1fb7da750a0b33..f49fed7da1e23387e2060d90ce4bda558523b507 100644 (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);