~ubuntu-branches/ubuntu/hardy/irssi/hardy-security

« back to all changes in this revision

Viewing changes to src/core/session.c

  • Committer: Bazaar Package Importer
  • Author(s): Christian Bjälevik
  • Date: 2007-04-28 02:52:01 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070428025201-2c4swxnpn4wr7fpg
Tags: 0.8.11-0ubuntu1
* New upstream release:
  - http://www.irssi.org/news/ChangeLog
* debian/{control,compat}:
  - Bump Standards.
* debian/patches/00list:
  - Disable 05upgrade-check-binary.patch, applied upstream.
  - Disable 08doublefree.patch, applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
static char **session_args;
39
39
 
40
 
void session_set_binary(const char *path)
 
40
#ifndef HAVE_GLIB2
 
41
static char *g_find_program_in_path(const char *path)
41
42
{
42
43
        const char *envpath;
43
44
        char **paths, **tmp;
44
45
        char *str;
45
 
 
46
 
        g_free_and_null(irssi_binary);
 
46
        char *result = NULL;
47
47
 
48
48
        if (g_path_is_absolute(path)) {
49
49
                /* full path - easy */
50
 
                irssi_binary = g_strdup(path);
51
 
                return;
 
50
                if(access(path, X_OK) == -1)
 
51
                        return NULL;
 
52
                else
 
53
                        return g_strdup(path);
52
54
        }
53
55
 
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);
58
60
                g_free(str);
59
 
                return;
 
61
                if (access(result, X_OK) == -1) {
 
62
                        g_free(result);
 
63
                        return NULL;
 
64
                }
 
65
                else
 
66
                        return result;
60
67
        }
61
68
 
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;
65
72
 
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) {
70
 
                        irssi_binary = str;
 
77
                        result = str;
71
78
                        break;
72
79
                }
73
80
                g_free(str);
74
81
        }
75
82
        g_strfreev(paths);
 
83
 
 
84
        return result;
 
85
}
 
86
#endif
 
87
 
 
88
void session_set_binary(const char *path)
 
89
{
 
90
        g_free_and_null(irssi_binary);
 
91
 
 
92
        irssi_binary = g_find_program_in_path(path);
76
93
}
77
94
 
78
95
void session_upgrade(void)
80
97
        if (session_args == NULL)
81
98
                return;
82
99
 
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));
86
103
}
90
107
{
91
108
        CONFIG_REC *session;
92
109
        char *session_file, *str;
 
110
        char *binary;
93
111
 
94
112
        if (*data == '\0')
95
113
                data = irssi_binary;
96
 
        if (data == NULL)
97
 
                cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
 
114
 
 
115
        if ((binary = g_find_program_in_path(data)) == NULL)
 
116
                cmd_return_error(CMDERR_PROGRAM_NOT_FOUND);
98
117
 
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());
 
131
        g_free(binary);
 
132
        g_free(session_file);
112
133
        session_args = g_strsplit(str, " ", -1);
113
134
        g_free(str);
114
135