summaryrefslogtreecommitdiff
path: root/accel-pppd/cli
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd/cli')
-rw-r--r--accel-pppd/cli/cli.c4
-rw-r--r--accel-pppd/cli/show_sessions.c37
-rw-r--r--accel-pppd/cli/std_cmd.c10
-rw-r--r--accel-pppd/cli/tcp.c3
-rw-r--r--accel-pppd/cli/telnet.c3
5 files changed, 48 insertions, 9 deletions
diff --git a/accel-pppd/cli/cli.c b/accel-pppd/cli/cli.c
index 5009a74..00d5ffb 100644
--- a/accel-pppd/cli/cli.c
+++ b/accel-pppd/cli/cli.c
@@ -219,9 +219,11 @@ static void load_config(void)
conf_cli_prompt = (char *)def_cli_prompt;
}
-static void __init init(void)
+static void init(void)
{
load_config();
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
}
+
+DEFINE_INIT(10, init);
diff --git a/accel-pppd/cli/show_sessions.c b/accel-pppd/cli/show_sessions.c
index 555fa88..d7a8a82 100644
--- a/accel-pppd/cli/show_sessions.c
+++ b/accel-pppd/cli/show_sessions.c
@@ -29,6 +29,7 @@ struct col_t
struct list_head entry;
struct column_t *column;
int width;
+ int hidden;
};
struct row_t
@@ -131,6 +132,7 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
int i, n, total_width, def_columns = 0;
struct ppp_t *ppp;
char *buf = NULL;
+ int match_key_f = 0, order_key_f = 0;
LIST_HEAD(c_list);
LIST_HEAD(r_list);
LIST_HEAD(t_list);
@@ -179,10 +181,15 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
if (ptr2)
*ptr2 = 0;
column = find_column(ptr1);
+ if (column == match_key)
+ match_key_f = 1;
+ if (column == order_key)
+ order_key_f = 1;
if (column) {
col = _malloc(sizeof(*col));
col->column = column;
col->width = strlen(column->name);
+ col->hidden = 0;
list_add_tail(&col->entry, &c_list);
} else {
if (!def_columns) {
@@ -197,6 +204,22 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
}
_free(columns);
+ if (match_key && !match_key_f) {
+ col = _malloc(sizeof(*col));
+ col->column = match_key;
+ col->width = 0;
+ col->hidden = 1;
+ list_add_tail(&col->entry, &c_list);
+ }
+
+ if (order_key && !order_key_f) {
+ col = _malloc(sizeof(*col));
+ col->column = order_key;
+ col->width = 0;
+ col->hidden = 1;
+ list_add_tail(&col->entry, &c_list);
+ }
+
pthread_rwlock_rdlock(&ppp_lock);
list_for_each_entry(ppp, &ppp_list, entry) {
row = _malloc(sizeof(*row));
@@ -244,8 +267,11 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
}
total_width = -1;
- list_for_each_entry(col, &c_list, entry)
+ list_for_each_entry(col, &c_list, entry) {
+ if (col->hidden)
+ continue;
total_width += col->width + 3;
+ }
buf = _malloc(total_width + 3);
if (!buf)
@@ -253,6 +279,8 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
ptr1 = buf;
list_for_each_entry(col, &c_list, entry) {
+ if (col->hidden)
+ continue;
n = strlen(col->column->name);
if (col->width > n + 1) {
ptr2 = ptr1;
@@ -278,6 +306,8 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
ptr1 = buf;
list_for_each_entry(col, &c_list, entry) {
+ if (col->hidden)
+ continue;
memset(ptr1, '-', col->width + 2);
ptr1 += col->width + 2;
*ptr1 = '+';
@@ -291,6 +321,8 @@ static int show_ses_exec(const char *cmd, char * const *f, int f_cnt, void *cli)
row = list_entry(r_list.next, typeof(*row), entry);
ptr1 = buf;
list_for_each_entry(cell, &row->cell_list, entry) {
+ if (cell->col->hidden)
+ continue;
ptr2 = ptr1;
sprintf(ptr1, " %s ", cell->buf);
ptr1 = strchr(ptr1, 0);
@@ -417,7 +449,7 @@ static void print_sid(const struct ppp_t *ppp, char *buf)
snprintf(buf, CELL_SIZE, "%s", ppp->sessionid);
}
-void __init init(void)
+static void init(void)
{
cli_register_simple_cmd2(show_ses_exec, show_ses_help, 2, "show", "sessions");
@@ -432,3 +464,4 @@ void __init init(void)
cli_show_ses_register("sid", "session id", print_sid);
}
+DEFINE_INIT(12, init);
diff --git a/accel-pppd/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c
index 43407f1..1c8e149 100644
--- a/accel-pppd/cli/std_cmd.c
+++ b/accel-pppd/cli/std_cmd.c
@@ -16,6 +16,7 @@
static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
{
+ struct timespec ts;
time_t dt;
int day,hour;
char statm_fname[128];
@@ -33,8 +34,8 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
fclose(f);
}
- time(&dt);
- dt -= triton_stat.start_time;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ dt = ts.tv_sec - triton_stat.start_time;
day = dt / (60 * 60 * 24);
dt %= 60 * 60 * 24;
hour = dt / (60 * 60);
@@ -161,7 +162,7 @@ static int terminate_exec2(int key, char * const *f, int f_cnt, void *cli)
list_for_each_entry(ppp, &ppp_list, entry) {
switch (key) {
case 0:
- if (strcmp(ppp->username, f[2]))
+ if (!ppp->username || strcmp(ppp->username, f[2]))
continue;
break;
case 1:
@@ -326,7 +327,7 @@ static void reload_help(char * const *fields, int fields_cnt, void *client)
cli_send(client, "reload - reload config file\r\n");
}
-static void __init init(void)
+static void init(void)
{
cli_register_simple_cmd2(show_stat_exec, show_stat_help, 2, "show", "stat");
cli_register_simple_cmd2(terminate_exec, terminate_help, 1, "terminate");
@@ -335,3 +336,4 @@ static void __init init(void)
cli_register_simple_cmd2(exit_exec, exit_help, 1, "exit");
}
+DEFINE_INIT(12, init);
diff --git a/accel-pppd/cli/tcp.c b/accel-pppd/cli/tcp.c
index 260225f..fea0e4e 100644
--- a/accel-pppd/cli/tcp.c
+++ b/accel-pppd/cli/tcp.c
@@ -339,7 +339,7 @@ static void start_server(const char *host, int port)
triton_context_wakeup(&serv_ctx);
}
-static void __init init(void)
+static void init(void)
{
const char *opt;
char *host, *d;
@@ -369,3 +369,4 @@ err_fmt:
free(host);
}
+DEFINE_INIT(11, init);
diff --git a/accel-pppd/cli/telnet.c b/accel-pppd/cli/telnet.c
index 82bcb0d..2643692 100644
--- a/accel-pppd/cli/telnet.c
+++ b/accel-pppd/cli/telnet.c
@@ -718,7 +718,7 @@ static void load_history_file(void)
fclose(f);
}
-static void __init init(void)
+static void init(void)
{
const char *opt;
char *host, *d;
@@ -757,3 +757,4 @@ err_fmt:
free(host);
}
+DEFINE_INIT(11, init);