aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 6b54ed3b6ec..a1050c4309a 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -49,10 +49,14 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
49# include <cygwin/fs.h> 49# include <cygwin/fs.h>
50#endif 50#endif
51 51
52#if defined DARWIN_OS || defined __FreeBSD__ 52#if defined DARWIN_OS || defined __FreeBSD__ || defined __OpenBSD__
53# include <sys/sysctl.h> 53# include <sys/sysctl.h>
54#endif 54#endif
55 55
56#ifdef DARWIN_OS
57# include <libproc.h>
58#endif
59
56#ifdef __FreeBSD__ 60#ifdef __FreeBSD__
57/* Sparc/ARM machine/frame.h has 'struct frame' which conflicts with Emacs's 61/* Sparc/ARM machine/frame.h has 'struct frame' which conflicts with Emacs's
58 'struct frame', so rename it. */ 62 'struct frame', so rename it. */
@@ -3061,37 +3065,43 @@ list_system_processes (void)
3061 return proclist; 3065 return proclist;
3062} 3066}
3063 3067
3064#elif defined DARWIN_OS || defined __FreeBSD__ 3068#elif defined DARWIN_OS || defined __FreeBSD__ || defined __OpenBSD__
3065 3069
3066Lisp_Object 3070Lisp_Object
3067list_system_processes (void) 3071list_system_processes (void)
3068{ 3072{
3069#ifdef DARWIN_OS 3073#ifdef DARWIN_OS
3070 int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL}; 3074 int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
3075#elif defined __OpenBSD__
3076 int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0,
3077 sizeof (struct kinfo_proc), 4096};
3071#else 3078#else
3072 int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PROC}; 3079 int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PROC};
3073#endif 3080#endif
3074 size_t len; 3081 size_t len;
3082 size_t mibsize = sizeof mib / sizeof mib[0];
3075 struct kinfo_proc *procs; 3083 struct kinfo_proc *procs;
3076 size_t i; 3084 size_t i;
3077 3085
3078 Lisp_Object proclist = Qnil; 3086 Lisp_Object proclist = Qnil;
3079 3087
3080 if (sysctl (mib, 3, NULL, &len, NULL, 0) != 0 || len == 0) 3088 if (sysctl (mib, mibsize, NULL, &len, NULL, 0) != 0 || len == 0)
3081 return proclist; 3089 return proclist;
3082 3090
3083 procs = xmalloc (len); 3091 procs = xmalloc (len);
3084 if (sysctl (mib, 3, procs, &len, NULL, 0) != 0 || len == 0) 3092 if (sysctl (mib, mibsize, procs, &len, NULL, 0) != 0 || len == 0)
3085 { 3093 {
3086 xfree (procs); 3094 xfree (procs);
3087 return proclist; 3095 return proclist;
3088 } 3096 }
3089 3097
3090 len /= sizeof (struct kinfo_proc); 3098 len /= sizeof procs[0];
3091 for (i = 0; i < len; i++) 3099 for (i = 0; i < len; i++)
3092 { 3100 {
3093#ifdef DARWIN_OS 3101#ifdef DARWIN_OS
3094 proclist = Fcons (INT_TO_INTEGER (procs[i].kp_proc.p_pid), proclist); 3102 proclist = Fcons (INT_TO_INTEGER (procs[i].kp_proc.p_pid), proclist);
3103#elif defined __OpenBSD__
3104 proclist = Fcons (INT_TO_INTEGER (procs[i].p_pid), proclist);
3095#else 3105#else
3096 proclist = Fcons (INT_TO_INTEGER (procs[i].ki_pid), proclist); 3106 proclist = Fcons (INT_TO_INTEGER (procs[i].ki_pid), proclist);
3097#endif 3107#endif
@@ -3865,8 +3875,21 @@ system_process_attributes (Lisp_Object pid)
3865 if (gr) 3875 if (gr)
3866 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); 3876 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
3867 3877
3878 char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
3879 char *comm;
3880
3881 if (proc_pidpath (proc_id, pathbuf, sizeof(pathbuf)) > 0)
3882 {
3883 if ((comm = strrchr (pathbuf, '/')))
3884 comm++;
3885 else
3886 comm = pathbuf;
3887 }
3888 else
3889 comm = proc.kp_proc.p_comm;
3890
3868 decoded_comm = (code_convert_string_norecord 3891 decoded_comm = (code_convert_string_norecord
3869 (build_unibyte_string (proc.kp_proc.p_comm), 3892 (build_unibyte_string (comm),
3870 Vlocale_coding_system, 0)); 3893 Vlocale_coding_system, 0));
3871 3894
3872 attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs); 3895 attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);