comparison src/sysdep.c @ 100567:387ca5b2d869

* sysdep.c (system_process_attributes): Add implementation for Solaris. * s/sol2-10.h (HAVE_PROCFS, _STRUCTURED_PROC): New defines.
author Dan Nicolaescu <dann@ics.uci.edu>
date Fri, 19 Dec 2008 20:58:37 +0000
parents 91f7b663a0fd
children 7d5b97314a0a
comparison
equal deleted inserted replaced
100566:91f7b663a0fd 100567:387ca5b2d869
3287 3287
3288 #define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff) 3288 #define MAJOR(d) (((unsigned)(d) >> 8) & 0xfff)
3289 #define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12)) 3289 #define MINOR(d) (((unsigned)(d) & 0xff) | (((unsigned)(d) & 0xfff00000) >> 12))
3290 3290
3291 static Lisp_Object 3291 static Lisp_Object
3292 procfs_ttyname (rdev) 3292 procfs_ttyname (int rdev)
3293 { 3293 {
3294 FILE *fdev = NULL; 3294 FILE *fdev = NULL;
3295 char name[PATH_MAX]; 3295 char name[PATH_MAX];
3296 3296
3297 BLOCK_INPUT; 3297 BLOCK_INPUT;
3358 UNBLOCK_INPUT; 3358 UNBLOCK_INPUT;
3359 return retval; 3359 return retval;
3360 } 3360 }
3361 3361
3362 Lisp_Object 3362 Lisp_Object
3363 system_process_attributes (pid) 3363 system_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;
3368 struct passwd *pw; 3367 struct passwd *pw;
3369 struct group *gr; 3368 struct group *gr;
3606 } 3605 }
3607 3606
3608 UNGCPRO; 3607 UNGCPRO;
3609 return attrs; 3608 return attrs;
3610 } 3609 }
3611 3610 #elif defined (SOLARIS2) && defined (HAVE_PROCFS)
3612 #elif !defined (WINDOWSNT) 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 */
3613 3626
3614 Lisp_Object 3627 Lisp_Object
3615 system_process_attributes (Lisp_Object pid) 3628 system_process_attributes (Lisp_Object pid)
3616 { 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 }
3749
3750 #elif !defined (WINDOWSNT)
3751
3752 Lisp_Object
3753 system_process_attributes (Lisp_Object pid)
3754 {
3617 return Qnil 3755 return Qnil
3618 } 3756 }
3619 3757
3620 #endif /* !defined (WINDOWSNT) */ 3758 #endif /* !defined (WINDOWSNT) */
3621 3759