static qltimer_t* new_timer(qdict_t *args, const char *mod, const char *func) { qltimer_t *timer; timer = (qltimer_t*)qalloc(sizeof(qltimer_t)); if (timer == NULL) { return NULL; } timer->args = args; timer->mod = qstring_new(mod); timer->func = qstring_new(func); if (timer->mod == NULL || timer->func == NULL) { goto error; } return timer; error: if (timer->mod) { qstring_destroy(timer->mod); } if (timer->func) { qstring_destroy(timer->func); } qfree(timer); return NULL; }
static void free_timer(void *data) { qltimer_t *timer; timer = (qltimer_t*)data; if (timer->args) { qdict_free(timer->args); } qstring_destroy(timer->mod); qstring_destroy(timer->func); qfree(timer); }
void qlogger_open_file() { qstring_t file; char buff[30] = {'\0'}; time_t t; struct tm tm; t = time(NULL); memset(&tm, 0, sizeof(struct tm)); localtime_r(&t, &tm); strftime((char*)(&buff[0]), sizeof(buff), "%Y%m%d-%H%M%S", &tm); logger->log_size = 0; if (logger->fd != -1) { fsync(logger->fd); close(logger->fd); } file = qstring_new(config.log_path); file = qstring_catvprintf(file, "/qserver_%s.log", buff); logger->fd = open(file, O_CREAT | O_TRUNC | O_RDWR, S_IWUSR | S_IRUSR | S_IWOTH | S_IROTH | S_IRGRP | S_IWGRP); if (logger->fd == -1) { qstdout("open log file %s error: %s\n", file, strerror(errno)); exit(-1); } qstring_destroy(file); }