]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/file: tolerate /proc failures
authorVMware, Inc <>
Wed, 20 Jul 2011 20:52:10 +0000 (13:52 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Wed, 20 Jul 2011 20:52:10 +0000 (13:52 -0700)
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 <mvanzin@vmware.com>
open-vm-tools/lib/file/fileLockPosix.c

index e2394f5d1f9d5c023b130ae8edc47325f33ea45f..6d01e8b58d51ee3c54781e0eefbf4045c5b6267d 100644 (file)
@@ -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;