#define LD_CACHE_FILE "/etc/ld.so.cache"
#define INT2STR_YN(a) ((a) == 0 ? "NO" : "YES")
+static int g_xdg_log = 0;
+static int g_xdg_ini = 0;
static char g_log_file[PATH_MAX];
+static char g_ini_file[PATH_MAX];
static char *g_log_buf = NULL;
extern char ** environ;
return read_file_1st_line(path, Buffer, BufLen);
}
+static int is_dir_exist(const char *fmt, ...)
+{
+ va_list arg;
+ struct stat st;
+ char path[4096];
+
+ va_start(arg, fmt);
+ vsnprintf(path, sizeof(path), fmt, arg);
+ va_end(arg);
+
+ memset(&st, 0, sizeof(st));
+ if (stat(path, &st) < 0)
+ {
+ return 0;
+ }
+
+ if (st.st_mode & S_IFDIR)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+static void touch_new_file(char *filename)
+{
+ char *pos = NULL;
+ FILE *fp = NULL;
+
+ if (access(filename, F_OK) == -1)
+ {
+ for (pos = filename; *pos; pos++)
+ {
+ if (*pos == '/')
+ {
+ *pos = 0;
+ if (!is_dir_exist("%s", filename))
+ {
+ mkdir(filename, 0755);
+ }
+ *pos = '/';
+ }
+ }
+
+ fp = fopen(filename, "w+");
+ if (fp)
+ {
+ fclose(fp);
+ }
+ }
+}
+
static int find_exe_path(const char *exe, char *pathbuf, int buflen)
{
int i;
if (envs)
{
vlog("recover success, argc=%d evecve <%s>\n", j, guiexe);
+ dump_args("EXECVE", newargv);
execve(guiexe, newargv, envs);
}
else
newargv[j++] = pkexec;
newargv[j++] = path;
- for (i = 1; i < argc && j < MAX_PARAS - 2; i++)
+ for (i = 1; i < argc && j < MAX_PARAS; i++)
{
+ if (strcmp(argv[i], "--xdg") == 0)
+ {
+ continue;
+ }
newargv[j++] = argv[i];
}
- newargv[j++] = create_environ_param(VTOY_ENV_STR, environ);
- newargv[j++] = exepara;
+
+ if (j < MAX_PARAS)
+ {
+ newargv[j++] = create_environ_param(VTOY_ENV_STR, environ);
+ }
+
+ if (j < MAX_PARAS)
+ {
+ newargv[j++] = exepara;
+ }
+
+ if (g_xdg_log && j + 1 < MAX_PARAS)
+ {
+ newargv[j++] = "-l";
+ newargv[j++] = g_log_file;
+ }
+
+ if (g_xdg_ini && j + 1 < MAX_PARAS)
+ {
+ newargv[j++] = "-i";
+ newargv[j++] = g_ini_file;
+ }
dump_args("PKEXEC", newargv);
execv(pkexec, newargv);
return pstNode ? 1 : 0;
}
-static int detect_gui_exe_path(const char *curpath, char *pathbuf, int buflen)
+static int detect_gui_exe_path(int argc, char **argv, const char *curpath, char *pathbuf, int buflen)
{
+ int i;
int ret;
int ver;
int libflag = 0;
char line[256];
mode_t mode;
struct stat filestat;
-
- if (access("./ventoy_gui_type", F_OK) != -1)
+
+ for (i = 1; i < argc; i++)
+ {
+ if (argv[i] && strcmp(argv[i], "--gtk2") == 0)
+ {
+ guitype = "gtk";
+ ver = 2;
+ }
+ else if (argv[i] && strcmp(argv[i], "--gtk3") == 0)
+ {
+ guitype = "gtk";
+ ver = 3;
+ }
+ else if (argv[i] && strcmp(argv[i], "--gtk4") == 0)
+ {
+ guitype = "gtk";
+ ver = 4;
+ }
+ else if (argv[i] && strcmp(argv[i], "--qt4") == 0)
+ {
+ guitype = "qt";
+ ver = 4;
+ }
+ else if (argv[i] && strcmp(argv[i], "--qt5") == 0)
+ {
+ guitype = "qt";
+ ver = 5;
+ }
+ else if (argv[i] && strcmp(argv[i], "--qt6") == 0)
+ {
+ guitype = "qt";
+ ver = 6;
+ }
+ }
+
+ if (guitype)
+ {
+ vlog("Get GUI type from param <%s%d>.\n", guitype, ver);
+ }
+ else if (access("./ventoy_gui_type", F_OK) != -1)
{
vlog("Get GUI type from ventoy_gui_type file.\n");
vlog("=============== VentoyGui %s ===============\n", VTOY_GUI_ARCH);
vlog("=========================================================\n");
vlog("=========================================================\n");
+ vlog("log file is <%s>\n", g_log_file);
euid = geteuid();
getcwd(curpath, sizeof(curpath));
return 1;
}
- if (detect_gui_exe_path(curpath, path, sizeof(path)))
+ if (detect_gui_exe_path(argc, argv, curpath, path, sizeof(path)))
{
return 1;
}
{
vlog("We have root privileges, just exec %s\n", path);
argv[0] = path;
- argv[1] = NULL;
execv(argv[0], argv);
}
else
{
int i;
int ret;
+ const char *env = NULL;
snprintf(g_log_file, sizeof(g_log_file), "log.txt");
for (i = 0; i < argc; i++)
{
if (argv[i] && argv[i + 1] && strcmp(argv[i], "-l") == 0)
{
+ touch_new_file(argv[i + 1]);
snprintf(g_log_file, sizeof(g_log_file), "%s", argv[i + 1]);
- break;
+ }
+ else if (argv[i] && argv[i + 1] && strcmp(argv[i], "-i") == 0)
+ {
+ touch_new_file(argv[i + 1]);
+ }
+ else if (argv[i] && strcmp(argv[i], "--xdg") == 0)
+ {
+ env = getenv("XDG_CACHE_HOME");
+ if (env)
+ {
+ g_xdg_log = 1;
+ snprintf(g_log_file, sizeof(g_log_file), "%s/ventoy/ventoy.log", env);
+ touch_new_file(g_log_file);
+ }
+ else
+ {
+ env = getenv("HOME");
+ if (env && is_dir_exist("%s/.cache", env))
+ {
+ g_xdg_log = 1;
+ snprintf(g_log_file, sizeof(g_log_file), "%s/.cache/ventoy/ventoy.log", env);
+ touch_new_file(g_log_file);
+ }
+ }
+
+ env = getenv("XDG_CONFIG_HOME");
+ if (env)
+ {
+ g_xdg_ini = 1;
+ snprintf(g_ini_file, sizeof(g_ini_file), "%s/ventoy/Ventoy2Disk.ini", env);
+ touch_new_file(g_ini_file);
+ }
+ else
+ {
+ env = getenv("HOME");
+ if (env && is_dir_exist("%s/.config", env))
+ {
+ g_xdg_ini = 1;
+ snprintf(g_ini_file, sizeof(g_ini_file), "%s/.config/ventoy/Ventoy2Disk.ini", env);
+ touch_new_file(g_ini_file);
+ }
+ }
}
}