localtime замінено на реентерабельну версію - localtime_r, передача
struct tm по константному вказівнику замінена на передачу по
константному посиланню.
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
time_t tt = stgTime - 3600;
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
time_t tt = stgTime - 3600;
-struct tm * t1 = localtime(&tt);
+struct tm t1;
+localtime_r(&tt, &t1);
USER_STAT stat(property.GetStat());
USER_STAT stat(property.GetStat());
-if (store->SaveMonthStat(stat, t1->tm_mon, t1->tm_year, login))
+if (store->SaveMonthStat(stat, t1.tm_mon, t1.tm_year, login))
{
WriteServLog("Cannot write month stat for user %s.", login.c_str());
WriteServLog("%s", store->GetStrError().c_str());
{
WriteServLog("Cannot write month stat for user %s.", login.c_str());
WriteServLog("%s", store->GetStrError().c_str());
static int daysInMonth[12] =
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static int daysInMonth[12] =
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-time_t secMonth = daysInMonth[(tms->tm_mon + 11) % 12] * 24 * 3600; // Previous month
+time_t secMonth = daysInMonth[(tms.tm_mon + 11) % 12] * 24 * 3600; // Previous month
-if (tms->tm_year % 4 == 0 && tms->tm_mon == 1)
+if (tms.tm_year % 4 == 0 && tms.tm_mon == 1)
{
// Leap year
secMonth += 24 * 3600;
{
// Leap year
secMonth += 24 * 3600;
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-time_t t;
-struct tm * tm;
-t = stgTime;
-tm = localtime(&t);
+time_t t = stgTime;
+struct tm tm;
+localtime_r(&t, &tm);
int daysCurrMon = DaysInCurrentMonth();
int daysCurrMon = DaysInCurrentMonth();
-double pt = (tm->tm_mday - 1) / (double)daysCurrMon;
+double pt = (tm.tm_mday - 1) / (double)daysCurrMon;
passiveTime = (time_t)(pt * 24 * 3600 * daysCurrMon);
}
passiveTime = (time_t)(pt * 24 * 3600 * daysCurrMon);
}
printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid());
USERS * us = (USERS*) d;
printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid());
USERS * us = (USERS*) d;
-int min = t->tm_min;
-int day = t->tm_mday;
+int min = t.tm_min;
+int day = t.tm_mday;
printfd(__FILE__,"Day = %d Min = %d\n", day, min);
printfd(__FILE__,"Day = %d Min = %d\n", day, min);
for_each(us->users.begin(), us->users.end(), mem_fun_ref(&USER::Run));
tt = stgTime;
for_each(us->users.begin(), us->users.end(), mem_fun_ref(&USER::Run));
tt = stgTime;
{
printfd(__FILE__,"Sec = %d\n", stgTime);
{
printfd(__FILE__,"Sec = %d\n", stgTime);
- printfd(__FILE__,"New Minute. old = %d current = %d\n", min, t->tm_min);
- min = t->tm_min;
+ printfd(__FILE__,"New Minute. old = %d current = %d\n", min, t.tm_min);
+ min = t.tm_min;
- t = localtime(&tt);
- if (day != t->tm_mday)
{
printfd(__FILE__,"Sec = %d\n", stgTime);
{
printfd(__FILE__,"Sec = %d\n", stgTime);
- printfd(__FILE__,"New Day. old = %d current = %d\n", day, t->tm_mday);
- day = t->tm_mday;
+ printfd(__FILE__,"New Day. old = %d current = %d\n", day, t.tm_mday);
+ day = t.tm_mday;
return NULL;
}
//-----------------------------------------------------------------------------
return NULL;
}
//-----------------------------------------------------------------------------
-void USERS::NewMinute(const struct tm * t)
+void USERS::NewMinute(const struct tm & t)
{
//Write traff, reset session traff. Fake disconnect-connect
{
//Write traff, reset session traff. Fake disconnect-connect
-if (t->tm_hour == 23 && t->tm_min == 59)
+if (t.tm_hour == 23 && t.tm_min == 59)
{
printfd(__FILE__,"MidnightResetSessionStat\n");
for_each(users.begin(), users.end(), mem_fun_ref(&USER::MidnightResetSessionStat));
{
printfd(__FILE__,"MidnightResetSessionStat\n");
for_each(users.begin(), users.end(), mem_fun_ref(&USER::MidnightResetSessionStat));
RealDelUser();
}
//-----------------------------------------------------------------------------
RealDelUser();
}
//-----------------------------------------------------------------------------
-void USERS::NewDay(const struct tm * t)
+void USERS::NewDay(const struct tm & t)
int dayFee = settings->GetDayFee();
if (dayFee == 0)
dayFee = DaysInCurrentMonth();
printfd(__FILE__, "DayFee = %d\n", dayFee);
int dayFee = settings->GetDayFee();
if (dayFee == 0)
dayFee = DaysInCurrentMonth();
printfd(__FILE__, "DayFee = %d\n", dayFee);
-printfd(__FILE__, "Today = %d DayResetTraff = %d\n", t1->tm_mday, settings->GetDayResetTraff());
+printfd(__FILE__, "Today = %d DayResetTraff = %d\n", t1.tm_mday, settings->GetDayResetTraff());
printfd(__FILE__, "DayFeeIsLastDay = %d\n", settings->GetDayFeeIsLastDay());
if (!settings->GetDayFeeIsLastDay())
printfd(__FILE__, "DayFeeIsLastDay = %d\n", settings->GetDayFeeIsLastDay());
if (!settings->GetDayFeeIsLastDay())
- if (t->tm_mday == dayFee)
+ if (t.tm_mday == dayFee)
{
printfd(__FILE__, "DayFee\n");
for_each(users.begin(), users.end(), mem_fun_ref(&USER::ProcessDayFee));
{
printfd(__FILE__, "DayFee\n");
for_each(users.begin(), users.end(), mem_fun_ref(&USER::ProcessDayFee));
}
}
//-----------------------------------------------------------------------------
}
}
//-----------------------------------------------------------------------------
-void USERS::DayResetTraff(const struct tm * t1)
+void USERS::DayResetTraff(const struct tm & t1)
{
int dayResetTraff = settings->GetDayResetTraff();
if (dayResetTraff == 0)
dayResetTraff = DaysInCurrentMonth();
{
int dayResetTraff = settings->GetDayResetTraff();
if (dayResetTraff == 0)
dayResetTraff = DaysInCurrentMonth();
-if (t1->tm_mday == dayResetTraff)
+if (t1.tm_mday == dayResetTraff)
{
printfd(__FILE__, "ResetTraff\n");
for_each(users.begin(), users.end(), mem_fun_ref(&USER::ProcessNewMonth));
{
printfd(__FILE__, "ResetTraff\n");
for_each(users.begin(), users.end(), mem_fun_ref(&USER::ProcessNewMonth));
loginIndex.erase(user->GetLogin());
}
//-----------------------------------------------------------------------------
loginIndex.erase(user->GetLogin());
}
//-----------------------------------------------------------------------------
-bool USERS::TimeToWriteDetailStat(const struct tm * t)
+bool USERS::TimeToWriteDetailStat(const struct tm & t)
{
int statTime = settings->GetDetailStatWritePeriod();
switch (statTime)
{
case dsPeriod_1:
{
int statTime = settings->GetDetailStatWritePeriod();
switch (statTime)
{
case dsPeriod_1:
return true;
break;
case dsPeriod_1_2:
return true;
break;
case dsPeriod_1_2:
- if (t->tm_min % 30 == 0)
+ if (t.tm_min % 30 == 0)
return true;
break;
case dsPeriod_1_4:
return true;
break;
case dsPeriod_1_4:
- if (t->tm_min % 15 == 0)
+ if (t.tm_min % 15 == 0)
return true;
break;
case dsPeriod_1_6:
return true;
break;
case dsPeriod_1_6:
- if (t->tm_min % 10 == 0)
+ if (t.tm_min % 10 == 0)
#define USERS_H
#include <pthread.h>
#define USERS_H
#include <pthread.h>
#include <ctime>
#include <string>
#include <map>
#include <ctime>
#include <string>
#include <map>
void DelUserFromIndexes(user_iter user);
static void * Run(void *);
void DelUserFromIndexes(user_iter user);
static void * Run(void *);
- void NewMinute(const struct tm * t);
- void NewDay(const struct tm * t);
- void DayResetTraff(const struct tm * t);
+ void NewMinute(const struct tm & t);
+ void NewDay(const struct tm & t);
+ void DayResetTraff(const struct tm & t);
- bool TimeToWriteDetailStat(const struct tm * t);
+ bool TimeToWriteDetailStat(const struct tm & t);
list<USER> users;
list<USER_TO_DEL> usersToDelete;
list<USER> users;
list<USER_TO_DEL> usersToDelete;