diff options
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | src/sysdep.c | 140 |
2 files changed, 143 insertions, 0 deletions
| @@ -56,6 +56,9 @@ affected by this, as SGI stopped supporting IRIX in December 2013. | |||
| 56 | 56 | ||
| 57 | * Changes in Emacs 25.2 | 57 | * Changes in Emacs 25.2 |
| 58 | 58 | ||
| 59 | -- | ||
| 60 | ** `process-attributes' on Darwin systems now return more information. | ||
| 61 | |||
| 59 | +++ | 62 | +++ |
| 60 | ** A number of accessors for the value returned by 'file-attributes' | 63 | ** A number of accessors for the value returned by 'file-attributes' |
| 61 | has been added. They are: 'file-attribute-type', | 64 | has been added. They are: 'file-attribute-type', |
diff --git a/src/sysdep.c b/src/sysdep.c index 3faa696d89f..53affbf3dbf 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -3567,6 +3567,146 @@ system_process_attributes (Lisp_Object pid) | |||
| 3567 | return attrs; | 3567 | return attrs; |
| 3568 | } | 3568 | } |
| 3569 | 3569 | ||
| 3570 | #elif defined DARWIN_OS | ||
| 3571 | |||
| 3572 | static struct timespec | ||
| 3573 | timeval_to_timespec (struct timeval t) | ||
| 3574 | { | ||
| 3575 | return make_timespec (t.tv_sec, t.tv_usec * 1000); | ||
| 3576 | } | ||
| 3577 | |||
| 3578 | static Lisp_Object | ||
| 3579 | make_lisp_timeval (struct timeval t) | ||
| 3580 | { | ||
| 3581 | return make_lisp_time (timeval_to_timespec (t)); | ||
| 3582 | } | ||
| 3583 | |||
| 3584 | Lisp_Object | ||
| 3585 | system_process_attributes (Lisp_Object pid) | ||
| 3586 | { | ||
| 3587 | int proc_id; | ||
| 3588 | int pagesize = getpagesize (); | ||
| 3589 | unsigned long npages; | ||
| 3590 | int fscale; | ||
| 3591 | struct passwd *pw; | ||
| 3592 | struct group *gr; | ||
| 3593 | char *ttyname; | ||
| 3594 | size_t len; | ||
| 3595 | char args[MAXPATHLEN]; | ||
| 3596 | struct timeval starttime; | ||
| 3597 | struct timespec t, now; | ||
| 3598 | struct rusage *rusage; | ||
| 3599 | dev_t tdev; | ||
| 3600 | uid_t uid; | ||
| 3601 | gid_t gid; | ||
| 3602 | |||
| 3603 | int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID}; | ||
| 3604 | struct kinfo_proc proc; | ||
| 3605 | size_t proclen = sizeof proc; | ||
| 3606 | |||
| 3607 | Lisp_Object attrs = Qnil; | ||
| 3608 | Lisp_Object decoded_comm; | ||
| 3609 | |||
| 3610 | CHECK_NUMBER_OR_FLOAT (pid); | ||
| 3611 | CONS_TO_INTEGER (pid, int, proc_id); | ||
| 3612 | mib[3] = proc_id; | ||
| 3613 | |||
| 3614 | if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0) | ||
| 3615 | return attrs; | ||
| 3616 | |||
| 3617 | uid = proc.kp_eproc.e_ucred.cr_uid; | ||
| 3618 | attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs); | ||
| 3619 | |||
| 3620 | block_input (); | ||
| 3621 | pw = getpwuid (uid); | ||
| 3622 | unblock_input (); | ||
| 3623 | if (pw) | ||
| 3624 | attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); | ||
| 3625 | |||
| 3626 | gid = proc.kp_eproc.e_pcred.p_svgid; | ||
| 3627 | attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs); | ||
| 3628 | |||
| 3629 | block_input (); | ||
| 3630 | gr = getgrgid (gid); | ||
| 3631 | unblock_input (); | ||
| 3632 | if (gr) | ||
| 3633 | attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); | ||
| 3634 | |||
| 3635 | decoded_comm = (code_convert_string_norecord | ||
| 3636 | (build_unibyte_string (proc.kp_proc.p_comm), | ||
| 3637 | Vlocale_coding_system, 0)); | ||
| 3638 | |||
| 3639 | attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs); | ||
| 3640 | { | ||
| 3641 | char state[2] = {'\0', '\0'}; | ||
| 3642 | switch (proc.kp_proc.p_stat) | ||
| 3643 | { | ||
| 3644 | case SRUN: | ||
| 3645 | state[0] = 'R'; | ||
| 3646 | break; | ||
| 3647 | |||
| 3648 | case SSLEEP: | ||
| 3649 | state[0] = 'S'; | ||
| 3650 | break; | ||
| 3651 | |||
| 3652 | case SZOMB: | ||
| 3653 | state[0] = 'Z'; | ||
| 3654 | break; | ||
| 3655 | |||
| 3656 | case SSTOP: | ||
| 3657 | state[0] = 'T'; | ||
| 3658 | break; | ||
| 3659 | |||
| 3660 | case SIDL: | ||
| 3661 | state[0] = 'I'; | ||
| 3662 | break; | ||
| 3663 | } | ||
| 3664 | attrs = Fcons (Fcons (Qstate, build_string (state)), attrs); | ||
| 3665 | } | ||
| 3666 | |||
| 3667 | attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (proc.kp_eproc.e_ppid)), | ||
| 3668 | attrs); | ||
| 3669 | attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.kp_eproc.e_pgid)), | ||
| 3670 | attrs); | ||
| 3671 | |||
| 3672 | tdev = proc.kp_eproc.e_tdev; | ||
| 3673 | block_input (); | ||
| 3674 | ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR); | ||
| 3675 | unblock_input (); | ||
| 3676 | if (ttyname) | ||
| 3677 | attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs); | ||
| 3678 | |||
| 3679 | attrs = Fcons (Fcons (Qtpgid, make_fixnum_or_float (proc.kp_eproc.e_tpgid)), | ||
| 3680 | attrs); | ||
| 3681 | |||
| 3682 | rusage = proc.kp_proc.p_ru; | ||
| 3683 | if (rusage) | ||
| 3684 | { | ||
| 3685 | attrs = Fcons (Fcons (Qminflt, make_fixnum_or_float (rusage->ru_minflt)), | ||
| 3686 | attrs); | ||
| 3687 | attrs = Fcons (Fcons (Qmajflt, make_fixnum_or_float (rusage->ru_majflt)), | ||
| 3688 | attrs); | ||
| 3689 | |||
| 3690 | attrs = Fcons (Fcons (Qutime, make_lisp_timeval (rusage->ru_utime)), | ||
| 3691 | attrs); | ||
| 3692 | attrs = Fcons (Fcons (Qstime, make_lisp_timeval (rusage->ru_stime)), | ||
| 3693 | attrs); | ||
| 3694 | t = timespec_add (timeval_to_timespec (rusage->ru_utime), | ||
| 3695 | timeval_to_timespec (rusage->ru_stime)); | ||
| 3696 | attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs); | ||
| 3697 | } | ||
| 3698 | |||
| 3699 | starttime = proc.kp_proc.p_starttime; | ||
| 3700 | attrs = Fcons (Fcons (Qnice, make_number (proc.kp_proc.p_nice)), attrs); | ||
| 3701 | attrs = Fcons (Fcons (Qstart, make_lisp_timeval (starttime)), attrs); | ||
| 3702 | |||
| 3703 | now = current_timespec (); | ||
| 3704 | t = timespec_sub (now, timeval_to_timespec (starttime)); | ||
| 3705 | attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); | ||
| 3706 | |||
| 3707 | return attrs; | ||
| 3708 | } | ||
| 3709 | |||
| 3570 | /* The WINDOWSNT implementation is in w32.c. | 3710 | /* The WINDOWSNT implementation is in w32.c. |
| 3571 | The MSDOS implementation is in dosfns.c. */ | 3711 | The MSDOS implementation is in dosfns.c. */ |
| 3572 | #elif !defined (WINDOWSNT) && !defined (MSDOS) | 3712 | #elif !defined (WINDOWSNT) && !defined (MSDOS) |