sysrq

package module
v0.0.0-...-38dd78d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2017 License: MPL-2.0 Imports: 3 Imported by: 1

README

sysrq

Go client to perform low-level commands via the Linux SysRq interface (accessible at /proc/sysrq-trigger).

Among other things, SysRq can crash the system by forcing a NULL pointer dereference, which makes it a good fit for Chaos Engineering experiments.

CLI

In addition to the Go library, there's a sysrq command-line tool you can install from source:

go get -u github.com/mlafeldt/sysrq/cmd/sysrq

Use the tool to trigger one or more commands:

sudo sysrq <cmd>...

This will print a list of all available commands:

sysrq -list

Vagrant playground

Here's how to run SysRq commands against a local Vagrant machine:

# Start Vagrant machine
vagrant up

# Trigger crash command
make trigger CMD=crash

# Show system logs
make log
...
ubuntu-xenial login: [   94.116848] sysrq: SysRq : Trigger a crash
[   94.152571] BUG: unable to handle kernel NULL pointer dereference at           (null)
[   94.263679] IP: [<ffffffff81504df6>] sysrq_handle_crash+0x16/0x20
...

# Fix Vagrant machine
vagrant reload

Docker

Since Docker mounts /proc/sysrq-trigger as read-only, you cannot run commands against other containers, but you can still affect the host system:

docker run --rm -v /proc/sysrq-trigger:/sysrq -e TRIGGER_FILE=/sysrq mlafeldt/sysrq <cmd>...

Author

This project is being developed by Mathias Lafeldt.

Documentation

Overview

Package sysrq allows to perform low-level commands via the Linux SysRq interface. See https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/sysrq.rst and https://en.wikipedia.org/wiki/Magic_SysRq_key for more information.

Index

Constants

This section is empty.

Variables

Commands is a list of supported SysRq commands.

Functions

func Trigger

func Trigger(cmd ...Command) error

Trigger performs one or more commands via the Linux SysRq interface.

Types

type Command

type Command byte

Command is a SysRq command.

const (
	// Reboot immediately reboots the system without syncing or unmounting
	// your disks.
	Reboot Command = 'b'

	// Crash performs a system crash by a NULL pointer dereference. A
	// crashdump will be taken if configured.
	Crash Command = 'c'

	// TerminateAllTasks sends a SIGTERM to all processes, except for init.
	TerminateAllTasks Command = 'e'

	// MemoryFullOOMKill calls the OOM killer to kill a memory hog process,
	// but doesn't panic if nothing can be killed.
	MemoryFullOOMKill Command = 'f'

	// Help displays help (actually any other key than those listed here
	// will display help.)
	Help Command = 'h'

	// KillAllTasks sends a SIGKILL to all processes, except for init.
	KillAllTasks Command = 'i'

	// ThawFilesystems forcibly "Just thaw it" - filesystems frozen by the
	// FIFREEZE ioctl.
	ThawFilesystems Command = 'j'

	// SAK (Secure Access Key) kills all programs on the current virtual
	// console.
	SAK Command = 'k'

	// ShowBacktraceAllActiveCPUs shows a stack backtrace for all active
	// CPUs.
	ShowBacktraceAllActiveCPUs Command = 'l'

	// ShowMemoryUsage dumps current memory info to your console.
	ShowMemoryUsage Command = 'm'

	// NiceAllRTTasks will make RT tasks nice-able.
	NiceAllRTTasks Command = 'n'

	// Poweroff shuts your system off (if configured and supported).
	Poweroff Command = 'o'

	// ShowRegisters dumps the current registers and flags to your console.
	ShowRegisters Command = 'p'

	// ShowAllTimers dumps per CPU lists of all armed hrtimers (but NOT
	// regular timer_list timers) and detailed information about all
	// clockevent devices.
	ShowAllTimers Command = 'q'

	// Unraw turns off keyboard raw mode and sets it to XLATE.
	Unraw Command = 'r'

	// Sync attempts to sync all mounted filesystems.
	Sync Command = 's'

	// ShowTaskStates dumps a list of current tasks and their information
	// to your console.
	ShowTaskStates Command = 't'

	// Unmount attempts to remount all mounted filesystems read-only.
	Unmount Command = 'u'

	// ShowBlockedTasks dumps tasks that are in uninterruptable (blocked)
	// state.
	ShowBlockedTasks Command = 'w'

	// DumpFtraceBuffer dumps the ftrace buffer.
	DumpFtraceBuffer Command = 'z'

	// Loglevel0 sets the console log level to 0. In this level, only
	// emergency messages like PANICs or OOPSes would make it to your
	// console.
	Loglevel0 Command = '0'

	// Loglevel1 sets the console log level to 1.
	Loglevel1 Command = '1'

	// Loglevel2 sets the console log level to 2.
	Loglevel2 Command = '2'

	// Loglevel3 sets the console log level to 3.
	Loglevel3 Command = '3'

	// Loglevel4 sets the console log level to 4.
	Loglevel4 Command = '4'

	// Loglevel5 sets the console log level to 5.
	Loglevel5 Command = '5'

	// Loglevel6 sets the console log level to 6.
	Loglevel6 Command = '6'

	// Loglevel7 sets the console log level to 7.
	Loglevel7 Command = '7'

	// Loglevel8 sets the console log level to 8.
	Loglevel8 Command = '8'

	// Loglevel9 sets the console log level to 9, the most verbose level.
	Loglevel9 Command = '9'

	// DefaultTriggerFile is the location of the file where SysRq commands
	// are written to by default.
	DefaultTriggerFile = "/proc/sysrq-trigger"
)

func FromString

func FromString(s string) (Command, error)

FromString creates a Command from a string.

func (Command) String

func (cmd Command) String() string

String converts a Command to a string.

type SysRq

type SysRq struct {
	TriggerFile string
}

SysRq is used to configure access to the Linux SysRq interface.

func (SysRq) Trigger

func (sysrq SysRq) Trigger(cmd ...Command) error

Trigger performs one or more commands via the Linux SysRq interface.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL