| 363 | } |
| 364 | |
| 365 | int rmdevpath(usbdevice* kb){ |
| 366 | euid_guard_start; |
| 367 | int index = INDEX_OF(kb, keyboard); |
| 368 | if(kb->infifo != 0){ |
| 369 | int fd = kb->infifo - 1; |
| 370 | #ifdef OS_MAC |
| 371 | fcntl(fd, F_SETFL, O_RDWR | O_NONBLOCK); // hack to prevent the following hack from blocking if the GUI was running |
| 372 | #endif |
| 373 | if (write(fd, "\n", 1) < 0) |
| 374 | ckb_warn("Unable to write to filedescriptor %d: %s", fd, strerror(errno)); |
| 375 | close(fd); |
| 376 | kb->infifo = 0; |
| 377 | } |
| 378 | for(int i = 0; i < OUTFIFO_MAX; i++) |
| 379 | _rmnotifynode(kb, i); |
| 380 | char path[DEVPATH_LEN + 2]; |
| 381 | snprintf(path, sizeof(path), "%s%d", devpath, index); |
| 382 | if(rm_recursive(path) != 0 && errno != ENOENT){ |
| 383 | ckb_warn("Unable to delete %s: %s", path, strerror(errno)); |
| 384 | euid_guard_stop; |
| 385 | return -1; |
| 386 | } |
| 387 | ckb_info("Removed device path %s", path); |
| 388 | euid_guard_stop; |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static inline uchar FWBcdToBin(const uchar v){ |
| 393 | return ((v >> 4) * 10) + (v & 0xF); |
no test coverage detected