Skip to content

Commit

Permalink
Hide U flag altogether if not on Linux
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Švagelj <[email protected]>
  • Loading branch information
Caellian committed Nov 1, 2024
1 parent 6ab89e5 commit 24da64a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion doc/man.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
13 changes: 10 additions & 3 deletions src/conky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
#ifdef defined(__linux__)
"U"
#endif
#ifdef BUILD_X11
"x:y:w:a:X:m:f:"
#ifdef OWN_WINDOW
Expand Down Expand Up @@ -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
{nullptr, 0, nullptr, 0}
};

void setup_inotify() {
#ifdef HAVE_SYS_INOTIFY_H
Expand Down
7 changes: 6 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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__) || \
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 24da64a

Please sign in to comment.