]>
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 char g_log_file
[PATH_MAX
];
37 static char *g_log_buf
= NULL
;
38 extern char ** environ
;
40 #define CACHEMAGIC "ld.so-1.7.0"
44 int flags
; /* This is 1 for an ELF library. */
45 unsigned int key
, value
; /* String table indices. */
50 char magic
[sizeof CACHEMAGIC
- 1];
52 struct file_entry libs
[0];
55 #define CACHEMAGIC_NEW "glibc-ld.so.cache"
56 #define CACHE_VERSION "1.1"
57 #define CACHEMAGIC_VERSION_NEW CACHEMAGIC_NEW CACHE_VERSION
61 int32_t flags
; /* This is 1 for an ELF library. */
62 uint32_t key
, value
; /* String table indices. */
63 uint32_t osversion
; /* Required OS version. */
64 uint64_t hwcap
; /* Hwcap entry. */
69 char magic
[sizeof CACHEMAGIC_NEW
- 1];
70 char version
[sizeof CACHE_VERSION
- 1];
71 uint32_t nlibs
; /* Number of entries. */
72 uint32_t len_strings
; /* Size of string table. */
73 uint32_t unused
[5]; /* Leave space for future extensions
74 and align to 8 byte boundary. */
75 struct file_entry_new libs
[0]; /* Entries describing libraries. */
76 /* After this the string table of size len_strings is found. */
79 /* Used to align cache_file_new. */
80 #define ALIGN_CACHE(addr) \
81 (((addr) + __alignof__ (struct cache_file_new) -1) \
82 & (~(__alignof__ (struct cache_file_new) - 1)))
84 #define vlog(fmt, args...) ventoy_syslog(0, fmt, ##args)
86 void ventoy_syslog(int level
, const char *Fmt
, ...)
99 localtime_r(&stamp
, &ttm
);
104 buflen
= MAX_LOG_BUF
;
109 buflen
= sizeof(log
);
113 vsnprintf(buf
, buflen
, Fmt
, arg
);
116 fp
= fopen(g_log_file
, "a+");
119 fprintf(fp
, "[%04u/%02u/%02u %02u:%02u:%02u] %s",
120 ttm
.tm_year
+ 1900, ttm
.tm_mon
, ttm
.tm_mday
,
121 ttm
.tm_hour
, ttm
.tm_min
, ttm
.tm_sec
,
127 printf("[%04u/%02u/%02u %02u:%02u:%02u] %s",
128 ttm
.tm_year
+ 1900, ttm
.tm_mon
, ttm
.tm_mday
,
129 ttm
.tm_hour
, ttm
.tm_min
, ttm
.tm_sec
,
134 static int is_gtk_env(void)
136 const char *env
= NULL
;
138 env
= getenv("GNOME_SETUP_DISPLAY");
139 if (env
&& env
[0] == ':')
141 vlog("GNOME_SETUP_DISPLAY=%s\n", env
);
145 env
= getenv("DESKTOP_SESSION");
146 if (env
&& strcasecmp(env
, "xfce") == 0)
148 vlog("DESKTOP_SESSION=%s\n", env
);
155 static int is_qt_env(void)
160 static int detect_gtk_version(int libflag
)
167 gtk2
= libflag
& LIB_FLAG_GTK2
;
168 gtk3
= libflag
& LIB_FLAG_GTK3
;
169 gtk4
= libflag
& LIB_FLAG_GTK4
;
170 glade2
= libflag
& LIB_FLAG_GLADE2
;
172 if (gtk2
> 0 && glade2
> 0 && (gtk3
== 0 && gtk4
== 0))
177 if (gtk3
> 0 && (gtk2
== 0 && gtk4
== 0))
182 if (gtk4
> 0 && (gtk2
== 0 && gtk3
== 0))
197 if (gtk2
> 0 && glade2
> 0)
205 static int detect_qt_version(int libflag
)
211 qt4
= libflag
& LIB_FLAG_QT4
;
212 qt5
= libflag
& LIB_FLAG_QT5
;
213 qt6
= libflag
& LIB_FLAG_QT6
;
215 if (qt4
> 0 && (qt5
== 0 && qt6
== 0))
220 if (qt5
> 0 && (qt4
== 0 && qt6
== 0))
225 if (qt6
> 0 && (qt4
== 0 && qt5
== 0))
248 int bit_from_machine(const char *machine
)
250 if (strstr(machine
, "64"))
260 int get_os_bit(int *bit
)
263 struct utsname unameData
;
265 memset(&unameData
, 0, sizeof(unameData
));
266 ret
= uname(&unameData
);
269 vlog("uname error, code: %d\n", errno
);
273 *bit
= strstr(unameData
.machine
, "64") ? 64 : 32;
274 vlog("uname -m <%s> %dbit\n", unameData
.machine
, *bit
);
279 int read_file_1st_line(const char *file
, char *buffer
, int buflen
)
283 fp
= fopen(file
, "r");
286 vlog("Failed to open file %s code:%d", file
, errno
);
290 fgets(buffer
, buflen
, fp
);
295 static int read_pid_cmdline(long pid
, char *Buffer
, int BufLen
)
299 snprintf(path
, sizeof(path
), "/proc/%ld/cmdline", pid
);
300 return read_file_1st_line(path
, Buffer
, BufLen
);
303 static int find_exe_path(const char *exe
, char *pathbuf
, int buflen
)
308 char *saveptr
= NULL
;
310 const char *env
= getenv("PATH");
317 newenv
= strdup(env
);
324 while (NULL
!= (tmpptr
= strtok_r(tmpptr
, ":", &saveptr
)))
326 snprintf(path
, sizeof(path
), "%s/%s", tmpptr
, exe
);
327 if (access(path
, F_OK
) != -1)
329 snprintf(pathbuf
, buflen
, "%s", path
);
340 void dump_args(const char *prefix
, char **argv
)
344 vlog("=========%s ARGS BEGIN===========\n", prefix
);
347 vlog("argv[%d]=<%s>\n", i
, argv
[i
]);
350 vlog("=========%s ARGS END===========\n", prefix
);
358 const char *env
= NULL
;
360 env
= getenv("DISPLAY");
361 if (NULL
== env
|| env
[0] != ':')
363 vlog("DISPLAY not exist(%p). Not in X environment.\n", env
);
367 ret
= get_os_bit(&bit
);
370 vlog("Failed to get os bit.\n");
374 buildbit
= strstr(VTOY_GUI_ARCH
, "64") ? 64 : 32;
375 vlog("Build bit is %d (%s)\n", buildbit
, VTOY_GUI_ARCH
);
379 vlog("Current system is %d bit (%s). Please run the correct VentoyGUI.\n", bit
, VTOY_GUI_ARCH
);
386 static char * find_argv(int argc
, char **argv
, char *key
)
391 len
= (int)strlen(key
);
392 for (i
= 0; i
< argc
; i
++)
394 if (strncmp(argv
[i
], key
, len
) == 0)
403 static int adjust_cur_dir(char *argv0
)
415 for (pos
= argv0
; pos
&& *pos
; pos
++)
436 static char **recover_environ_param(char *env
)
442 char **newenvs
= NULL
;
444 for (i
= 0; env
[i
]; i
++)
452 newenvs
= malloc(sizeof(char *) * (cnt
+ 1));
455 vlog("malloc new envs fail %d\n", cnt
+ 1);
458 memset(newenvs
, 0, sizeof(char *) * (cnt
+ 1));
460 for (j
= i
= 0; env
[i
]; i
++)
465 newenvs
[k
++] = env
+ j
;
470 vlog("recover environ %d %d\n", cnt
, k
);
474 static int restart_main(int argc
, char **argv
, char *guiexe
)
480 char *newargv
[MAX_PARAS
+ 1] = { NULL
};
482 para
= find_argv(argc
, argv
, VTOY_ENV_STR
);
485 vlog("failed to find %s\n", VTOY_ENV_STR
);
489 newargv
[j
++] = guiexe
;
490 for (i
= 1; i
< argc
&& j
< MAX_PARAS
; i
++)
492 if (strncmp(argv
[i
], "_vtoy_", 6) != 0)
494 newargv
[j
++] = argv
[i
];
498 envs
= recover_environ_param(para
+ strlen(VTOY_ENV_STR
));
501 vlog("recover success, argc=%d evecve <%s>\n", j
, guiexe
);
502 execve(guiexe
, newargv
, envs
);
506 vlog("recover failed, argc=%d evecv <%s>\n", j
, guiexe
);
507 execv(guiexe
, newargv
);
513 static char *create_environ_param(const char *prefix
, char **envs
)
522 prelen
= strlen(prefix
);
523 for (i
= 0; envs
[i
]; i
++)
526 envlen
+= strlen(envs
[i
]) + 1;
529 para
= malloc(prelen
+ envlen
);
532 vlog("failed to malloc env str %d\n", prelen
+ envlen
);
537 memcpy(cur
, prefix
, prelen
);
540 for (i
= 0; envs
[i
]; i
++)
542 envlen
= strlen(envs
[i
]);
543 memcpy(cur
, envs
[i
], envlen
);
549 vlog("create environment param %d\n", cnt
);
553 static int restart_by_pkexec(int argc
, char **argv
, const char *curpath
, const char *exe
)
559 char pkexec
[PATH_MAX
];
560 char exepara
[PATH_MAX
];
561 char *newargv
[MAX_PARAS
+ 1] = { NULL
};
563 vlog("try restart self by pkexec ...\n");
565 if (find_exe_path("pkexec", pkexec
, sizeof(pkexec
)))
567 vlog("Find pkexec at <%s>\n", pkexec
);
571 vlog("pkexec not found\n");
575 if (argv
[0][0] != '/')
577 snprintf(path
, sizeof(path
), "%s/%s", curpath
, argv
[0]);
581 snprintf(path
, sizeof(path
), "%s", argv
[0]);
583 snprintf(exepara
, sizeof(exepara
), "%s%s", VTOY_GUI_PATH
, exe
);
585 newargv
[j
++] = pkexec
;
587 for (i
= 1; i
< argc
&& j
< MAX_PARAS
- 2; i
++)
589 newargv
[j
++] = argv
[i
];
591 newargv
[j
++] = create_environ_param(VTOY_ENV_STR
, environ
);
592 newargv
[j
++] = exepara
;
594 dump_args("PKEXEC", newargv
);
595 execv(pkexec
, newargv
);
600 static int ld_cache_lib_check(const char *lib
, int *flag
)
602 if (((*flag
) & LIB_FLAG_GTK3
) == 0)
604 if (strncmp(lib
, "libgtk-3.so", 11) == 0)
606 vlog("LIB:<%s>\n", lib
);
607 *flag
|= LIB_FLAG_GTK3
;
612 if (((*flag
) & LIB_FLAG_GTK2
) == 0)
614 if (strncmp(lib
, "libgtk-x11-2.0.so", 17) == 0)
616 vlog("LIB:<%s>\n", lib
);
617 *flag
|= LIB_FLAG_GTK2
;
622 if (((*flag
) & LIB_FLAG_GTK4
) == 0)
624 if (strncmp(lib
, "libgtk-4.so", 11) == 0)
626 vlog("LIB:<%s>\n", lib
);
627 *flag
|= LIB_FLAG_GTK4
;
632 if (((*flag
) & LIB_FLAG_QT4
) == 0)
634 if (strncmp(lib
, "libQt4", 6) == 0)
636 vlog("LIB:<%s>\n", lib
);
637 *flag
|= LIB_FLAG_QT4
;
642 if (((*flag
) & LIB_FLAG_QT5
) == 0)
644 if (strncmp(lib
, "libQt5", 6) == 0)
646 vlog("LIB:<%s>\n", lib
);
647 *flag
|= LIB_FLAG_QT5
;
652 if (((*flag
) & LIB_FLAG_QT6
) == 0)
654 if (strncmp(lib
, "libQt6", 6) == 0)
656 vlog("LIB:<%s>\n", lib
);
657 *flag
|= LIB_FLAG_QT6
;
662 if (((*flag
) & LIB_FLAG_GLADE2
) == 0)
664 if (strncmp(lib
, "libglade-2", 10) == 0)
666 vlog("LIB:<%s>\n", lib
);
667 *flag
|= LIB_FLAG_GLADE2
;
675 static int parse_ld_cache(int *flag
)
682 size_t cache_size
= 0;
683 const char *cache_data
= NULL
;
684 struct cache_file
*cache
= NULL
;
685 struct cache_file_new
*cache_new
= NULL
;
689 fd
= open(LD_CACHE_FILE
, O_RDONLY
);
692 vlog("failed to open %s err:%d\n", LD_CACHE_FILE
, errno
);
696 if (fstat(fd
, &st
) < 0 || st
.st_size
== 0)
702 cache
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
703 if (cache
== MAP_FAILED
)
709 cache_size
= st
.st_size
;
710 if (cache_size
< sizeof (struct cache_file
))
712 vlog("File is not a cache file.\n");
713 munmap (cache
, cache_size
);
718 if (memcmp(cache
->magic
, CACHEMAGIC
, sizeof CACHEMAGIC
- 1))
720 /* This can only be the new format without the old one. */
721 cache_new
= (struct cache_file_new
*) cache
;
723 if (memcmp(cache_new
->magic
, CACHEMAGIC_NEW
, sizeof CACHEMAGIC_NEW
- 1) ||
724 memcmp (cache_new
->version
, CACHE_VERSION
, sizeof CACHE_VERSION
- 1))
726 munmap (cache
, cache_size
);
732 /* This is where the strings start. */
733 cache_data
= (const char *) cache_new
;
737 /* Check for corruption, avoiding overflow. */
738 if ((cache_size
- sizeof (struct cache_file
)) / sizeof (struct file_entry
) < cache
->nlibs
)
740 vlog("File is not a cache file.\n");
741 munmap (cache
, cache_size
);
746 offset
= ALIGN_CACHE(sizeof (struct cache_file
) + (cache
->nlibs
* sizeof (struct file_entry
)));
748 /* This is where the strings start. */
749 cache_data
= (const char *) &cache
->libs
[cache
->nlibs
];
751 /* Check for a new cache embedded in the old format. */
752 if (cache_size
> (offset
+ sizeof (struct cache_file_new
)))
754 cache_new
= (struct cache_file_new
*) ((void *)cache
+ offset
);
756 if (memcmp(cache_new
->magic
, CACHEMAGIC_NEW
, sizeof CACHEMAGIC_NEW
- 1) == 0 &&
757 memcmp(cache_new
->version
, CACHE_VERSION
, sizeof CACHE_VERSION
- 1) == 0)
759 cache_data
= (const char *) cache_new
;
767 vlog("%d libs found in cache format 0\n", cache
->nlibs
);
768 for (i
= 0; i
< cache
->nlibs
; i
++)
770 ld_cache_lib_check(cache_data
+ cache
->libs
[i
].key
, flag
);
773 else if (format
== 1)
775 vlog("%d libs found in cache format 1\n", cache_new
->nlibs
);
777 for (i
= 0; i
< cache_new
->nlibs
; i
++)
779 ld_cache_lib_check(cache_data
+ cache_new
->libs
[i
].key
, flag
);
783 vlog("ldconfig lib flags 0x%x\n", *flag
);
784 vlog("lib flags GLADE2:[%s] GTK2:[%s] GTK3:[%s] GTK4:[%s] QT4:[%s] QT5:[%s] QT6:[%s]\n",
785 INT2STR_YN((*flag
) & LIB_FLAG_GLADE2
), INT2STR_YN((*flag
) & LIB_FLAG_GTK2
),
786 INT2STR_YN((*flag
) & LIB_FLAG_GTK3
), INT2STR_YN((*flag
) & LIB_FLAG_GTK4
),
787 INT2STR_YN((*flag
) & LIB_FLAG_QT4
), INT2STR_YN((*flag
) & LIB_FLAG_QT5
),
788 INT2STR_YN((*flag
) & LIB_FLAG_QT6
));
790 munmap (cache
, cache_size
);
795 static int gui_type_check(VTOY_JSON
*pstNode
)
798 const char *env
= NULL
;
799 const char *arch
= NULL
;
800 const char *srctype
= NULL
;
801 const char *srcname
= NULL
;
802 const char *condition
= NULL
;
803 const char *expression
= NULL
;
806 arch
= vtoy_json_get_string_ex(pstNode
, "arch");
807 srctype
= vtoy_json_get_string_ex(pstNode
, "type");
808 srcname
= vtoy_json_get_string_ex(pstNode
, "name");
809 condition
= vtoy_json_get_string_ex(pstNode
, "condition");
810 expression
= vtoy_json_get_string_ex(pstNode
, "expression");
812 if (srctype
== NULL
|| srcname
== NULL
|| condition
== NULL
)
817 if (arch
&& NULL
== strstr(arch
, VTOY_GUI_ARCH
))
822 vlog("check <%s> <%s> <%s>\n", srctype
, srcname
, condition
);
824 if (strcmp(srctype
, "file") == 0)
826 if (access(srcname
, F_OK
) == -1)
831 if (strcmp(condition
, "exist") == 0)
833 vlog("File %s exist\n", srcname
);
836 else if (strcmp(condition
, "contains") == 0)
838 fp
= fopen(srcname
, "r");
844 while (fgets(line
, sizeof(line
), fp
))
846 if (strstr(line
, expression
))
848 vlog("File %s contains %s\n", srcname
, expression
);
858 else if (strcmp(srctype
, "env") == 0)
860 env
= getenv(srcname
);
866 if (strcmp(condition
, "exist") == 0)
868 vlog("env %s exist\n", srcname
);
871 else if (strcmp(condition
, "equal") == 0)
873 if (strcmp(expression
, env
) == 0)
875 vlog("env %s is %s\n", srcname
, env
);
880 else if (strcmp(condition
, "contains") == 0)
882 if (strstr(env
, expression
))
884 vlog("env %s is %s contains %s\n", srcname
, env
, expression
);
894 static int read_file_to_buf(const char *FileName
, int ExtLen
, void **Bufer
, int *BufLen
)
900 fp
= fopen(FileName
, "rb");
903 vlog("Failed to open file %s", FileName
);
907 fseek(fp
, 0, SEEK_END
);
908 FileSize
= (int)ftell(fp
);
910 Data
= malloc(FileSize
+ ExtLen
);
917 fseek(fp
, 0, SEEK_SET
);
918 fread(Data
, 1, FileSize
, fp
);
928 static int distro_check_gui_env(char *type
, int len
, int *pver
)
933 VTOY_JSON
*pstNode
= NULL
;
934 VTOY_JSON
*pstJson
= NULL
;
936 vlog("distro_check_gui_env ...\n");
938 if (access("./tool/distro_gui_type.json", F_OK
) == -1)
940 vlog("distro_gui_type.json file not exist\n");
944 read_file_to_buf("./tool/distro_gui_type.json", 1, (void **)&pBuf
, &size
);
947 pstJson
= vtoy_json_create();
948 vtoy_json_parse(pstJson
, pBuf
);
950 for (pstNode
= pstJson
->pstChild
; pstNode
; pstNode
= pstNode
->pstNext
)
952 if (gui_type_check(pstNode
->pstChild
))
954 length
= (int)snprintf(type
, len
, "%s", vtoy_json_get_string_ex(pstNode
->pstChild
, "gui"));
955 *pver
= type
[length
- 1] - '0';
956 type
[length
- 1] = 0;
961 vtoy_json_destroy(pstJson
);
962 return pstNode
? 1 : 0;
965 static int detect_gui_exe_path(const char *curpath
, char *pathbuf
, int buflen
)
970 const char *guitype
= NULL
;
973 struct stat filestat
;
975 if (access("./ventoy_gui_type", F_OK
) != -1)
977 vlog("Get GUI type from ventoy_gui_type file.\n");
980 read_file_1st_line("./ventoy_gui_type", line
, sizeof(line
));
981 if (strncmp(line
, "gtk2", 4) == 0)
986 parse_ld_cache(&libflag
);
987 if ((libflag
& LIB_FLAG_GLADE2
) == 0)
989 vlog("libglade2 is necessary for GTK2, but not found.\n");
993 else if (strncmp(line
, "gtk3", 4) == 0)
998 else if (strncmp(line
, "gtk4", 4) == 0)
1003 else if (strncmp(line
, "qt4", 3) == 0)
1008 else if (strncmp(line
, "qt5", 3) == 0)
1013 else if (strncmp(line
, "qt6", 3) == 0)
1020 vlog("Current X environment is NOT supported.\n");
1026 vlog("Now detect the GUI type ...\n");
1028 parse_ld_cache(&libflag
);
1030 if ((LIB_FLAG_GTK
& libflag
) > 0 && (LIB_FLAG_QT
& libflag
) == 0)
1033 ver
= detect_gtk_version(libflag
);
1035 else if ((LIB_FLAG_GTK
& libflag
) == 0 && (LIB_FLAG_QT
& libflag
) > 0)
1038 ver
= detect_qt_version(libflag
);
1040 else if ((LIB_FLAG_GTK
& libflag
) > 0 && (LIB_FLAG_QT
& libflag
) > 0)
1042 if (distro_check_gui_env(line
, sizeof(line
), &ver
))
1045 vlog("distro_check_gui <%s%d> ...\n", line
, ver
);
1047 else if (is_gtk_env())
1050 ver
= detect_gtk_version(libflag
);
1052 else if (is_qt_env())
1055 ver
= detect_qt_version(libflag
);
1059 vlog("Can not distinguish GTK and QT, default use GTK.\n");
1061 ver
= detect_gtk_version(libflag
);
1066 vlog("Current X environment is NOT supported.\n");
1071 snprintf(pathbuf
, buflen
, "%s/tool/%s/Ventoy2Disk.%s%d", curpath
, VTOY_GUI_ARCH
, guitype
, ver
);
1073 vlog("This is %s%d X environment.\n", guitype
, ver
);
1074 vlog("exe = %s\n", pathbuf
);
1076 if (access(pathbuf
, F_OK
) == -1)
1078 vlog("%s is not exist.\n", pathbuf
);
1082 if (access(pathbuf
, X_OK
) == -1)
1084 vlog("execute permission check fail, try chmod.\n", pathbuf
);
1085 if (stat(pathbuf
, &filestat
) == 0)
1087 mode
= filestat
.st_mode
| S_IXUSR
| S_IXGRP
| S_IXOTH
;
1088 ret
= chmod(pathbuf
, mode
);
1089 vlog("old mode=%o new mode=%o ret=%d\n", filestat
.st_mode
, mode
, ret
);
1094 vlog("execute permission check success.\n");
1100 int real_main(int argc
, char **argv
)
1105 char path
[PATH_MAX
];
1106 char curpath
[PATH_MAX
];
1108 ret
= adjust_cur_dir(argv
[0]);
1111 vlog("=========================================================\n");
1112 vlog("=========================================================\n");
1113 vlog("=============== VentoyGui %s ===============\n", VTOY_GUI_ARCH
);
1114 vlog("=========================================================\n");
1115 vlog("=========================================================\n");
1118 getcwd(curpath
, sizeof(curpath
));
1120 vlog("pid:%ld ppid:%ld uid:%d euid:%d\n", (long)getpid(), (long)getppid(), getuid(), euid
);
1121 vlog("adjust dir:%d current path:%s\n", ret
, curpath
);
1122 dump_args("RAW", argv
);
1124 if (access("./boot/boot.img", F_OK
) == -1)
1126 vlog("Please run under the correct directory!\n");
1130 exe
= find_argv(argc
, argv
, VTOY_GUI_PATH
);
1135 vlog("Invalid euid %d when restart.\n", euid
);
1139 return restart_main(argc
, argv
, exe
+ strlen(VTOY_GUI_PATH
));
1148 if (detect_gui_exe_path(curpath
, path
, sizeof(path
)))
1155 vlog("We have root privileges, just exec %s\n", path
);
1158 execv(argv
[0], argv
);
1162 vlog("EUID check failed.\n");
1165 restart_by_pkexec(argc
, argv
, curpath
, path
);
1167 vlog("### Please run with root privileges. ###\n");
1175 int main(int argc
, char **argv
)
1180 snprintf(g_log_file
, sizeof(g_log_file
), "log.txt");
1181 for (i
= 0; i
< argc
; i
++)
1183 if (argv
[i
] && argv
[i
+ 1] && strcmp(argv
[i
], "-l") == 0)
1185 snprintf(g_log_file
, sizeof(g_log_file
), "%s", argv
[i
+ 1]);
1190 g_log_buf
= malloc(MAX_LOG_BUF
);
1193 vlog("Failed to malloc log buffer %d\n", MAX_LOG_BUF
);
1197 ret
= real_main(argc
, argv
);