Skip to content

Commit ef88c17

Browse files
committed
Handle more signal cases along with a non-file lock case
1 parent 8235d4f commit ef88c17

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

โ€Žsrc/cb/src/clipboard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2-
Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
2+
Copyright (C) 2024 Jackson Huff and other contributors on GitHub.com
33
SPDX-License-Identifier: GPL-3.0-or-later
44
This program is free software: you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -171,7 +171,7 @@ void Clipboard::getLock() {
171171
if (kill(pid, 0) == -1) break;
172172
#endif
173173
if (!isLocked()) break;
174-
std::this_thread::sleep_for(std::chrono::milliseconds(250));
174+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
175175
}
176176
}
177177
writeToFile(metadata.lock, std::to_string(thisPID()));

โ€Žsrc/cb/src/clipboard.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* The Clipboard Project - Cut, copy, and paste anything, anytime, anywhere, all from the terminal.
2-
Copyright (C) 2023 Jackson Huff and other contributors on GitHub.com
2+
Copyright (C) 2024 Jackson Huff and other contributors on GitHub.com
33
SPDX-License-Identifier: GPL-3.0-or-later
44
This program is free software: you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -310,7 +310,17 @@ class Clipboard {
310310
std::vector<std::string> ignoreSecrets();
311311
void applyIgnoreRules();
312312
bool isUnused();
313-
bool isLocked() { return fs::exists(metadata.lock); }
313+
bool isLocked() {
314+
if (!fs::is_regular_file(metadata.lock)) {
315+
if (fs::exists(metadata.lock)) // Handle the case where the lock file is not a regular file
316+
fs::remove(metadata.lock);
317+
return false;
318+
}
319+
// auto pid = std::stoi(fileContents(metadata.lock).value());
320+
// Check if the PID
321+
322+
return true;
323+
}
314324
void getLock();
315325
void releaseLock() { fs::remove(metadata.lock); }
316326
std::string name() const { return this_name; }

โ€Žsrc/cb/src/utils/utils.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void setupHandlers() {
245245
#endif
246246
});
247247

248-
signal(SIGINT, [](int) {
248+
auto exitCleanly = [](int) {
249249
fprintf(stderr, "%s", formatColors("[blank]").data());
250250
if (!stopIndicator(false)) {
251251
// Indicator thread is not currently running. TODO: Write an unbuffered newline, and maybe a cancelation
@@ -257,7 +257,11 @@ void setupHandlers() {
257257
indicator.join();
258258
exit(EXIT_FAILURE);
259259
}
260-
});
260+
};
261+
262+
signal(SIGINT, exitCleanly);
263+
signal(SIGTERM, exitCleanly);
264+
signal(SIGQUIT, exitCleanly);
261265

262266
forker.atFork([]() {
263267
// As the indicator thread still exists in memory in the forked process,
@@ -377,7 +381,10 @@ void setupVariables(int& argc, char* argv[]) {
377381

378382
arguments.assign(argv + 1, argv + argc);
379383

380-
clipboard_invocation = argv[0];
384+
if (argv[0][0] != nullptr)
385+
clipboard_invocation = argv[0];
386+
else
387+
clipboard_invocation = "cb";
381388
}
382389

383390
template <typename T>

0 commit comments

Comments
ย (0)