aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog3
-rw-r--r--src/s/sol2-10.h6
-rw-r--r--src/sysdep.c144
3 files changed, 150 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 5ed15b4e59a..2536b664c1b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,6 +1,9 @@
12008-12-19 Dan Nicolaescu <dann@ics.uci.edu> 12008-12-19 Dan Nicolaescu <dann@ics.uci.edu>
2 2
3 * sysdep.c: Include alloca.h. 3 * sysdep.c: Include alloca.h.
4 (system_process_attributes): Add implementation for Solaris.
5
6 * s/sol2-10.h (HAVE_PROCFS, _STRUCTURED_PROC): New defines.
4 7
52008-12-19 Dan Nicolaescu <dann@ics.uci.edu> 82008-12-19 Dan Nicolaescu <dann@ics.uci.edu>
6 9
diff --git a/src/s/sol2-10.h b/src/s/sol2-10.h
index 44f5ce7de85..865e17525c4 100644
--- a/src/s/sol2-10.h
+++ b/src/s/sol2-10.h
@@ -21,5 +21,11 @@
21#undef UNEXEC 21#undef UNEXEC
22#define UNEXEC unexsol.o 22#define UNEXEC unexsol.o
23 23
24/* This is used in list_system_processes. */
25#define HAVE_PROCFS 1
26
27/* This is needed for the system_process_attributes implementation. */
28#define _STRUCTURED_PROC 1
29
24/* arch-tag: 7c51a134-5469-4d16-aa00-d69224640eeb 30/* arch-tag: 7c51a134-5469-4d16-aa00-d69224640eeb
25 (do not change this comment) */ 31 (do not change this comment) */
diff --git a/src/sysdep.c b/src/sysdep.c
index 4b3ca59691e..a1b0ace8375 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3289,7 +3289,7 @@ get_up_time (time_t *sec, unsigned *usec)
3289#define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12)) 3289#define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12))
3290 3290
3291static Lisp_Object 3291static Lisp_Object
3292procfs_ttyname (rdev) 3292procfs_ttyname (int rdev)
3293{ 3293{
3294 FILE *fdev = NULL; 3294 FILE *fdev = NULL;
3295 char name[PATH_MAX]; 3295 char name[PATH_MAX];
@@ -3360,8 +3360,7 @@ procfs_get_total_memory (void)
3360} 3360}
3361 3361
3362Lisp_Object 3362Lisp_Object
3363system_process_attributes (pid) 3363system_process_attributes (Lisp_Object pid)
3364 Lisp_Object pid;
3365{ 3364{
3366 char procfn[PATH_MAX], fn[PATH_MAX]; 3365 char procfn[PATH_MAX], fn[PATH_MAX];
3367 struct stat st; 3366 struct stat st;
@@ -3608,6 +3607,145 @@ system_process_attributes (pid)
3608 UNGCPRO; 3607 UNGCPRO;
3609 return attrs; 3608 return attrs;
3610} 3609}
3610#elif defined (SOLARIS2) && defined (HAVE_PROCFS)
3611
3612/* The <procfs.h> header does not like to be included if _LP64 is defined and
3613 __FILE_OFFSET_BITS == 64. This is an ugly workaround that. */
3614#if !defined (_LP64) && defined (_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
3615#define PROCFS_FILE_OFFSET_BITS_HACK 1
3616#undef _FILE_OFFSET_BITS
3617#else
3618#define PROCFS_FILE_OFFSET_BITS_HACK 0
3619#endif
3620
3621#include <procfs.h>
3622
3623#if PROCFS_FILE_OFFSET_BITS_HACK == 1
3624#define _FILE_OFFSET_BITS 64
3625#endif /* PROCFS_FILE_OFFSET_BITS_HACK == 1 */
3626
3627Lisp_Object
3628system_process_attributes (Lisp_Object pid)
3629{
3630 char procfn[PATH_MAX], fn[PATH_MAX];
3631 struct stat st;
3632 struct passwd *pw;
3633 struct group *gr;
3634 char *procfn_end;
3635 struct psinfo pinfo;
3636 int fd;
3637 ssize_t nread;
3638 int proc_id, uid, gid;
3639 Lisp_Object attrs = Qnil;
3640 Lisp_Object decoded_cmd, tem;
3641 struct gcpro gcpro1, gcpro2;
3642 EMACS_INT uid_eint, gid_eint;
3643
3644 CHECK_NUMBER_OR_FLOAT (pid);
3645 proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid);
3646 sprintf (procfn, "/proc/%u", proc_id);
3647 if (stat (procfn, &st) < 0)
3648 return attrs;
3649
3650 GCPRO2 (attrs, decoded_cmd);
3651
3652 /* euid egid */
3653 uid = st.st_uid;
3654 /* Use of EMACS_INT stops GCC whining about limited range of data type. */
3655 uid_eint = uid;
3656 attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs);
3657 BLOCK_INPUT;
3658 pw = getpwuid (uid);
3659 UNBLOCK_INPUT;
3660 if (pw)
3661 attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
3662
3663 gid = st.st_gid;
3664 gid_eint = gid;
3665 attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs);
3666 BLOCK_INPUT;
3667 gr = getgrgid (gid);
3668 UNBLOCK_INPUT;
3669 if (gr)
3670 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
3671
3672 strcpy (fn, procfn);
3673 procfn_end = fn + strlen (fn);
3674 strcpy (procfn_end, "/psinfo");
3675 fd = emacs_open (fn, O_RDONLY, 0);
3676 if (fd >= 0
3677 && (nread = read (fd, (char*)&pinfo, sizeof(struct psinfo)) > 0))
3678 {
3679 attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (pinfo.pr_ppid)), attrs);
3680 attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (pinfo.pr_pgid)), attrs);
3681 attrs = Fcons (Fcons (Qsess, make_fixnum_or_float (pinfo.pr_sid)), attrs);
3682
3683 {
3684 char state_str[2];
3685 state_str[0] = pinfo.pr_lwp.pr_sname;
3686 state_str[1] = '\0';
3687 tem = build_string (state_str);
3688 attrs = Fcons (Fcons (Qstate, tem), attrs);
3689 }
3690
3691 /* FIXME: missing Qttyname. psinfo.pr_ttydev is a dev_t,
3692 need to get a string from it. */
3693
3694 /* FIXME: missing: Qtpgid */
3695
3696 /* FIXME: missing:
3697 Qminflt
3698 Qmajflt
3699 Qcminflt
3700 Qcmajflt
3701
3702 Qstime
3703 Qcstime
3704 Are they available? */
3705
3706 attrs = Fcons (Fcons (Qutime,
3707 list3 (make_number (pinfo.pr_time.tv_sec >> 16),
3708 make_number (pinfo.pr_time.tv_sec & 0xffff),
3709 make_number (pinfo.pr_time.tv_nsec))),
3710 attrs);
3711
3712 attrs = Fcons (Fcons (Qcutime,
3713 list3 (make_number (pinfo.pr_ctime.tv_sec >> 16),
3714 make_number (pinfo.pr_ctime.tv_sec & 0xffff),
3715 make_number (pinfo.pr_ctime.tv_nsec))),
3716 attrs);
3717
3718 attrs = Fcons (Fcons (Qpri, make_number (pinfo.pr_lwp.pr_pri)), attrs);
3719 attrs = Fcons (Fcons (Qnice, make_number (pinfo.pr_lwp.pr_nice)), attrs);
3720 attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (pinfo.pr_nlwp)), attrs);
3721
3722 attrs = Fcons (Fcons (Qstart,
3723 list3 (make_number (pinfo.pr_start.tv_sec >> 16),
3724 make_number (pinfo.pr_start.tv_sec & 0xffff),
3725 make_number (pinfo.pr_start.tv_nsec))),
3726 attrs);
3727 attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (pinfo.pr_size)), attrs);
3728 attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (pinfo.pr_rssize)), attrs);
3729
3730 /* pr_pctcpu and pr_pctmem are encoded as a fixed point 16 bit number in [0 ... 1]. */
3731 attrs = Fcons (Fcons (Qpcpu, (pinfo.pr_pctcpu * 100.0) / (double)0x8000), attrs);
3732 attrs = Fcons (Fcons (Qpmem, (pinfo.pr_pctmem * 100.0) / (double)0x8000), attrs);
3733
3734 decoded_cmd
3735 = code_convert_string_norecord (make_unibyte_string (pinfo.pr_fname,
3736 strlen (pinfo.pr_fname)),
3737 Vlocale_coding_system, 0);
3738 attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
3739 decoded_cmd
3740 = code_convert_string_norecord (make_unibyte_string (pinfo.pr_psargs,
3741 strlen (pinfo.pr_psargs)),
3742 Vlocale_coding_system, 0);
3743 attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs);
3744 }
3745
3746 UNGCPRO;
3747 return attrs;
3748}
3611 3749
3612#elif !defined (WINDOWSNT) 3750#elif !defined (WINDOWSNT)
3613 3751