2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
core.c : irssi
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2007-05-08 14:41:10 -04:00
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2000-04-26 04:03:38 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
2001-06-01 16:21:07 -04:00
|
|
|
#include <signal.h>
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
#include "args.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "pidwait.h"
|
2001-06-01 16:21:07 -04:00
|
|
|
#include "misc.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
#include "net-disconnect.h"
|
2000-07-16 15:00:41 -04:00
|
|
|
#include "net-sendbuffer.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "signals.h"
|
|
|
|
#include "settings.h"
|
2001-11-18 20:48:58 -05:00
|
|
|
#include "session.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-31 20:26:46 -04:00
|
|
|
#include "chat-protocols.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "servers.h"
|
|
|
|
#include "chatnets.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "commands.h"
|
2000-12-04 19:53:04 -05:00
|
|
|
#include "expandos.h"
|
2001-02-10 00:54:35 -05:00
|
|
|
#include "write-buffer.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "log.h"
|
|
|
|
#include "rawlog.h"
|
2000-10-09 19:40:18 -04:00
|
|
|
#include "ignore.h"
|
2004-08-19 20:03:40 -04:00
|
|
|
#include "recode.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "channels.h"
|
|
|
|
#include "queries.h"
|
|
|
|
#include "nicklist.h"
|
2001-01-20 23:09:48 -05:00
|
|
|
#include "nickmatch-cache.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
|
2001-09-10 15:50:53 -04:00
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
# include <sys/resource.h>
|
2008-04-28 05:27:13 -04:00
|
|
|
static struct rlimit orig_core_rlimit;
|
2001-09-10 15:50:53 -04:00
|
|
|
#endif
|
|
|
|
|
2000-09-30 18:49:48 -04:00
|
|
|
void chat_commands_init(void);
|
|
|
|
void chat_commands_deinit(void);
|
|
|
|
|
2001-07-15 10:07:48 -04:00
|
|
|
void log_away_init(void);
|
|
|
|
void log_away_deinit(void);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
int irssi_gui;
|
2001-10-21 09:22:28 -04:00
|
|
|
int irssi_init_finished;
|
2002-03-10 10:20:44 -05:00
|
|
|
int reload_config;
|
2006-10-20 08:50:08 -04:00
|
|
|
time_t client_start_time;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
static char *irssi_dir, *irssi_config_file;
|
2001-07-14 15:10:17 -04:00
|
|
|
static GSList *dialog_type_queue, *dialog_text_queue;
|
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
const char *get_irssi_dir(void)
|
|
|
|
{
|
|
|
|
return irssi_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return full path for ~/.irssi/config */
|
|
|
|
const char *get_irssi_config(void)
|
|
|
|
{
|
|
|
|
return irssi_config_file;
|
|
|
|
}
|
|
|
|
|
2002-03-10 10:20:44 -05:00
|
|
|
static void sig_reload_config(int signo)
|
|
|
|
{
|
|
|
|
reload_config = TRUE;
|
|
|
|
}
|
|
|
|
|
2001-09-10 15:50:53 -04:00
|
|
|
static void read_settings(void)
|
2001-06-01 16:21:07 -04:00
|
|
|
{
|
|
|
|
#ifndef WIN32
|
2002-01-04 16:20:32 -05:00
|
|
|
static int signals[] = {
|
2002-03-10 10:20:44 -05:00
|
|
|
SIGINT, SIGQUIT, SIGTERM,
|
2001-06-01 16:21:07 -04:00
|
|
|
SIGALRM, SIGUSR1, SIGUSR2
|
|
|
|
};
|
2002-01-04 16:20:32 -05:00
|
|
|
static char *signames[] = {
|
2002-03-10 10:20:44 -05:00
|
|
|
"int", "quit", "term",
|
2001-06-01 16:21:07 -04:00
|
|
|
"alrm", "usr1", "usr2"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *ignores;
|
|
|
|
struct sigaction act;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
ignores = settings_get_str("ignore_signals");
|
|
|
|
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
|
2002-03-10 10:20:44 -05:00
|
|
|
/* reload config on SIGHUP */
|
|
|
|
act.sa_handler = sig_reload_config;
|
|
|
|
sigaction(SIGHUP, &act, NULL);
|
|
|
|
|
2001-06-01 16:21:07 -04:00
|
|
|
for (n = 0; n < sizeof(signals)/sizeof(signals[0]); n++) {
|
|
|
|
act.sa_handler = find_substr(ignores, signames[n]) ?
|
|
|
|
SIG_IGN : SIG_DFL;
|
|
|
|
sigaction(signals[n], &act, NULL);
|
|
|
|
}
|
2001-09-10 15:50:53 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
if (!settings_get_bool("override_coredump_limit"))
|
|
|
|
setrlimit(RLIMIT_CORE, &orig_core_rlimit);
|
|
|
|
else {
|
|
|
|
struct rlimit rlimit;
|
|
|
|
|
|
|
|
rlimit.rlim_cur = RLIM_INFINITY;
|
|
|
|
rlimit.rlim_max = RLIM_INFINITY;
|
|
|
|
if (setrlimit(RLIMIT_CORE, &rlimit) == -1)
|
|
|
|
settings_set_bool("override_coredump_limit", FALSE);
|
|
|
|
}
|
|
|
|
#endif
|
2001-06-01 16:21:07 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-07-14 15:10:17 -04:00
|
|
|
static void sig_gui_dialog(const char *type, const char *text)
|
|
|
|
{
|
|
|
|
dialog_type_queue = g_slist_append(dialog_type_queue, g_strdup(type));
|
|
|
|
dialog_text_queue = g_slist_append(dialog_text_queue, g_strdup(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_init_finished(void)
|
|
|
|
{
|
|
|
|
GSList *type, *text;
|
|
|
|
|
|
|
|
signal_remove("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
|
|
|
|
signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
|
|
|
|
|
|
|
|
/* send the dialog texts that were in queue before irssi
|
|
|
|
was initialized */
|
|
|
|
type = dialog_type_queue;
|
|
|
|
text = dialog_text_queue;
|
|
|
|
for (; text != NULL; text = text->next, type = type->next) {
|
|
|
|
signal_emit("gui dialog", 2, type->data, text->data);
|
|
|
|
g_free(type->data);
|
|
|
|
g_free(text->data);
|
|
|
|
}
|
|
|
|
g_slist_free(dialog_type_queue);
|
|
|
|
g_slist_free(dialog_text_queue);
|
|
|
|
}
|
|
|
|
|
2007-05-23 20:25:36 -04:00
|
|
|
static char *fix_path(const char *str)
|
|
|
|
{
|
|
|
|
char *new_str = convert_home(str);
|
|
|
|
if (!g_path_is_absolute(new_str)) {
|
|
|
|
char *tmp_str = new_str;
|
|
|
|
new_str = g_strdup_printf("%s/%s", g_get_current_dir(), tmp_str);
|
|
|
|
g_free(tmp_str);
|
|
|
|
}
|
|
|
|
return new_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void core_register_options(void)
|
2001-07-14 20:39:48 -04:00
|
|
|
{
|
2008-02-03 11:48:02 -05:00
|
|
|
static GOptionEntry options[] = {
|
|
|
|
{ "config", 0, 0, G_OPTION_ARG_STRING, &irssi_config_file, "Configuration file location (~/.irssi/config)", "PATH" },
|
|
|
|
{ "home", 0, 0, G_OPTION_ARG_STRING, &irssi_dir, "Irssi home dir location (~/.irssi)", "PATH" },
|
|
|
|
{ NULL }
|
2001-07-14 20:39:48 -04:00
|
|
|
};
|
2001-07-16 12:56:52 -04:00
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
args_register(options);
|
2007-05-23 20:25:36 -04:00
|
|
|
session_register_options();
|
|
|
|
}
|
|
|
|
|
|
|
|
void core_preinit(const char *path)
|
|
|
|
{
|
|
|
|
const char *home;
|
|
|
|
char *str;
|
|
|
|
int len;
|
2001-07-14 20:39:48 -04:00
|
|
|
|
2002-10-19 13:48:10 -04:00
|
|
|
if (irssi_dir == NULL) {
|
|
|
|
home = g_get_home_dir();
|
|
|
|
if (home == NULL)
|
|
|
|
home = ".";
|
|
|
|
|
|
|
|
irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, home);
|
2007-05-23 20:25:36 -04:00
|
|
|
} else {
|
|
|
|
str = irssi_dir;
|
|
|
|
irssi_dir = fix_path(str);
|
2008-02-03 11:48:02 -05:00
|
|
|
g_free(str);
|
2007-05-23 20:25:36 -04:00
|
|
|
len = strlen(irssi_dir);
|
|
|
|
if (irssi_dir[len-1] == G_DIR_SEPARATOR)
|
|
|
|
irssi_dir[len-1] = '\0';
|
2002-10-19 13:48:10 -04:00
|
|
|
}
|
2001-07-14 20:39:48 -04:00
|
|
|
if (irssi_config_file == NULL)
|
2002-02-10 09:33:42 -05:00
|
|
|
irssi_config_file = g_strdup_printf("%s/"IRSSI_HOME_CONFIG, irssi_dir);
|
2007-05-23 20:25:36 -04:00
|
|
|
else {
|
|
|
|
str = irssi_config_file;
|
|
|
|
irssi_config_file = fix_path(str);
|
2008-02-03 11:48:02 -05:00
|
|
|
g_free(str);
|
2007-05-23 20:25:36 -04:00
|
|
|
}
|
2001-11-18 20:48:58 -05:00
|
|
|
|
2007-05-23 20:25:36 -04:00
|
|
|
session_set_binary(path);
|
2001-07-14 20:39:48 -04:00
|
|
|
}
|
|
|
|
|
2001-10-21 09:22:28 -04:00
|
|
|
static void sig_irssi_init_finished(void)
|
|
|
|
{
|
|
|
|
irssi_init_finished = TRUE;
|
|
|
|
}
|
|
|
|
|
2007-04-07 10:20:00 -04:00
|
|
|
void core_init(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-07-14 15:10:17 -04:00
|
|
|
dialog_type_queue = NULL;
|
|
|
|
dialog_text_queue = NULL;
|
2006-10-20 08:50:08 -04:00
|
|
|
client_start_time = time(NULL);
|
2001-07-14 15:10:17 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
modules_init();
|
2000-10-26 14:57:23 -04:00
|
|
|
#ifndef WIN32
|
2000-04-26 04:03:38 -04:00
|
|
|
pidwait_init();
|
2000-10-26 14:57:23 -04:00
|
|
|
#endif
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
net_disconnect_init();
|
2000-07-16 15:00:41 -04:00
|
|
|
net_sendbuffer_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
signals_init();
|
2001-07-14 15:10:17 -04:00
|
|
|
|
|
|
|
signal_add_first("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
|
|
|
|
signal_add_first("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
settings_init();
|
2000-05-15 04:25:45 -04:00
|
|
|
commands_init();
|
2001-11-18 20:48:58 -05:00
|
|
|
nickmatch_cache_init();
|
|
|
|
session_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-31 20:26:46 -04:00
|
|
|
chat_protocols_init();
|
2000-08-26 11:39:44 -04:00
|
|
|
chatnets_init();
|
2000-12-04 19:53:04 -05:00
|
|
|
expandos_init();
|
2000-10-09 19:40:18 -04:00
|
|
|
ignore_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
servers_init();
|
2001-02-10 00:54:35 -05:00
|
|
|
write_buffer_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
log_init();
|
2001-07-15 10:07:48 -04:00
|
|
|
log_away_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
rawlog_init();
|
2004-08-19 20:03:40 -04:00
|
|
|
recode_init();
|
2000-08-26 11:39:44 -04:00
|
|
|
|
|
|
|
channels_init();
|
|
|
|
queries_init();
|
|
|
|
nicklist_init();
|
2000-09-30 18:49:48 -04:00
|
|
|
|
|
|
|
chat_commands_init();
|
2001-06-01 16:21:07 -04:00
|
|
|
|
|
|
|
settings_add_str("misc", "ignore_signals", "");
|
2006-10-20 08:14:06 -04:00
|
|
|
settings_add_bool("misc", "override_coredump_limit", FALSE);
|
2001-09-10 15:50:53 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
getrlimit(RLIMIT_CORE, &orig_core_rlimit);
|
|
|
|
#endif
|
|
|
|
read_settings();
|
|
|
|
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
2001-10-21 09:22:28 -04:00
|
|
|
signal_add("irssi init finished", (SIGNAL_FUNC) sig_irssi_init_finished);
|
2001-06-01 16:21:07 -04:00
|
|
|
|
2001-08-13 20:41:59 -04:00
|
|
|
settings_check();
|
|
|
|
|
|
|
|
module_register("core", "core");
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void core_deinit(void)
|
|
|
|
{
|
2002-02-15 03:37:06 -05:00
|
|
|
module_uniq_destroy("WINDOW ITEM TYPE");
|
|
|
|
|
2001-09-10 15:50:53 -04:00
|
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
2001-10-21 09:22:28 -04:00
|
|
|
signal_remove("irssi init finished", (SIGNAL_FUNC) sig_irssi_init_finished);
|
2001-06-01 16:21:07 -04:00
|
|
|
|
2000-09-30 18:49:48 -04:00
|
|
|
chat_commands_deinit();
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
nicklist_deinit();
|
|
|
|
queries_deinit();
|
|
|
|
channels_deinit();
|
|
|
|
|
2004-08-19 20:03:40 -04:00
|
|
|
recode_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
rawlog_deinit();
|
2001-07-15 10:07:48 -04:00
|
|
|
log_away_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
log_deinit();
|
2001-02-10 00:54:35 -05:00
|
|
|
write_buffer_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
servers_deinit();
|
2000-10-09 19:40:18 -04:00
|
|
|
ignore_deinit();
|
2000-12-04 19:53:04 -05:00
|
|
|
expandos_deinit();
|
2000-08-26 11:39:44 -04:00
|
|
|
chatnets_deinit();
|
2000-08-31 20:26:46 -04:00
|
|
|
chat_protocols_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-11-18 20:48:58 -05:00
|
|
|
session_deinit();
|
2001-01-28 02:22:22 -05:00
|
|
|
nickmatch_cache_deinit();
|
2000-05-15 04:25:45 -04:00
|
|
|
commands_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
settings_deinit();
|
|
|
|
signals_deinit();
|
2000-07-16 15:00:41 -04:00
|
|
|
net_sendbuffer_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
net_disconnect_deinit();
|
|
|
|
|
2000-10-26 14:57:23 -04:00
|
|
|
#ifndef WIN32
|
2000-04-26 04:03:38 -04:00
|
|
|
pidwait_deinit();
|
2000-10-26 14:57:23 -04:00
|
|
|
#endif
|
2000-04-26 04:03:38 -04:00
|
|
|
modules_deinit();
|
2001-07-14 20:39:48 -04:00
|
|
|
|
|
|
|
g_free(irssi_dir);
|
|
|
|
g_free(irssi_config_file);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|