Handle return value from signal in the External clipboard driver

Absolutely zero chance of signal ever failing, but still.
This commit is contained in:
Tamás Bálint Misius 2023-12-15 18:24:39 +01:00
parent fb9cba0d01
commit 9f431c6393
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2

View File

@ -103,14 +103,26 @@ namespace Clipboard
class ExternalClipboardImpl : public ClipboardImpl
{
bool initialized = false;
public:
ExternalClipboardImpl()
{
signal(SIGPIPE, SIG_IGN); // avoids problems with popen
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) // avoids problems with popen
{
std::cerr << "failed to initialize clipboard driver: signal: " << strerror(errno) << std::endl;
return;
}
initialized = true;
}
void SetClipboardData() final override
{
if (!initialized)
{
std::cerr << "failed to set clipboard data: clipboard driver not initialized" << std::endl;
return;
}
auto preset = GetPreset();
if (!preset)
{
@ -149,6 +161,11 @@ namespace Clipboard
GetClipboardDataResult GetClipboardData() final override
{
if (!initialized)
{
std::cerr << "cannot get save from clipboard: clipboard driver not initialized" << std::endl;
return GetClipboardDataUnknown{};
}
auto getTarget = [](ByteString command) -> std::optional<std::vector<char>> {
if (!command.size())
{