From 5656ad352d3f64dc84f8d4cbae5907e5348b53a6 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 19 Nov 2001 13:33:28 +0000 Subject: [PATCH] session_set_binary() - we can't get the full path to irssi binary from argv[0] and we need it, so its searched now. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2079 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/session.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/core/session.c b/src/core/session.c index e74b4774..de265b62 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -30,13 +30,42 @@ #include "servers-setup.h" static char *session_file; -static const char *irssi_binary; /* from argv[0] */ +static char *irssi_binary; static GIOChannel *next_handle; void session_set_binary(const char *path) { - irssi_binary = path; + char **paths, **tmp; + char *str; + + g_free_and_null(irssi_binary); + + if (g_path_is_absolute(path)) { + /* full path - easy */ + irssi_binary = g_strdup(path); + return; + } + + 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); + g_free(str); + return; + } + + /* we'll need to find it from path. */ + paths = g_strsplit(g_getenv("PATH"), ":", -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; + break; + } + g_free(str); + } + g_strfreev(paths); } /* SYNTAX: UPGRADE [] */ @@ -52,7 +81,7 @@ static void cmd_upgrade(const char *data) data = irssi_binary; /* make sure we can execute it */ - if (access(data, X_OK) != 0) + if (data == NULL || access(data, X_OK) != 0) cmd_return_error(CMDERR_ERRNO); /* save the session */ @@ -214,6 +243,8 @@ void session_init(void) void session_deinit(void) { + g_free_not_null(irssi_binary); + command_unbind("upgrade", (SIGNAL_FUNC) cmd_upgrade); signal_remove("session save", (SIGNAL_FUNC) sig_session_save);