From c5e666566a38a401cdf8d6683f0c53b864f1e82a Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Fri, 19 Mar 2004 16:58:57 +0000 Subject: [PATCH] fixed race when process disappeared shortly after reading /proc git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1314 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/src/vserver-stat.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/util-vserver/src/vserver-stat.c b/util-vserver/src/vserver-stat.c index 298223f..e3ead78 100644 --- a/util-vserver/src/vserver-stat.c +++ b/util-vserver/src/vserver-stat.c @@ -208,7 +208,8 @@ registerXid(struct Vector *vec, struct process_info *process) } // open the process's status file to get the ctx number, and other stat -struct process_info *get_process_info(char *pid) +struct process_info * +get_process_info(char *pid) { int fd; char buffer[1024]; @@ -230,6 +231,8 @@ struct process_info *get_process_info(char *pid) WRITE_MSG(2, "): "); WRITE_STR(2, strerror(err)); WRITE_MSG(2, "\n"); + + return 0; } memcpy(buffer, "/proc/", 6); idx = 6; @@ -438,8 +441,11 @@ int main(int argc, char **argv) if (!isdigit(*dir_entry->d_name)) continue; - if (atoi(dir_entry->d_name) != my_pid) - registerXid(&xid_data, get_process_info(dir_entry->d_name)); + if (atoi(dir_entry->d_name) != my_pid) { + struct process_info * info = get_process_info(dir_entry->d_name); + if (info) + registerXid(&xid_data, info); + } } closedir(proc_dir); -- 1.8.1.5