Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix putlog timestamp: localtime() -> localtime_r() #1441

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
21 changes: 11 additions & 10 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static int nested_debug = 0;
static void write_debug()
{
int x;
char s[25];
char s[26];

if (nested_debug) {
/* Yoicks, if we have this there's serious trouble!
Expand All @@ -247,7 +247,7 @@ static void write_debug()
x = creat("DEBUG.DEBUG", 0644);
if (x >= 0) {
setsock(x, SOCK_NONSOCK);
strlcpy(s, ctime(&now), sizeof s);
ctime_r(&now, s);
dprintf(-x, "Debug (%s) written %s\n"
"Please report problem to https://github.com/eggheads/eggdrop/issues\n"
"Check doc/BUG-REPORT on how to do so.", ver, s);
Expand Down Expand Up @@ -275,8 +275,8 @@ static void write_debug()
if (x < 0) {
putlog(LOG_MISC, "*", "* Failed to write DEBUG");
} else {
strlcpy(s, ctime(&now), sizeof s);
dprintf(-x, "Debug (%s) written %s\n", ver, s);
ctime_r(&now, s);
dprintf(-x, "Debug (%s) written %s", ver, s);
#ifdef EGG_PATCH
dprintf(-x, "Patch level: %s\n", EGG_PATCH);
#else
Expand Down Expand Up @@ -575,7 +575,7 @@ static void core_secondly()
}
nowmins = now / 60;
if (nowmins > lastmin) {
memcpy(&nowtm, localtime(&now), sizeof(struct tm));
localtime_r(&now, &nowtm);
i = 0;
/* Once a minute */
++lastmin;
Expand All @@ -599,10 +599,11 @@ static void core_secondly()
check_botnet_pings();

if (!miltime) { /* At midnight */
char s[25];
char s[26];
int j;

strlcpy(s, ctime(&now), sizeof s);
ctime_r(&now, s);
s[24] = 0;
if (quiet_save < 3)
putlog(LOG_ALL, "*", "--- %.11s%s", s, s + 20);
call_hook(HOOK_BACKUP);
Expand Down Expand Up @@ -946,7 +947,7 @@ static void init_random(void) {
int main(int arg_c, char **arg_v)
{
int i, j, xx;
char s[25];
char s[26];
FILE *f;
struct sigaction sv;
struct chanset_t *chan;
Expand Down Expand Up @@ -1068,8 +1069,8 @@ int main(int arg_c, char **arg_v)
dns_thread_head = nmalloc(sizeof(struct dns_thread_node));
dns_thread_head->next = NULL;
#endif
strlcpy(s, ctime(&now), sizeof s);
memmove(&s[11], &s[20], strlen(&s[20]) + 1);
ctime_r(&now, s);
s[24] = 0;
putlog(LOG_ALL, "*", "--- Loading %s (%s)", ver, s);
chanprog();
if (!encrypt_pass2 && !encrypt_pass) {
Expand Down
14 changes: 7 additions & 7 deletions src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,20 +517,20 @@ void putlog (int type, char *chname, const char *format, ...)
va_list va;
time_t now2 = time(NULL);
static time_t now2_last = 0; /* cache expensive localtime() */
static struct tm *t;
static struct tm t;

if (now2 != now2_last) {
now2_last = now2;
t = localtime(&now2);
localtime_r(&now2, &t);
}

va_start(va, format);

/* Create the timestamp */
if (shtime) {
strftime(stamp, sizeof(stamp) - 2, log_ts, t);
strcat(stamp, " ");
tsl = strlen(stamp);
tsl = strftime(stamp, sizeof(stamp) - 2, log_ts, &t);
stamp[tsl++] = ' ';
stamp[tsl] = 0;
}
else
*stamp = '\0';
Expand All @@ -544,9 +544,9 @@ void putlog (int type, char *chname, const char *format, ...)
out[LOGLINEMAX - tsl] = 0;
if (keep_all_logs) {
if (!logfile_suffix[0])
strftime(ct, 12, ".%d%b%Y", t);
strftime(ct, 12, ".%d%b%Y", &t);
else {
strftime(ct, 80, logfile_suffix, t);
strftime(ct, 80, logfile_suffix, &t);
ct[80] = 0;
s2 = ct;
/* replace spaces by underscores */
Expand Down
7 changes: 4 additions & 3 deletions src/mod/channels.mod/channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static char *convert_element(char *src, char *dst)
static void write_channels()
{
FILE *f;
char s[sizeof chanfile + 4], w[1024], w2[1024], name[163];
char s[sizeof chanfile + 4], s1[26], w[1024], w2[1024], name[163];
char need1[242], need2[242], need3[242], need4[242], need5[242];
struct chanset_t *chan;
struct udef_struct *ul;
Expand All @@ -401,8 +401,9 @@ static void write_channels()
}
if (!quiet_save)
putlog(LOG_MISC, "*", "Writing channel file...");
fprintf(f, "#Dynamic Channel File for %s (%s) -- written %s\n",
botnetnick, ver, ctime(&now));
ctime_r(&now, s1);
fprintf(f, "#Dynamic Channel File for %s (%s) -- written %s",
botnetnick, ver, s1);
for (chan = chanset; chan; chan = chan->next) {
convert_element(chan->dname, name);
get_mode_protect(chan, w);
Expand Down
7 changes: 4 additions & 3 deletions src/mod/ctcp.mod/ctcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ static int ctcp_CLIENTINFO(char *nick, char *uhosr, char *handle,
static int ctcp_TIME(char *nick, char *uhost, char *handle, char *object,
char *keyword, char *text)
{
char tms[25];
char s[26];

if (ctcp_mode == 1)
return 1;
strlcpy(tms, ctime(&now), sizeof tms);
simple_sprintf(ctcp_reply, "%s\001TIME %s\001", ctcp_reply, tms);
ctime_r(&now, s);
s[24] = 0;
simple_sprintf(ctcp_reply, "%s\001TIME %s\001", ctcp_reply, s);
return 1;
}

Expand Down
7 changes: 3 additions & 4 deletions src/mod/uptime.mod/uptime.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,12 @@ static int uptime_expmem()
static void uptime_report(int idx, int details)
{
int delta_seconds;
char *next_update_at;
char next_update_at[26];

if (details) {
delta_seconds = (int) (next_update - time(NULL));
next_update_at = ctime(&next_update);
next_update_at[strlen(next_update_at) - 1] = 0;

ctime_r(&next_update, next_update_at);
next_update_at[24] = 0;
dprintf(idx, " %d uptime packet%s sent\n", uptimecount,
(uptimecount != 1) ? "s" : "");
dprintf(idx, " Approximately %-.2f hours until next update "
Expand Down
5 changes: 3 additions & 2 deletions src/tclmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,13 @@ static int tcl_unixtime STDVAR
static int tcl_ctime STDVAR
{
time_t tt;
char s[25];
char s[26];

BADARGS(2, 2, " unixtime");

tt = (time_t) atol(argv[1]);
strlcpy(s, ctime(&tt), sizeof s);
ctime_r(&tt, s);
s[24] = 0;
Tcl_AppendResult(irp, s, NULL);
return TCL_OK;
}
Expand Down
8 changes: 3 additions & 5 deletions src/userrec.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,7 @@ void write_userfile(int idx)
{
FILE *f;
char new_userfile[(sizeof userfile) + 4]; /* 4 = strlen("~new") */
char s1[81];
time_t tt;
char s[26];
struct userrec *u;
int ok;

Expand All @@ -657,9 +656,8 @@ void write_userfile(int idx)
putlog(LOG_MISC, "*", "%s", USERF_WRITING);

sort_userlist();
tt = now;
strlcpy(s1, ctime(&tt), sizeof s1);
fprintf(f, "#4v: %s -- %s -- written %s", ver, botnetnick, s1);
ctime_r(&now, s);
fprintf(f, "#4v: %s -- %s -- written %s", ver, botnetnick, s);
ok = 1;
/* Add all users except the -t user */
for (u = userlist; u && ok; u = u->next)
Expand Down