]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Plugson/src/main_linux.c
Add /F option for VentoyPlugson.exe to use the system default browser.
[Ventoy.git] / Plugson / src / main_linux.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/stat.h>
10 #include <sys/wait.h>
11 #include <sys/types.h>
12 #include <linux/limits.h>
13 #include <ventoy_define.h>
14 #include <ventoy_util.h>
15 #include <ventoy_json.h>
16 #include <ventoy_disk.h>
17 #include <ventoy_http.h>
18
19 char g_log_file[MAX_PATH];
20 char g_cur_dir[MAX_PATH];
21 char g_ventoy_dir[MAX_PATH];
22
23 int ventoy_log_init(void);
24 void ventoy_log_exit(void);
25
26 void ventoy_signal_stop(int sig)
27 {
28 vlog("ventoy server exit due to signal ...\n");
29 printf("ventoy server exit ...\n");
30
31 ventoy_http_stop();
32 ventoy_http_exit();
33 #ifndef VENTOY_SIM
34 ventoy_www_exit();
35 #endif
36 ventoy_disk_exit();
37 ventoy_log_exit();
38 exit(0);
39 }
40
41 int main(int argc, char **argv)
42 {
43 int rc;
44 const char *ip = "127.0.0.1";
45 const char *port = "24681";
46
47 if (argc != 9)
48 {
49 printf("Invalid argc %d\n", argc);
50 return 1;
51 }
52
53 if (isdigit(argv[1][0]))
54 {
55 ip = argv[1];
56 }
57
58 if (isdigit(argv[2][0]))
59 {
60 port = argv[2];
61 }
62
63 strlcpy(g_ventoy_dir, argv[3]);
64 scnprintf(g_log_file, sizeof(g_log_file), "%s/%s", g_ventoy_dir, LOG_FILE);
65 ventoy_log_init();
66
67 getcwd(g_cur_dir, MAX_PATH);
68
69 if (!ventoy_is_directory_exist("./ventoy"))
70 {
71 printf("%s/ventoy directory does not exist\n", g_cur_dir);
72 return 1;
73 }
74
75 ventoy_get_disk_info(argv);
76
77 vlog("===============================================\n");
78 vlog("===== Ventoy Plugson %s:%s =====\n", ip, port);
79 vlog("===============================================\n");
80
81 ventoy_disk_init();
82 #ifndef VENTOY_SIM
83 rc = ventoy_www_init();
84 if (rc)
85 {
86 printf("Failed to init web data, check log for details.\n");
87 ventoy_disk_exit();
88 ventoy_log_exit();
89 return 1;
90 }
91 #endif
92 ventoy_http_init();
93
94 rc = ventoy_http_start(ip, port);
95 if (rc)
96 {
97 printf("Ventoy failed to start http server, check ./ventoy/plugson.log for detail\n");
98 }
99 else
100 {
101 signal(SIGINT, ventoy_signal_stop);
102 signal(SIGTSTP, ventoy_signal_stop);
103 signal(SIGQUIT, ventoy_signal_stop);
104 while (1)
105 {
106 sleep(100);
107 }
108 }
109
110 return 0;
111 }
112