Browse Source

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.
master
Pandora 7 years ago
parent
commit
59cdccb3e5
No known key found for this signature in database GPG Key ID: 55DB77C2A03E1EF5
  1. 28
      i3lock.c
  2. 3
      i3lock.h
  3. 23
      unlock_indicator.c
  4. 3
      unlock_indicator.h

28
i3lock.c

@ -182,6 +182,9 @@ bool skip_repeated_empty_password = false;
// for the rendering thread, so we can clean it up // for the rendering thread, so we can clean it up
pthread_t draw_thread; 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_VERT 0
#define BAR_FLAT 1 #define BAR_FLAT 1
@ -1097,6 +1100,8 @@ int main(int argc, char *argv[]) {
{"bar-periodic-step", required_argument, NULL, 0}, {"bar-periodic-step", required_argument, NULL, 0},
{"bar-position", required_argument, NULL, 0}, {"bar-position", required_argument, NULL, 0},
{"redraw-thread", no_argument, NULL, 0},
{NULL, no_argument, NULL, 0}}; {NULL, no_argument, NULL, 0}};
if ((pw = getpwuid(getuid())) == NULL) if ((pw = getpwuid(getuid())) == NULL)
@ -1579,9 +1584,10 @@ int main(int argc, char *argv[]) {
if (sscanf(arg, "%31s", bar_expr) != 1) { if (sscanf(arg, "%31s", bar_expr) != 1) {
errx(1, "bar-position must be of the form [pos] with a max length of 31\n"); 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; break;
case 'f': case 'f':
@ -1816,15 +1822,17 @@ int main(int argc, char *argv[]) {
* file descriptor becomes readable). */ * file descriptor becomes readable). */
ev_invoke(main_loop, xcb_check, 0); 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) { if (show_clock || bar_enabled) {
struct timespec ts; if (redraw_thread) {
double s; struct timespec ts;
double ns = modf(refresh_rate, &s); double s;
ts.tv_sec = (time_t) s; double ns = modf(refresh_rate, &s);
ts.tv_nsec = ns * NANOSECONDS_IN_SECOND; ts.tv_sec = (time_t) s;
(void) pthread_create(&draw_thread, NULL, start_time_redraw_tick, (void*) &ts); 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); ev_loop(main_loop, 0);

3
i3lock.h

@ -1,6 +1,9 @@
#ifndef _I3LOCK_H #ifndef _I3LOCK_H
#define _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 macro will only print debug output when started with --debug.
* This is important because xautolock (for example) closes stdout/stderr by * This is important because xautolock (for example) closes stdout/stderr by
* default, so just printing something to stdout will lead to the data ending * default, so just printing something to stdout will lead to the data ending

23
unlock_indicator.c

@ -133,6 +133,9 @@ extern xcb_screen_t *screen;
* Local variables. * Local variables.
******************************************************************************/ ******************************************************************************/
/* time stuff */
static struct ev_periodic *time_redraw_tick;
/* Cache the screen’s visual, necessary for creating a Cairo context. */ /* Cache the screen’s visual, necessary for creating a Cairo context. */
static xcb_visualtype_t *vistype; static xcb_visualtype_t *vistype;
@ -969,7 +972,7 @@ void clear_indicator(void) {
redraw_screen(); redraw_screen();
} }
void* start_time_redraw_tick(void* arg) { void* start_time_redraw_tick_pthread(void* arg) {
struct timespec *ts = (struct timespec *) arg; struct timespec *ts = (struct timespec *) arg;
while(1) { while(1) {
nanosleep(ts, NULL); nanosleep(ts, NULL);
@ -977,3 +980,21 @@ void* start_time_redraw_tick(void* arg) {
} }
return NULL; 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);
}
}

3
unlock_indicator.h

@ -51,5 +51,6 @@ void init_colors_once(void);
void redraw_screen(void); void redraw_screen(void);
void clear_indicator(void); void clear_indicator(void);
void start_time_redraw_timeout(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 #endif

Loading…
Cancel
Save