From e5798bef38435b582d9fc1c51efbf36b2b7fbe20 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 26 Aug 2011 18:58:04 +0000 Subject: 2011-08-26 Pedro Alves gdb/ * common/linux-osdata.c (get_cores_used_by_process): Don't assume opening /proc/PID/task always succeeds. --- gdb/common/linux-osdata.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'gdb/common') diff --git a/gdb/common/linux-osdata.c b/gdb/common/linux-osdata.c index 78659d4..a356bb8 100644 --- a/gdb/common/linux-osdata.c +++ b/gdb/common/linux-osdata.c @@ -259,27 +259,29 @@ get_cores_used_by_process (pid_t pid, int *cores) sprintf (taskdir, "/proc/%d/task", pid); dir = opendir (taskdir); - - while ((dp = readdir (dir)) != NULL) + if (dir) { - pid_t tid; - int core; + while ((dp = readdir (dir)) != NULL) + { + pid_t tid; + int core; - if (!isdigit (dp->d_name[0]) - || NAMELEN (dp) > sizeof ("4294967295") - 1) - continue; + if (!isdigit (dp->d_name[0]) + || NAMELEN (dp) > sizeof ("4294967295") - 1) + continue; - tid = atoi (dp->d_name); - core = linux_common_core_of_thread (ptid_build (pid, tid, 0)); + tid = atoi (dp->d_name); + core = linux_common_core_of_thread (ptid_build (pid, tid, 0)); - if (core >= 0) - { - ++cores[core]; - ++task_count; + if (core >= 0) + { + ++cores[core]; + ++task_count; + } } - } - closedir (dir); + closedir (dir); + } return task_count; } -- cgit v1.1