1
0
mirror of https://github.com/irssi/irssi.git synced 2024-10-13 05:03:45 -04:00

Apply 05upgrade-check-binary.dpatch with some modifications.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4366 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Emanuele Giaquinta 2006-09-18 22:32:33 +00:00 committed by exg
parent 9f0cd484e5
commit 8ca4e8544b
5 changed files with 39 additions and 13 deletions

View File

@ -40,7 +40,8 @@ enum {
CMDERR_NOT_GOOD_IDEA, /* not good idea to do, -yes overrides this */ CMDERR_NOT_GOOD_IDEA, /* not good idea to do, -yes overrides this */
CMDERR_INVALID_TIME, /* invalid time specification */ CMDERR_INVALID_TIME, /* invalid time specification */
CMDERR_INVALID_CHARSET, /* invalid charset 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' */ /* Return the full command for `alias' */

View File

@ -37,42 +37,59 @@ char *irssi_binary = NULL;
static char **session_args; 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; const char *envpath;
char **paths, **tmp; char **paths, **tmp;
char *str; char *str;
char *result = NULL;
g_free_and_null(irssi_binary);
if (g_path_is_absolute(path)) { if (g_path_is_absolute(path)) {
/* full path - easy */ /* full path - easy */
irssi_binary = g_strdup(path); if(access(path, X_OK) == -1)
return; return NULL;
else
return g_strdup(path);
} }
if (strchr(path, G_DIR_SEPARATOR) != NULL) { if (strchr(path, G_DIR_SEPARATOR) != NULL) {
/* relative path */ /* relative path */
str = g_get_current_dir(); 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); 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. */ /* we'll need to find it from path. */
envpath = g_getenv("PATH"); envpath = g_getenv("PATH");
if (envpath == NULL) return; if (envpath == NULL) return NULL;
paths = g_strsplit(envpath, ":", -1); paths = g_strsplit(envpath, ":", -1);
for (tmp = paths; *tmp != NULL; tmp++) { for (tmp = paths; *tmp != NULL; tmp++) {
str = g_strconcat(*tmp, G_DIR_SEPARATOR_S, path, NULL); str = g_strconcat(*tmp, G_DIR_SEPARATOR_S, path, NULL);
if (access(str, X_OK) == 0) { if (access(str, X_OK) == 0) {
irssi_binary = str; result = str;
break; break;
} }
g_free(str); g_free(str);
} }
g_strfreev(paths); 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) void session_upgrade(void)
@ -80,7 +97,7 @@ void session_upgrade(void)
if (session_args == NULL) if (session_args == NULL)
return; return;
execvp(session_args[0], session_args); execv(session_args[0], session_args);
fprintf(stderr, "exec failed: %s: %s\n", fprintf(stderr, "exec failed: %s: %s\n",
session_args[0], g_strerror(errno)); session_args[0], g_strerror(errno));
} }
@ -90,10 +107,14 @@ static void cmd_upgrade(const char *data)
{ {
CONFIG_REC *session; CONFIG_REC *session;
char *session_file, *str; char *session_file, *str;
char *binary;
if (*data == '\0') if (*data == '\0')
data = irssi_binary; data = irssi_binary;
if ((binary = g_find_program_in_path(data)) == NULL)
cmd_return_error(CMDERR_PROGRAM_NOT_FOUND);
/* save the session */ /* save the session */
session_file = g_strdup_printf("%s/session", get_irssi_dir()); session_file = g_strdup_printf("%s/session", get_irssi_dir());
session = config_open(session_file, 0600); 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 /* data may contain some other program as well, like
/UPGRADE /usr/bin/screen irssi */ /UPGRADE /usr/bin/screen irssi */
str = g_strdup_printf("%s --noconnect --session=%s --home=%s --config=%s", 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); g_free(session_file);
session_args = g_strsplit(str, " ", -1); session_args = g_strsplit(str, " ", -1);
g_free(str); g_free(str);

View File

@ -50,7 +50,8 @@ static int ret_texts[] = {
TXT_NOT_GOOD_IDEA, TXT_NOT_GOOD_IDEA,
TXT_INVALID_TIME, TXT_INVALID_TIME,
TXT_INVALID_CHARSET, TXT_INVALID_CHARSET,
TXT_EVAL_MAX_RECURSE TXT_EVAL_MAX_RECURSE,
TXT_PROGRAM_NOT_FOUND
}; };
int command_hide_output; int command_hide_output;

View File

@ -220,6 +220,7 @@ FORMAT_REC fecommon_core_formats[] = {
{ "invalid_size", "Invalid size", 0 }, { "invalid_size", "Invalid size", 0 },
{ "invalid_charset", "Invalid charset: $0", 1, { 0 } }, { "invalid_charset", "Invalid charset: $0", 1, { 0 } },
{ "eval_max_recurse", "/eval hit maximum recursion limit", 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 }, { NULL, "Themes", 0 },

View File

@ -189,6 +189,7 @@ enum {
TXT_INVALID_SIZE, TXT_INVALID_SIZE,
TXT_INVALID_CHARSET, TXT_INVALID_CHARSET,
TXT_EVAL_MAX_RECURSE, TXT_EVAL_MAX_RECURSE,
TXT_PROGRAM_NOT_FOUND,
TXT_FILL_11, TXT_FILL_11,