mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-28 17:48:39 +00:00
parent
fa045548af
commit
b0cb25059b
@ -163,7 +163,7 @@ file.
|
||||
**-U \| \--unique**
|
||||
|
||||
: Conky won't start if another Conky process is already running. Implemented
|
||||
only for Linux, FreeBSD and Haiku.
|
||||
only for Linux, FreeBSD, NetBSD and Haiku.
|
||||
|
||||
**-v \| -V \| \--version**
|
||||
|
||||
|
@ -53,7 +53,7 @@ bool bsdcommon::init_kvm() {
|
||||
}
|
||||
|
||||
kvm_initialised = true;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void bsdcommon::deinit_kvm() {
|
||||
@ -223,7 +223,7 @@ static bool is_top_process(BSD_COMMON_PROC_STRUCT *p) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static int32_t get_pd(BSD_COMMON_PROC_STRUCT *p) {
|
||||
static int32_t get_pid(BSD_COMMON_PROC_STRUCT *p) {
|
||||
#if defined(__NetBSD__)
|
||||
return p->p_pid;
|
||||
#else
|
||||
@ -309,7 +309,7 @@ void bsdcommon::update_top_info() {
|
||||
continue;
|
||||
}
|
||||
|
||||
proc = get_process(get_pd(p));
|
||||
proc = get_process(get_pid(p));
|
||||
if (!proc) {
|
||||
continue;
|
||||
}
|
||||
@ -317,3 +317,36 @@ void bsdcommon::update_top_info() {
|
||||
proc_from_bsdproc(proc, p);
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_process(BSD_COMMON_PROC_STRUCT *p, const char *name) {
|
||||
#if defined(__NetBSD__)
|
||||
return p->p_comm[0] != 0 && strcmp(p->p_comm, name) == 0;
|
||||
#else
|
||||
#error Not supported BSD system
|
||||
#endif
|
||||
}
|
||||
|
||||
bool bsdcommon::is_conky_already_running() {
|
||||
if (!init_kvm()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct process *proc = nullptr;
|
||||
short unsigned int nprocs = 0;
|
||||
int instances = 0;
|
||||
|
||||
BSD_COMMON_PROC_STRUCT *ps = get_processes(&nprocs);
|
||||
if (ps == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nprocs && instances < 2; ++i) {
|
||||
BSD_COMMON_PROC_STRUCT *p = &ps[i];
|
||||
|
||||
if (is_process(p, "conky")) {
|
||||
++instances;
|
||||
}
|
||||
}
|
||||
|
||||
return instances > 1;
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ namespace bsdcommon {
|
||||
|
||||
void get_number_of_running_processes(short unsigned int *run_procs);
|
||||
void update_top_info();
|
||||
};
|
||||
bool is_conky_already_running();
|
||||
}
|
||||
|
||||
#endif /*BSDCOMMON_H_*/
|
||||
|
@ -2110,9 +2110,9 @@ void set_current_config() {
|
||||
const char *getopt_string =
|
||||
"vVqdDSs:t:u:i:hc:p:"
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
|
||||
defined(__HAIKU__)
|
||||
defined(__HAIKU__) || defined(__NetBSD__)
|
||||
"U"
|
||||
#endif /* Linux || FreeBSD || Haiku */
|
||||
#endif /* Linux || FreeBSD || Haiku || NetBSD */
|
||||
#ifdef BUILD_X11
|
||||
"x:y:w:a:X:m:f:"
|
||||
#ifdef OWN_WINDOW
|
||||
@ -2144,9 +2144,9 @@ const struct option longopts[] = {
|
||||
{"text", 1, nullptr, 't'}, {"interval", 1, nullptr, 'u'},
|
||||
{"pause", 1, nullptr, 'p'},
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
|
||||
defined(__HAIKU__)
|
||||
defined(__HAIKU__) || defined(__NetBSD__)
|
||||
{"unique", 0, nullptr, 'U'},
|
||||
#endif /* Linux || FreeBSDi || Haiku */
|
||||
#endif /* Linux || FreeBSDi || Haiku || NetBSD */
|
||||
{nullptr, 0, nullptr, 0}
|
||||
};
|
||||
|
||||
|
10
src/main.cc
10
src/main.cc
@ -282,9 +282,9 @@ static void print_help(const char *prog_name) {
|
||||
" -p, --pause=SECS pause for SECS seconds at startup "
|
||||
"before doing anything\n"
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
|
||||
defined(__HAIKU__)
|
||||
defined(__HAIKU__) || defined(__NetBSD__)
|
||||
" -U, --unique only one conky process can be created\n"
|
||||
#endif /* Linux || FreeBSD || Haiku */
|
||||
#endif /* Linux || FreeBSD || Haiku || NetBSD */
|
||||
, prog_name);
|
||||
}
|
||||
|
||||
@ -368,18 +368,18 @@ int main(int argc, char **argv) {
|
||||
break;
|
||||
#endif /* BUILD_X11 */
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
|
||||
defined(__HAIKU__)
|
||||
defined(__HAIKU__) || defined(__NetBSD__)
|
||||
case 'U':
|
||||
unique_process = true;
|
||||
break;
|
||||
#endif /* Linux || FreeBSD || Haiku */
|
||||
#endif /* Linux || FreeBSD || Haiku || NetBSD */
|
||||
case '?':
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
|
||||
defined(__HAIKU__)
|
||||
defined(__HAIKU__) || defined(__NetBSD__)
|
||||
if (unique_process && is_conky_already_running()) {
|
||||
NORM_ERR("already running");
|
||||
return 0;
|
||||
|
@ -322,3 +322,6 @@ int update_diskio(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool is_conky_already_running() {
|
||||
return bsdcommon::is_conky_already_running();
|
||||
}
|
||||
|
@ -20,4 +20,6 @@
|
||||
int get_entropy_avail(unsigned int *);
|
||||
int get_entropy_poolsize(unsigned int *);
|
||||
|
||||
bool is_conky_already_running();
|
||||
|
||||
#endif /*NETBSD_H_*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user