make render thread optional

theoretical potential security concerns; no use unless using bar and you care... I hammered pretty hard on my kb for a while to try and see if it's possible to configure it poorly and get the render thread to crash, but to no avail.
This commit is contained in:
Pandora 2017-12-08 02:29:05 -05:00
parent 3edfb79f96
commit 59cdccb3e5
No known key found for this signature in database
GPG Key ID: 55DB77C2A03E1EF5
4 changed files with 45 additions and 12 deletions

View File

@ -182,6 +182,9 @@ bool skip_repeated_empty_password = false;
// for the rendering thread, so we can clean it up
pthread_t draw_thread;
// main thread still sometimes calls redraw()
// allow you to disable. handy if you use bar with lots of crap.
bool redraw_thread = false;
#define BAR_VERT 0
#define BAR_FLAT 1
@ -1097,6 +1100,8 @@ int main(int argc, char *argv[]) {
{"bar-periodic-step", required_argument, NULL, 0},
{"bar-position", required_argument, NULL, 0},
{"redraw-thread", no_argument, NULL, 0},
{NULL, no_argument, NULL, 0}};
if ((pw = getpwuid(getuid())) == NULL)
@ -1579,9 +1584,10 @@ int main(int argc, char *argv[]) {
if (sscanf(arg, "%31s", bar_expr) != 1) {
errx(1, "bar-position must be of the form [pos] with a max length of 31\n");
}
}
else if (strcmp(longopts[longoptind].name, "redraw-thread") == 0) {
redraw_thread = true;
}
break;
case 'f':
@ -1816,15 +1822,17 @@ int main(int argc, char *argv[]) {
* file descriptor becomes readable). */
ev_invoke(main_loop, xcb_check, 0);
// boy i sure hope this doesnt change in the future
#define NANOSECONDS_IN_SECOND 1000000000
if (show_clock || bar_enabled) {
struct timespec ts;
double s;
double ns = modf(refresh_rate, &s);
ts.tv_sec = (time_t) s;
ts.tv_nsec = ns * NANOSECONDS_IN_SECOND;
(void) pthread_create(&draw_thread, NULL, start_time_redraw_tick, (void*) &ts);
if (redraw_thread) {
struct timespec ts;
double s;
double ns = modf(refresh_rate, &s);
ts.tv_sec = (time_t) s;
ts.tv_nsec = ns * NANOSECONDS_IN_SECOND;
(void) pthread_create(&draw_thread, NULL, start_time_redraw_tick_pthread, (void*) &ts);
} else {
start_time_redraw_tick(main_loop);
}
}
ev_loop(main_loop, 0);

View File

@ -1,6 +1,9 @@
#ifndef _I3LOCK_H
#define _I3LOCK_H
// boy i sure hope this doesnt change in the future
#define NANOSECONDS_IN_SECOND 1000000000
/* This macro will only print debug output when started with --debug.
* This is important because xautolock (for example) closes stdout/stderr by
* default, so just printing something to stdout will lead to the data ending

View File

@ -133,6 +133,9 @@ extern xcb_screen_t *screen;
* Local variables.
******************************************************************************/
/* time stuff */
static struct ev_periodic *time_redraw_tick;
/* Cache the screens visual, necessary for creating a Cairo context. */
static xcb_visualtype_t *vistype;
@ -969,7 +972,7 @@ void clear_indicator(void) {
redraw_screen();
}
void* start_time_redraw_tick(void* arg) {
void* start_time_redraw_tick_pthread(void* arg) {
struct timespec *ts = (struct timespec *) arg;
while(1) {
nanosleep(ts, NULL);
@ -977,3 +980,21 @@ void* start_time_redraw_tick(void* arg) {
}
return NULL;
}
static void time_redraw_cb(struct ev_loop *loop, ev_periodic *w, int revents) {
redraw_screen();
}
void start_time_redraw_tick(struct ev_loop* main_loop) {
if (time_redraw_tick) {
ev_periodic_set(time_redraw_tick, 0., refresh_rate, 0);
ev_periodic_again(main_loop, time_redraw_tick);
} else {
if (!(time_redraw_tick = calloc(sizeof(struct ev_periodic), 1))) {
return;
}
ev_periodic_init(time_redraw_tick, time_redraw_cb, 0., refresh_rate, 0);
ev_periodic_start(main_loop, time_redraw_tick);
}
}

View File

@ -51,5 +51,6 @@ void init_colors_once(void);
void redraw_screen(void);
void clear_indicator(void);
void start_time_redraw_timeout(void);
void* start_time_redraw_tick(void* arg);
void* start_time_redraw_tick_pthread(void* arg);
void start_time_redraw_tick(struct ev_loop* main_loop);
#endif