From: Alan T. DeKok Date: Wed, 27 Jun 2018 22:18:06 +0000 (-0400) Subject: move radmin stuff into radmin.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04748ab70fbd2b05b3ea1d1f3d2b347aaa4009ae;p=thirdparty%2Ffreeradius-server.git move radmin stuff into radmin.c --- diff --git a/src/main/radiusd.c b/src/main/radiusd.c index 16bf108a6c3..166e1000bc1 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -123,36 +123,6 @@ static int talloc_config_set(main_config_t *config) return 0; } -/** radmin functions, tables, and callbacks - * - */ -static struct timeval start_time; - -static int fr_uptime(FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[]) -{ - struct timeval now; - - gettimeofday(&now, NULL); - fr_timeval_subtract(&now, &now, &start_time); - - fprintf(fp, "Uptime: %u.%06u seconds\n", - (int) now.tv_sec, - (int) now.tv_usec); - - return 0; -} - -static fr_cmd_table_t radmin_radiusd[] = { - { - .syntax = "uptime", - .func = fr_uptime, - .help = "Show uptime since the server started", - .read_only = true - }, - - CMD_TABLE_END -}; -/* end of radmin functions, tables, and callbacks */ /** Create module and xlat per-thread instances * @@ -236,7 +206,6 @@ int main(int argc, char *argv[]) rad_debug_lvl = 0; fr_time_start(); - gettimeofday(&start_time, NULL); /* @@ -656,13 +625,6 @@ int main(int argc, char *argv[]) fr_exit(EXIT_FAILURE); } - if (radmin) { - if (fr_radmin_register(NULL, NULL, radmin_radiusd) < 0) { - PERROR("Failed initializing radmin"); - fr_exit(EXIT_FAILURE); - } - } - /* * Initialize the global event loop which handles things like * systemd, and single-server mode. diff --git a/src/main/radmin.c b/src/main/radmin.c index 251eb4caa35..5809b4f9131 100644 --- a/src/main/radmin.c +++ b/src/main/radmin.c @@ -151,12 +151,6 @@ static void *fr_radmin(UNUSED void *ctx) continue; } - if (strcmp(line, "exit") == 0) { - radius_signal_self(RADIUS_SIGNAL_SELF_TERM); - stop = true; - break; - } - if (strcmp(line, "help") == 0) { fr_command_debug(stdout, radmin_cmd); continue; @@ -180,11 +174,64 @@ static void *fr_radmin(UNUSED void *ctx) return NULL; } + +/** radmin functions, tables, and callbacks + * + */ +static struct timeval start_time; + +static int cmd_exit(UNUSED FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[]) +{ + radius_signal_self(RADIUS_SIGNAL_SELF_TERM); + stop = true; + + return 0; +} + +static int cmd_uptime(FILE *fp, UNUSED void *ctx, UNUSED int argc, UNUSED char const *argv[]) +{ + struct timeval now; + + gettimeofday(&now, NULL); + fr_timeval_subtract(&now, &now, &start_time); + + fprintf(fp, "Uptime: %u.%06u seconds\n", + (int) now.tv_sec, + (int) now.tv_usec); + + return 0; +} + +static fr_cmd_table_t cmd_table[] = { + { + .syntax = "exit", + .func = cmd_exit, + .help = "Tell the server to exit immediately.", + .read_only = false + }, + + { + .syntax = "uptime", + .func = cmd_uptime, + .help = "Show uptime since the server started.", + .read_only = true + }, + + CMD_TABLE_END +}; + void fr_radmin_start(void) { int rcode; pthread_attr_t attr; + gettimeofday(&start_time, NULL); + + if (fr_radmin_register(NULL, NULL, cmd_table) < 0) { + PERROR("Failed initializing radmin"); + fr_exit(EXIT_FAILURE); + } + (void) pthread_attr_init(&attr); (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);