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.
|
|
|
|
|
|
|
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
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>
|
|
|
|
struct rlimit orig_core_rlimit;
|
|
|
|
#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;
|
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);
|
|
|
|
}
|
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
void core_init_paths(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
static struct poptOption options[] = {
|
|
|
|
{ "config", 0, POPT_ARG_STRING, NULL, 0, "Configuration file location (~/.irssi/config)", "PATH" },
|
|
|
|
{ "home", 0, POPT_ARG_STRING, NULL, 0, "Irssi home dir location (~/.irssi)", "PATH" },
|
|
|
|
{ NULL, '\0', 0, NULL }
|
|
|
|
};
|
2001-07-16 12:56:52 -04:00
|
|
|
char *str;
|
2001-07-14 20:39:48 -04:00
|
|
|
int n, len;
|
|
|
|
|
|
|
|
for (n = 1; n < argc; n++) {
|
|
|
|
if (strncmp(argv[n], "--home=", 7) == 0) {
|
|
|
|
g_free_not_null(irssi_dir);
|
|
|
|
irssi_dir = convert_home(argv[n]+7);
|
|
|
|
len = strlen(irssi_dir);
|
|
|
|
if (irssi_dir[len-1] == G_DIR_SEPARATOR)
|
|
|
|
irssi_dir[len-1] = '\0';
|
2002-02-07 14:30:58 -05:00
|
|
|
} else if (strncmp(argv[n], "--config=", 9) == 0) {
|
2001-07-14 20:39:48 -04:00
|
|
|
g_free_not_null(irssi_config_file);
|
|
|
|
irssi_config_file = convert_home(argv[n]+9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-16 12:56:52 -04:00
|
|
|
if (irssi_dir != NULL && !g_path_is_absolute(irssi_dir)) {
|
|
|
|
str = irssi_dir;
|
|
|
|
irssi_dir = g_strdup_printf("%s/%s", g_get_current_dir(), str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irssi_config_file != NULL &&
|
|
|
|
!g_path_is_absolute(irssi_config_file)) {
|
|
|
|
str = irssi_config_file;
|
|
|
|
irssi_config_file =
|
|
|
|
g_strdup_printf("%s/%s", g_get_current_dir(), str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
args_register(options);
|
|
|
|
|
|
|
|
if (irssi_dir == NULL)
|
|
|
|
irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, g_get_home_dir());
|
|
|
|
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);
|
2001-11-18 20:48:58 -05:00
|
|
|
|
|
|
|
session_set_binary(argv[0]);
|
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;
|
|
|
|
}
|
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
void core_init(int argc, char *argv[])
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-07-14 15:10:17 -04:00
|
|
|
dialog_type_queue = NULL;
|
|
|
|
dialog_text_queue = NULL;
|
|
|
|
|
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();
|
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", "");
|
2001-09-10 15:50:53 -04:00
|
|
|
settings_add_bool("misc", "override_coredump_limit", TRUE);
|
|
|
|
|
|
|
|
#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();
|
|
|
|
|
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
|
|
|
}
|