int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { gDebug = (getenv("ANDROID_SDKMAN_DEBUG") != NULL); PVOID oldWow64Value = disableWow64FsRedirection(); CPath javaPath; if (!findJavaInEnvPath(&javaPath) && !findJavaInRegistry(&javaPath) && !findJavaInProgramFiles(&javaPath)) { msgBox("Failed to find Java on your system. Please reinstall it."); return 2; } _ASSERT(!javaPath.isEmpty()); revertWow64FsRedirection(oldWow64Value); // For debugging it's convenient to override the tools directory location CPath toolsDir(getenv("ANDROID_SDKMAN_TOOLS_DIR")); if (toolsDir.isEmpty()) { if (!getModuleDir(&toolsDir)) { displayLastError("Failed to get program's filename: "); return 1; } } _ASSERT(!toolsDir.isEmpty()); CPath tmpDir; if (!mkTempDir("temp-android-tool", &tmpDir)) { return 1; } _ASSERT(!tmpDir.isEmpty()); if (!mkDirs(tmpDir.cstr(), sMkDirList)) { return 1; } if (!copyFiles(toolsDir.cstr(), tmpDir.cstr(), sFilesToCopy)) { return 1; } if (!execSdkManager(javaPath.cstr(), toolsDir.cstr(), tmpDir.cstr(), lpCmdLine)) { displayLastError("Failed to start SDK Manager: "); return 1; } return 0; }
char* moveToSubDir(char *path) { char tempdir[PATH_MAX]; DIR *dirp; struct dirent *dp; strcpy(tempdir, path); if (mkTempDir(tempdir) == NULL) return NULL; dirp = opendir(path); if (dirp == NULL) { printf("opendir error\n"); rmdir(tempdir); return NULL; } while ((dp = readdir(dirp)) != NULL) { char oldpath[PATH_MAX]; char newpath[PATH_MAX]; if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0) continue; strcpy(oldpath, path); if (path[strlen(path) - 1] != '/') strcat(oldpath, "/"); strcat(oldpath, dp->d_name); if (strcmp(oldpath, tempdir) == 0) continue; strcpy(newpath, tempdir); strcat(newpath, "/"); strcat(newpath, dp->d_name); printf("mv %s to %s\n", oldpath, newpath); rename(oldpath, newpath); } closedir(dirp); strcpy(path, tempdir); return path; }
void openCtrl(struct display *d) { CtrlRec *cr; const char *dname; char *sockdir; struct sockaddr_un sa; if (!*fifoDir) return; if (d) cr = &d->ctrl, dname = displayName(d); else cr = &ctrl, dname = 0; if (cr->fd < 0) { if (mkdir(fifoDir, 0755)) { if (errno != EEXIST) { logError("mkdir %\"s failed: %m; no control sockets will be available\n", fifoDir); return; } } else { chmod(fifoDir, 0755); /* override umask */ } sockdir = 0; strApp(&sockdir, fifoDir, dname ? "/dmctl-" : "/dmctl", dname, (char *)0); if (sockdir) { strApp(&cr->path, sockdir, "/socket", (char *)0); if (cr->path) { if (strlen(cr->path) >= sizeof(sa.sun_path)) { logError("path %\"s too long; control socket will not be available\n", cr->path); #ifdef HONORS_SOCKET_PERMS } else if (mkdir(sockdir, 0700) && errno != EEXIST) { logError("mkdir %\"s failed: %m; control socket will not be available\n", sockdir); } else if (unlink(cr->path) && errno != ENOENT) { logError("unlink %\"s failed: %m; control socket will not be available\n", cr->path); } else { #else } else if (unlink(sockdir) && errno != ENOENT) { logError("unlink %\"s failed: %m; control socket will not be available\n", sockdir); } else if (!strApp(&cr->realdir, sockdir, "-XXXXXX", (char *)0)) { } else if (!mkTempDir(cr->realdir)) { logError("mkdir %\"s failed: %m; control socket will not be available\n", cr->realdir); free(cr->realdir); cr->realdir = 0; } else if (symlink(cr->realdir, sockdir)) { logError("symlink %\"s => %\"s failed: %m; control socket will not be available\n", sockdir, cr->realdir); rmdir(cr->realdir); free(cr->realdir); cr->realdir = 0; } else { chown(sockdir, 0, d ? 0 : fifoGroup); chmod(sockdir, 0750); #endif if ((cr->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { logError("Cannot create control socket: %m\n"); } else { sa.sun_family = AF_UNIX; strcpy(sa.sun_path, cr->path); if (!bind(cr->fd, (struct sockaddr *)&sa, sizeof(sa))) { if (!listen(cr->fd, 5)) { #ifdef HONORS_SOCKET_PERMS chmod(cr->path, 0660); if (!d) chown(cr->path, -1, fifoGroup); chmod(sockdir, 0755); #else chmod(cr->path, 0666); #endif registerCloseOnFork(cr->fd); registerInput(cr->fd); free(sockdir); return; } unlink(cr->path); logError("Cannot listen on control socket %\"s: %m\n", cr->path); } else { logError("Cannot bind control socket %\"s: %m\n", cr->path); } close(cr->fd); cr->fd = -1; } #ifdef HONORS_SOCKET_PERMS rmdir(sockdir); #else unlink(sockdir); rmdir(cr->realdir); free(cr->realdir); cr->realdir = 0; #endif } free(cr->path); cr->path = 0; } free(sockdir); } }
static std::string mkTempDir(const char * prefix) { return mkTempDir(std::string(prefix)); }