diff options
| author | Harald Welte <laforge@gnumonks.org> | 2019-06-04 12:10:11 +0200 | 
|---|---|---|
| committer | Harald Welte <laforge@gnumonks.org> | 2019-06-05 10:01:20 +0000 | 
| commit | cb5e8312b6eaecb4080276b0288de3949e5616e7 (patch) | |
| tree | 85666957173fc4fe7e65aca9789dfe7fc2aaeb03 /src | |
| parent | 7b74551b93421d30d5f0346042993ff763ddbe25 (diff) | |
fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements
Instead of copy+pasting the same LOGPFSMSRC("State change to " ...)
with slightly different trailer depending on the FSM timer, let's first
snprintf() to a stack variable and then have a single log statement.
Change-Id: I49528c4ca1fa11aef09c2092615dccca450b847c
Diffstat (limited to 'src')
| -rw-r--r-- | src/fsm.c | 32 | 
1 files changed, 15 insertions, 17 deletions
| @@ -609,33 +609,31 @@ static int state_chg(struct osmo_fsm_inst *fi, uint32_t new_state,  		st->onleave(fi, new_state);  	if (fsm_log_timeouts) { +		char trailer[64]; +		trailer[0] = '\0';  		if (keep_timer && fi->timer.active) {  			/* This should always give us a timeout, but just in case the return value indicates error, omit  			 * logging the remaining time. */  			if (osmo_timer_remaining(&fi->timer, NULL, &remaining)) -				LOGPFSMSRC(fi, file, line, -					   "State change to %s (keeping " OSMO_T_FMT ")\n", -					   osmo_fsm_state_name(fsm, new_state), -					   OSMO_T_FMT_ARGS(fi->T)); +				snprintf(trailer, sizeof(trailer), "(keeping " OSMO_T_FMT ")", +					 OSMO_T_FMT_ARGS(fi->T));  			else -				LOGPFSMSRC(fi, file, line, -					   "State change to %s (keeping " OSMO_T_FMT ", %ld.%03lds remaining)\n", -					   osmo_fsm_state_name(fsm, new_state), -					   OSMO_T_FMT_ARGS(fi->T), remaining.tv_sec, remaining.tv_usec / 1000); +				snprintf(trailer, sizeof(trailer), "(keeping " OSMO_T_FMT +					  ", %ld.%03lds remaining)", OSMO_T_FMT_ARGS(fi->T), +					  remaining.tv_sec, remaining.tv_usec / 1000);  		} else if (timeout_ms) { -			if (timeout_ms % 1000 == 0) { +			if (timeout_ms % 1000 == 0)  				/* keep log output legacy compatible to avoid autotest failures */ -				LOGPFSMSRC(fi, file, line, "State change to %s (" OSMO_T_FMT ", %lus)\n", -					   osmo_fsm_state_name(fsm, new_state), +				snprintf(trailer, sizeof(trailer), "(" OSMO_T_FMT ", %lus)",  					   OSMO_T_FMT_ARGS(T), timeout_ms/1000); -			} else { -				LOGPFSMSRC(fi, file, line, "State change to %s (" OSMO_T_FMT ", %lums)\n", -					   osmo_fsm_state_name(fsm, new_state), +			else +				snprintf(trailer, sizeof(trailer), "(" OSMO_T_FMT ", %lums)",  					   OSMO_T_FMT_ARGS(T), timeout_ms); -			}  		} else -			LOGPFSMSRC(fi, file, line, "State change to %s (no timeout)\n", -				   osmo_fsm_state_name(fsm, new_state)); +			snprintf(trailer, sizeof(trailer), "(no timeout)"); + +		LOGPFSMSRC(fi, file, line, "State change to %s %s\n", +			   osmo_fsm_state_name(fsm, new_state), trailer);  	} else {  		LOGPFSMSRC(fi, file, line, "state_chg to %s\n",  			   osmo_fsm_state_name(fsm, new_state)); | 
