* bug#55153: 29.0.50; Implement system_process_attributes on Cygwin @ 2022-04-27 15:00 Ken Brown 2022-04-27 15:16 ` Ken Brown 0 siblings, 1 reply; 6+ messages in thread From: Ken Brown @ 2022-04-27 15:00 UTC (permalink / raw) To: 55153 I just noticed, as a result of the failure of desktop-tests--emacs-pid-running-p, that system_process_attributes was never implemented on Cygwin. This turns out to be quite easy to do since most of the GNU/Linux code works without change on Cygwin. I'll submit a patch in a follow-up email. Ken ^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#55153: 29.0.50; Implement system_process_attributes on Cygwin 2022-04-27 15:00 bug#55153: 29.0.50; Implement system_process_attributes on Cygwin Ken Brown @ 2022-04-27 15:16 ` Ken Brown 2022-04-27 15:52 ` Eli Zaretskii 0 siblings, 1 reply; 6+ messages in thread From: Ken Brown @ 2022-04-27 15:16 UTC (permalink / raw) To: 55153 [-- Attachment #1: Type: text/plain, Size: 540 bytes --] On 4/27/2022 11:00 AM, Ken Brown wrote: > I just noticed, as a result of the failure of > desktop-tests--emacs-pid-running-p, that system_process_attributes was never > implemented on Cygwin. This turns out to be quite easy to do since most of the > GNU/Linux code works without change on Cygwin. I'll submit a patch in a > follow-up email. Patch attached. It's written against the master branch, but it can easily be backported to the release branch. It seems safe enough to me, but I don't have strong feelings about it. Ken [-- Attachment #2: 0001-Implement-system_process_attributes-on-Cygwin.patch --] [-- Type: text/plain, Size: 2565 bytes --] From 1a603fc40bca37e1eba0fcfa82448323b89641c5 Mon Sep 17 00:00:00 2001 From: Ken Brown <kbrown@cornell.edu> Date: Wed, 27 Apr 2022 10:46:57 -0400 Subject: [PATCH] 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) --- src/sysdep.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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); -- 2.36.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#55153: 29.0.50; Implement system_process_attributes on Cygwin 2022-04-27 15:16 ` Ken Brown @ 2022-04-27 15:52 ` Eli Zaretskii 2022-04-27 16:45 ` Ken Brown 0 siblings, 1 reply; 6+ messages in thread From: Eli Zaretskii @ 2022-04-27 15:52 UTC (permalink / raw) To: Ken Brown; +Cc: 55153 > Date: Wed, 27 Apr 2022 11:16:46 -0400 > From: Ken Brown <kbrown@cornell.edu> > > +# 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); Is what you read from /proc/<pid>/ctty guaranteed to be pure-ASCII string? If not, build_string is not the best idea here; you need to produce a unibyte string and decode it. Thanks. P.S. Doesn't this warrant a NEWS entry? ^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#55153: 29.0.50; Implement system_process_attributes on Cygwin 2022-04-27 15:52 ` Eli Zaretskii @ 2022-04-27 16:45 ` Ken Brown 2022-04-27 17:12 ` Eli Zaretskii 0 siblings, 1 reply; 6+ messages in thread From: Ken Brown @ 2022-04-27 16:45 UTC (permalink / raw) To: Eli Zaretskii; +Cc: 55153 [-- Attachment #1: Type: text/plain, Size: 913 bytes --] On 4/27/2022 11:53 AM, Eli Zaretskii wrote: >> Date: Wed, 27 Apr 2022 11:16:46 -0400 >> From: Ken Brown <kbrown@cornell.edu> >> >> +# 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); > > Is what you read from /proc/<pid>/ctty guaranteed to be pure-ASCII > string? Yes. It's typically something like "/dev/pty0". > P.S. Doesn't this warrant a NEWS entry? Revised patch attached, with a NEWS entry. Ken [-- Attachment #2: 0001-Implement-system_process_attributes-on-Cygwin.patch --] [-- Type: text/plain, Size: 3072 bytes --] From 5af483b3adcd475a2d544c8f23462d90055498c0 Mon Sep 17 00:00:00 2001 From: Ken Brown <kbrown@cornell.edu> Date: Wed, 27 Apr 2022 10:46:57 -0400 Subject: [PATCH] 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 2ecad81b11..335a55e656 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2149,6 +2149,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. + \f ---------------------------------------------------------------------- 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); -- 2.36.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#55153: 29.0.50; Implement system_process_attributes on Cygwin 2022-04-27 16:45 ` Ken Brown @ 2022-04-27 17:12 ` Eli Zaretskii 2022-04-27 17:25 ` Ken Brown 0 siblings, 1 reply; 6+ messages in thread From: Eli Zaretskii @ 2022-04-27 17:12 UTC (permalink / raw) To: Ken Brown; +Cc: 55153 > Date: Wed, 27 Apr 2022 12:45:45 -0400 > Cc: 55153@debbugs.gnu.org > From: Ken Brown <kbrown@cornell.edu> > > > Is what you read from /proc/<pid>/ctty guaranteed to be pure-ASCII > > string? > > Yes. It's typically something like "/dev/pty0". > > > P.S. Doesn't this warrant a NEWS entry? > > Revised patch attached, with a NEWS entry. Thanks, LGTM. ^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#55153: 29.0.50; Implement system_process_attributes on Cygwin 2022-04-27 17:12 ` Eli Zaretskii @ 2022-04-27 17:25 ` Ken Brown 0 siblings, 0 replies; 6+ messages in thread From: Ken Brown @ 2022-04-27 17:25 UTC (permalink / raw) To: Eli Zaretskii; +Cc: 55153-done On 4/27/2022 1:12 PM, Eli Zaretskii wrote: > Thanks, LGTM. Pushed to master. Closing. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-04-27 17:25 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-04-27 15:00 bug#55153: 29.0.50; Implement system_process_attributes on Cygwin Ken Brown 2022-04-27 15:16 ` Ken Brown 2022-04-27 15:52 ` Eli Zaretskii 2022-04-27 16:45 ` Ken Brown 2022-04-27 17:12 ` Eli Zaretskii 2022-04-27 17:25 ` Ken Brown
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.