From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:15 +0000 (-0700) Subject: Set up pid/socket directory earlier X-Git-Tag: stable-10.2.0~439 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=edf9be0fa0c0037292daebba2b79b625b68f42c2;p=thirdparty%2Fopen-vm-tools.git Set up pid/socket directory earlier /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. --- diff --git a/open-vm-tools/vgauth/service/servicePosix.c b/open-vm-tools/vgauth/service/servicePosix.c index 202dab14f..bf6c98a73 100644 --- a/open-vm-tools/vgauth/service/servicePosix.c +++ b/open-vm-tools/vgauth/service/servicePosix.c @@ -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; diff --git a/open-vm-tools/vgauth/serviceImpl/netPosix.c b/open-vm-tools/vgauth/serviceImpl/netPosix.c index 5efcf21aa..f3cb59d90 100644 --- a/open-vm-tools/vgauth/serviceImpl/netPosix.c +++ b/open-vm-tools/vgauth/serviceImpl/netPosix.c @@ -37,6 +37,64 @@ #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); } diff --git a/open-vm-tools/vgauth/serviceImpl/serviceInt.h b/open-vm-tools/vgauth/serviceImpl/serviceInt.h index 8bf3af3cf..73bb51526 100644 --- a/open-vm-tools/vgauth/serviceImpl/serviceInt.h +++ b/open-vm-tools/vgauth/serviceImpl/serviceInt.h @@ -225,6 +225,9 @@ extern gboolean gVerboseLogging; extern char *gInstallDir; +#ifndef _WIN32 +gboolean ServiceNetworkCreateSocketDir(void); +#endif VGAuthError ServiceNetworkListen(ServiceConnection *conn, // IN/OUT gboolean makeSecure);