b.liu | 9bcf493 | 2024-02-06 17:17:43 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <unistd.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <signal.h> |
| 5 | #include <fcntl.h> |
| 6 | |
| 7 | #include "mbtk_utils.h" |
| 8 | |
| 9 | static int running = 0; |
| 10 | |
| 11 | static void sig_handler(int sig) |
| 12 | { |
| 13 | printf("Signal : %d\n", sig); |
| 14 | running = 0; |
| 15 | } |
| 16 | |
| 17 | |
| 18 | int main(int argc, char *argv[]) |
| 19 | { |
| 20 | int fd = open("/tmp/usb.info", O_CREAT | O_WRONLY); |
| 21 | signal(SIGINT, sig_handler); |
| 22 | signal(SIGTERM, sig_handler); |
| 23 | if(fd > 0) { |
| 24 | char buff[1024]; |
| 25 | running = 1; |
| 26 | while(running){ |
| 27 | memset(buff, 0, 1024); |
| 28 | if(mbtk_cmd_line("cat /sys/class/android_usb/android0/state", buff, 1024)) { |
| 29 | write(fd, buff, strlen(buff)); |
| 30 | write(fd, "\n", 1); |
| 31 | } |
| 32 | sleep(1); |
| 33 | } |
| 34 | close(fd); |
| 35 | } |
| 36 | return 0; |
| 37 | } |
| 38 | |