]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LinuxGUI/Ventoy2Disk/main.c
1.0.49 release
[Ventoy.git] / LinuxGUI / Ventoy2Disk / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <string.h>
5 #include <errno.h>
6 #include <ctype.h>
7 #include <unistd.h>
8 #include <fcntl.h>
9 #include <sys/wait.h>
10 #include <ventoy_define.h>
11 #include <ventoy_util.h>
12 #include <ventoy_json.h>
13 #include <ventoy_disk.h>
14 #include <ventoy_http.h>
15
16 int ventoy_log_init(void);
17 void ventoy_log_exit(void);
18
19 void ventoy_signal_stop(int sig)
20 {
21 vlog("ventoy server exit due to signal ...\n");
22 printf("ventoy server exit ...\n");
23
24 ventoy_http_stop();
25 ventoy_http_exit();
26 ventoy_disk_exit();
27 ventoy_log_exit();
28 exit(0);
29 }
30
31 int main(int argc, char **argv)
32 {
33 int rc;
34 const char *ip = "127.0.0.1";
35 const char *port = "24680";
36
37 if (argc != 3)
38 {
39 printf("Invalid argc %d\n", argc);
40 return 1;
41 }
42
43 if (isdigit(argv[1][0]))
44 {
45 ip = argv[1];
46 }
47
48 if (isdigit(argv[2][0]))
49 {
50 port = argv[2];
51 }
52
53 ventoy_log_init();
54
55 vlog("===============================================\n");
56 vlog("===== Ventoy2Disk %s %s:%s =====\n", ventoy_get_local_version(), ip, port);
57 vlog("===============================================\n");
58
59 ventoy_disk_init();
60
61 ventoy_http_init();
62
63 rc = ventoy_http_start(ip, port);
64 if (rc)
65 {
66 printf("Ventoy failed to start http server, check log.txt for detail\n");
67 }
68 else
69 {
70 signal(SIGINT, ventoy_signal_stop);
71 signal(SIGTSTP, ventoy_signal_stop);
72 signal(SIGQUIT, ventoy_signal_stop);
73 while (1)
74 {
75 sleep(100);
76 }
77 }
78
79 return 0;
80 }
81