]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LinuxGUI/Ventoy2Disk/ventoy_gui.c
10 #include <sys/utsname.h>
11 #include <sys/types.h>
12 #include <linux/limits.h>
14 #include <sys/fcntl.h>
16 #include "ventoy_json.h"
18 #define LIB_FLAG_GTK2 (1 << 0)
19 #define LIB_FLAG_GTK3 (1 << 1)
20 #define LIB_FLAG_GTK4 (1 << 2)
21 #define LIB_FLAG_QT4 (1 << 3)
22 #define LIB_FLAG_QT5 (1 << 4)
23 #define LIB_FLAG_QT6 (1 << 5)
24 #define LIB_FLAG_GLADE2 (1 << 30)
26 #define LIB_FLAG_GTK (LIB_FLAG_GTK2 | LIB_FLAG_GTK3 | LIB_FLAG_GTK4)
27 #define LIB_FLAG_QT (LIB_FLAG_QT4 | LIB_FLAG_QT5 | LIB_FLAG_QT6)
30 #define MAX_LOG_BUF (1024 * 1024)
31 #define VTOY_GUI_PATH "_vtoy_gui_path_="
32 #define VTOY_ENV_STR "_vtoy_env_str_="
33 #define LD_CACHE_FILE "/etc/ld.so.cache"
34 #define INT2STR_YN(a) ((a) == 0 ? "NO" : "YES")
36 static int g_xdg_log
= 0;
37 static int g_xdg_ini
= 0;
38 static char g_log_file
[PATH_MAX
];
39 static char g_ini_file
[PATH_MAX
];
40 static char *g_log_buf
= NULL
;
41 extern char ** environ
;
43 #define CACHEMAGIC "ld.so-1.7.0"
47 int flags
; /* This is 1 for an ELF library. */
48 unsigned int key
, value
; /* String table indices. */
53 char magic
[sizeof CACHEMAGIC
- 1];
55 struct file_entry libs
[0];
58 #define CACHEMAGIC_NEW "glibc-ld.so.cache"
59 #define CACHE_VERSION "1.1"
60 #define CACHEMAGIC_VERSION_NEW CACHEMAGIC_NEW CACHE_VERSION
64 int32_t flags
; /* This is 1 for an ELF library. */
65 uint32_t key
, value
; /* String table indices. */
66 uint32_t osversion
; /* Required OS version. */
67 uint64_t hwcap
; /* Hwcap entry. */
72 char magic
[sizeof CACHEMAGIC_NEW
- 1];
73 char version
[sizeof CACHE_VERSION
- 1];
74 uint32_t nlibs
; /* Number of entries. */
75 uint32_t len_strings
; /* Size of string table. */
76 uint32_t unused
[5]; /* Leave space for future extensions
77 and align to 8 byte boundary. */
78 struct file_entry_new libs
[0]; /* Entries describing libraries. */
79 /* After this the string table of size len_strings is found. */
82 /* Used to align cache_file_new. */
83 #define ALIGN_CACHE(addr) \
84 (((addr) + __alignof__ (struct cache_file_new) -1) \
85 & (~(__alignof__ (struct cache_file_new) - 1)))
87 #define vlog(fmt, args...) ventoy_syslog(0, fmt, ##args)
89 void ventoy_syslog(int level
, const char *Fmt
, ...)
102 localtime_r(&stamp
, &ttm
);
107 buflen
= MAX_LOG_BUF
;
112 buflen
= sizeof(log
);
116 vsnprintf(buf
, buflen
, Fmt
, arg
);
119 fp
= fopen(g_log_file
, "a+");
122 fprintf(fp
, "[%04u/%02u/%02u %02u:%02u:%02u] %s",
123 ttm
.tm_year
+ 1900, ttm
.tm_mon
, ttm
.tm_mday
,
124 ttm
.tm_hour
, ttm
.tm_min
, ttm
.tm_sec
,
130 printf("[%04u/%02u/%02u %02u:%02u:%02u] %s",
131 ttm
.tm_year
+ 1900, ttm
.tm_mon
, ttm
.tm_mday
,
132 ttm
.tm_hour
, ttm
.tm_min
, ttm
.tm_sec
,
137 static int is_gtk_env(void)
139 const char *env
= NULL
;
141 env
= getenv("GNOME_SETUP_DISPLAY");
142 if (env
&& env
[0] == ':')
144 vlog("GNOME_SETUP_DISPLAY=%s\n", env
);
148 env
= getenv("DESKTOP_SESSION");
149 if (env
&& strcasecmp(env
, "xfce") == 0)
151 vlog("DESKTOP_SESSION=%s\n", env
);
158 static int is_qt_env(void)
163 static int detect_gtk_version(int libflag
)
170 gtk2
= libflag
& LIB_FLAG_GTK2
;
171 gtk3
= libflag
& LIB_FLAG_GTK3
;
172 gtk4
= libflag
& LIB_FLAG_GTK4
;
173 glade2
= libflag
& LIB_FLAG_GLADE2
;
175 if (gtk2
> 0 && glade2
> 0 && (gtk3
== 0 && gtk4
== 0))
180 if (gtk3
> 0 && (gtk2
== 0 && gtk4
== 0))
185 if (gtk4
> 0 && (gtk2
== 0 && gtk3
== 0))
200 if (gtk2
> 0 && glade2
> 0)
208 static int detect_qt_version(int libflag
)
214 qt4
= libflag
& LIB_FLAG_QT4
;
215 qt5
= libflag
& LIB_FLAG_QT5
;
216 qt6
= libflag
& LIB_FLAG_QT6
;
218 if (qt4
> 0 && (qt5
== 0 && qt6
== 0))
223 if (qt5
> 0 && (qt4
== 0 && qt6
== 0))
228 if (qt6
> 0 && (qt4
== 0 && qt5
== 0))
251 int bit_from_machine(const char *machine
)
253 if (strstr(machine
, "64"))
263 int get_os_bit(int *bit
)
266 struct utsname unameData
;
268 memset(&unameData
, 0, sizeof(unameData
));
269 ret
= uname(&unameData
);
272 vlog("uname error, code: %d\n", errno
);
276 *bit
= strstr(unameData
.machine
, "64") ? 64 : 32;
277 vlog("uname -m <%s> %dbit\n", unameData
.machine
, *bit
);
282 int read_file_1st_line(const char *file
, char *buffer
, int buflen
)
286 fp
= fopen(file
, "r");
289 vlog("Failed to open file %s code:%d", file
, errno
);
293 fgets(buffer
, buflen
, fp
);
298 static int read_pid_cmdline(long pid
, char *Buffer
, int BufLen
)
302 snprintf(path
, sizeof(path
), "/proc/%ld/cmdline", pid
);
303 return read_file_1st_line(path
, Buffer
, BufLen
);
306 static int find_exe_path(const char *exe
, char *pathbuf
, int buflen
)
311 char *saveptr
= NULL
;
313 const char *env
= getenv("PATH");
320 newenv
= strdup(env
);
327 while (NULL
!= (tmpptr
= strtok_r(tmpptr
, ":", &saveptr
)))
329 snprintf(path
, sizeof(path
), "%s/%s", tmpptr
, exe
);
330 if (access(path
, F_OK
) != -1)
332 snprintf(pathbuf
, buflen
, "%s", path
);
343 void dump_args(const char *prefix
, char **argv
)
347 vlog("=========%s ARGS BEGIN===========\n", prefix
);
350 vlog("argv[%d]=<%s>\n", i
, argv
[i
]);
353 vlog("=========%s ARGS END===========\n", prefix
);
361 const char *env
= NULL
;
363 env
= getenv("DISPLAY");
364 if (NULL
== env
|| env
[0] != ':')
366 vlog("DISPLAY not exist(%p). Not in X environment.\n", env
);
370 ret
= get_os_bit(&bit
);
373 vlog("Failed to get os bit.\n");
377 buildbit
= strstr(VTOY_GUI_ARCH
, "64") ? 64 : 32;
378 vlog("Build bit is %d (%s)\n", buildbit
, VTOY_GUI_ARCH
);
382 vlog("Current system is %d bit (%s). Please run the correct VentoyGUI.\n", bit
, VTOY_GUI_ARCH
);
389 static char * find_argv(int argc
, char **argv
, char *key
)
394 len
= (int)strlen(key
);
395 for (i
= 0; i
< argc
; i
++)
397 if (strncmp(argv
[i
], key
, len
) == 0)
406 static int adjust_cur_dir(char *argv0
)
418 for (pos
= argv0
; pos
&& *pos
; pos
++)
439 static char **recover_environ_param(char *env
)
445 char **newenvs
= NULL
;
447 for (i
= 0; env
[i
]; i
++)
455 newenvs
= malloc(sizeof(char *) * (cnt
+ 1));
458 vlog("malloc new envs fail %d\n", cnt
+ 1);
461 memset(newenvs
, 0, sizeof(char *) * (cnt
+ 1));
463 for (j
= i
= 0; env
[i
]; i
++)
468 newenvs
[k
++] = env
+ j
;
473 vlog("recover environ %d %d\n", cnt
, k
);
477 static int restart_main(int argc
, char **argv
, char *guiexe
)
483 char *newargv
[MAX_PARAS
+ 1] = { NULL
};
485 para
= find_argv(argc
, argv
, VTOY_ENV_STR
);
488 vlog("failed to find %s\n", VTOY_ENV_STR
);
492 newargv
[j
++] = guiexe
;
493 for (i
= 1; i
< argc
&& j
< MAX_PARAS
; i
++)
495 if (strncmp(argv
[i
], "_vtoy_", 6) != 0)
497 newargv
[j
++] = argv
[i
];
501 envs
= recover_environ_param(para
+ strlen(VTOY_ENV_STR
));
504 vlog("recover success, argc=%d evecve <%s>\n", j
, guiexe
);
505 dump_args("EXECVE", newargv
);
506 execve(guiexe
, newargv
, envs
);
510 vlog("recover failed, argc=%d evecv <%s>\n", j
, guiexe
);
511 execv(guiexe
, newargv
);
517 static char *create_environ_param(const char *prefix
, char **envs
)
526 prelen
= strlen(prefix
);
527 for (i
= 0; envs
[i
]; i
++)
530 envlen
+= strlen(envs
[i
]) + 1;
533 para
= malloc(prelen
+ envlen
);
536 vlog("failed to malloc env str %d\n", prelen
+ envlen
);
541 memcpy(cur
, prefix
, prelen
);
544 for (i
= 0; envs
[i
]; i
++)
546 envlen
= strlen(envs
[i
]);
547 memcpy(cur
, envs
[i
], envlen
);
553 vlog("create environment param %d\n", cnt
);
557 static int restart_by_pkexec(int argc
, char **argv
, const char *curpath
, const char *exe
)
563 char pkexec
[PATH_MAX
];
564 char exepara
[PATH_MAX
];
565 char *newargv
[MAX_PARAS
+ 1] = { NULL
};
567 vlog("try restart self by pkexec ...\n");
569 if (find_exe_path("pkexec", pkexec
, sizeof(pkexec
)))
571 vlog("Find pkexec at <%s>\n", pkexec
);
575 vlog("pkexec not found\n");
579 if (argv
[0][0] != '/')
581 snprintf(path
, sizeof(path
), "%s/%s", curpath
, argv
[0]);
585 snprintf(path
, sizeof(path
), "%s", argv
[0]);
587 snprintf(exepara
, sizeof(exepara
), "%s%s", VTOY_GUI_PATH
, exe
);
589 newargv
[j
++] = pkexec
;
591 for (i
= 1; i
< argc
&& j
< MAX_PARAS
; i
++)
593 if (strcmp(argv
[i
], "--xdg") == 0)
597 newargv
[j
++] = argv
[i
];
602 newargv
[j
++] = create_environ_param(VTOY_ENV_STR
, environ
);
607 newargv
[j
++] = exepara
;
610 if (g_xdg_log
&& j
+ 1 < MAX_PARAS
)
613 newargv
[j
++] = g_log_file
;
616 if (g_xdg_ini
&& j
+ 1 < MAX_PARAS
)
619 newargv
[j
++] = g_ini_file
;
622 dump_args("PKEXEC", newargv
);
623 execv(pkexec
, newargv
);
628 static int ld_cache_lib_check(const char *lib
, int *flag
)
630 if (((*flag
) & LIB_FLAG_GTK3
) == 0)
632 if (strncmp(lib
, "libgtk-3.so", 11) == 0)
634 vlog("LIB:<%s>\n", lib
);
635 *flag
|= LIB_FLAG_GTK3
;
640 if (((*flag
) & LIB_FLAG_GTK2
) == 0)
642 if (strncmp(lib
, "libgtk-x11-2.0.so", 17) == 0)
644 vlog("LIB:<%s>\n", lib
);
645 *flag
|= LIB_FLAG_GTK2
;
650 if (((*flag
) & LIB_FLAG_GTK4
) == 0)
652 if (strncmp(lib
, "libgtk-4.so", 11) == 0)
654 vlog("LIB:<%s>\n", lib
);
655 *flag
|= LIB_FLAG_GTK4
;
660 if (((*flag
) & LIB_FLAG_QT4
) == 0)
662 if (strncmp(lib
, "libQt4", 6) == 0)
664 vlog("LIB:<%s>\n", lib
);
665 *flag
|= LIB_FLAG_QT4
;
670 if (((*flag
) & LIB_FLAG_QT5
) == 0)
672 if (strncmp(lib
, "libQt5", 6) == 0)
674 vlog("LIB:<%s>\n", lib
);
675 *flag
|= LIB_FLAG_QT5
;
680 if (((*flag
) & LIB_FLAG_QT6
) == 0)
682 if (strncmp(lib
, "libQt6", 6) == 0)
684 vlog("LIB:<%s>\n", lib
);
685 *flag
|= LIB_FLAG_QT6
;
690 if (((*flag
) & LIB_FLAG_GLADE2
) == 0)
692 if (strncmp(lib
, "libglade-2", 10) == 0)
694 vlog("LIB:<%s>\n", lib
);
695 *flag
|= LIB_FLAG_GLADE2
;
703 static int parse_ld_cache(int *flag
)
710 size_t cache_size
= 0;
711 const char *cache_data
= NULL
;
712 struct cache_file
*cache
= NULL
;
713 struct cache_file_new
*cache_new
= NULL
;
717 fd
= open(LD_CACHE_FILE
, O_RDONLY
);
720 vlog("failed to open %s err:%d\n", LD_CACHE_FILE
, errno
);
724 if (fstat(fd
, &st
) < 0 || st
.st_size
== 0)
730 cache
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
731 if (cache
== MAP_FAILED
)
737 cache_size
= st
.st_size
;
738 if (cache_size
< sizeof (struct cache_file
))
740 vlog("File is not a cache file.\n");
741 munmap (cache
, cache_size
);
746 if (memcmp(cache
->magic
, CACHEMAGIC
, sizeof CACHEMAGIC
- 1))
748 /* This can only be the new format without the old one. */
749 cache_new
= (struct cache_file_new
*) cache
;
751 if (memcmp(cache_new
->magic
, CACHEMAGIC_NEW
, sizeof CACHEMAGIC_NEW
- 1) ||
752 memcmp (cache_new
->version
, CACHE_VERSION
, sizeof CACHE_VERSION
- 1))
754 munmap (cache
, cache_size
);
760 /* This is where the strings start. */
761 cache_data
= (const char *) cache_new
;
765 /* Check for corruption, avoiding overflow. */
766 if ((cache_size
- sizeof (struct cache_file
)) / sizeof (struct file_entry
) < cache
->nlibs
)
768 vlog("File is not a cache file.\n");
769 munmap (cache
, cache_size
);
774 offset
= ALIGN_CACHE(sizeof (struct cache_file
) + (cache
->nlibs
* sizeof (struct file_entry
)));
776 /* This is where the strings start. */
777 cache_data
= (const char *) &cache
->libs
[cache
->nlibs
];
779 /* Check for a new cache embedded in the old format. */
780 if (cache_size
> (offset
+ sizeof (struct cache_file_new
)))
782 cache_new
= (struct cache_file_new
*) ((void *)cache
+ offset
);
784 if (memcmp(cache_new
->magic
, CACHEMAGIC_NEW
, sizeof CACHEMAGIC_NEW
- 1) == 0 &&
785 memcmp(cache_new
->version
, CACHE_VERSION
, sizeof CACHE_VERSION
- 1) == 0)
787 cache_data
= (const char *) cache_new
;
795 vlog("%d libs found in cache format 0\n", cache
->nlibs
);
796 for (i
= 0; i
< cache
->nlibs
; i
++)
798 ld_cache_lib_check(cache_data
+ cache
->libs
[i
].key
, flag
);
801 else if (format
== 1)
803 vlog("%d libs found in cache format 1\n", cache_new
->nlibs
);
805 for (i
= 0; i
< cache_new
->nlibs
; i
++)
807 ld_cache_lib_check(cache_data
+ cache_new
->libs
[i
].key
, flag
);
811 vlog("ldconfig lib flags 0x%x\n", *flag
);
812 vlog("lib flags GLADE2:[%s] GTK2:[%s] GTK3:[%s] GTK4:[%s] QT4:[%s] QT5:[%s] QT6:[%s]\n",
813 INT2STR_YN((*flag
) & LIB_FLAG_GLADE2
), INT2STR_YN((*flag
) & LIB_FLAG_GTK2
),
814 INT2STR_YN((*flag
) & LIB_FLAG_GTK3
), INT2STR_YN((*flag
) & LIB_FLAG_GTK4
),
815 INT2STR_YN((*flag
) & LIB_FLAG_QT4
), INT2STR_YN((*flag
) & LIB_FLAG_QT5
),
816 INT2STR_YN((*flag
) & LIB_FLAG_QT6
));
818 munmap (cache
, cache_size
);
823 static int gui_type_check(VTOY_JSON
*pstNode
)
826 const char *env
= NULL
;
827 const char *arch
= NULL
;
828 const char *srctype
= NULL
;
829 const char *srcname
= NULL
;
830 const char *condition
= NULL
;
831 const char *expression
= NULL
;
834 arch
= vtoy_json_get_string_ex(pstNode
, "arch");
835 srctype
= vtoy_json_get_string_ex(pstNode
, "type");
836 srcname
= vtoy_json_get_string_ex(pstNode
, "name");
837 condition
= vtoy_json_get_string_ex(pstNode
, "condition");
838 expression
= vtoy_json_get_string_ex(pstNode
, "expression");
840 if (srctype
== NULL
|| srcname
== NULL
|| condition
== NULL
)
845 if (arch
&& NULL
== strstr(arch
, VTOY_GUI_ARCH
))
850 vlog("check <%s> <%s> <%s>\n", srctype
, srcname
, condition
);
852 if (strcmp(srctype
, "file") == 0)
854 if (access(srcname
, F_OK
) == -1)
859 if (strcmp(condition
, "exist") == 0)
861 vlog("File %s exist\n", srcname
);
864 else if (strcmp(condition
, "contains") == 0)
866 fp
= fopen(srcname
, "r");
872 while (fgets(line
, sizeof(line
), fp
))
874 if (strstr(line
, expression
))
876 vlog("File %s contains %s\n", srcname
, expression
);
886 else if (strcmp(srctype
, "env") == 0)
888 env
= getenv(srcname
);
894 if (strcmp(condition
, "exist") == 0)
896 vlog("env %s exist\n", srcname
);
899 else if (strcmp(condition
, "equal") == 0)
901 if (strcmp(expression
, env
) == 0)
903 vlog("env %s is %s\n", srcname
, env
);
908 else if (strcmp(condition
, "contains") == 0)
910 if (strstr(env
, expression
))
912 vlog("env %s is %s contains %s\n", srcname
, env
, expression
);
922 static int read_file_to_buf(const char *FileName
, int ExtLen
, void **Bufer
, int *BufLen
)
928 fp
= fopen(FileName
, "rb");
931 vlog("Failed to open file %s", FileName
);
935 fseek(fp
, 0, SEEK_END
);
936 FileSize
= (int)ftell(fp
);
938 Data
= malloc(FileSize
+ ExtLen
);
945 fseek(fp
, 0, SEEK_SET
);
946 fread(Data
, 1, FileSize
, fp
);
956 static int distro_check_gui_env(char *type
, int len
, int *pver
)
961 VTOY_JSON
*pstNode
= NULL
;
962 VTOY_JSON
*pstJson
= NULL
;
964 vlog("distro_check_gui_env ...\n");
966 if (access("./tool/distro_gui_type.json", F_OK
) == -1)
968 vlog("distro_gui_type.json file not exist\n");
972 read_file_to_buf("./tool/distro_gui_type.json", 1, (void **)&pBuf
, &size
);
975 pstJson
= vtoy_json_create();
976 vtoy_json_parse(pstJson
, pBuf
);
978 for (pstNode
= pstJson
->pstChild
; pstNode
; pstNode
= pstNode
->pstNext
)
980 if (gui_type_check(pstNode
->pstChild
))
982 length
= (int)snprintf(type
, len
, "%s", vtoy_json_get_string_ex(pstNode
->pstChild
, "gui"));
983 *pver
= type
[length
- 1] - '0';
984 type
[length
- 1] = 0;
989 vtoy_json_destroy(pstJson
);
990 return pstNode
? 1 : 0;
993 static int detect_gui_exe_path(int argc
, char **argv
, const char *curpath
, char *pathbuf
, int buflen
)
999 const char *guitype
= NULL
;
1002 struct stat filestat
;
1004 for (i
= 1; i
< argc
; i
++)
1006 if (argv
[i
] && strcmp(argv
[i
], "--gtk2") == 0)
1011 else if (argv
[i
] && strcmp(argv
[i
], "--gtk3") == 0)
1016 else if (argv
[i
] && strcmp(argv
[i
], "--gtk4") == 0)
1021 else if (argv
[i
] && strcmp(argv
[i
], "--qt4") == 0)
1026 else if (argv
[i
] && strcmp(argv
[i
], "--qt5") == 0)
1031 else if (argv
[i
] && strcmp(argv
[i
], "--qt6") == 0)
1040 vlog("Get GUI type from param <%s%d>.\n", guitype
, ver
);
1042 else if (access("./ventoy_gui_type", F_OK
) != -1)
1044 vlog("Get GUI type from ventoy_gui_type file.\n");
1047 read_file_1st_line("./ventoy_gui_type", line
, sizeof(line
));
1048 if (strncmp(line
, "gtk2", 4) == 0)
1053 parse_ld_cache(&libflag
);
1054 if ((libflag
& LIB_FLAG_GLADE2
) == 0)
1056 vlog("libglade2 is necessary for GTK2, but not found.\n");
1060 else if (strncmp(line
, "gtk3", 4) == 0)
1065 else if (strncmp(line
, "gtk4", 4) == 0)
1070 else if (strncmp(line
, "qt4", 3) == 0)
1075 else if (strncmp(line
, "qt5", 3) == 0)
1080 else if (strncmp(line
, "qt6", 3) == 0)
1087 vlog("Current X environment is NOT supported.\n");
1093 vlog("Now detect the GUI type ...\n");
1095 parse_ld_cache(&libflag
);
1097 if ((LIB_FLAG_GTK
& libflag
) > 0 && (LIB_FLAG_QT
& libflag
) == 0)
1100 ver
= detect_gtk_version(libflag
);
1102 else if ((LIB_FLAG_GTK
& libflag
) == 0 && (LIB_FLAG_QT
& libflag
) > 0)
1105 ver
= detect_qt_version(libflag
);
1107 else if ((LIB_FLAG_GTK
& libflag
) > 0 && (LIB_FLAG_QT
& libflag
) > 0)
1109 if (distro_check_gui_env(line
, sizeof(line
), &ver
))
1112 vlog("distro_check_gui <%s%d> ...\n", line
, ver
);
1114 else if (is_gtk_env())
1117 ver
= detect_gtk_version(libflag
);
1119 else if (is_qt_env())
1122 ver
= detect_qt_version(libflag
);
1126 vlog("Can not distinguish GTK and QT, default use GTK.\n");
1128 ver
= detect_gtk_version(libflag
);
1133 vlog("Current X environment is NOT supported.\n");
1138 snprintf(pathbuf
, buflen
, "%s/tool/%s/Ventoy2Disk.%s%d", curpath
, VTOY_GUI_ARCH
, guitype
, ver
);
1140 vlog("This is %s%d X environment.\n", guitype
, ver
);
1141 vlog("exe = %s\n", pathbuf
);
1143 if (access(pathbuf
, F_OK
) == -1)
1145 vlog("%s is not exist.\n", pathbuf
);
1149 if (access(pathbuf
, X_OK
) == -1)
1151 vlog("execute permission check fail, try chmod.\n", pathbuf
);
1152 if (stat(pathbuf
, &filestat
) == 0)
1154 mode
= filestat
.st_mode
| S_IXUSR
| S_IXGRP
| S_IXOTH
;
1155 ret
= chmod(pathbuf
, mode
);
1156 vlog("old mode=%o new mode=%o ret=%d\n", filestat
.st_mode
, mode
, ret
);
1161 vlog("execute permission check success.\n");
1167 int real_main(int argc
, char **argv
)
1172 char path
[PATH_MAX
];
1173 char curpath
[PATH_MAX
];
1175 ret
= adjust_cur_dir(argv
[0]);
1178 vlog("=========================================================\n");
1179 vlog("=========================================================\n");
1180 vlog("=============== VentoyGui %s ===============\n", VTOY_GUI_ARCH
);
1181 vlog("=========================================================\n");
1182 vlog("=========================================================\n");
1183 vlog("log file is <%s>\n", g_log_file
);
1186 getcwd(curpath
, sizeof(curpath
));
1188 vlog("pid:%ld ppid:%ld uid:%d euid:%d\n", (long)getpid(), (long)getppid(), getuid(), euid
);
1189 vlog("adjust dir:%d current path:%s\n", ret
, curpath
);
1190 dump_args("RAW", argv
);
1192 if (access("./boot/boot.img", F_OK
) == -1)
1194 vlog("Please run under the correct directory!\n");
1198 exe
= find_argv(argc
, argv
, VTOY_GUI_PATH
);
1203 vlog("Invalid euid %d when restart.\n", euid
);
1207 return restart_main(argc
, argv
, exe
+ strlen(VTOY_GUI_PATH
));
1216 if (detect_gui_exe_path(argc
, argv
, curpath
, path
, sizeof(path
)))
1223 vlog("We have root privileges, just exec %s\n", path
);
1225 execv(argv
[0], argv
);
1229 vlog("EUID check failed.\n");
1232 restart_by_pkexec(argc
, argv
, curpath
, path
);
1234 vlog("### Please run with root privileges. ###\n");
1242 int main(int argc
, char **argv
)
1246 const char *env
= NULL
;
1248 snprintf(g_log_file
, sizeof(g_log_file
), "log.txt");
1249 for (i
= 0; i
< argc
; i
++)
1251 if (argv
[i
] && argv
[i
+ 1] && strcmp(argv
[i
], "-l") == 0)
1253 snprintf(g_log_file
, sizeof(g_log_file
), "%s", argv
[i
+ 1]);
1256 else if (argv
[i
] && strcmp(argv
[i
], "--xdg") == 0)
1258 env
= getenv("XDG_CACHE_HOME");
1262 snprintf(g_log_file
, sizeof(g_log_file
), "%s/ventoy.log", env
);
1265 env
= getenv("XDG_CONFIG_HOME");
1269 snprintf(g_ini_file
, sizeof(g_ini_file
), "%s/Ventoy2Disk.ini", env
);
1274 g_log_buf
= malloc(MAX_LOG_BUF
);
1277 vlog("Failed to malloc log buffer %d\n", MAX_LOG_BUF
);
1281 ret
= real_main(argc
, argv
);