2008-04-01 18:52:26 +02:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
2016-03-06 10:49:27 +01:00
|
|
|
* rb_lib.c: libircd initialization functions at the like
|
2008-04-01 18:52:26 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005,2006 ircd-ratbox development team
|
|
|
|
* Copyright (C) 2005,2006 Aaron Sethman <androsyn@ratbox.org>
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-07-01 05:04:00 +02:00
|
|
|
#include <rb/rb.h>
|
2016-07-13 07:17:21 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2016-07-01 05:04:00 +02:00
|
|
|
#include <rb/commio_int.h>
|
2016-07-13 07:17:21 +02:00
|
|
|
#include <rb/event_int.h>
|
2016-07-01 05:04:00 +02:00
|
|
|
#include <rb/ssl.h>
|
2016-07-13 07:17:21 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 00:45:24 +02:00
|
|
|
#ifdef HAVE_EXECINFO_H
|
|
|
|
#include <execinfo.h>
|
|
|
|
#endif
|
|
|
|
|
2008-04-01 18:52:26 +02:00
|
|
|
static log_cb *rb_log;
|
|
|
|
static restart_cb *rb_restart;
|
|
|
|
static die_cb *rb_die;
|
|
|
|
|
|
|
|
static struct timeval rb_time;
|
|
|
|
static char errbuf[512];
|
|
|
|
|
|
|
|
/* this doesn't do locales...oh well i guess */
|
|
|
|
|
|
|
|
static const char *months[] = {
|
2008-12-03 00:49:39 +01:00
|
|
|
"January", "February", "March", "April",
|
|
|
|
"May", "June", "July", "August",
|
|
|
|
"September", "October", "November", "December"
|
2008-04-01 18:52:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *weekdays[] = {
|
2008-12-03 00:49:39 +01:00
|
|
|
"Sunday", "Monday", "Tuesday", "Wednesday",
|
|
|
|
"Thursday", "Friday", "Saturday"
|
2008-04-01 18:52:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *s_month[] = {
|
|
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
|
|
|
|
"Aug", "Sep", "Oct", "Nov", "Dec"
|
2008-12-03 00:49:39 +01:00
|
|
|
};
|
2008-04-01 18:52:26 +02:00
|
|
|
|
|
|
|
static const char *s_weekdays[] = {
|
|
|
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
|
|
|
};
|
|
|
|
|
|
|
|
char *
|
|
|
|
rb_ctime(const time_t t, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
struct tm *tp;
|
|
|
|
static char timex[128];
|
|
|
|
size_t tlen;
|
|
|
|
#if defined(HAVE_GMTIME_R)
|
|
|
|
struct tm tmr;
|
|
|
|
tp = gmtime_r(&t, &tmr);
|
|
|
|
#else
|
|
|
|
tp = gmtime(&t);
|
|
|
|
#endif
|
|
|
|
if(buf == NULL)
|
|
|
|
{
|
|
|
|
p = timex;
|
|
|
|
tlen = sizeof(timex);
|
2008-12-03 00:49:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-01 18:52:26 +02:00
|
|
|
p = buf;
|
|
|
|
tlen = len;
|
|
|
|
}
|
|
|
|
|
2010-11-23 15:52:18 +01:00
|
|
|
if(rb_unlikely(tp == NULL))
|
|
|
|
{
|
|
|
|
rb_strlcpy(p, "", tlen);
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(p, tlen, "%s %s %d %02u:%02u:%02u %d",
|
2008-12-03 00:49:39 +01:00
|
|
|
s_weekdays[tp->tm_wday], s_month[tp->tm_mon],
|
|
|
|
tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, tp->tm_year + 1900);
|
|
|
|
return (p);
|
2008-04-01 18:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* I hate this..but its sort of ircd standard now.. */
|
|
|
|
char *
|
|
|
|
rb_date(const time_t t, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct tm *gm;
|
|
|
|
#if defined(HAVE_GMTIME_R)
|
|
|
|
struct tm gmbuf;
|
|
|
|
gm = gmtime_r(&t, &gmbuf);
|
|
|
|
#else
|
|
|
|
gm = gmtime(&t);
|
|
|
|
#endif
|
|
|
|
|
2008-06-25 07:28:30 +02:00
|
|
|
if(rb_unlikely(gm == NULL))
|
2008-04-01 18:52:26 +02:00
|
|
|
{
|
2008-12-03 00:49:39 +01:00
|
|
|
rb_strlcpy(buf, "", len);
|
|
|
|
return (buf);
|
2008-04-01 18:52:26 +02:00
|
|
|
}
|
2008-12-03 00:49:39 +01:00
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(buf, len, "%s %s %d %d -- %02u:%02u:%02u +00:00",
|
2008-12-03 00:49:39 +01:00
|
|
|
weekdays[gm->tm_wday], months[gm->tm_mon], gm->tm_mday,
|
|
|
|
gm->tm_year + 1900, gm->tm_hour, gm->tm_min, gm->tm_sec);
|
|
|
|
return (buf);
|
2008-04-01 18:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
time_t
|
|
|
|
rb_current_time(void)
|
|
|
|
{
|
|
|
|
return rb_time.tv_sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct timeval *
|
|
|
|
rb_current_time_tv(void)
|
|
|
|
{
|
|
|
|
return &rb_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_lib_log(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
if(rb_log == NULL)
|
|
|
|
return;
|
|
|
|
va_start(args, format);
|
2016-02-10 02:25:32 +01:00
|
|
|
vsnprintf(errbuf, sizeof(errbuf), format, args);
|
2008-04-01 18:52:26 +02:00
|
|
|
va_end(args);
|
|
|
|
rb_log(errbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_lib_die(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
if(rb_die == NULL)
|
|
|
|
abort();
|
|
|
|
va_start(args, format);
|
2016-02-10 02:25:32 +01:00
|
|
|
vsnprintf(errbuf, sizeof(errbuf), format, args);
|
2008-04-01 18:52:26 +02:00
|
|
|
va_end(args);
|
|
|
|
rb_die(errbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_lib_restart(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
if(rb_restart == NULL)
|
|
|
|
abort();
|
|
|
|
va_start(args, format);
|
2016-02-10 02:25:32 +01:00
|
|
|
vsnprintf(errbuf, sizeof(errbuf), format, args);
|
2008-04-01 18:52:26 +02:00
|
|
|
va_end(args);
|
|
|
|
rb_restart(errbuf);
|
2014-02-28 00:53:13 +01:00
|
|
|
abort();
|
2008-04-01 18:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_set_time(void)
|
|
|
|
{
|
|
|
|
struct timeval newtime;
|
|
|
|
|
2008-06-25 07:28:30 +02:00
|
|
|
if(rb_unlikely(rb_gettimeofday(&newtime, NULL) == -1))
|
2008-04-01 18:52:26 +02:00
|
|
|
{
|
|
|
|
rb_lib_log("Clock Failure (%s)", strerror(errno));
|
|
|
|
rb_lib_restart("Clock Failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newtime.tv_sec < rb_time.tv_sec)
|
|
|
|
rb_set_back_events(rb_time.tv_sec - newtime.tv_sec);
|
|
|
|
|
|
|
|
memcpy(&rb_time, &newtime, sizeof(struct timeval));
|
|
|
|
}
|
|
|
|
|
2016-07-01 05:04:00 +02:00
|
|
|
extern const char *rb_serno;
|
2008-12-03 00:49:39 +01:00
|
|
|
|
2008-04-01 18:52:26 +02:00
|
|
|
const char *
|
|
|
|
rb_lib_version(void)
|
|
|
|
{
|
2008-12-22 10:49:01 +01:00
|
|
|
static char version_info[512];
|
|
|
|
char ssl_info[512];
|
|
|
|
rb_get_ssl_info(ssl_info, sizeof(ssl_info));
|
2016-07-01 05:04:00 +02:00
|
|
|
snprintf(version_info, sizeof(version_info), "librb version: %s - %s", rb_serno, ssl_info);
|
2008-12-22 10:49:01 +01:00
|
|
|
return version_info;
|
2008-04-01 18:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-12-03 00:49:39 +01:00
|
|
|
rb_lib_init(log_cb * ilog, restart_cb * irestart, die_cb * idie, int closeall, int maxcon,
|
|
|
|
size_t dh_size, size_t fd_heap_size)
|
2008-04-01 18:52:26 +02:00
|
|
|
{
|
|
|
|
rb_set_time();
|
|
|
|
rb_log = ilog;
|
|
|
|
rb_restart = irestart;
|
|
|
|
rb_die = idie;
|
|
|
|
rb_event_init();
|
|
|
|
rb_init_bh();
|
|
|
|
rb_fdlist_init(closeall, maxcon, fd_heap_size);
|
|
|
|
rb_init_netio();
|
|
|
|
rb_init_rb_dlink_nodes(dh_size);
|
|
|
|
if(rb_io_supports_event())
|
|
|
|
{
|
|
|
|
rb_io_init_event();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_lib_loop(long delay)
|
|
|
|
{
|
|
|
|
time_t next;
|
|
|
|
rb_set_time();
|
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
if(delay == 0)
|
|
|
|
delay = -1;
|
2008-04-01 18:52:26 +02:00
|
|
|
|
|
|
|
while(1)
|
2016-07-13 07:17:21 +02:00
|
|
|
rb_select(-1);
|
2008-04-01 18:52:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_STRTOK_R
|
|
|
|
char *
|
2008-12-03 00:49:39 +01:00
|
|
|
rb_strtok_r(char *s, const char *delim, char **save)
|
2008-04-01 18:52:26 +02:00
|
|
|
{
|
|
|
|
char *token;
|
|
|
|
|
2008-12-03 00:49:39 +01:00
|
|
|
if(s == NULL)
|
2008-04-01 18:52:26 +02:00
|
|
|
s = *save;
|
|
|
|
|
|
|
|
/* Scan leading delimiters. */
|
|
|
|
s += strspn(s, delim);
|
|
|
|
|
2008-12-03 00:49:39 +01:00
|
|
|
if(*s == '\0')
|
2008-04-01 18:52:26 +02:00
|
|
|
{
|
|
|
|
*save = s;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
token = s;
|
|
|
|
s = strpbrk(token, delim);
|
2008-12-03 00:49:39 +01:00
|
|
|
|
|
|
|
if(s == NULL)
|
2008-04-01 18:52:26 +02:00
|
|
|
*save = (token + strlen(token));
|
|
|
|
else
|
|
|
|
{
|
2008-12-03 00:49:39 +01:00
|
|
|
*s = '\0';
|
2008-04-01 18:52:26 +02:00
|
|
|
*save = s + 1;
|
|
|
|
}
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
#else
|
2008-12-03 00:49:39 +01:00
|
|
|
char *
|
|
|
|
rb_strtok_r(char *s, const char *delim, char **save)
|
2008-04-01 18:52:26 +02:00
|
|
|
{
|
|
|
|
return strtok_r(s, delim, save);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static const char base64_table[] =
|
|
|
|
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
2008-12-03 00:49:39 +01:00
|
|
|
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
|
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
|
|
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
|
|
|
|
};
|
2008-04-01 18:52:26 +02:00
|
|
|
|
|
|
|
static const char base64_pad = '=';
|
|
|
|
|
|
|
|
static const short base64_reverse_table[256] = {
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
|
|
|
|
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
|
2008-12-03 00:49:39 +01:00
|
|
|
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
2008-04-01 18:52:26 +02:00
|
|
|
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
|
|
|
|
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
|
|
|
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned char *
|
|
|
|
rb_base64_encode(const unsigned char *str, int length)
|
|
|
|
{
|
|
|
|
const unsigned char *current = str;
|
|
|
|
unsigned char *p;
|
|
|
|
unsigned char *result;
|
|
|
|
|
2008-12-03 00:49:39 +01:00
|
|
|
if((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2)))
|
|
|
|
{
|
2008-04-01 18:52:26 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
result = (unsigned char *)rb_malloc(((length + 2) / 3) * 5);
|
2008-04-01 18:52:26 +02:00
|
|
|
p = result;
|
|
|
|
|
2008-12-03 00:49:39 +01:00
|
|
|
while(length > 2)
|
|
|
|
{
|
2008-04-01 18:52:26 +02:00
|
|
|
*p++ = base64_table[current[0] >> 2];
|
|
|
|
*p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
|
|
|
|
*p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
|
|
|
|
*p++ = base64_table[current[2] & 0x3f];
|
|
|
|
|
|
|
|
current += 3;
|
2008-12-03 00:49:39 +01:00
|
|
|
length -= 3;
|
2008-04-01 18:52:26 +02:00
|
|
|
}
|
|
|
|
|
2008-12-03 00:49:39 +01:00
|
|
|
if(length != 0)
|
|
|
|
{
|
2008-04-01 18:52:26 +02:00
|
|
|
*p++ = base64_table[current[0] >> 2];
|
2008-12-03 00:49:39 +01:00
|
|
|
if(length > 1)
|
|
|
|
{
|
2008-04-01 18:52:26 +02:00
|
|
|
*p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
|
|
|
|
*p++ = base64_table[(current[1] & 0x0f) << 2];
|
|
|
|
*p++ = base64_pad;
|
2008-12-03 00:49:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-01 18:52:26 +02:00
|
|
|
*p++ = base64_table[(current[0] & 0x03) << 4];
|
|
|
|
*p++ = base64_pad;
|
|
|
|
*p++ = base64_pad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char *
|
|
|
|
rb_base64_decode(const unsigned char *str, int length, int *ret)
|
|
|
|
{
|
|
|
|
const unsigned char *current = str;
|
|
|
|
int ch, i = 0, j = 0, k;
|
|
|
|
unsigned char *result;
|
2008-12-03 00:49:39 +01:00
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
result = (unsigned char *)rb_malloc(length + 1);
|
2008-04-01 18:52:26 +02:00
|
|
|
|
2008-12-03 00:49:39 +01:00
|
|
|
while((ch = *current++) != '\0' && length-- > 0)
|
|
|
|
{
|
|
|
|
if(ch == base64_pad)
|
|
|
|
break;
|
2008-04-01 18:52:26 +02:00
|
|
|
|
|
|
|
ch = base64_reverse_table[ch];
|
2008-12-03 00:49:39 +01:00
|
|
|
if(ch < 0)
|
|
|
|
continue;
|
2008-04-01 18:52:26 +02:00
|
|
|
|
2008-12-03 00:49:39 +01:00
|
|
|
switch (i % 4)
|
|
|
|
{
|
2008-04-01 18:52:26 +02:00
|
|
|
case 0:
|
|
|
|
result[j] = ch << 2;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
result[j++] |= ch >> 4;
|
|
|
|
result[j] = (ch & 0x0f) << 4;
|
|
|
|
break;
|
|
|
|
case 2:
|
2008-12-03 00:49:39 +01:00
|
|
|
result[j++] |= ch >> 2;
|
2008-04-01 18:52:26 +02:00
|
|
|
result[j] = (ch & 0x03) << 6;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
result[j++] |= ch;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
k = j;
|
|
|
|
|
2008-12-03 00:49:39 +01:00
|
|
|
if(ch == base64_pad)
|
|
|
|
{
|
|
|
|
switch (i % 4)
|
|
|
|
{
|
2008-04-01 18:52:26 +02:00
|
|
|
case 1:
|
|
|
|
free(result);
|
|
|
|
return NULL;
|
|
|
|
case 2:
|
|
|
|
k++;
|
2014-09-21 17:44:34 +02:00
|
|
|
/* FALLTHROUGH */
|
2008-04-01 18:52:26 +02:00
|
|
|
case 3:
|
|
|
|
result[k++] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result[j] = '\0';
|
|
|
|
*ret = j;
|
|
|
|
return result;
|
|
|
|
}
|
2016-06-29 00:45:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
void *bt_stack[64];
|
|
|
|
char bt_symbuf[64][256];
|
|
|
|
const char *bt_symbol[64];
|
|
|
|
|
|
|
|
#ifdef HAVE_EXECINFO_H
|
|
|
|
void *const *rb_backtrace(int *const usrlen)
|
|
|
|
{
|
|
|
|
int len = backtrace(bt_stack, 64);
|
|
|
|
if(usrlen) *usrlen = len;
|
|
|
|
return bt_stack;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void *const *rb_backtrace(int *const usrlen)
|
|
|
|
{
|
|
|
|
if(usrlen) *usrlen = 0;
|
|
|
|
return bt_stack;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_EXECINFO_H
|
|
|
|
const char *const *rb_backtrace_symbols(int *const usrlen)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
void *const *const stack = rb_backtrace(&len);
|
|
|
|
char *const *const symbol = backtrace_symbols(stack, len);
|
|
|
|
if(!symbol)
|
|
|
|
len = 0;
|
|
|
|
|
|
|
|
if(usrlen)
|
|
|
|
*usrlen = len;
|
|
|
|
|
|
|
|
for(int i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
rb_strlcpy(bt_symbuf[i], symbol[i], sizeof(bt_symbuf[i]));
|
|
|
|
bt_symbol[i] = bt_symbuf[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
free((char **)symbol);
|
|
|
|
return bt_symbol;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
const char *const *rb_backtrace_symbols(int *const usrlen)
|
|
|
|
{
|
|
|
|
if(usrlen) *usrlen = 0;
|
|
|
|
return bt_symbol;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_EXECINFO_H
|
|
|
|
void rb_backtrace_log_symbols(void)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
const char *const *const symbol = rb_backtrace_symbols(&len);
|
|
|
|
for(int i = 0; i < len; i++)
|
|
|
|
rb_lib_log("%2d: %s", i, symbol[i]);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void rb_backtrace_log_symbols(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|