Browse Source

Fix a few tsak glitches on hotplug

tags/r14.0.0
Timothy Pearson 5 years ago
parent
commit
f449d57ba7
1 changed files with 10 additions and 14 deletions
  1. 10
    14
      tsak/main.cpp

+ 10
- 14
tsak/main.cpp View File

@@ -334,7 +334,7 @@ bool setupPipe()
334 334
 
335 335
 bool setupLockingPipe(bool writepid)
336 336
 {
337
-	/* Create the FIFOs if they do not exist */
337
+	/* Create the FIFOs as they may not exist */
338 338
 	umask(0);
339 339
 	mkdir(FIFO_DIR,0644);
340 340
 
@@ -385,17 +385,6 @@ void restart_tsak()
385 385
 		}
386 386
 	}
387 387
 
388
-	// Wait for process termination
389
-	sleep(1);
390
-
391
-	// Release all exclusive keyboard locks
392
-	for (int current_keyboard=0;current_keyboard<keyboard_fd_num;current_keyboard++) {
393
-		if(ioctl(keyboard_fds[current_keyboard], EVIOCGRAB, 0) < 0) {
394
-			fprintf(stderr, "[tsak] Failed to release exclusive input device lock\n");
395
-		}
396
-		close(keyboard_fds[current_keyboard]);
397
-	}
398
-
399 388
 	// Unset the exclusive file lock
400 389
 	if (mPipe_fd_out != -1) {
401 390
 		struct flock fl;
@@ -647,7 +636,7 @@ int main (int argc, char *argv[])
647 636
 								while (1) {
648 637
 									if ((rd = read(keyboard_fds[current_keyboard], ev, size)) < size) {
649 638
 										fprintf(stderr, "[tsak] Read failed.\n");
650
-										break;
639
+										return 13;
651 640
 									}
652 641
 
653 642
 									if (ev[0].value == 0 && ev[0].type == 1) { // Read the key release event
@@ -699,13 +688,20 @@ int main (int argc, char *argv[])
699 688
 						return 0;
700 689
 					}
701 690
 
691
+					// Close all keyboard file descriptors; we don't need them in this process and they can end up dangling/locked during forced restart
692
+					for (int current_keyboard=0;current_keyboard<keyboard_fd_num;current_keyboard++) {
693
+						close(keyboard_fds[current_keyboard]);
694
+						keyboard_fds[current_keyboard] = 0;
695
+					}
696
+					keyboard_fd_num = 0;
697
+
702 698
 					// Prevent multiple process instances from starting
703 699
 					setupLockingPipe(true);
704 700
 
705 701
 					// Wait a little bit so that udev hotplug can stabilize before we start monitoring
706 702
 					sleep(1);
707 703
 
708
-					fprintf(stderr, "[tsak] Hotplug monitoring process started\n");
704
+					fprintf(stderr, "[tsak] Hotplug monitoring process started (%ld)\n", getpid());
709 705
 
710 706
 					// Monitor for hotplugged keyboards
711 707
 					int j;

Loading…
Cancel
Save