mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-17 18:45:10 +00:00
Added disable_auto_reload option, callback fixes.
There were some issues with reloading and the threaded callback framework, which I think are mostly resolved now, but may need more testing.
This commit is contained in:
parent
19303af8da
commit
39f01e216b
@ -157,6 +157,15 @@
|
||||
<listitem>Default shading color and border's shading color
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command>
|
||||
<option>disable_auto_reload</option>
|
||||
</command>
|
||||
</term>
|
||||
<listitem>Enable to disable the inotify-based auto config reload feature.
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command>
|
||||
|
30
src/common.c
30
src/common.c
@ -279,10 +279,12 @@ static struct update_cb {
|
||||
volatile char running;
|
||||
} update_cb_head = {
|
||||
.next = NULL,
|
||||
.func = NULL,
|
||||
};
|
||||
|
||||
static void *run_update_callback(void *);
|
||||
static int threading_started;
|
||||
static void *run_update_callback(void *) __attribute__((noreturn));
|
||||
|
||||
static int threading_started = 0;
|
||||
|
||||
/* Register an update callback. Don't allow duplicates, to minimise side
|
||||
* effects and overhead. */
|
||||
@ -308,10 +310,12 @@ void add_update_callback(void (*func)(void))
|
||||
sem_init(&uc->end_wait, 0, 0);
|
||||
|
||||
if (threading_started) {
|
||||
if (!uc->running) {
|
||||
uc->running = 1;
|
||||
pthread_create(&uc->thread, NULL, &run_update_callback, uc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Free the list element uc and all decendants recursively. */
|
||||
static void __free_update_callbacks(struct update_cb *uc)
|
||||
@ -323,7 +327,9 @@ static void __free_update_callbacks(struct update_cb *uc)
|
||||
/* send cancellation request, then trigger and join the thread */
|
||||
uc->running = 0;
|
||||
sem_post(&uc->start_wait);
|
||||
pthread_join(uc->thread, NULL);
|
||||
}
|
||||
if (pthread_join(uc->thread, NULL)) {
|
||||
NORM_ERR("Error destroying thread");
|
||||
}
|
||||
|
||||
/* finally destroy the semaphores */
|
||||
@ -356,21 +362,24 @@ void start_update_threading(void)
|
||||
threading_started = 1;
|
||||
|
||||
for (uc = update_cb_head.next; uc; uc = uc->next) {
|
||||
if (!uc->running) {
|
||||
uc->running = 1;
|
||||
pthread_create(&uc->thread, NULL, &run_update_callback, uc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void *run_update_callback(void *data)
|
||||
{
|
||||
struct update_cb *ucb = data;
|
||||
|
||||
if (!ucb || !ucb->func) pthread_exit(NULL);
|
||||
|
||||
while (1) {
|
||||
sem_wait(&ucb->start_wait);
|
||||
if (ucb->running == 0)
|
||||
return NULL;
|
||||
if (sem_wait(&ucb->start_wait)) pthread_exit(NULL);
|
||||
if (ucb->running == 0) pthread_exit(NULL);
|
||||
(*ucb->func)();
|
||||
sem_post(&ucb->end_wait);
|
||||
if (sem_post(&ucb->end_wait)) pthread_exit(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -397,8 +406,11 @@ void update_stuff(void)
|
||||
|
||||
prepare_update();
|
||||
|
||||
for (uc = update_cb_head.next; uc; uc = uc->next)
|
||||
sem_post(&uc->start_wait);
|
||||
for (uc = update_cb_head.next; uc; uc = uc->next) {
|
||||
if (sem_post(&uc->start_wait)) {
|
||||
NORM_ERR("Semaphore error");
|
||||
}
|
||||
}
|
||||
/* need to synchronise here, otherwise locking is needed (as data
|
||||
* would be printed with some update callbacks still running) */
|
||||
for (uc = update_cb_head.next; uc; uc = uc->next)
|
||||
|
23
src/conky.cc
23
src/conky.cc
@ -126,6 +126,9 @@
|
||||
/* debugging level, used by logging.h */
|
||||
int global_debug_level = 0;
|
||||
|
||||
/* disable inotify auto reload feature if desired */
|
||||
int disable_auto_reload = 0;
|
||||
|
||||
/* two strings for internal use */
|
||||
static char *tmpstring1, *tmpstring2;
|
||||
|
||||
@ -424,7 +427,7 @@ int get_total_updates(void)
|
||||
|
||||
#define SECRIT_MULTILINE_CHAR '\x02'
|
||||
|
||||
static inline int calc_text_width(const char *s)
|
||||
int calc_text_width(const char *s)
|
||||
{
|
||||
size_t slen = strlen(s);
|
||||
|
||||
@ -854,7 +857,7 @@ void set_update_interval(double interval)
|
||||
update_interval_old = interval;
|
||||
}
|
||||
|
||||
static inline int get_string_width(const char *s)
|
||||
int get_string_width(const char *s)
|
||||
{
|
||||
return *s ? calc_text_width(s) : 0;
|
||||
}
|
||||
@ -2272,12 +2275,12 @@ static void main_loop(void)
|
||||
break;
|
||||
}
|
||||
#ifdef HAVE_SYS_INOTIFY_H
|
||||
if (inotify_fd != -1 && inotify_config_wd == -1 && current_config != 0) {
|
||||
if (!disable_auto_reload && inotify_fd != -1 && inotify_config_wd == -1 && current_config != 0) {
|
||||
inotify_config_wd = inotify_add_watch(inotify_fd,
|
||||
current_config,
|
||||
IN_MODIFY);
|
||||
}
|
||||
if (inotify_fd != -1 && inotify_config_wd != -1 && current_config != 0) {
|
||||
if (!disable_auto_reload && inotify_fd != -1 && inotify_config_wd != -1 && current_config != 0) {
|
||||
int len = 0, idx = 0;
|
||||
fd_set descriptors;
|
||||
struct timeval time_to_wait;
|
||||
@ -2313,6 +2316,10 @@ static void main_loop(void)
|
||||
idx += INOTIFY_EVENT_SIZE + ev->len;
|
||||
}
|
||||
}
|
||||
} else if (disable_auto_reload && inotify_fd != -1) {
|
||||
inotify_rm_watch(inotify_fd, inotify_config_wd);
|
||||
close(inotify_fd);
|
||||
inotify_fd = inotify_config_wd = 0;
|
||||
}
|
||||
#endif /* HAVE_SYS_INOTIFY_H */
|
||||
|
||||
@ -2342,6 +2349,7 @@ static void reload_config(void)
|
||||
{
|
||||
char *current_config_copy = strdup(current_config);
|
||||
clean_up(NULL, NULL);
|
||||
sleep(1); /* slight pause */
|
||||
current_config = current_config_copy;
|
||||
initialisation(argc_copy, argv_copy);
|
||||
}
|
||||
@ -2350,6 +2358,8 @@ void clean_up(void *memtofree1, void* memtofree2)
|
||||
{
|
||||
int i;
|
||||
|
||||
free_update_callbacks();
|
||||
|
||||
#ifdef NCURSES
|
||||
if(output_methods & TO_NCURSES) {
|
||||
endwin();
|
||||
@ -2401,8 +2411,6 @@ void clean_up(void *memtofree1, void* memtofree2)
|
||||
|
||||
#endif /* X11 */
|
||||
|
||||
free_update_callbacks();
|
||||
|
||||
free_templates();
|
||||
|
||||
if (info.first_process) {
|
||||
@ -3169,6 +3177,9 @@ char load_config_file(const char *f)
|
||||
CONF("extra_newline") {
|
||||
extra_newline = string_to_bool(value);
|
||||
}
|
||||
CONF("disable_auto_reload") {
|
||||
disable_auto_reload = string_to_bool(value);
|
||||
}
|
||||
CONF("out_to_stderr") {
|
||||
if(string_to_bool(value))
|
||||
output_methods |= TO_STDERR;
|
||||
|
Loading…
Reference in New Issue
Block a user