]> code.delx.au - gnu-emacs/blobdiff - src/process.c
(frame-initialize): Remove spurious setting of
[gnu-emacs] / src / process.c
index 3c6fdbb16812302b9fffaab462bbd5a21b09686c..fd19fc9288d473c39c36c30b43632846a2406622 100644 (file)
@@ -7246,10 +7246,10 @@ procfs_system_process_attributes (pid)
   char procbuf[1025], *p, *q;
   int fd;
   ssize_t nread;
-  char cmd[PATH_MAX];
+  const char *cmd;
   char *cmdline = NULL;
-  size_t cmdsize;
-  int c;
+  size_t cmdsize, cmdline_size;
+  unsigned char c;
   int proc_id, ppid, uid, gid, pgrp, sess, tty, tpgid, thcount;
   unsigned long long utime, stime, cutime, cstime, start;
   long priority, nice, rss;
@@ -7277,7 +7277,7 @@ procfs_system_process_attributes (pid)
   uid_eint = uid;
   attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs);
   BLOCK_INPUT;
-  pw = (struct passwd *) getpwuid (uid);
+  pw = getpwuid (uid);
   UNBLOCK_INPUT;
   if (pw)
     attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
@@ -7286,7 +7286,7 @@ procfs_system_process_attributes (pid)
   gid_eint = gid;
   attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs);
   BLOCK_INPUT;
-  gr = (struct group *) getgrgid (gid);
+  gr = getgrgid (gid);
   UNBLOCK_INPUT;
   if (gr)
     attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
@@ -7300,18 +7300,25 @@ procfs_system_process_attributes (pid)
       procbuf[nread] = '\0';
       p = procbuf;
 
-      p = strchr (p, '(') + 1;
-      q = strchr (p, ')');
-      /* comm */
-      if (q > p)
+      cmd = NULL;
+      p = strchr (p, '(');
+      if (p != NULL)
        {
-         memcpy (cmd, p, q - p);
-         cmd[q - p] = '\0';
+         q = strrchr (p + 1, ')');
+         /* comm */
+         if (q != NULL)
+           {
+             cmd = p + 1;
+             cmdsize = q - cmd;
+           }
+       }
+      if (cmd == NULL)
+       {
+         cmd = "???";
+         cmdsize = 3;
        }
-      else
-       strcpy (cmd, "???");
       /* Command name is encoded in locale-coding-system; decode it.  */
-      cmd_str = make_unibyte_string (cmd, q ? q - p : 3);
+      cmd_str = make_unibyte_string (cmd, cmdsize);
       decoded_cmd = code_convert_string_norecord (cmd_str,
                                                  Vlocale_coding_system, 0);
       attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
@@ -7412,17 +7419,17 @@ procfs_system_process_attributes (pid)
   fd = emacs_open (fn, O_RDONLY, 0);
   if (fd >= 0)
     {
-      for (cmdsize = 0; emacs_read (fd, (char *)&c, 1) == 1; cmdsize++)
+      for (cmdline_size = 0; emacs_read (fd, &c, 1) == 1; cmdline_size++)
        {
          if (isspace (c) || c == '\\')
-           cmdsize++;  /* for later quoting, see below */
+           cmdline_size++;     /* for later quoting, see below */
        }
-      if (cmdsize)
+      if (cmdline_size)
        {
-         cmdline = xmalloc (cmdsize + 1);
+         cmdline = xmalloc (cmdline_size + 1);
          lseek (fd, 0L, SEEK_SET);
          cmdline[0] = '\0';
-         if ((nread = read (fd, cmdline, cmdsize)) >= 0)
+         if ((nread = read (fd, cmdline, cmdline_size)) >= 0)
            cmdline[nread++] = '\0';
          /* We don't want trailing null characters.  */
          for (p = cmdline + nread - 1; p > cmdline && !*p; p--)
@@ -7439,18 +7446,18 @@ procfs_system_process_attributes (pid)
              else if (*p == '\0')
                *p = ' ';
            }
-         cmdsize = nread;
+         cmdline_size = nread;
        }
       else
        {
-         cmdsize = strlen (cmd) + 2;
-         cmdline = xmalloc (cmdsize + 1);
+         cmdline_size = cmdsize + 2;
+         cmdline = xmalloc (cmdline_size + 1);
          strcpy (cmdline, "[");
-         strcat (strcat (cmdline, cmd), "]");
+         strcat (strncat (cmdline, cmd, cmdsize), "]");
        }
       emacs_close (fd);
       /* Command line is encoded in locale-coding-system; decode it.  */
-      cmd_str = make_unibyte_string (cmdline, cmdsize);
+      cmd_str = make_unibyte_string (cmdline, cmdline_size);
       decoded_cmd = code_convert_string_norecord (cmd_str,
                                                  Vlocale_coding_system, 0);
       xfree (cmdline);
@@ -7485,14 +7492,14 @@ DEFUN ("system-process-attributes", Fsystem_process_attributes,
 
 Value is an alist where each element is a cons cell of the form
 
-    \(ATTR . VALUE)
+    \(KEY . VALUE)
 
 If this functionality is unsupported, the value is nil.
 
 See `list-system-processes' for getting a list of all process IDs.
 
-The attributes that this function may return are listed below,
-together with the type of the associated value (in parentheses).
+The KEYs of the attributes that this function may return are listed
+below, together with the type of the associated VALUE (in parentheses).
 Not all platforms support all of these attributes; unsupported
 attributes will not appear in the returned alist.
 Unless explicitly indicated otherwise, numbers can have either
@@ -7933,7 +7940,7 @@ extern int frame_garbaged;
 extern EMACS_TIME timer_check ();
 extern int timers_run;
 
-Lisp_Object QCtype;
+Lisp_Object QCtype, QCname;
 
 /* As described above, except assuming that there are no subprocesses:
 
@@ -8213,14 +8220,14 @@ DEFUN ("system-process-attributes", Fsystem_process_attributes,
 
 Value is an alist where each element is a cons cell of the form
 
-    \(ATTR . VALUE)
+    \(KEY . VALUE)
 
 If this functionality is unsupported, the value is nil.
 
 See `list-system-processes' for getting a list of all process IDs.
 
-The attributes that this function may return are listed below,
-together with the type of the associated value (in parentheses).
+The KEYs of the attributes that this function may return are listed
+below, together with the type of the associated VALUE (in parentheses).
 Not all platforms support all of these attributes; unsupported
 attributes will not appear in the returned alist.
 Unless explicitly indicated otherwise, numbers can have either
@@ -8273,6 +8280,8 @@ syms_of_process ()
 {
   QCtype = intern (":type");
   staticpro (&QCtype);
+  QCname = intern (":name");
+  staticpro (&QCname);
 
   defsubr (&Sget_buffer_process);
   defsubr (&Sprocess_inherit_coding_system_flag);