summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2011-05-30 11:24:27 +0400
committerKozlov Dmitry <dima@server>2011-05-30 11:24:27 +0400
commit276beb78cea777ff8d81d9f5a4cd107c5a3dc2aa (patch)
treef50c4e781ba13c3ee59382a4466cfafa31ef464a
parent01afc34e830f2adf94c191a3c4f2761888dae53b (diff)
downloadaccel-ppp-276beb78cea777ff8d81d9f5a4cd107c5a3dc2aa.tar.gz
accel-ppp-276beb78cea777ff8d81d9f5a4cd107c5a3dc2aa.zip
rewrited initialization procedure (fix gcc-4.6 builds)
-rw-r--r--accel-pppd/auth/auth_chap_md5.c3
-rw-r--r--accel-pppd/auth/auth_mschap_v1.c3
-rw-r--r--accel-pppd/auth/auth_mschap_v2.c3
-rw-r--r--accel-pppd/auth/auth_pap.c3
-rw-r--r--accel-pppd/cli/cli.c4
-rw-r--r--accel-pppd/cli/show_sessions.c3
-rw-r--r--accel-pppd/cli/std_cmd.c3
-rw-r--r--accel-pppd/cli/tcp.c3
-rw-r--r--accel-pppd/cli/telnet.c3
-rw-r--r--accel-pppd/ctrl/l2tp/dict.c3
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c3
-rw-r--r--accel-pppd/ctrl/l2tp/netlink.c3
-rw-r--r--accel-pppd/ctrl/l2tp/packet.c3
-rw-r--r--accel-pppd/ctrl/pppoe/cli.c3
-rw-r--r--accel-pppd/ctrl/pppoe/mac_filter.c3
-rw-r--r--accel-pppd/ctrl/pppoe/pppoe.c3
-rw-r--r--accel-pppd/ctrl/pptp/pptp.c3
-rw-r--r--accel-pppd/extra/chap-secrets.c3
-rw-r--r--accel-pppd/extra/ippool.c4
-rw-r--r--accel-pppd/extra/pppd_compat.c4
-rw-r--r--accel-pppd/extra/shaper_tbf.c3
-rw-r--r--accel-pppd/extra/sigchld.c4
-rw-r--r--accel-pppd/iprange.c3
-rw-r--r--accel-pppd/log.c3
-rw-r--r--accel-pppd/logs/log_file.c4
-rw-r--r--accel-pppd/logs/log_pgsql.c4
-rw-r--r--accel-pppd/logs/log_tcp.c3
-rw-r--r--accel-pppd/main.c104
-rw-r--r--accel-pppd/ppp/ccp_mppe.c3
-rw-r--r--accel-pppd/ppp/ipcp_opt_dns.c4
-rw-r--r--accel-pppd/ppp/ipcp_opt_ipaddr.c3
-rw-r--r--accel-pppd/ppp/lcp_opt_accomp.c3
-rw-r--r--accel-pppd/ppp/lcp_opt_magic.c4
-rw-r--r--accel-pppd/ppp/lcp_opt_mru.c3
-rw-r--r--accel-pppd/ppp/lcp_opt_pcomp.c3
-rw-r--r--accel-pppd/ppp/ppp.c3
-rw-r--r--accel-pppd/ppp/ppp_auth.c3
-rw-r--r--accel-pppd/ppp/ppp_ccp.c3
-rw-r--r--accel-pppd/ppp/ppp_fsm.c3
-rw-r--r--accel-pppd/ppp/ppp_ipcp.c3
-rw-r--r--accel-pppd/ppp/ppp_lcp.c3
-rw-r--r--accel-pppd/radius/dm_coa.c4
-rw-r--r--accel-pppd/radius/packet.c4
-rw-r--r--accel-pppd/radius/radius.c3
-rw-r--r--accel-pppd/radius/req.c4
-rw-r--r--accel-pppd/radius/stat_accm.c3
-rw-r--r--accel-pppd/triton/triton.c29
-rw-r--r--accel-pppd/triton/triton.h4
-rw-r--r--accel-pppd/triton/triton_p.h8
49 files changed, 174 insertions, 117 deletions
diff --git a/accel-pppd/auth/auth_chap_md5.c b/accel-pppd/auth/auth_chap_md5.c
index a9a5572..8744160 100644
--- a/accel-pppd/auth/auth_chap_md5.c
+++ b/accel-pppd/auth/auth_chap_md5.c
@@ -414,7 +414,7 @@ static void chap_recv(struct ppp_handler_t *h)
log_ppp_warn("chap-md5: unknown code received %x\n", hdr->code);
}
-static void __init auth_chap_md5_init()
+static void auth_chap_md5_init()
{
char *opt;
@@ -445,3 +445,4 @@ static void __init auth_chap_md5_init()
log_emerg("chap-md5: failed to register handler\n");
}
+DEFINE_INIT(4, auth_chap_md5_init);
diff --git a/accel-pppd/auth/auth_mschap_v1.c b/accel-pppd/auth/auth_mschap_v1.c
index 237e3aa..85e3037 100644
--- a/accel-pppd/auth/auth_mschap_v1.c
+++ b/accel-pppd/auth/auth_mschap_v1.c
@@ -494,7 +494,7 @@ static void chap_recv(struct ppp_handler_t *h)
log_ppp_warn("mschap-v1: unknown code received %x\n", hdr->code);
}
-static void __init auth_mschap_v1_init()
+static void auth_mschap_v1_init()
{
char *opt;
@@ -523,3 +523,4 @@ static void __init auth_mschap_v1_init()
log_emerg("mschap-v1: failed to register handler\n");
}
+DEFINE_INIT(4, auth_mschap_v1_init);
diff --git a/accel-pppd/auth/auth_mschap_v2.c b/accel-pppd/auth/auth_mschap_v2.c
index c14e44f..f7407e8 100644
--- a/accel-pppd/auth/auth_mschap_v2.c
+++ b/accel-pppd/auth/auth_mschap_v2.c
@@ -629,7 +629,7 @@ static void chap_recv(struct ppp_handler_t *h)
log_ppp_warn("mschap-v2: unknown code received %x\n",hdr->code);
}
-static void __init auth_mschap_v2_init()
+static void auth_mschap_v2_init()
{
urandom_fd = open("/dev/urandom", O_RDONLY);
if (urandom_fd < 0) {
@@ -641,3 +641,4 @@ static void __init auth_mschap_v2_init()
log_emerg("mschap-v2: failed to register handler\n");
}
+DEFINE_INIT(4, auth_mschap_v2_init);
diff --git a/accel-pppd/auth/auth_pap.c b/accel-pppd/auth/auth_pap.c
index c03a9a1..5b20210 100644
--- a/accel-pppd/auth/auth_pap.c
+++ b/accel-pppd/auth/auth_pap.c
@@ -265,7 +265,7 @@ static void pap_recv(struct ppp_handler_t *h)
}
}
-static void __init auth_pap_init()
+static void auth_pap_init()
{
char *opt;
@@ -280,3 +280,4 @@ static void __init auth_pap_init()
ppp_auth_register_handler(&pap);
}
+DEFINE_INIT(4, auth_pap_init);
diff --git a/accel-pppd/cli/cli.c b/accel-pppd/cli/cli.c
index 5009a74..00d5ffb 100644
--- a/accel-pppd/cli/cli.c
+++ b/accel-pppd/cli/cli.c
@@ -219,9 +219,11 @@ static void load_config(void)
conf_cli_prompt = (char *)def_cli_prompt;
}
-static void __init init(void)
+static void init(void)
{
load_config();
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+
+DEFINE_INIT(10, init);
diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c
index 555fa88..3fb3f0a 100644
--- a/accel-pppd/cli/show_sessions.c
+++ b/accel-pppd/cli/show_sessions.c
@@ -417,7 +417,7 @@ static void print_sid(const struct ppp_t *ppp, char *buf)
snprintf(buf, CELL_SIZE, "%s", ppp->sessionid);
}
-void __init init(void)
+static void init(void)
{
cli_register_simple_cmd2(show_ses_exec, show_ses_help, 2, "show", "sessions");
@@ -432,3 +432,4 @@ void __init init(void)
cli_show_ses_register("sid", "session id", print_sid);
}
+DEFINE_INIT(12, init);
diff --git a/accel-pppd/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c
index 0754b19..e24b3fa 100644
--- a/accel-pppd/cli/std_cmd.c
+++ b/accel-pppd/cli/std_cmd.c
@@ -326,7 +326,7 @@ static void reload_help(char * const *fields, int fields_cnt, void *client)
cli_send(client, "reload - reload config file\r\n");
}
-static void __init init(void)
+static void init(void)
{
cli_register_simple_cmd2(show_stat_exec, show_stat_help, 2, "show", "stat");
cli_register_simple_cmd2(terminate_exec, terminate_help, 1, "terminate");
@@ -335,3 +335,4 @@ static void __init init(void)
cli_register_simple_cmd2(exit_exec, exit_help, 1, "exit");
}
+DEFINE_INIT(12, init);
diff --git a/accel-pppd/cli/tcp.c b/accel-pppd/cli/tcp.c
index 260225f..fea0e4e 100644
--- a/accel-pppd/cli/tcp.c
+++ b/accel-pppd/cli/tcp.c
@@ -339,7 +339,7 @@ static void start_server(const char *host, int port)
triton_context_wakeup(&serv_ctx);
}
-static void __init init(void)
+static void init(void)
{
const char *opt;
char *host, *d;
@@ -369,3 +369,4 @@ err_fmt:
free(host);
}
+DEFINE_INIT(11, init);
diff --git a/accel-pppd/cli/telnet.c b/accel-pppd/cli/telnet.c
index 82bcb0d..2643692 100644
--- a/accel-pppd/cli/telnet.c
+++ b/accel-pppd/cli/telnet.c
@@ -718,7 +718,7 @@ static void load_history_file(void)
fclose(f);
}
-static void __init init(void)
+static void init(void)
{
const char *opt;
char *host, *d;
@@ -757,3 +757,4 @@ err_fmt:
free(host);
}
+DEFINE_INIT(11, init);
diff --git a/accel-pppd/ctrl/l2tp/dict.c b/accel-pppd/ctrl/l2tp/dict.c
index c93ccd4..aaa7da4 100644
--- a/accel-pppd/ctrl/l2tp/dict.c
+++ b/accel-pppd/ctrl/l2tp/dict.c
@@ -257,7 +257,7 @@ static int l2tp_dict_load(const char *fname)
return r;
}
-static void __init dict_init(void)
+static void dict_init(void)
{
char *opt;
@@ -269,3 +269,4 @@ static void __init dict_init(void)
_exit(EXIT_FAILURE);
}
+DEFINE_INIT(20, dict_init);
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index 8dcfb40..0f36a98 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -1128,7 +1128,7 @@ static void load_config(void)
conf_dir300_quirk = atoi(opt);
}
-static void __init l2tp_init(void)
+static void l2tp_init(void)
{
l2tp_conn = malloc(L2TP_MAX_TID * sizeof(void *));
memset(l2tp_conn, 0, L2TP_MAX_TID * sizeof(void *));
@@ -1144,3 +1144,4 @@ static void __init l2tp_init(void)
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+DEFINE_INIT(22, l2tp_init);
diff --git a/accel-pppd/ctrl/l2tp/netlink.c b/accel-pppd/ctrl/l2tp/netlink.c
index 7c8c79a..c8dce89 100644
--- a/accel-pppd/ctrl/l2tp/netlink.c
+++ b/accel-pppd/ctrl/l2tp/netlink.c
@@ -80,7 +80,7 @@ void l2tp_nl_create_session(int tid, int sid, int peer_sid)
nl_socket_free(nl_sock);
}
-static void __init init(void)
+static void init(void)
{
struct nl_sock *nl_sock = nl_socket_alloc();
@@ -92,3 +92,4 @@ static void __init init(void)
nl_socket_free(nl_sock);
}
+DEFINE_INIT(21, init);
diff --git a/accel-pppd/ctrl/l2tp/packet.c b/accel-pppd/ctrl/l2tp/packet.c
index e3f6896..d312118 100644
--- a/accel-pppd/ctrl/l2tp/packet.c
+++ b/accel-pppd/ctrl/l2tp/packet.c
@@ -485,10 +485,11 @@ int l2tp_packet_add_octets(struct l2tp_packet_t *pack, int id, const uint8_t *va
return 0;
}
-static void __init init(void)
+static void init(void)
{
attr_pool = mempool_create(sizeof(struct l2tp_attr_t));
pack_pool = mempool_create(sizeof(struct l2tp_packet_t));
buf_pool = mempool_create(L2TP_MAX_PACKET_SIZE);
}
+DEFINE_INIT(21, init);
diff --git a/accel-pppd/ctrl/pppoe/cli.c b/accel-pppd/ctrl/pppoe/cli.c
index 9929f66..37aec3a 100644
--- a/accel-pppd/ctrl/pppoe/cli.c
+++ b/accel-pppd/ctrl/pppoe/cli.c
@@ -189,7 +189,7 @@ static int set_ac_name_exec(const char *cmd, char * const *f, int f_cnt, void *c
//===================================
-static void __init init(void)
+static void init(void)
{
cli_register_simple_cmd2(show_stat_exec, NULL, 2, "show", "stat");
cli_register_simple_cmd2(intf_exec, intf_help, 2, "pppoe", "interface");
@@ -203,3 +203,4 @@ static void __init init(void)
cli_register_simple_cmd2(show_ac_name_exec, NULL, 3, "pppoe", "show", "AC-Name");
}
+DEFINE_INIT(22, init);
diff --git a/accel-pppd/ctrl/pppoe/mac_filter.c b/accel-pppd/ctrl/pppoe/mac_filter.c
index 9b101c6..8d72c31 100644
--- a/accel-pppd/ctrl/pppoe/mac_filter.c
+++ b/accel-pppd/ctrl/pppoe/mac_filter.c
@@ -244,7 +244,7 @@ static void cmd_help(char * const *fields, int fields_cnt, void *client)
cli_send(client, "pppoe mac-filter show - show current mac-filter list\r\n");
}
-static void __init init(void)
+static void init(void)
{
const char *opt = conf_get_opt("pppoe", "mac-filter");
if (!opt || mac_filter_load(opt))
@@ -253,3 +253,4 @@ static void __init init(void)
cli_register_simple_cmd2(cmd_exec, cmd_help, 2, "pppoe", "mac-filter");
}
+DEFINE_INIT(20, init);
diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c
index c7612e2..cd1d256 100644
--- a/accel-pppd/ctrl/pppoe/pppoe.c
+++ b/accel-pppd/ctrl/pppoe/pppoe.c
@@ -1241,7 +1241,7 @@ static int init_secret(struct pppoe_serv_t *serv)
return 0;
}
-static void __init pppoe_init(void)
+static void pppoe_init(void)
{
struct conf_sect_t *s = conf_get_section("pppoe");
struct conf_option_t *opt;
@@ -1288,3 +1288,4 @@ static void __init pppoe_init(void)
conf_ac_name = _strdup("accel-ppp");
}
+DEFINE_INIT(21, pppoe_init);
diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c
index 17087fa..1626712 100644
--- a/accel-pppd/ctrl/pptp/pptp.c
+++ b/accel-pppd/ctrl/pptp/pptp.c
@@ -724,7 +724,7 @@ static void load_config(void)
conf_verbose = 1;
}
-static void __init pptp_init(void)
+static void pptp_init(void)
{
struct sockaddr_in addr;
char *opt;
@@ -776,3 +776,4 @@ static void __init pptp_init(void)
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+DEFINE_INIT(20, pptp_init);
diff --git a/accel-pppd/extra/chap-secrets.c b/accel-pppd/extra/chap-secrets.c
index a42ab23..ee83bce 100644
--- a/accel-pppd/extra/chap-secrets.c
+++ b/accel-pppd/extra/chap-secrets.c
@@ -268,7 +268,7 @@ static void load_config(void)
conf_gw_ip_address = inet_addr(opt);
}
-static void __init init(void)
+static void init(void)
{
load_config();
@@ -280,3 +280,4 @@ static void __init init(void)
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+DEFINE_INIT(100, init);
diff --git a/accel-pppd/extra/ippool.c b/accel-pppd/extra/ippool.c
index 20da17c..b5711d0 100644
--- a/accel-pppd/extra/ippool.c
+++ b/accel-pppd/extra/ippool.c
@@ -182,7 +182,7 @@ static struct ipdb_t ipdb = {
.put = put_ip,
};
-static void __init ipool_init(void)
+static void ippool_init(void)
{
struct conf_sect_t *s = conf_get_section("ip-pool");
struct conf_option_t *opt;
@@ -206,3 +206,5 @@ static void __init ipool_init(void)
ipdb_register(&ipdb);
}
+DEFINE_INIT(100, ippool_init);
+
diff --git a/accel-pppd/extra/pppd_compat.c b/accel-pppd/extra/pppd_compat.c
index 5fa9beb..aa6f6b5 100644
--- a/accel-pppd/extra/pppd_compat.c
+++ b/accel-pppd/extra/pppd_compat.c
@@ -497,7 +497,7 @@ static void fill_env(char **env, struct pppd_compat_pd_t *pd)
}
}
-static void __init init(void)
+static void init(void)
{
char *opt;
@@ -537,3 +537,5 @@ static void __init init(void)
}
#endif
}
+
+DEFINE_INIT(101, init);
diff --git a/accel-pppd/extra/shaper_tbf.c b/accel-pppd/extra/shaper_tbf.c
index c276869..997b0e9 100644
--- a/accel-pppd/extra/shaper_tbf.c
+++ b/accel-pppd/extra/shaper_tbf.c
@@ -1256,7 +1256,7 @@ static int clock_init(void)
return 0;
}
-static void __init init(void)
+static void init(void)
{
if (clock_init())
return;
@@ -1281,3 +1281,4 @@ static void __init init(void)
cli_show_ses_register("rate-limit", "rate limit down-stream/up-stream (Kbit)", print_rate);
}
+DEFINE_INIT(100, init);
diff --git a/accel-pppd/extra/sigchld.c b/accel-pppd/extra/sigchld.c
index 08bab93..8f1a979 100644
--- a/accel-pppd/extra/sigchld.c
+++ b/accel-pppd/extra/sigchld.c
@@ -109,8 +109,10 @@ void __export sigchld_unlock()
pthread_mutex_unlock(&handlers_lock);
}
-static void __init init(void)
+static void init(void)
{
if (pthread_create(&sigchld_thr, NULL, sigchld_thread, NULL))
log_emerg("sigchld: pthread_create: %s\n", strerror(errno));
}
+
+DEFINE_INIT(100, init); \ No newline at end of file
diff --git a/accel-pppd/iprange.c b/accel-pppd/iprange.c
index 411dcb7..315a572 100644
--- a/accel-pppd/iprange.c
+++ b/accel-pppd/iprange.c
@@ -138,9 +138,10 @@ int __export iprange_tunnel_check(in_addr_t ipaddr)
return !check_range(&client_ranges, ipaddr);
}
-static void __init iprange_init(void)
+static void iprange_init(void)
{
load_ranges(&client_ranges, "client-ip-range");
//load_ranges(&tunnel_ranges, "tunnel-ip-range");
}
+DEFINE_INIT(10, iprange_init);
diff --git a/accel-pppd/log.c b/accel-pppd/log.c
index fc50d27..38f4bce 100644
--- a/accel-pppd/log.c
+++ b/accel-pppd/log.c
@@ -490,7 +490,7 @@ static void load_config(void)
}
}
-static void __init log_init(void)
+static void log_init(void)
{
struct sigaction sa = {
.sa_handler = sighup,
@@ -509,3 +509,4 @@ static void __init log_init(void)
sigaction(SIGHUP, &sa, NULL);
}
+DEFINE_INIT(0, log_init);
diff --git a/accel-pppd/logs/log_file.c b/accel-pppd/logs/log_file.c
index c6aed8e..f1a5018 100644
--- a/accel-pppd/logs/log_file.c
+++ b/accel-pppd/logs/log_file.c
@@ -678,7 +678,7 @@ static struct log_target_t fail_log_target =
};
-static void __init init(void)
+static void init(void)
{
char *opt;
@@ -765,3 +765,5 @@ static void __init init(void)
triton_event_register_handler(EV_CTRL_STARTED, (triton_event_func)ev_ctrl_started);
triton_event_register_handler(EV_CTRL_FINISHED, (triton_event_func)ev_ctrl_finished);
}
+
+DEFINE_INIT(1, init);
diff --git a/accel-pppd/logs/log_pgsql.c b/accel-pppd/logs/log_pgsql.c
index af67e0b..742ee62 100644
--- a/accel-pppd/logs/log_pgsql.c
+++ b/accel-pppd/logs/log_pgsql.c
@@ -280,7 +280,7 @@ static struct log_target_t target = {
.log = general_log,
};
-static void __init init(void)
+static void init(void)
{
char *opt;
@@ -319,3 +319,5 @@ static void __init init(void)
log_register_target(&target);
}
+
+DEFINE_INIT(1, init);
diff --git a/accel-pppd/logs/log_tcp.c b/accel-pppd/logs/log_tcp.c
index 306c450..ceaeb1c 100644
--- a/accel-pppd/logs/log_tcp.c
+++ b/accel-pppd/logs/log_tcp.c
@@ -301,7 +301,7 @@ static struct triton_context_t tcp_ctx ={
.before_switch = log_switch,
};
-static void __init init(void)
+static void init(void)
{
struct conf_sect_t *s = conf_get_section("log");
struct conf_option_t *opt;
@@ -321,3 +321,4 @@ static void __init init(void)
triton_context_wakeup(&tcp_ctx);
}
+DEFINE_INIT(1, init);
diff --git a/accel-pppd/main.c b/accel-pppd/main.c
index c408736..e153caf 100644
--- a/accel-pppd/main.c
+++ b/accel-pppd/main.c
@@ -14,77 +14,9 @@
#include "log.h"
#include "events.h"
-static int goto_daemon;
static char *pid_file;
static char *conf_file;
-#define ARG_MAX 128
-static int parse_cmdline(char ***argv)
-{
- FILE *f;
- int i;
- size_t len;
-
- f = fopen("/proc/self/cmdline", "r");
- if (!f) {
- perror("open cmdline");
- _exit(EXIT_FAILURE);
- }
-
- *argv = _malloc(ARG_MAX * sizeof(void *));
- memset(*argv, 0, ARG_MAX * sizeof(void *));
-
- for(i = 0; i < ARG_MAX; i++) {
- len = 0;
- if (getdelim(&(*argv)[i], &len, 0, f) < 0)
- break;
- }
-
- fclose(f);
-
- return i;
-}
-static void __init __main(void)
-{
- int i,argc;
- char **argv;
-
- argc=parse_cmdline(&argv);
-
- if (argc < 2)
- goto usage;
-
- for(i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-d"))
- goto_daemon = 1;
- else if (!strcmp(argv[i], "-p")) {
- if (i == argc - 1)
- goto usage;
- pid_file = argv[++i];
- } else if (!strcmp(argv[i], "-c")) {
- if (i == argc - 1)
- goto usage;
- conf_file = argv[++i];
- }
- }
-
- if (!conf_file)
- goto usage;
-
- if (triton_init(conf_file))
- _exit(EXIT_FAILURE);
-
- return;
-
-usage:
- printf("usage: accel-pppd [-d] [-p <file>] -c <file>\n\
- where:\n\
- -d - daemon mode\n\
- -p - write pid to <file>\n\
- -c - config file\n");
- _exit(EXIT_FAILURE);
-}
-
static void change_limits(void)
{
FILE *f;
@@ -126,7 +58,30 @@ static void config_reload(int num)
int main(int argc, char **argv)
{
sigset_t set;
- int sig;
+ int i, sig, goto_daemon = 0;
+
+ if (argc < 2)
+ goto usage;
+
+ for(i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-d"))
+ goto_daemon = 1;
+ else if (!strcmp(argv[i], "-p")) {
+ if (i == argc - 1)
+ goto usage;
+ pid_file = argv[++i];
+ } else if (!strcmp(argv[i], "-c")) {
+ if (i == argc - 1)
+ goto usage;
+ conf_file = argv[++i];
+ }
+ }
+
+ if (!conf_file)
+ goto usage;
+
+ if (triton_init(conf_file))
+ _exit(EXIT_FAILURE);
if (goto_daemon) {
/*pid_t pid = fork();
@@ -157,9 +112,6 @@ int main(int argc, char **argv)
}
}
- //signal(SIGTERM, sigterm);
- //signal(SIGPIPE, sigterm);
-
change_limits();
if (triton_load_modules("modules"))
@@ -206,5 +158,13 @@ int main(int argc, char **argv)
triton_terminate();
return EXIT_SUCCESS;
+
+usage:
+ printf("usage: accel-pppd [-d] [-p <file>] -c <file>\n\
+ where:\n\
+ -d - daemon mode\n\
+ -p - write pid to <file>\n\
+ -c - config file\n");
+ _exit(EXIT_FAILURE);
}
diff --git a/accel-pppd/ppp/ccp_mppe.c b/accel-pppd/ppp/ccp_mppe.c
index 9c3febe..58f5d4f 100644
--- a/accel-pppd/ppp/ccp_mppe.c
+++ b/accel-pppd/ppp/ccp_mppe.c
@@ -289,7 +289,7 @@ static void load_config(void)
conf_mppe = -1;
}
-static void __init mppe_opt_init()
+static void mppe_opt_init()
{
ccp_option_register(&mppe_opt_hnd);
triton_event_register_handler(EV_MPPE_KEYS, (triton_event_func)ev_mppe_keys);
@@ -298,3 +298,4 @@ static void __init mppe_opt_init()
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+DEFINE_INIT(4, mppe_opt_init);
diff --git a/accel-pppd/ppp/ipcp_opt_dns.c b/accel-pppd/ppp/ipcp_opt_dns.c
index f488f3c..4427b0e 100644
--- a/accel-pppd/ppp/ipcp_opt_dns.c
+++ b/accel-pppd/ppp/ipcp_opt_dns.c
@@ -152,7 +152,7 @@ static void load_config(void)
conf_dns2 = inet_addr(opt);
}
-static void __init dns_opt_init()
+static void dns_opt_init()
{
ipcp_option_register(&dns1_opt_hnd);
ipcp_option_register(&dns2_opt_hnd);
@@ -160,3 +160,5 @@ static void __init dns_opt_init()
load_config();
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+
+DEFINE_INIT(4, dns_opt_init);
diff --git a/accel-pppd/ppp/ipcp_opt_ipaddr.c b/accel-pppd/ppp/ipcp_opt_ipaddr.c
index ed0de51..388df19 100644
--- a/accel-pppd/ppp/ipcp_opt_ipaddr.c
+++ b/accel-pppd/ppp/ipcp_opt_ipaddr.c
@@ -216,7 +216,7 @@ static void load_config(void)
conf_check_exists = 1;
}
-static void __init ipaddr_opt_init()
+static void ipaddr_opt_init()
{
ipcp_option_register(&ipaddr_opt_hnd);
load_config();
@@ -224,3 +224,4 @@ static void __init ipaddr_opt_init()
triton_event_register_handler(EV_PPP_STARTED, (triton_event_func)if_up);
}
+DEFINE_INIT(4, ipaddr_opt_init);
diff --git a/accel-pppd/ppp/lcp_opt_accomp.c b/accel-pppd/ppp/lcp_opt_accomp.c
index 241b0e0..33347d8 100644
--- a/accel-pppd/ppp/lcp_opt_accomp.c
+++ b/accel-pppd/ppp/lcp_opt_accomp.c
@@ -99,8 +99,9 @@ static void accomp_print(void (*print)(const char *fmt,...),struct lcp_option_t
print("<accomp>");
}
-static void __init accomp_opt_init()
+static void accomp_opt_init()
{
lcp_option_register(&accomp_opt_hnd);
}
+DEFINE_INIT(4, accomp_opt_init);
diff --git a/accel-pppd/ppp/lcp_opt_magic.c b/accel-pppd/ppp/lcp_opt_magic.c
index 6c0deb5..3e694d2 100644
--- a/accel-pppd/ppp/lcp_opt_magic.c
+++ b/accel-pppd/ppp/lcp_opt_magic.c
@@ -99,7 +99,9 @@ static void magic_print(void (*print)(const char *fmt,...),struct lcp_option_t *
print("<magic %04x>", magic_opt->magic);
}
-static void __init magic_opt_init()
+static void magic_opt_init()
{
lcp_option_register(&magic_opt_hnd);
}
+
+DEFINE_INIT(4, magic_opt_init);
diff --git a/accel-pppd/ppp/lcp_opt_mru.c b/accel-pppd/ppp/lcp_opt_mru.c
index 78e06b5..577e019 100644
--- a/accel-pppd/ppp/lcp_opt_mru.c
+++ b/accel-pppd/ppp/lcp_opt_mru.c
@@ -186,10 +186,11 @@ static void load_config(void)
}
}
-static void __init mru_opt_init()
+static void mru_opt_init()
{
load_config();
lcp_option_register(&mru_opt_hnd);
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+DEFINE_INIT(4, mru_opt_init);
diff --git a/accel-pppd/ppp/lcp_opt_pcomp.c b/accel-pppd/ppp/lcp_opt_pcomp.c
index 1f8532b..fec5e7b 100644
--- a/accel-pppd/ppp/lcp_opt_pcomp.c
+++ b/accel-pppd/ppp/lcp_opt_pcomp.c
@@ -99,8 +99,9 @@ static void pcomp_print(void (*print)(const char *fmt,...),struct lcp_option_t *
print("<pcomp>");
}
-static void __init pcomp_opt_init()
+static void pcomp_opt_init()
{
lcp_option_register(&pcomp_opt_hnd);
}
+DEFINE_INIT(4, pcomp_opt_init);
diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c
index 5a4006c..e62107f 100644
--- a/accel-pppd/ppp/ppp.c
+++ b/accel-pppd/ppp/ppp.c
@@ -652,7 +652,7 @@ static void load_config(void)
conf_single_session = -1;
}
-static void __init init(void)
+static void init(void)
{
char *opt;
FILE *f;
@@ -682,3 +682,4 @@ static void __init init(void)
atexit(save_seq);
}
+DEFINE_INIT(2, init);
diff --git a/accel-pppd/ppp/ppp_auth.c b/accel-pppd/ppp/ppp_auth.c
index c67b4e2..e02d8c1 100644
--- a/accel-pppd/ppp/ppp_auth.c
+++ b/accel-pppd/ppp/ppp_auth.c
@@ -372,9 +372,10 @@ int __export ppp_auth_restart(struct ppp_t *ppp)
return 0;
}
-static void __init ppp_auth_init()
+static void ppp_auth_init()
{
ppp_register_layer("auth", &auth_layer);
lcp_option_register(&auth_opt_hnd);
}
+DEFINE_INIT(3, ppp_auth_init);
diff --git a/accel-pppd/ppp/ppp_ccp.c b/accel-pppd/ppp/ppp_ccp.c
index 5a5d6f1..7c19191 100644
--- a/accel-pppd/ppp/ppp_ccp.c
+++ b/accel-pppd/ppp/ppp_ccp.c
@@ -762,7 +762,7 @@ static void load_config(void)
conf_ccp = atoi(opt);
}
-static void __init ccp_init(void)
+static void ccp_init(void)
{
ppp_register_layer("ccp", &ccp_layer);
@@ -770,3 +770,4 @@ static void __init ccp_init(void)
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+DEFINE_INIT(3, ccp_init);
diff --git a/accel-pppd/ppp/ppp_fsm.c b/accel-pppd/ppp/ppp_fsm.c
index 01427a6..180b30e 100644
--- a/accel-pppd/ppp/ppp_fsm.c
+++ b/accel-pppd/ppp/ppp_fsm.c
@@ -538,9 +538,10 @@ static void load_config(void)
conf_timeout = atoi(opt);
}
-void __init fsm_init(void)
+static void fsm_init(void)
{
load_config();
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+DEFINE_INIT(3, fsm_init);
diff --git a/accel-pppd/ppp/ppp_ipcp.c b/accel-pppd/ppp/ppp_ipcp.c
index 72760d5..3962702 100644
--- a/accel-pppd/ppp/ppp_ipcp.c
+++ b/accel-pppd/ppp/ppp_ipcp.c
@@ -688,8 +688,9 @@ static struct ppp_layer_t ipcp_layer =
.free = ipcp_layer_free,
};
-static void __init ipcp_init(void)
+static void ipcp_init(void)
{
ppp_register_layer("ipcp", &ipcp_layer);
}
+DEFINE_INIT(3, ipcp_init);
diff --git a/accel-pppd/ppp/ppp_lcp.c b/accel-pppd/ppp/ppp_lcp.c
index 56a3ca6..048ada5 100644
--- a/accel-pppd/ppp/ppp_lcp.c
+++ b/accel-pppd/ppp/ppp_lcp.c
@@ -845,7 +845,7 @@ static void load_config(void)
conf_echo_failure = atoi(opt);
}
-static void __init lcp_init(void)
+static void lcp_init(void)
{
load_config();
@@ -854,3 +854,4 @@ static void __init lcp_init(void)
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+DEFINE_INIT(3, lcp_init);
diff --git a/accel-pppd/radius/dm_coa.c b/accel-pppd/radius/dm_coa.c
index 366bb41..005ecfd 100644
--- a/accel-pppd/radius/dm_coa.c
+++ b/accel-pppd/radius/dm_coa.c
@@ -256,7 +256,7 @@ static struct dm_coa_serv_t serv = {
.hnd.read = dm_coa_read,
};
-static void __init init(void)
+static void init(void)
{
struct sockaddr_in addr;
@@ -293,3 +293,5 @@ static void __init init(void)
triton_md_enable_handler(&serv.hnd, MD_MODE_READ);
triton_context_wakeup(&serv.ctx);
}
+
+DEFINE_INIT(101, init);
diff --git a/accel-pppd/radius/packet.c b/accel-pppd/radius/packet.c
index b6230d6..db45c6a 100644
--- a/accel-pppd/radius/packet.c
+++ b/accel-pppd/radius/packet.c
@@ -648,9 +648,11 @@ int rad_packet_send(struct rad_packet_t *pack, int fd, struct sockaddr_in *addr)
return 0;
}
-static void __init init(void)
+static void init(void)
{
attr_pool = mempool_create(sizeof(struct rad_attr_t));
packet_pool = mempool_create(sizeof(struct rad_packet_t));
buf_pool = mempool_create(REQ_LENGTH_MAX);
}
+
+DEFINE_INIT(101, init);
diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c
index 1900e0f..2bf9bd4 100644
--- a/accel-pppd/radius/radius.c
+++ b/accel-pppd/radius/radius.c
@@ -535,7 +535,7 @@ static int load_config(void)
return 0;
}
-static void __init radius_init(void)
+static void radius_init(void)
{
char *opt;
char *dict = DICTIONARY;
@@ -579,3 +579,4 @@ static void __init radius_init(void)
stat_interim_query_5m = stat_accm_create(5 * 60);
}
+DEFINE_INIT(100, radius_init);
diff --git a/accel-pppd/radius/req.c b/accel-pppd/radius/req.c
index 1fa79ad..7464ac9 100644
--- a/accel-pppd/radius/req.c
+++ b/accel-pppd/radius/req.c
@@ -268,7 +268,7 @@ int rad_req_wait(struct rad_req_t *req, int timeout)
return 0;
}
-void __init req_init(void)
+static void req_init(void)
{
urandom_fd = open("/dev/urandom", O_RDONLY);
if (!urandom_fd) {
@@ -276,3 +276,5 @@ void __init req_init(void)
_exit(EXIT_FAILURE);
}
}
+
+DEFINE_INIT(101, req_init);
diff --git a/accel-pppd/radius/stat_accm.c b/accel-pppd/radius/stat_accm.c
index 8d4ad3d..53c23cb 100644
--- a/accel-pppd/radius/stat_accm.c
+++ b/accel-pppd/radius/stat_accm.c
@@ -90,8 +90,9 @@ unsigned long stat_accm_get_avg(struct stat_accm_t *s)
return val;
}
-static void __init init(void)
+static void init(void)
{
item_pool = mempool_create(sizeof(struct item_t));
}
+DEFINE_INIT(101, init);
diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c
index df3d5c1..4d3359b 100644
--- a/accel-pppd/triton/triton.c
+++ b/accel-pppd/triton/triton.c
@@ -22,6 +22,8 @@ static LIST_HEAD(ctx_queue);
static spinlock_t ctx_list_lock = SPINLOCK_INITIALIZER;
static LIST_HEAD(ctx_list);
+static LIST_HEAD(init_list);
+
static int terminate;
static int need_terminate;
@@ -523,6 +525,24 @@ static void ru_update(struct triton_timer_t *t)
ru_stime = rusage.ru_stime;
}
+void __export triton_register_init(int order, void (*func)(void))
+{
+ struct _triton_init_t *i1, *i = _malloc(sizeof(*i));
+ struct list_head *p = init_list.prev;
+
+
+ i->order = order;
+ i->func = func;
+
+ while (p != &init_list) {
+ i1 = list_entry(p, typeof(*i1), entry);
+ if (order > i1->order)
+ break;
+ p = p->prev;
+ }
+ list_add(&i->entry, p);
+}
+
int __export triton_init(const char *conf_file)
{
ctx_pool = mempool_create(sizeof(struct _triton_context_t));
@@ -548,8 +568,17 @@ int __export triton_init(const char *conf_file)
int __export triton_load_modules(const char *mod_sect)
{
+ struct _triton_init_t *i;
+
if (load_modules(mod_sect))
return -1;
+
+ while (!list_empty(&init_list)) {
+ i = list_entry(init_list.next, typeof(*i), entry);
+ i->func();
+ list_del(&i->entry);
+ _free(i);
+ }
return 0;
}
diff --git a/accel-pppd/triton/triton.h b/accel-pppd/triton/triton.h
index 98ef111..95851c2 100644
--- a/accel-pppd/triton/triton.h
+++ b/accel-pppd/triton/triton.h
@@ -106,6 +106,8 @@ void triton_stop_collect_cpu_usage(void);
int triton_module_loaded(const char *name);
+void triton_register_init(int order, void (*func)(void));
+
#define TRITON_OK 0
#define TRITON_ERR_NOCOMP -1
@@ -137,4 +139,6 @@ void triton_terminate(void);
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
+#define DEFINE_INIT(o, func) static void __init __init__(void){triton_register_init(o,func);}
+
#endif
diff --git a/accel-pppd/triton/triton_p.h b/accel-pppd/triton/triton_p.h
index 235eb70..2eb2e62 100644
--- a/accel-pppd/triton/triton_p.h
+++ b/accel-pppd/triton/triton_p.h
@@ -82,6 +82,14 @@ struct _triton_ctx_call_t
void (*func)(void *);
};
+struct _triton_init_t
+{
+ struct list_head entry;
+
+ int order;
+ void (*func)(void);
+};
+
int log_init(void);
int md_init();
int timer_init();