]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move radmin stuff into radmin.c
authorAlan T. DeKok <aland@freeradius.org>
Wed, 27 Jun 2018 22:18:06 +0000 (18:18 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 27 Jun 2018 22:18:06 +0000 (18:18 -0400)
src/main/radiusd.c
src/main/radmin.c

index 16bf108a6c3b465641cbcaa47e079b34f2249ca3..166e1000bc13acfa69e6ddb7380eae2ba12b2c7a 100644 (file)
@@ -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.
index 251eb4caa3507bc736cc9792ff5f9fc8a2c96155..5809b4f9131b6e2387d64adc7102aa644817c6f0 100644 (file)
@@ -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);