diff options
| author | Andreas Schwab | 2008-08-23 18:04:42 +0000 |
|---|---|---|
| committer | Andreas Schwab | 2008-08-23 18:04:42 +0000 |
| commit | 8399d035cca082d01ea49929c9628ee9dd45a5d8 (patch) | |
| tree | 70747984f0003e98c85c3d289994891b5e774a0f /src/process.c | |
| parent | 069e777d77a5516d7ed22bd4e5558de0a5aaecff (diff) | |
| download | emacs-8399d035cca082d01ea49929c9628ee9dd45a5d8.tar.gz emacs-8399d035cca082d01ea49929c9628ee9dd45a5d8.zip | |
(procfs_system_process_attributes): Fix portability
problems.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/process.c b/src/process.c index dd41ba5e25a..6bb652a974f 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -7246,10 +7246,10 @@ procfs_system_process_attributes (pid) | |||
| 7246 | char procbuf[1025], *p, *q; | 7246 | char procbuf[1025], *p, *q; |
| 7247 | int fd; | 7247 | int fd; |
| 7248 | ssize_t nread; | 7248 | ssize_t nread; |
| 7249 | char cmd[PATH_MAX]; | 7249 | const char *cmd; |
| 7250 | char *cmdline = NULL; | 7250 | char *cmdline = NULL; |
| 7251 | size_t cmdsize; | 7251 | size_t cmdsize; |
| 7252 | int c; | 7252 | unsigned char c; |
| 7253 | int proc_id, ppid, uid, gid, pgrp, sess, tty, tpgid, thcount; | 7253 | int proc_id, ppid, uid, gid, pgrp, sess, tty, tpgid, thcount; |
| 7254 | unsigned long long utime, stime, cutime, cstime, start; | 7254 | unsigned long long utime, stime, cutime, cstime, start; |
| 7255 | long priority, nice, rss; | 7255 | long priority, nice, rss; |
| @@ -7277,7 +7277,7 @@ procfs_system_process_attributes (pid) | |||
| 7277 | uid_eint = uid; | 7277 | uid_eint = uid; |
| 7278 | attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs); | 7278 | attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs); |
| 7279 | BLOCK_INPUT; | 7279 | BLOCK_INPUT; |
| 7280 | pw = (struct passwd *) getpwuid (uid); | 7280 | pw = getpwuid (uid); |
| 7281 | UNBLOCK_INPUT; | 7281 | UNBLOCK_INPUT; |
| 7282 | if (pw) | 7282 | if (pw) |
| 7283 | attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); | 7283 | attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); |
| @@ -7286,7 +7286,7 @@ procfs_system_process_attributes (pid) | |||
| 7286 | gid_eint = gid; | 7286 | gid_eint = gid; |
| 7287 | attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs); | 7287 | attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs); |
| 7288 | BLOCK_INPUT; | 7288 | BLOCK_INPUT; |
| 7289 | gr = (struct group *) getgrgid (gid); | 7289 | gr = getgrgid (gid); |
| 7290 | UNBLOCK_INPUT; | 7290 | UNBLOCK_INPUT; |
| 7291 | if (gr) | 7291 | if (gr) |
| 7292 | attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); | 7292 | attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); |
| @@ -7300,18 +7300,25 @@ procfs_system_process_attributes (pid) | |||
| 7300 | procbuf[nread] = '\0'; | 7300 | procbuf[nread] = '\0'; |
| 7301 | p = procbuf; | 7301 | p = procbuf; |
| 7302 | 7302 | ||
| 7303 | p = strchr (p, '(') + 1; | 7303 | cmd = NULL; |
| 7304 | q = strchr (p, ')'); | 7304 | p = strchr (p, '('); |
| 7305 | /* comm */ | 7305 | if (p != NULL) |
| 7306 | if (q > p) | ||
| 7307 | { | 7306 | { |
| 7308 | memcpy (cmd, p, q - p); | 7307 | q = strrchr (p + 1, ')'); |
| 7309 | cmd[q - p] = '\0'; | 7308 | /* comm */ |
| 7309 | if (q != NULL) | ||
| 7310 | { | ||
| 7311 | cmd = p + 1; | ||
| 7312 | cmdsize = q - cmd; | ||
| 7313 | } | ||
| 7314 | } | ||
| 7315 | if (cmd == NULL) | ||
| 7316 | { | ||
| 7317 | cmd = "???"; | ||
| 7318 | cmdsize = 3; | ||
| 7310 | } | 7319 | } |
| 7311 | else | ||
| 7312 | strcpy (cmd, "???"); | ||
| 7313 | /* Command name is encoded in locale-coding-system; decode it. */ | 7320 | /* Command name is encoded in locale-coding-system; decode it. */ |
| 7314 | cmd_str = make_unibyte_string (cmd, q ? q - p : 3); | 7321 | cmd_str = make_unibyte_string (cmd, cmdsize); |
| 7315 | decoded_cmd = code_convert_string_norecord (cmd_str, | 7322 | decoded_cmd = code_convert_string_norecord (cmd_str, |
| 7316 | Vlocale_coding_system, 0); | 7323 | Vlocale_coding_system, 0); |
| 7317 | attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs); | 7324 | attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs); |
| @@ -7412,7 +7419,7 @@ procfs_system_process_attributes (pid) | |||
| 7412 | fd = emacs_open (fn, O_RDONLY, 0); | 7419 | fd = emacs_open (fn, O_RDONLY, 0); |
| 7413 | if (fd >= 0) | 7420 | if (fd >= 0) |
| 7414 | { | 7421 | { |
| 7415 | for (cmdsize = 0; emacs_read (fd, (char *)&c, 1) == 1; cmdsize++) | 7422 | for (cmdsize = 0; emacs_read (fd, &c, 1) == 1; cmdsize++) |
| 7416 | { | 7423 | { |
| 7417 | if (isspace (c) || c == '\\') | 7424 | if (isspace (c) || c == '\\') |
| 7418 | cmdsize++; /* for later quoting, see below */ | 7425 | cmdsize++; /* for later quoting, see below */ |