— Scoopta 4 days ago
Made reloading way simpler
1 files changed, 9 insertions(+), 22 deletions(-)

M src/main.c
M src/main.c +9 -22
@@ 30,9 30,7 @@
 static char* CONFIG_LOCATION;
 static char* COLORS_LOCATION;
 static struct map* config;
-static bool restart = false;
-static pthread_mutex_t mutex;
-static pthread_cond_t _restart;
+static char** _argv;
 
 static void print_usage(char** argv) {
 	char* slash = strrchr(argv[0], '/');

          
@@ 53,32 51,25 @@
 exit(0);
 }
 
+static gboolean reload(gpointer data) {
+	(void) data;
+	execvp(_argv[0], _argv);
+	return FALSE;
+}
+
 void sig(int32_t signum) {
 	switch(signum) {
 	case SIGINT:
 		exit(0);
 		break;
 	case SIGUSR1:
-		restart = true;
-		pthread_mutex_lock(&mutex);
-		pthread_cond_broadcast(&_restart);
-		pthread_mutex_unlock(&mutex);
+		g_idle_add(G_SOURCE_FUNC(reload), NULL);
 		break;
 	}
 }
 
-static void* run_restart(void* data) {
-	char** argv = data;
-	while(!restart) {
-		pthread_mutex_lock(&mutex);
-		pthread_cond_wait(&_restart, &mutex);
-		pthread_mutex_unlock(&mutex);
-	}
-	execvp(argv[0], argv);
-	return NULL;
-}
-
 int main(int argc, char** argv) {
+	_argv = argv;
 	const struct option opts[] = {
 		{
 			.name = "help",

          
@@ 351,10 342,6 @@
 } else {
 		bar_init(config, bar_name, config_get(config, bar_name, "-output", NULL), CONFIG_LOCATION);
 	}
-	pthread_mutex_init(&mutex, NULL);
-	pthread_cond_init(&_restart, NULL);
-	pthread_t thread;
-	pthread_create(&thread, NULL, run_restart, argv);
 	struct sigaction sigact;
 	sigact.sa_handler = sig;
 	sigaction(SIGINT, &sigact, NULL);