]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Set up pid/socket directory earlier
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:15 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:15 +0000 (11:23 -0700)
/var/run/vmware is used for both the sockets and the
pid file.  In fresh open-vm-tools scenarios, it tends
not to exist when we need it for the pid file.  Refactor
the code and make sure it exists soon enough to be used
for the pid file.

open-vm-tools/vgauth/service/servicePosix.c
open-vm-tools/vgauth/serviceImpl/netPosix.c
open-vm-tools/vgauth/serviceImpl/serviceInt.h

index 202dab14f154de95726e65173df5d43417f33089..bf6c98a73a867cde78929c69c8806dfba14cd886 100644 (file)
@@ -297,6 +297,9 @@ ServiceDaemonize(const char *path,
    ASSERT(path);
 
    if (pidPath) {
+      if (!ServiceNetworkCreateSocketDir()) {
+         return FALSE;
+      }
       pidPathFd = g_open(pidPath, O_WRONLY | O_CREAT, 0644);
       if (pidPathFd == -1) {
          err = errno;
index 5efcf21aa9024d815763827909e2d85bbe6c7927..f3cb59d90009c9a583466f0e55b79c0ee4fdf201 100644 (file)
 #include "VGAuthProto.h"
 
 
+/*
+ ******************************************************************************
+ * ServiceNetworkCreateSocketDir --                                      */ /**
+ *
+ * Creates the directory for the UNIX domain sockets and pid files.
+ *
+ * @return TRUE on success, FALSE on failure.
+ *
+ ******************************************************************************
+ */
+
+gboolean
+ServiceNetworkCreateSocketDir(void)
+{
+   gboolean bRet = TRUE;
+   char *socketDir = NULL;
+
+   socketDir = g_path_get_dirname(SERVICE_PUBLIC_PIPE_NAME);
+   ASSERT(socketDir != NULL);
+
+   /*
+    * Punt if its there but not a directory.
+    *
+    * g_file_test() on a symlink will return true for IS_DIR
+    * if it's a link pointing to a directory, since glib
+    * uses stat() instead of lstat().
+    */
+   if (g_file_test(socketDir, G_FILE_TEST_EXISTS) &&
+       (!g_file_test(socketDir, G_FILE_TEST_IS_DIR) ||
+       g_file_test(socketDir, G_FILE_TEST_IS_SYMLINK))) {
+      bRet = FALSE;
+      Warning("%s: socket dir path '%s' already exists as a non-directory; "
+              "aborting\n", __FUNCTION__, socketDir);
+      goto abort;
+   }
+
+   /*
+    * XXX May want to add some security checks here.
+    */
+   if (!g_file_test(socketDir, G_FILE_TEST_EXISTS)) {
+      int ret;
+
+      ret = ServiceFileMakeDirTree(socketDir, 0755);
+      if (ret < 0) {
+         bRet = FALSE;
+         Warning("%s: failed to create socket dir '%s' error: %d\n",
+                 __FUNCTION__, socketDir, ret);
+         goto abort;
+      }
+      Log("%s: Created socket directory '%s'\n", __FUNCTION__, socketDir);
+   }
+abort:
+   g_free(socketDir);
+
+   return bRet;
+}
+
+
 /*
  ******************************************************************************
  * ServiceNetworkListen --                                               */ /**
@@ -64,7 +122,6 @@ ServiceNetworkListen(ServiceConnection *conn,            // IN/OUT
    struct stat stbuf;
    uid_t uid;
    gid_t gid;
-   char *socketDir = NULL;
 
    /*
     * For some reason, this is simply hardcoded in sys/un.h
@@ -81,41 +138,11 @@ ServiceNetworkListen(ServiceConnection *conn,            // IN/OUT
     * Make sure the socket dir exists.  In theory this is only ever done once,
     * but something could clobber it.
     */
-   socketDir = g_path_get_dirname(SERVICE_PUBLIC_PIPE_NAME);
-   ASSERT(socketDir != NULL);
-
-   /*
-    * Punt if its there but not a directory.
-    *
-    * g_file_test() on a symlink will return true for IS_DIR
-    * if it's a link pointing to a directory, since glib
-    * uses stat() instead of lstat().
-    */
-   if (g_file_test(socketDir, G_FILE_TEST_EXISTS) &&
-       (!g_file_test(socketDir, G_FILE_TEST_IS_DIR) ||
-       g_file_test(socketDir, G_FILE_TEST_IS_SYMLINK))) {
+   if (!ServiceNetworkCreateSocketDir()) {
       err = VGAUTH_E_COMM;
-      Warning("%s: socket dir path '%s' already exists as a non-directory; "
-              "aborting\n", __FUNCTION__, socketDir);
       goto abort;
    }
 
-   /*
-    * XXX May want to add some security checks here.
-    */
-   if (!g_file_test(socketDir, G_FILE_TEST_EXISTS)) {
-      ret = ServiceFileMakeDirTree(socketDir, 0755);
-      if (ret < 0) {
-         err = VGAUTH_E_COMM;
-         Warning("%s: failed to create socket dir '%s' %d\n",
-                 __FUNCTION__, socketDir, ret);
-         goto abort;
-      }
-      Log("%s: Created socket directory '%s'\n", __FUNCTION__, socketDir);
-   }
-   g_free(socketDir);
-   socketDir = NULL;
-
    sock = socket(PF_UNIX, SOCK_STREAM, 0);
    if (sock < 0) {
       err = VGAUTH_E_COMM;
@@ -193,7 +220,6 @@ ServiceNetworkListen(ServiceConnection *conn,            // IN/OUT
    return VGAUTH_E_OK;
 
 abort:
-   g_free(socketDir);
    if (sock >= 0) {
       close(sock);
    }
index 8bf3af3cf44a994e518ce8d0b932dc430a1f6d24..73bb51526b3bc43a10e22f132cd1a1cb26e1c4d2 100644 (file)
@@ -225,6 +225,9 @@ extern gboolean gVerboseLogging;
 
 extern char *gInstallDir;
 
+#ifndef _WIN32
+gboolean ServiceNetworkCreateSocketDir(void);
+#endif
 
 VGAuthError ServiceNetworkListen(ServiceConnection *conn,            // IN/OUT
                                  gboolean makeSecure);