Skip to content

Commit

Permalink
Implement -U for Haiku.
Browse files Browse the repository at this point in the history
This patch also fixes a compilation error on Haiku.

Compiled with `cmake -DBUILD_X11=FALSE ..`

Tested on Haiku-r1beta5.
Takes part of brndnmtthws#2072.
  • Loading branch information
g0mb4 committed Nov 14, 2024
1 parent a0ee703 commit ec8fd63
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 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
20 changes: 19 additions & 1 deletion src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <cerrno>
#include <ctime>
#include <vector>
#include <wordexp.h>
#include "config.h"
#include "conky.h"
#include "core.h"
Expand All @@ -62,8 +61,14 @@
#include "openbsd.h"
#elif defined(__APPLE__) && defined(__MACH__)
#include "darwin.h" // strings.h
#elif defined(__HAIKU__)
#include "haiku.h"
#endif

#if !defined(__HAIKU__)
#include <wordexp.h>
#endif /* !Haiku */

#include "update-cb.hh"

#ifdef BUILD_CURL
Expand Down Expand Up @@ -133,6 +138,7 @@ double get_time() {
/* Converts '~/...' paths to '/home/blah/...'. It's similar to
* variable_substitute, works for any enviroment variable */
std::string to_real_path(const std::string &source) {
#if !defined(__HAIKU__)
wordexp_t p;
char **w;
int i;
Expand All @@ -144,6 +150,18 @@ std::string to_real_path(const std::string &source) {
const char *resolved_path = strdup(w[0]);
wordfree(&p);
return std::string(resolved_path);
#else /* !Haiku */
char resolved_path[B_PATH_NAME_LENGTH] = {0};
const char *csource = source.c_str();
if (*csource == '~') {
const int home_len = strlen(HAIKU_HOME_DIR);
strncpy(resolved_path, HAIKU_HOME_DIR, B_PATH_NAME_LENGTH - 1);
strncpy(resolved_path + home_len, csource + 1, B_PATH_NAME_LENGTH - 1 - home_len);
return std::string(resolved_path);
} else {
return source;
}
#endif /* !Haiku */
}

int open_fifo(const char *file, int *reported) {
Expand Down
10 changes: 6 additions & 4 deletions src/conky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2107,9 +2107,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 @@ -2140,9 +2141,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;
}
6 changes: 6 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,8 @@ inline int statfs(const char *path, struct statfs *buf) {
#define f_bfree free_blocks
#define f_fstypename fsh_name

#define HAIKU_HOME_DIR "/boot/home"

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 ec8fd63

Please sign in to comment.