]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
kernel/reboot: move reboot sysctls to its own file
authortangmeng <tangmeng@uniontech.com>
Thu, 17 Feb 2022 04:23:21 +0000 (12:23 +0800)
committerLuis Chamberlain <mcgrof@kernel.org>
Wed, 6 Apr 2022 20:43:44 +0000 (13:43 -0700)
kernel/sysctl.c is a kitchen sink where everyone leaves their dirty
dishes, this makes it very difficult to maintain.

To help with this maintenance let's start by moving sysctls to places
where they actually belong.  The proc sysctl maintainers do not want to
know what sysctl knobs you wish to add for your own piece of code, we
just care about the core logic.

All filesystem syctls now get reviewed by fs folks. This commit
follows the commit of fs, move the poweroff_cmd and ctrl-alt-del
sysctls to its own file, kernel/reboot.c.

Signed-off-by: tangmeng <tangmeng@uniontech.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
include/linux/reboot.h
kernel/reboot.c
kernel/sysctl.c

index af907a3d68d1df44cb0981c6eb18e221a76ca282..a2429648d8315dcbf8e1c52ccb4f867d68e7e49d 100644 (file)
@@ -71,12 +71,8 @@ extern void kernel_restart(char *cmd);
 extern void kernel_halt(void);
 extern void kernel_power_off(void);
 
-extern int C_A_D; /* for sysctl */
 void ctrl_alt_del(void);
 
-#define POWEROFF_CMD_PATH_LEN  256
-extern char poweroff_cmd[POWEROFF_CMD_PATH_LEN];
-
 extern void orderly_poweroff(bool force);
 extern void orderly_reboot(void);
 void hw_protection_shutdown(const char *reason, int ms_until_forced);
index 6bcc5d6a6572b7decf4b731d9f130374555bf7d5..ed4e6dfb7d44dd92b5b00d5271e010a47a399d32 100644 (file)
@@ -23,7 +23,7 @@
  * this indicates whether you can reboot with ctrl-alt-del: the default is yes
  */
 
-int C_A_D = 1;
+static int C_A_D = 1;
 struct pid *cad_pid;
 EXPORT_SYMBOL(cad_pid);
 
@@ -417,9 +417,37 @@ void ctrl_alt_del(void)
                kill_cad_pid(SIGINT, 1);
 }
 
-char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
+#define POWEROFF_CMD_PATH_LEN  256
+static char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
 static const char reboot_cmd[] = "/sbin/reboot";
 
+#ifdef CONFIG_SYSCTL
+static struct ctl_table kern_reboot_table[] = {
+       {
+               .procname       = "poweroff_cmd",
+               .data           = &poweroff_cmd,
+               .maxlen         = POWEROFF_CMD_PATH_LEN,
+               .mode           = 0644,
+               .proc_handler   = proc_dostring,
+       },
+       {
+               .procname       = "ctrl-alt-del",
+               .data           = &C_A_D,
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = proc_dointvec,
+       },
+       { }
+};
+
+static void __init kernel_reboot_sysctls_init(void)
+{
+       register_sysctl_init("kernel", kern_reboot_table);
+}
+#else
+#define kernel_reboot_sysctls_init() do { } while (0)
+#endif /* CONFIG_SYSCTL */
+
 static int run_cmd(const char *cmd)
 {
        char **argv;
@@ -886,6 +914,8 @@ static int __init reboot_ksysfs_init(void)
                return ret;
        }
 
+       kernel_reboot_sysctls_init();
+
        return 0;
 }
 late_initcall(reboot_ksysfs_init);
index 8241c5401ee85f5dac9fe1a00c58fd6977b76dde..5e43569ce2be8d1f92bf4c05747871a1eaacb591 100644 (file)
@@ -1798,13 +1798,6 @@ static struct ctl_table kern_table[] = {
                .proc_handler   = proc_dointvec,
        },
 #endif
-       {
-               .procname       = "ctrl-alt-del",
-               .data           = &C_A_D,
-               .maxlen         = sizeof(int),
-               .mode           = 0644,
-               .proc_handler   = proc_dointvec,
-       },
 #ifdef CONFIG_FUNCTION_TRACER
        {
                .procname       = "ftrace_enabled",
@@ -2111,13 +2104,6 @@ static struct ctl_table kern_table[] = {
                .proc_handler   = proc_dointvec,
        },
 #endif
-       {
-               .procname       = "poweroff_cmd",
-               .data           = &poweroff_cmd,
-               .maxlen         = POWEROFF_CMD_PATH_LEN,
-               .mode           = 0644,
-               .proc_handler   = proc_dostring,
-       },
 #ifdef CONFIG_KEYS
        {
                .procname       = "keys",