show sessions uptime format
Posted: 06 Jan 2018, 02:11
Is it possible to include an uptime display parameter in seconds?
High performance PPTP/L2TP/PPPoE/IPoE server for Linux
https://accel-ppp.org/forum/
Code: Select all
diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c
index 47adb3a..b1f27e0 100644
--- a/accel-pppd/cli/show_sessions.c
+++ b/accel-pppd/cli/show_sessions.c
@@ -468,27 +468,16 @@ static void print_state(struct ap_session *ses, char *buf)
static void print_uptime(struct ap_session *ses, char *buf)
{
- time_t uptime;
- int day,hour,min,sec;
- char time_str[14];
-
- if (ses->stop_time)
- uptime = ses->stop_time - ses->start_time;
- else {
- uptime = _time();
- uptime -= ses->start_time;
- }
-
- day = uptime/ (24*60*60); uptime %= (24*60*60);
- hour = uptime / (60*60); uptime %= (60*60);
- min = uptime / 60;
- sec = uptime % 60;
- if (day)
- snprintf(time_str, 13, "%i.%02i:%02i:%02i", day, hour, min, sec);
- else
- snprintf(time_str, 13, "%02i:%02i:%02i", hour, min, sec);
-
- sprintf(buf, "%s", time_str);
+time_t uptime;
+char time_str[14];
+if (ses->stop_time)
+ uptime = ses->stop_time - ses->start_time;
+else {
+ uptime = _time();
+ uptime -= ses->start_time;
+}
+snprintf(time_str, 13, "%ld", uptime);
+sprintf(buf, "%s", time_str);
}
static void print_calling_sid(struct ap_session *ses, char *buf)
Code: Select all
root@dev:/opt/accel-ppp-code# accel-cmd show sessions
ifname | username | calling-sid | ip | type | comp | state | uptime
--------+----------+-------------------+------------+------+------+--------+--------
ipoe0 | | 00:0c:29:e3:86:f5 | 100.64.0.2 | ipoe | | active | 1071