Hide U flag altogether if not on Linux

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
This commit is contained in:
Tin Švagelj
2024-11-01 06:44:00 +01:00
committed by Brenden Matthews
parent e6465e8298
commit 3ed65249be
3 changed files with 18 additions and 5 deletions

View File

@@ -162,7 +162,8 @@ file.
**-U \| \--unique**
: Conky won't start if another Conky process is already running.
: Conky won't start if another Conky process is already running. Implemented
only for Linux.
**-v \| -V \| \--version**

View File

@@ -2106,7 +2106,10 @@ void set_current_config() {
/* : means that character before that takes an argument */
const char *getopt_string =
"vVqdDSs:t:u:i:hc:p:U"
"vVqdDSs:t:u:i:hc:p:"
#if defined(__linux__)
"U"
#endif
#ifdef BUILD_X11
"x:y:w:a:X:m:f:"
#ifdef OWN_WINDOW
@@ -2136,8 +2139,12 @@ const struct option longopts[] = {
{"double-buffer", 0, nullptr, 'b'}, {"window-id", 1, nullptr, 'w'},
#endif /* BUILD_X11 */
{"text", 1, nullptr, 't'}, {"interval", 1, nullptr, 'u'},
{"pause", 1, nullptr, 'p'}, {"unique", 0, nullptr, 'U'},
{nullptr, 0, nullptr, 0}};
{"pause", 1, nullptr, 'p'},
#if defined(__linux__)
{"unique", 0, nullptr, 'U'},
#endif /* Linux */
{nullptr, 0, nullptr, 0}
};
void setup_inotify() {
#ifdef HAVE_SYS_INOTIFY_H

View File

@@ -275,6 +275,7 @@ static void print_help(const char *prog_name) {
prog_name);
}
#if defined(__linux__)
// NOTE: Only works on systems where there is a /proc/[pid]/stat file.
static bool is_conky_already_running() {
DIR *dir;
@@ -312,6 +313,7 @@ static bool is_conky_already_running() {
closedir(dir);
return instances > 1;
}
#endif /* Linux */
inline void reset_optind() {
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
@@ -392,19 +394,22 @@ int main(int argc, char **argv) {
window.window = strtol(optarg, nullptr, 0);
break;
#endif /* BUILD_X11 */
#if defined(__linux__)
case 'U':
unique_process = true;
break;
#endif /* Linux */
case '?':
return EXIT_FAILURE;
}
}
#if defined(__linux__)
if (unique_process && is_conky_already_running()) {
NORM_ERR("already running");
return 0;
}
#endif /* Linux */
try {
set_current_config();