diff --git a/doc/man.md.j2 b/doc/man.md.j2 index 85d1eda483..bd9db7fb88 100644 --- a/doc/man.md.j2 +++ b/doc/man.md.j2 @@ -163,7 +163,7 @@ file. **-U \| \--unique** : Conky won't start if another Conky process is already running. Implemented - only for Linux and FreeBSD. + only for Linux, FreeBSD and Haiku. **-v \| -V \| \--version** diff --git a/src/common.cc b/src/common.cc index 4b63b9dd5a..ae4e26b32c 100644 --- a/src/common.cc +++ b/src/common.cc @@ -56,7 +56,7 @@ #include "timeinfo.h" #include "top.h" -#if defined(_POSIX_C_SOURCE) && !defined(__OpenBSD__) +#if defined(_POSIX_C_SOURCE) && !defined(__OpenBSD__) && !defined(__HAIKU__) #include #endif @@ -141,7 +141,7 @@ double get_time() { return tv.tv_sec + (tv.tv_nsec * 1e-9); } -#if defined(_POSIX_C_SOURCE) && !defined(__OpenBSD__) +#if defined(_POSIX_C_SOURCE) && !defined(__OpenBSD__) && !defined(__HAIKU__) std::filesystem::path to_real_path(const std::string &source) { wordexp_t p; char **w; diff --git a/src/conky.cc b/src/conky.cc index 3589d568c5..c450365c6d 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2109,9 +2109,10 @@ void set_current_config() { /* : means that character before that takes an argument */ const char *getopt_string = "vVqdDSs:t:u:i:hc:p:" -#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__HAIKU__) "U" -#endif /* Linux || FreeBSD */ +#endif /* Linux || FreeBSD || Haiku */ #ifdef BUILD_X11 "x:y:w:a:X:m:f:" #ifdef OWN_WINDOW @@ -2142,9 +2143,10 @@ const struct option longopts[] = { #endif /* BUILD_X11 */ {"text", 1, nullptr, 't'}, {"interval", 1, nullptr, 'u'}, {"pause", 1, nullptr, 'p'}, -#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__HAIKU__) {"unique", 0, nullptr, 'U'}, -#endif /* Linux || FreeBSD */ +#endif /* Linux || FreeBSDi || Haiku */ {nullptr, 0, nullptr, 0} }; diff --git a/src/haiku.cc b/src/haiku.cc index 73ec54f78c..7029df1927 100644 --- a/src/haiku.cc +++ b/src/haiku.cc @@ -247,3 +247,25 @@ void get_battery_short_status(char *buffer, unsigned int n, const char *bat) { int get_entropy_avail(unsigned int *val) { return 1; } int get_entropy_poolsize(unsigned int *val) { return 1; } + +/****************************************** + * Check if more than one conky process * + * is running * + ******************************************/ + +bool is_conky_already_running(void) { + int32 team_cookie = 0; + team_info team_info; + int32 thread_cookie = 0; + thread_info thread_info; + int32 instances = 0; + + while (get_next_team_info(&team_cookie, &team_info) >= B_OK) { + while (get_next_thread_info(team_info.team, &thread_cookie, &thread_info) >= B_OK) { + if (!strcmp("conky", thread_info.name)) { + ++instances; + } + } + } + return instances > 1; +} diff --git a/src/haiku.h b/src/haiku.h index 801000b9f3..84c93208c6 100644 --- a/src/haiku.h +++ b/src/haiku.h @@ -18,6 +18,8 @@ #include +#include + #include "common.h" #include "conky.h" @@ -38,4 +40,6 @@ inline int statfs(const char *path, struct statfs *buf) { #define f_bfree free_blocks #define f_fstypename fsh_name +bool is_conky_already_running(void); + #endif /*HAIKU_H_*/ diff --git a/src/main.cc b/src/main.cc index 1b561681ae..2b0bf4e6eb 100644 --- a/src/main.cc +++ b/src/main.cc @@ -52,6 +52,10 @@ #include "freebsd.h" #endif /* FreeBSD */ +#if defined(__HAIKU__) +#include "haiku.h" +#endif /* Haiku */ + #ifdef BUILD_BUILTIN_CONFIG #include "defconfig.h" @@ -273,9 +277,10 @@ static void print_help(const char *prog_name) { " (and quit)\n" " -p, --pause=SECS pause for SECS seconds at startup " "before doing anything\n" -#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__HAIKU__) " -U, --unique only one conky process can be created\n" -#endif /* Linux || FreeBSD */ +#endif /* Linux || FreeBSD || Haiku */ , prog_name); } @@ -358,22 +363,24 @@ int main(int argc, char **argv) { window.window = strtol(optarg, nullptr, 0); break; #endif /* BUILD_X11 */ -#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__HAIKU__) case 'U': unique_process = true; break; -#endif /* Linux || FreeBSD */ +#endif /* Linux || FreeBSD || Haiku */ case '?': return EXIT_FAILURE; } } -#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__HAIKU__) if (unique_process && is_conky_already_running()) { NORM_ERR("already running"); return 0; } -#endif /* Linux || FreeBSD */ +#endif /* Linux || FreeBSD || Haiku */ try { set_current_config();