emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master f97d4460e0: Implement system_process_attributes on Cygwin


From: Ken Brown
Subject: master f97d4460e0: Implement system_process_attributes on Cygwin
Date: Wed, 27 Apr 2022 13:23:07 -0400 (EDT)

branch: master
commit f97d4460e007d7b37aa7defcf9113cb6bb8cab5a
Author: Ken Brown <kbrown@cornell.edu>
Commit: Ken Brown <kbrown@cornell.edu>

    Implement system_process_attributes on Cygwin
    
    * src/sysdep.c (system_process_attributes) [CYGWIN]: Implement,
    using the /proc filesystem.  The code is identical to the
    GNU/Linux code except for the 'ttname' attribute.  (Bug#55153)
    
    * etc/NEWS: Mention the change.
---
 etc/NEWS     |  5 +++++
 src/sysdep.c | 26 +++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 526afe27a5..fc37ca68de 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2154,6 +2154,11 @@ where those APIs are available.
 When 'w32-use-native-image-API' is non-nil, Emacs on MS-Windows now
 has built-in support for displaying BMP images.
 
+** Cygwin
+
+---
+*** 'process-attributes' is now implemented.
+
 
 ----------------------------------------------------------------------
 This file is part of GNU Emacs.
diff --git a/src/sysdep.c b/src/sysdep.c
index 9c1e59c02b..95295e7e67 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3193,7 +3193,7 @@ make_lisp_timeval (struct timeval t)
 
 #endif
 
-#ifdef GNU_LINUX
+#if defined (GNU_LINUX) || defined (CYGWIN)
 
 static Lisp_Object
 time_from_jiffies (unsigned long long ticks, Lisp_Object hz, Lisp_Object form)
@@ -3241,6 +3241,7 @@ get_up_time (void)
   return up;
 }
 
+# ifdef GNU_LINUX
 #define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff)
 #define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 
12))
 
@@ -3286,6 +3287,7 @@ procfs_ttyname (int rdev)
   unblock_input ();
   return build_string (name);
 }
+# endif        /* GNU_LINUX */
 
 static uintmax_t
 procfs_get_total_memory (void)
@@ -3434,7 +3436,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
          attrs = Fcons (Fcons (Qttname, procfs_ttyname (tty)), attrs);
+# endif
          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);
@@ -3483,6 +3487,26 @@ system_process_attributes (Lisp_Object pid)
     }
   unbind_to (count, Qnil);
 
+# ifdef CYGWIN
+  /* ttname */
+  strcpy (procfn_end, "/ctty");
+  fd = emacs_open (fn, O_RDONLY, 0);
+  if (fd < 0)
+    nread = 0;
+  else
+    {
+      record_unwind_protect_int (close_file_unwind, fd);
+      nread = emacs_read_quit (fd, procbuf, sizeof procbuf);
+    }
+  /* /proc/<pid>/ctty should always end in newline. */
+  if (0 < nread && procbuf[nread - 1] == '\n')
+    procbuf[nread - 1] = '\0';
+  else
+    procbuf[0] = '\0';
+  attrs = Fcons (Fcons (Qttname, build_string (procbuf)), attrs);
+  unbind_to (count, Qnil);
+# endif        /* CYGWIN */
+
   /* args */
   strcpy (procfn_end, "/cmdline");
   fd = emacs_open (fn, O_RDONLY, 0);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]