Skip to content

Commit

Permalink
Implement -U for Haiku. (#2079)
Browse files Browse the repository at this point in the history
* Implement `-U` for Haiku.

This patch also fixes a compilation error on Haiku.

Compiled with `cmake -DBUILD_X11=FALSE ..`

Tested on Haiku-r1beta5.
Takes part of #2072.

* Revert `common.cc`.

A cross-platform solution is already implemented in #2080.
This PR will be rebased *after* the OpenBSD fix was merged.

* Haiku: Remove `wordexp.h`.

Use the `to_real_path()` used for OpenBSD.

* Haiku: Remove `HAIKU_HOME_DIR`.

It was not used.
  • Loading branch information
g0mb4 authored Nov 29, 2024
1 parent fbbcb6c commit 4b33da9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/man.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
4 changes: 2 additions & 2 deletions src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <wordexp.h>
#endif

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions src/conky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
};

Expand Down
22 changes: 22 additions & 0 deletions src/haiku.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions src/haiku.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <kernel/fs_info.h>

#include <OS.h>

#include "common.h"
#include "conky.h"

Expand All @@ -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_*/
19 changes: 13 additions & 6 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#include "freebsd.h"
#endif /* FreeBSD */

#if defined(__HAIKU__)
#include "haiku.h"
#endif /* Haiku */

#ifdef BUILD_BUILTIN_CONFIG
#include "defconfig.h"

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4b33da9

Please sign in to comment.