83

The Linux Programming Interface has an exercise in Chapter 3 that goes like this:

When using the Linux-specific reboot() system call to reboot the system, the second argument, magic2, must be specified as one of a set of magic numbers (e.g., LINUX_REBOOT_MAGIC2). What is the significance of these numbers? (Converting them to hexadecimal provides a clue.)

The man page tells us magic2 can be one of LINUX_REBOOT_MAGIC2 (672274793), LINUX_REBOOT_MAGIC2A (85072278), LINUX_REBOOT_MAGIC2B (369367448), or LINUX_REBOOT_MAGIC2C (537993216). I failed to decipher their meaning in hex. I also looked at /usr/include/linux/reboot.h, which didn't give any helpful comment either.

I then searched in the kernel's source code for sys_reboot's definition. All I found was a declaration in a header file.

Therefore, my first question is, what is the significance of these numbers? My second question is, where's sys_reboot's definition, and how did you find it?

EDIT: I found the definition in kernel/sys.c. I only grepped for sys_reboot, and forgot to grep for the MAGIC numbers. I figured the definition must be hidden behind some macro trick, so I looked at the System.map file under /boot, and found it next to ctrl_alt_del. I then grepped for that symbol, which led me to the correct file. If I had compiled the kernel from source code, I could try to find which object file defined the symbol, and go from there.

Wei Hu
  • 2,888
  • 2
  • 27
  • 28
  • I do not understand how to use the man pages to see the information about `magic2`. I run `man reboot` but there is no mention of magic2. What should I run? – Hailee Jun 04 '23 at 15:47

2 Answers2

108

Just a guess, but those numbers look more interesting in hex:

672274793 = 0x28121969
 85072278 = 0x05121996
369367448 = 0x16041998
537993216 = 0x20112000

Developers' or developers' children's birthdays?

Regarding finding the syscall implementation, I did a git grep -n LINUX_REBOOT_MAGIC2 and found the definition in kernel/sys.c. The symbol sys_reboot is generated by the SYSCALL_DEFINE4(reboot, ... gubbins, I suspect.

araqnid
  • 127,052
  • 24
  • 157
  • 134
  • 33
    Dec 28, 1969 is Linus Torvalds' birth date [Wikipedia]. The others appear to be his children's birth dates, though I can only confirm one was born in December 1996 [random googling]. – Eric Seppanen Jan 26 '11 at 20:31
  • 34
    Confirmed, they are the birth dates of Linus and his 3 daughters. -> http://www.nndb.com/people/444/000022378/ – cdated Mar 24 '11 at 03:32
  • 2
    but my question is: why magic is required for this system call? My guess is to avoid rebooting after an accidental and unintended call to it. ie: the first thing the system call does before proceeding is to verify that the required magic is present... – lano1106 Feb 15 '20 at 18:56
30

It's the birthday of Linus Torvalds (The developer of the Linux kernel and the Git version control) and his 3 daughters. works as magic numbers to reboot the system.

http://en.wikipedia.org/wiki/Linus_Torvalds

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Ritwik Dey
  • 559
  • 1
  • 7
  • 17