summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmanuele Giaquinta <exg@irssi.org>2006-09-18 22:32:33 +0000
committerexg <exg@dbcabf3a-b0e7-0310-adc4-f8d773084564>2006-09-18 22:32:33 +0000
commit8ca4e8544bcd8543afcca0d0af55dc00a6921cc8 (patch)
tree19d3e7e8ed4b36946383c147cdb3778e61a05358 /src
parent9f0cd484e5a3442ee1ebb8daaf187bab87cb272f (diff)
downloadirssi-8ca4e8544bcd8543afcca0d0af55dc00a6921cc8.zip
Apply 05upgrade-check-binary.dpatch with some modifications.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4366 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r--src/core/commands.h3
-rw-r--r--src/core/session.c44
-rw-r--r--src/fe-common/core/fe-core-commands.c3
-rw-r--r--src/fe-common/core/module-formats.c1
-rw-r--r--src/fe-common/core/module-formats.h1
5 files changed, 39 insertions, 13 deletions
diff --git a/src/core/commands.h b/src/core/commands.h
index 0dda9f61..c68c5b24 100644
--- a/src/core/commands.h
+++ b/src/core/commands.h
@@ -40,7 +40,8 @@ enum {
CMDERR_NOT_GOOD_IDEA, /* not good idea to do, -yes overrides this */
CMDERR_INVALID_TIME, /* invalid time specification */
CMDERR_INVALID_CHARSET, /* invalid charset specification */
- CMDERR_EVAL_MAX_RECURSE /* eval hit recursion limit */
+ CMDERR_EVAL_MAX_RECURSE, /* eval hit recursion limit */
+ CMDERR_PROGRAM_NOT_FOUND /* program not found */
};
/* Return the full command for `alias' */
diff --git a/src/core/session.c b/src/core/session.c
index f8d70d3b..9bbd3eb7 100644
--- a/src/core/session.c
+++ b/src/core/session.c
@@ -37,42 +37,59 @@ char *irssi_binary = NULL;
static char **session_args;
-void session_set_binary(const char *path)
+#ifndef HAVE_GLIB2
+static char *g_find_program_in_path(const char *path)
{
const char *envpath;
char **paths, **tmp;
char *str;
-
- g_free_and_null(irssi_binary);
+ char *result = NULL;
if (g_path_is_absolute(path)) {
/* full path - easy */
- irssi_binary = g_strdup(path);
- return;
+ if(access(path, X_OK) == -1)
+ return NULL;
+ else
+ return g_strdup(path);
}
if (strchr(path, G_DIR_SEPARATOR) != NULL) {
/* relative path */
str = g_get_current_dir();
- irssi_binary = g_strconcat(str, G_DIR_SEPARATOR_S, path, NULL);
+ result = g_strconcat(str, G_DIR_SEPARATOR_S, path, NULL);
g_free(str);
- return;
+ if (access(result, X_OK) == -1) {
+ g_free(result);
+ return NULL;
+ }
+ else
+ return result;
}
/* we'll need to find it from path. */
envpath = g_getenv("PATH");
- if (envpath == NULL) return;
+ if (envpath == NULL) return NULL;
paths = g_strsplit(envpath, ":", -1);
for (tmp = paths; *tmp != NULL; tmp++) {
str = g_strconcat(*tmp, G_DIR_SEPARATOR_S, path, NULL);
if (access(str, X_OK) == 0) {
- irssi_binary = str;
+ result = str;
break;
}
g_free(str);
}
g_strfreev(paths);
+
+ return result;
+}
+#endif
+
+void session_set_binary(const char *path)
+{
+ g_free_and_null(irssi_binary);
+
+ irssi_binary = g_strdup(path);
}
void session_upgrade(void)
@@ -80,7 +97,7 @@ void session_upgrade(void)
if (session_args == NULL)
return;
- execvp(session_args[0], session_args);
+ execv(session_args[0], session_args);
fprintf(stderr, "exec failed: %s: %s\n",
session_args[0], g_strerror(errno));
}
@@ -90,10 +107,14 @@ static void cmd_upgrade(const char *data)
{
CONFIG_REC *session;
char *session_file, *str;
+ char *binary;
if (*data == '\0')
data = irssi_binary;
+ if ((binary = g_find_program_in_path(data)) == NULL)
+ cmd_return_error(CMDERR_PROGRAM_NOT_FOUND);
+
/* save the session */
session_file = g_strdup_printf("%s/session", get_irssi_dir());
session = config_open(session_file, 0600);
@@ -106,7 +127,8 @@ static void cmd_upgrade(const char *data)
/* data may contain some other program as well, like
/UPGRADE /usr/bin/screen irssi */
str = g_strdup_printf("%s --noconnect --session=%s --home=%s --config=%s",
- data, session_file, get_irssi_dir(), get_irssi_config());
+ binary, session_file, get_irssi_dir(), get_irssi_config());
+ g_free(binary);
g_free(session_file);
session_args = g_strsplit(str, " ", -1);
g_free(str);
diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c
index 545cf027..51b68b3d 100644
--- a/src/fe-common/core/fe-core-commands.c
+++ b/src/fe-common/core/fe-core-commands.c
@@ -50,7 +50,8 @@ static int ret_texts[] = {
TXT_NOT_GOOD_IDEA,
TXT_INVALID_TIME,
TXT_INVALID_CHARSET,
- TXT_EVAL_MAX_RECURSE
+ TXT_EVAL_MAX_RECURSE,
+ TXT_PROGRAM_NOT_FOUND
};
int command_hide_output;
diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c
index d9bfc48b..cae4b9a5 100644
--- a/src/fe-common/core/module-formats.c
+++ b/src/fe-common/core/module-formats.c
@@ -220,6 +220,7 @@ FORMAT_REC fecommon_core_formats[] = {
{ "invalid_size", "Invalid size", 0 },
{ "invalid_charset", "Invalid charset: $0", 1, { 0 } },
{ "eval_max_recurse", "/eval hit maximum recursion limit", 0 },
+ { "program_not_found", "Could not find file or file is not executable", 0 },
/* ---- */
{ NULL, "Themes", 0 },
diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h
index 8f481aca..135378ba 100644
--- a/src/fe-common/core/module-formats.h
+++ b/src/fe-common/core/module-formats.h
@@ -189,6 +189,7 @@ enum {
TXT_INVALID_SIZE,
TXT_INVALID_CHARSET,
TXT_EVAL_MAX_RECURSE,
+ TXT_PROGRAM_NOT_FOUND,
TXT_FILL_11,