38
38
static char **session_args;
40
void session_set_binary(const char *path)
41
static char *g_find_program_in_path(const char *path)
42
43
const char *envpath;
43
44
char **paths, **tmp;
46
g_free_and_null(irssi_binary);
48
48
if (g_path_is_absolute(path)) {
49
49
/* full path - easy */
50
irssi_binary = g_strdup(path);
50
if(access(path, X_OK) == -1)
53
return g_strdup(path);
54
56
if (strchr(path, G_DIR_SEPARATOR) != NULL) {
55
57
/* relative path */
56
58
str = g_get_current_dir();
57
irssi_binary = g_strconcat(str, G_DIR_SEPARATOR_S, path, NULL);
59
result = g_strconcat(str, G_DIR_SEPARATOR_S, path, NULL);
61
if (access(result, X_OK) == -1) {
62
69
/* we'll need to find it from path. */
63
70
envpath = g_getenv("PATH");
64
if (envpath == NULL) return;
71
if (envpath == NULL) return NULL;
66
73
paths = g_strsplit(envpath, ":", -1);
67
74
for (tmp = paths; *tmp != NULL; tmp++) {
68
75
str = g_strconcat(*tmp, G_DIR_SEPARATOR_S, path, NULL);
69
76
if (access(str, X_OK) == 0) {
88
void session_set_binary(const char *path)
90
g_free_and_null(irssi_binary);
92
irssi_binary = g_find_program_in_path(path);
78
95
void session_upgrade(void)
80
97
if (session_args == NULL)
83
execvp(session_args[0], session_args);
100
execv(session_args[0], session_args);
84
101
fprintf(stderr, "exec failed: %s: %s\n",
85
102
session_args[0], g_strerror(errno));
91
108
CONFIG_REC *session;
92
109
char *session_file, *str;
94
112
if (*data == '\0')
95
113
data = irssi_binary;
97
cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
115
if ((binary = g_find_program_in_path(data)) == NULL)
116
cmd_return_error(CMDERR_PROGRAM_NOT_FOUND);
99
118
/* save the session */
100
119
session_file = g_strdup_printf("%s/session", get_irssi_dir());
108
127
/* data may contain some other program as well, like
109
128
/UPGRADE /usr/bin/screen irssi */
110
129
str = g_strdup_printf("%s --noconnect --session=%s --home=%s --config=%s",
111
data, session_file, get_irssi_dir(), get_irssi_config());
130
binary, session_file, get_irssi_dir(), get_irssi_config());
132
g_free(session_file);
112
133
session_args = g_strsplit(str, " ", -1);