Skip to content

Commit 06d1776

Browse files
imtangmengmcgrof
authored andcommitted
kernel/reboot: move reboot sysctls to its own file
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 <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 8a04414 commit 06d1776

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

include/linux/reboot.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,8 @@ extern void kernel_restart(char *cmd);
7171
extern void kernel_halt(void);
7272
extern void kernel_power_off(void);
7373

74-
extern int C_A_D; /* for sysctl */
7574
void ctrl_alt_del(void);
7675

77-
#define POWEROFF_CMD_PATH_LEN 256
78-
extern char poweroff_cmd[POWEROFF_CMD_PATH_LEN];
79-
8076
extern void orderly_poweroff(bool force);
8177
extern void orderly_reboot(void);
8278
void hw_protection_shutdown(const char *reason, int ms_until_forced);

kernel/reboot.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* this indicates whether you can reboot with ctrl-alt-del: the default is yes
2424
*/
2525

26-
int C_A_D = 1;
26+
static int C_A_D = 1;
2727
struct pid *cad_pid;
2828
EXPORT_SYMBOL(cad_pid);
2929

@@ -417,9 +417,37 @@ void ctrl_alt_del(void)
417417
kill_cad_pid(SIGINT, 1);
418418
}
419419

420-
char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
420+
#define POWEROFF_CMD_PATH_LEN 256
421+
static char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
421422
static const char reboot_cmd[] = "/sbin/reboot";
422423

424+
#ifdef CONFIG_SYSCTL
425+
static struct ctl_table kern_reboot_table[] = {
426+
{
427+
.procname = "poweroff_cmd",
428+
.data = &poweroff_cmd,
429+
.maxlen = POWEROFF_CMD_PATH_LEN,
430+
.mode = 0644,
431+
.proc_handler = proc_dostring,
432+
},
433+
{
434+
.procname = "ctrl-alt-del",
435+
.data = &C_A_D,
436+
.maxlen = sizeof(int),
437+
.mode = 0644,
438+
.proc_handler = proc_dointvec,
439+
},
440+
{ }
441+
};
442+
443+
static void __init kernel_reboot_sysctls_init(void)
444+
{
445+
register_sysctl_init("kernel", kern_reboot_table);
446+
}
447+
#else
448+
#define kernel_reboot_sysctls_init() do { } while (0)
449+
#endif /* CONFIG_SYSCTL */
450+
423451
static int run_cmd(const char *cmd)
424452
{
425453
char **argv;
@@ -886,6 +914,8 @@ static int __init reboot_ksysfs_init(void)
886914
return ret;
887915
}
888916

917+
kernel_reboot_sysctls_init();
918+
889919
return 0;
890920
}
891921
late_initcall(reboot_ksysfs_init);

kernel/sysctl.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,13 +1798,6 @@ static struct ctl_table kern_table[] = {
17981798
.proc_handler = proc_dointvec,
17991799
},
18001800
#endif
1801-
{
1802-
.procname = "ctrl-alt-del",
1803-
.data = &C_A_D,
1804-
.maxlen = sizeof(int),
1805-
.mode = 0644,
1806-
.proc_handler = proc_dointvec,
1807-
},
18081801
#ifdef CONFIG_FUNCTION_TRACER
18091802
{
18101803
.procname = "ftrace_enabled",
@@ -2111,13 +2104,6 @@ static struct ctl_table kern_table[] = {
21112104
.proc_handler = proc_dointvec,
21122105
},
21132106
#endif
2114-
{
2115-
.procname = "poweroff_cmd",
2116-
.data = &poweroff_cmd,
2117-
.maxlen = POWEROFF_CMD_PATH_LEN,
2118-
.mode = 0644,
2119-
.proc_handler = proc_dostring,
2120-
},
21212107
#ifdef CONFIG_KEYS
21222108
{
21232109
.procname = "keys",

0 commit comments

Comments
 (0)