diff options
| author | Eli Zaretskii | 2009-01-03 15:02:30 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2009-01-03 15:02:30 +0000 |
| commit | e5c9f94c66a899121a3c665f9c312fb09370e9e9 (patch) | |
| tree | 31e782e76ffbdc22f7403ac06875ae4f9b2db2bc /src | |
| parent | 36a3859f9bf18c11e5a970b236efd626bba8d4b8 (diff) | |
| download | emacs-e5c9f94c66a899121a3c665f9c312fb09370e9e9.tar.gz emacs-e5c9f94c66a899121a3c665f9c312fb09370e9e9.zip | |
(system_process_attributes, list_system_processes): New functions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dosfns.c | 128 |
1 files changed, 127 insertions, 1 deletions
diff --git a/src/dosfns.c b/src/dosfns.c index 419a4ef44ee..12c260e1c63 100644 --- a/src/dosfns.c +++ b/src/dosfns.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* MS-DOS specific Lisp utilities. Coded by Manabu Higashida, 1991. | 1 | /* MS-DOS specific Lisp utilities. Coded by Manabu Higashida, 1991. |
| 2 | Major changes May-July 1993 Morten Welinder (only 10% original code left) | 2 | Major changes May-July 1993 Morten Welinder (only 10% original code left) |
| 3 | Copyright (C) 1991, 1993, 1996, 1997, 1998, 2001, 2002, 2003, 2004, | 3 | Copyright (C) 1991, 1993, 1996, 1997, 1998, 2001, 2002, 2003, 2004, |
| 4 | 2005, 2006, 2007, 2008 Free Software Foundation, Inc. | 4 | 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | This file is part of GNU Emacs. | 6 | This file is part of GNU Emacs. |
| 7 | 7 | ||
| @@ -38,10 +38,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 38 | #include "dispextern.h" | 38 | #include "dispextern.h" |
| 39 | #include "character.h" | 39 | #include "character.h" |
| 40 | #include "coding.h" | 40 | #include "coding.h" |
| 41 | #include "process.h" | ||
| 41 | #include <dpmi.h> | 42 | #include <dpmi.h> |
| 42 | #include <go32.h> | 43 | #include <go32.h> |
| 43 | #include <dirent.h> | 44 | #include <dirent.h> |
| 44 | #include <sys/vfs.h> | 45 | #include <sys/vfs.h> |
| 46 | #include <unistd.h> | ||
| 47 | #include <grp.h> | ||
| 48 | #include <crt0.h> | ||
| 45 | 49 | ||
| 46 | #ifndef __DJGPP_MINOR__ | 50 | #ifndef __DJGPP_MINOR__ |
| 47 | # define __tb _go32_info_block.linear_address_of_transfer_buffer; | 51 | # define __tb _go32_info_block.linear_address_of_transfer_buffer; |
| @@ -533,6 +537,128 @@ If the underlying system call fails, value is nil. */) | |||
| 533 | return value; | 537 | return value; |
| 534 | } | 538 | } |
| 535 | 539 | ||
| 540 | /* System depended enumeration of and access to system processes a-la | ||
| 541 | ps(1). Here, we only return info about the running Emacs process. | ||
| 542 | (There are no other processes on DOS, right?) */ | ||
| 543 | |||
| 544 | Lisp_Object | ||
| 545 | list_system_processes () | ||
| 546 | { | ||
| 547 | Lisp_Object proclist = Qnil; | ||
| 548 | |||
| 549 | proclist = Fcons (make_fixnum_or_float (getpid ()), proclist); | ||
| 550 | |||
| 551 | return proclist; | ||
| 552 | } | ||
| 553 | |||
| 554 | Lisp_Object | ||
| 555 | system_process_attributes (Lisp_Object pid) | ||
| 556 | { | ||
| 557 | int proc_id; | ||
| 558 | Lisp_Object attrs = Qnil; | ||
| 559 | |||
| 560 | CHECK_NUMBER_OR_FLOAT (pid); | ||
| 561 | proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid); | ||
| 562 | |||
| 563 | if (proc_id == getpid ()) | ||
| 564 | { | ||
| 565 | EMACS_INT uid, gid; | ||
| 566 | char *usr; | ||
| 567 | struct group *gr; | ||
| 568 | char cmd[FILENAME_MAX]; | ||
| 569 | char *cmdline = NULL, *p, *q; | ||
| 570 | size_t cmdline_size = 0; | ||
| 571 | int i; | ||
| 572 | Lisp_Object cmd_str, decoded_cmd, tem; | ||
| 573 | double pmem; | ||
| 574 | extern unsigned long ret_lim_data (); | ||
| 575 | |||
| 576 | uid = getuid (); | ||
| 577 | attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs); | ||
| 578 | usr = getlogin (); | ||
| 579 | if (usr) | ||
| 580 | attrs = Fcons (Fcons (Quser, build_string (usr)), attrs); | ||
| 581 | gid = getgid (); | ||
| 582 | attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs); | ||
| 583 | gr = getgrgid (gid); | ||
| 584 | if (gr) | ||
| 585 | attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); | ||
| 586 | strcpy (cmd, basename (__crt0_argv[0])); | ||
| 587 | /* Command name is encoded in locale-coding-system; decode it. */ | ||
| 588 | cmd_str = make_unibyte_string (cmd, strlen (cmd)); | ||
| 589 | decoded_cmd = code_convert_string_norecord (cmd_str, | ||
| 590 | Vlocale_coding_system, 0); | ||
| 591 | attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs); | ||
| 592 | /* Pretend we have 0 as PPID. */ | ||
| 593 | attrs = Fcons (Fcons (Qppid, make_number (0)), attrs); | ||
| 594 | attrs = Fcons (Fcons (Qpgrp, pid), attrs); | ||
| 595 | attrs = Fcons (Fcons (Qttname, build_string ("/dev/tty")), attrs); | ||
| 596 | /* We are never idle! */ | ||
| 597 | tem = Fget_internal_run_time (); | ||
| 598 | attrs = Fcons (Fcons (Qtime, tem), attrs); | ||
| 599 | attrs = Fcons (Fcons (Qthcount, make_number (1)), attrs); | ||
| 600 | attrs = Fcons (Fcons (Qstart, | ||
| 601 | Fsymbol_value (intern ("before-init-time"))), | ||
| 602 | attrs); | ||
| 603 | attrs = Fcons (Fcons (Qvsize, | ||
| 604 | make_fixnum_or_float ((unsigned long)sbrk(0)/1024)), | ||
| 605 | attrs); | ||
| 606 | attrs = Fcons (Fcons (Qetime, tem), attrs); | ||
| 607 | pmem = (double)((unsigned long) sbrk (0)) / ret_lim_data () * 100.0; | ||
| 608 | if (pmem > 100) | ||
| 609 | pmem = 100; | ||
| 610 | attrs = Fcons (Fcons (Qpmem, make_float (pmem)), attrs); | ||
| 611 | /* Pass 1: Count how much storage we need. */ | ||
| 612 | for (i = 0; i < __crt0_argc; i++) | ||
| 613 | { | ||
| 614 | cmdline_size += strlen (__crt0_argv[i]) + 1; /* +1 for blank delim */ | ||
| 615 | if (strpbrk (__crt0_argv[i], " \t\n\r\v\f")) | ||
| 616 | { | ||
| 617 | cmdline_size += 2; | ||
| 618 | for (p = __crt0_argv[i]; *p; p++) | ||
| 619 | { | ||
| 620 | if (*p == '"') | ||
| 621 | cmdline_size++; | ||
| 622 | } | ||
| 623 | } | ||
| 624 | } | ||
| 625 | /* Pass 2: Allocate storage and concatenate argv[]. */ | ||
| 626 | cmdline = xmalloc (cmdline_size + 1); | ||
| 627 | for (i = 0, q = cmdline; i < __crt0_argc; i++) | ||
| 628 | { | ||
| 629 | if (strpbrk (__crt0_argv[i], " \t\n\r\v\f")) | ||
| 630 | { | ||
| 631 | *q++ = '"'; | ||
| 632 | for (p = __crt0_argv[i]; *p; p++) | ||
| 633 | { | ||
| 634 | if (*p == '\"') | ||
| 635 | *q++ = '\\'; | ||
| 636 | *q++ = *p; | ||
| 637 | } | ||
| 638 | *q++ = '"'; | ||
| 639 | } | ||
| 640 | else | ||
| 641 | { | ||
| 642 | strcpy (q, __crt0_argv[i]); | ||
| 643 | q += strlen (__crt0_argv[i]); | ||
| 644 | } | ||
| 645 | *q++ = ' '; | ||
| 646 | } | ||
| 647 | /* Remove the trailing blank. */ | ||
| 648 | if (q > cmdline) | ||
| 649 | q[-1] = '\0'; | ||
| 650 | |||
| 651 | /* Command line is encoded in locale-coding-system; decode it. */ | ||
| 652 | cmd_str = make_unibyte_string (cmdline, strlen (cmdline)); | ||
| 653 | decoded_cmd = code_convert_string_norecord (cmd_str, | ||
| 654 | Vlocale_coding_system, 0); | ||
| 655 | xfree (cmdline); | ||
| 656 | attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs); | ||
| 657 | } | ||
| 658 | |||
| 659 | return attrs; | ||
| 660 | } | ||
| 661 | |||
| 536 | void | 662 | void |
| 537 | dos_cleanup (void) | 663 | dos_cleanup (void) |
| 538 | { | 664 | { |