aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorEli Zaretskii2008-09-19 17:21:16 +0000
committerEli Zaretskii2008-09-19 17:21:16 +0000
commita1e422f32d3adb6fed846dbcdbcc26072b8e7530 (patch)
tree01ba0c859ac70fbe21b525982cb416746025ae44 /src/process.c
parentc966fd27a1197e79b26d6230b85005168d31887a (diff)
downloademacs-a1e422f32d3adb6fed846dbcdbcc26072b8e7530.tar.gz
emacs-a1e422f32d3adb6fed846dbcdbcc26072b8e7530.zip
(procfs_system_process_attributes): Fix cmdline in case /proc/PID/cmdline
is empty.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/process.c b/src/process.c
index 80a657b2eda..75f36c5fce9 100644
--- a/src/process.c
+++ b/src/process.c
@@ -7419,17 +7419,17 @@ procfs_system_process_attributes (pid)
7419 fd = emacs_open (fn, O_RDONLY, 0); 7419 fd = emacs_open (fn, O_RDONLY, 0);
7420 if (fd >= 0) 7420 if (fd >= 0)
7421 { 7421 {
7422 for (cmdsize = 0; emacs_read (fd, &c, 1) == 1; cmdsize++) 7422 for (cmdline_size = 0; emacs_read (fd, &c, 1) == 1; cmdline_size++)
7423 { 7423 {
7424 if (isspace (c) || c == '\\') 7424 if (isspace (c) || c == '\\')
7425 cmdsize++; /* for later quoting, see below */ 7425 cmdline_size++; /* for later quoting, see below */
7426 } 7426 }
7427 if (cmdsize) 7427 if (cmdline_size)
7428 { 7428 {
7429 cmdline = xmalloc (cmdsize + 1); 7429 cmdline = xmalloc (cmdline_size + 1);
7430 lseek (fd, 0L, SEEK_SET); 7430 lseek (fd, 0L, SEEK_SET);
7431 cmdline[0] = '\0'; 7431 cmdline[0] = '\0';
7432 if ((nread = read (fd, cmdline, cmdsize)) >= 0) 7432 if ((nread = read (fd, cmdline, cmdline_size)) >= 0)
7433 cmdline[nread++] = '\0'; 7433 cmdline[nread++] = '\0';
7434 /* We don't want trailing null characters. */ 7434 /* We don't want trailing null characters. */
7435 for (p = cmdline + nread - 1; p > cmdline && !*p; p--) 7435 for (p = cmdline + nread - 1; p > cmdline && !*p; p--)
@@ -7446,18 +7446,18 @@ procfs_system_process_attributes (pid)
7446 else if (*p == '\0') 7446 else if (*p == '\0')
7447 *p = ' '; 7447 *p = ' ';
7448 } 7448 }
7449 cmdsize = nread; 7449 cmdline_size = nread;
7450 } 7450 }
7451 else 7451 else
7452 { 7452 {
7453 cmdsize = strlen (cmd) + 2; 7453 cmdline_size = cmdsize + 2;
7454 cmdline = xmalloc (cmdsize + 1); 7454 cmdline = xmalloc (cmdline_size + 1);
7455 strcpy (cmdline, "["); 7455 strcpy (cmdline, "[");
7456 strcat (strcat (cmdline, cmd), "]"); 7456 strcat (strncat (cmdline, cmd, cmdsize), "]");
7457 } 7457 }
7458 emacs_close (fd); 7458 emacs_close (fd);
7459 /* Command line is encoded in locale-coding-system; decode it. */ 7459 /* Command line is encoded in locale-coding-system; decode it. */
7460 cmd_str = make_unibyte_string (cmdline, cmdsize); 7460 cmd_str = make_unibyte_string (cmdline, cmdline_size);
7461 decoded_cmd = code_convert_string_norecord (cmd_str, 7461 decoded_cmd = code_convert_string_norecord (cmd_str,
7462 Vlocale_coding_system, 0); 7462 Vlocale_coding_system, 0);
7463 xfree (cmdline); 7463 xfree (cmdline);