Move time_t conversions to rc-misc.c so they can be shared
This commit is contained in:
parent
a3250e77d4
commit
cf5e9aa2bb
@ -23,6 +23,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
@ -68,5 +69,7 @@ RC_DEPTREE *_rc_deptree_load (int, int *);
|
|||||||
bool _rc_can_find_pids(void);
|
bool _rc_can_find_pids(void);
|
||||||
|
|
||||||
RC_SERVICE lookup_service_state(const char *service);
|
RC_SERVICE lookup_service_state(const char *service);
|
||||||
|
char *from_time_t(time_t tv);
|
||||||
|
time_t to_time_t(char *timestring);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -442,3 +442,37 @@ RC_SERVICE lookup_service_state(const char *service)
|
|||||||
return service_bits[i].bit;
|
return service_bits[i].bit;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *from_time_t(time_t tv)
|
||||||
|
{
|
||||||
|
char time_string[20];
|
||||||
|
|
||||||
|
strftime(time_string, 20, "%Y-%m-%d %H:%M:%S", localtime(&tv));
|
||||||
|
return time_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t to_time_t(char *timestring)
|
||||||
|
{
|
||||||
|
int check = 0;
|
||||||
|
int year = 0;
|
||||||
|
int month = 0;
|
||||||
|
int day = 0;
|
||||||
|
int hour = 0;
|
||||||
|
int min = 0;
|
||||||
|
int sec = 0;
|
||||||
|
struct tm breakdown = {0};
|
||||||
|
time_t result = -1;
|
||||||
|
|
||||||
|
check = sscanf(timestring, "%4d-%2d-%2d %2d:%2d:%2d",
|
||||||
|
&year, &month, &day, &hour, &min, &sec);
|
||||||
|
if (check == 6) {
|
||||||
|
breakdown.tm_year = year - 1900; /* years since 1900 */
|
||||||
|
breakdown.tm_mon = month - 1;
|
||||||
|
breakdown.tm_mday = day;
|
||||||
|
breakdown.tm_hour = hour;
|
||||||
|
breakdown.tm_min = min;
|
||||||
|
breakdown.tm_sec = sec;
|
||||||
|
result = mktime(&breakdown);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -185,7 +185,6 @@ static void child_process(char *exec, char **argv, char *svcname,
|
|||||||
char **c;
|
char **c;
|
||||||
char cmdline[PATH_MAX];
|
char cmdline[PATH_MAX];
|
||||||
time_t start_time;
|
time_t start_time;
|
||||||
char start_time_string[20];
|
|
||||||
char start_count_string[20];
|
char start_count_string[20];
|
||||||
|
|
||||||
#ifdef HAVE_PAM
|
#ifdef HAVE_PAM
|
||||||
@ -344,8 +343,7 @@ static void child_process(char *exec, char **argv, char *svcname,
|
|||||||
syslog(LOG_INFO, "Running command line: %s", cmdline);
|
syslog(LOG_INFO, "Running command line: %s", cmdline);
|
||||||
if (svcname) {
|
if (svcname) {
|
||||||
start_time = time(NULL);
|
start_time = time(NULL);
|
||||||
strftime(start_time_string, 20, "%Y-%m-%d %H:%M:%S", localtime(&start_time));
|
rc_service_value_set(svcname, "start_time", from_time_t(start_time));
|
||||||
rc_service_value_set(svcname, "start_time", start_time_string);
|
|
||||||
sprintf(start_count_string, "%i", start_count);
|
sprintf(start_count_string, "%i", start_count);
|
||||||
rc_service_value_set(svcname, "start_count", start_count_string);
|
rc_service_value_set(svcname, "start_count", start_count_string);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user