From 7b0e8e818805d11931b134d148a464fccb42fb49 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Mon, 17 Nov 2025 20:14:34 -0500 Subject: [PATCH] chore: WlClipboard remove unused executeCommand --- src/lib/platform/WlClipboard.cpp | 112 ------------------------------- src/lib/platform/WlClipboard.h | 3 - 2 files changed, 115 deletions(-) diff --git a/src/lib/platform/WlClipboard.cpp b/src/lib/platform/WlClipboard.cpp index d043172ad..3dc3fd373 100644 --- a/src/lib/platform/WlClipboard.cpp +++ b/src/lib/platform/WlClipboard.cpp @@ -402,118 +402,6 @@ std::string WlClipboard::get(Format format) const return data; } -std::string WlClipboard::executeCommand(const std::vector &args) const -{ - int pipefd[2]; - if (pipe(pipefd) == -1) { - LOG_WARN("failed to create pipe"); - return std::string(); - } - - FdGuard readFd(pipefd[0]); - FdGuard writeFd(pipefd[1]); - - // Set FD_CLOEXEC on pipe file descriptors - fcntl(readFd.get(), F_SETFD, FD_CLOEXEC); - fcntl(writeFd.get(), F_SETFD, FD_CLOEXEC); - - // Set up file actions for posix_spawn - posix_spawn_file_actions_t fileActions; - posix_spawn_file_actions_init(&fileActions); - - // Redirect stdout to pipe write end - posix_spawn_file_actions_adddup2(&fileActions, writeFd.get(), STDOUT_FILENO); - - // Redirect stderr to /dev/null - posix_spawn_file_actions_addopen(&fileActions, STDERR_FILENO, "/dev/null", O_WRONLY, 0); - - // Close pipe file descriptors in child - posix_spawn_file_actions_addclose(&fileActions, readFd.get()); - posix_spawn_file_actions_addclose(&fileActions, writeFd.get()); - - extern char **environ; - pid_t pid; - int spawnResult = posix_spawnp(&pid, args[0], &fileActions, nullptr, const_cast(args.data()), environ); - - posix_spawn_file_actions_destroy(&fileActions); - - if (spawnResult != 0) { - LOG_WARN("failed to spawn process: %s", strerror(spawnResult)); - return std::string(); - } - - ProcessGuard processGuard(pid); - - // Parent process - close write end - writeFd.close(); - - std::string result; - char buffer[4096]; - - // Use poll to read with timeout - struct pollfd pfd; - pfd.fd = readFd.get(); - pfd.events = POLLIN; - - auto start = std::chrono::steady_clock::now(); - while (true) { - auto now = std::chrono::steady_clock::now(); - auto elapsed = std::chrono::duration_cast(now - start).count(); - int remainingTimeout = kCommandTimeout - elapsed; - - if (remainingTimeout <= 0) { - break; // Timeout - } - - int pollResult = poll(&pfd, 1, remainingTimeout); - if (pollResult == 0) { - break; // Timeout - } else if (pollResult < 0) { - if (errno == EINTR) { - continue; // Interrupted, try again - } - break; // Error - } - - if (pfd.revents & POLLIN) { - ssize_t bytesRead = read(readFd.get(), buffer, sizeof(buffer)); - if (bytesRead > 0) { - result.append(buffer, bytesRead); - } else if (bytesRead == 0) { - break; // EOF - } else if (errno != EINTR) { - break; // Error - } - } - - if (pfd.revents & (POLLHUP | POLLERR)) { - break; // Pipe closed or error - } - } - - readFd.close(); - - int status; - bool processFinished = waitpidWithTimeout(pid, &status, 1000); // Give 1 more second - if (processFinished) { - processGuard.release(); - - if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { - // Remove trailing newline if present - if (!result.empty() && result.back() == '\n') { - result.pop_back(); - } - return result; - } else { - LOG_DEBUG1("command failed with status %d", WEXITSTATUS(status)); - return std::string(); - } - } else { - LOG_WARN("process did not terminate properly"); - return std::string(); - } -} - bool WlClipboard::executeCommandWithInput(const std::vector &args, const std::string &input) const { int pipefd[2]; diff --git a/src/lib/platform/WlClipboard.h b/src/lib/platform/WlClipboard.h index 95459059b..e6151e934 100644 --- a/src/lib/platform/WlClipboard.h +++ b/src/lib/platform/WlClipboard.h @@ -65,9 +65,6 @@ public: std::string get(Format format) const override; private: - //! Execute a command and return its output - std::string executeCommand(const std::vector &args) const; - //! Execute a command with input data bool executeCommandWithInput(const std::vector &args, const std::string &input) const;