1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

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
This commit is contained in:
Timo Sirainen 2001-11-19 13:33:28 +00:00 committed by cras
parent ee708c1469
commit 5656ad352d

View File

@ -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 [<irssi binary path>] */
@ -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);