Skip to content

Commit

Permalink
Reverted some breaking changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeDP committed Aug 21, 2021
1 parent e3102c9 commit b3c4ba1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
21 changes: 17 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "opts.h"

static void init(int argc, char *argv[]);
static void init_state(void);
static void sigsegv_handler(int signum);
static void check_clightd_version(void);
static void init_user_mod_path(enum CONFIG file, char *filename);
Expand Down Expand Up @@ -68,12 +69,10 @@ static void init(int argc, char *argv[]) {
init_opts(argc, argv);
log_conf();

state.version = VERSION;
memcpy(&state.current_loc, &conf.day_conf.loc, sizeof(loc_t));

if (!conf.wizard) {
/* We want any error while checking Clightd required version to be logged AFTER conf logging */
check_clightd_version();
check_clightd_version();
init_state();
/*
* Load user custom modules after opening log (thus this information is logged).
* Note that local (ie: placed in $HOME) modules have higher priority,
Expand All @@ -87,6 +86,20 @@ static void init(int argc, char *argv[]) {
}
}

static void init_state(void) {
state.version = VERSION;
memcpy(&state.current_loc, &conf.day_conf.loc, sizeof(loc_t));

/*
* Initial states -> undefined;
*/
state.sens_avail = -1;
state.next_event = -1;
state.day_time = -1;
state.ac_state = -1;
state.lid_state = -1;
}

/*
* If received a sigsegv, log a message, destroy lock then
* set sigsegv signal handler to default (SIG_DFL),
Expand Down
6 changes: 1 addition & 5 deletions src/modules/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ API(Sensor, conf_sens_vtable, conf.sens_conf);
API(MonitorOverride, conf_mon_override_vtable, conf.sens_conf.specific_curves);
MODULE_WITH_PAUSE("BACKLIGHT");

static void module_pre_start(void) {
state.sens_avail = -1;
}

static void init(void) {
capture_req.capture.reset_timer = true;
capture_req.capture.capture_only = false;
Expand Down Expand Up @@ -194,7 +190,7 @@ static void receive_waiting_init(const msg_t *const msg, UNUSED const void* user

SYSBUS_ARG(bl_args, CLIGHTD_SERVICE, "/org/clightd/clightd/Backlight", "org.clightd.clightd.Backlight", "Changed");
add_match(&bl_args, &bl_slot, on_bl_changed);

bl_fd = start_timer(CLOCK_BOOTTIME, 0, get_current_timeout() > 0);
m_register_fd(bl_fd, false, NULL);

Expand Down
5 changes: 0 additions & 5 deletions src/modules/daytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ DECLARE_MSG(temp_req, TEMP_REQ);
API(Daytime, conf_daytime_vtable, conf.day_conf);
MODULE("DAYTIME");

static void module_pre_start(void) {
state.next_event = -1;
state.day_time = -1;
}

static void init(void) {
temp_req.temp.daytime = -1;
temp_req.temp.smooth = -1;
Expand Down
6 changes: 0 additions & 6 deletions src/modules/upower.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ DECLARE_MSG(inh_req, INHIBIT_REQ);

MODULE("UPOWER");

static void module_pre_start(void) {
state.ac_state = -1;
state.lid_state = -1;
}


static void init(void) {
M_SUB(UPOWER_REQ);
M_SUB(LID_REQ);
Expand Down
16 changes: 6 additions & 10 deletions src/utils/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,22 @@ void log_message(const char *filename, int lineno, const char type, const char *
va_start(file_args, log_msg);
va_copy(args, file_args);

char header[128] = {0};
if (type != 'P') {
time_t t = time(NULL);
struct tm *tm = localtime(&t);
snprintf(header, sizeof(header), "(%c)[%02d:%02d:%02d]{%s:%d}\t", type, tm->tm_hour, tm->tm_min, tm->tm_sec, filename, lineno);
}

if (log_file) {
fprintf(log_file, "%s", header);
if (type != LOG_PLOT) {
time_t t = time(NULL);
struct tm *tm = localtime(&t);
fprintf(log_file, "(%c)[%02d:%02d:%02d]{%s:%d}\t", type, tm->tm_hour, tm->tm_min, tm->tm_sec, filename, lineno);
}
vfprintf(log_file, log_msg, file_args);
fflush(log_file);
}

/* In case of error, log to stdout too */
FILE *out = stdout;
if (type == 'E') {
if (type == LOG_ERR) {
out = stderr;
}

fprintf(out, "%s", header);
vfprintf(out, log_msg, args);
va_end(args);
va_end(file_args);
Expand Down

0 comments on commit b3c4ba1

Please sign in to comment.