From: VMware, Inc <> Date: Wed, 20 Jul 2011 20:52:10 +0000 (-0700) Subject: lib/file: tolerate /proc failures X-Git-Tag: 2011.07.19-450511~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=31df947e59a507beaba1a8255e7bdcc3a14fbc79;p=thirdparty%2Fopen-vm-tools.git lib/file: tolerate /proc failures The file locking code for POSIXen was depending on /proc, a Linuxism. Should /proc not be accessible, create a default process descriptor instead of failing. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/file/fileLockPosix.c b/open-vm-tools/lib/file/fileLockPosix.c index e2394f5d1..6d01e8b58 100644 --- a/open-vm-tools/lib/file/fileLockPosix.c +++ b/open-vm-tools/lib/file/fileLockPosix.c @@ -677,10 +677,9 @@ FileReadSlashProc(const char *procPath, // IN: static char * FileLockProcessDescriptor(pid_t pid) // IN: { - int err; char path[64]; - char *descriptor; char buffer[1024]; + char *descriptor = NULL; if (!FileLockIsValidProcess(pid)) { return NULL; @@ -688,9 +687,7 @@ FileLockProcessDescriptor(pid_t pid) // IN: Str_Sprintf(path, sizeof path, "/proc/%d/stat", pid); - err = FileReadSlashProc(path, buffer, sizeof buffer); - - if (err == 0) { + if (FileReadSlashProc(path, buffer, sizeof buffer) == 0) { char *p; char *q; char *rest; @@ -712,7 +709,6 @@ FileLockProcessDescriptor(pid_t pid) // IN: p = strchr(buffer, '('); if ((p == NULL) || (p == buffer) || (*(p - 1) != ' ')) { - argc = 0; goto bail; } @@ -721,12 +717,10 @@ FileLockProcessDescriptor(pid_t pid) // IN: q = strrchr(p + 1, ')'); if (q == NULL) { argc = 0; - goto bail; } rest = q + 1; if (*rest != ' ') { - argc = 0; goto bail; } @@ -755,21 +749,21 @@ FileLockProcessDescriptor(pid_t pid) // IN: } } -bail: - if (argc == 22) { descriptor = Str_SafeAsprintf(NULL, "%s-%s%s", argv[0], argv[21], argv[1]); - } else { - /* - * Since /proc didn't parse properly, emit a valid string that - * also provides a clue that there is problem. - */ - - descriptor = Str_SafeAsprintf(NULL, "%d-0", pid); } - } else { - descriptor = NULL; + } + +bail: + + if (descriptor == NULL) { + /* + * Accessing /proc failed in some way. Emit a valid string that also + * provides a clue that there is/was a problem. + */ + + descriptor = Str_SafeAsprintf(NULL, "%d-0", pid); } return descriptor;