github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/sentry/kernel/syslog.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package kernel 16 17 import ( 18 "fmt" 19 "math/rand" 20 21 "github.com/metacubex/gvisor/pkg/sync" 22 ) 23 24 // syslog represents a sentry-global kernel log. 25 // 26 // Currently, it contains only fun messages for a dmesg easter egg. 27 // 28 // +stateify savable 29 type syslog struct { 30 // mu protects the below. 31 mu sync.Mutex `state:"nosave"` 32 33 // msg is the syslog message buffer. It is lazily initialized. 34 msg []byte 35 } 36 37 // Log returns a copy of the syslog. 38 func (s *syslog) Log() []byte { 39 s.mu.Lock() 40 defer s.mu.Unlock() 41 42 if s.msg != nil { 43 // Already initialized, just return a copy. 44 o := make([]byte, len(s.msg)) 45 copy(o, s.msg) 46 return o 47 } 48 49 // Not initialized, create message. 50 allMessages := []string{ 51 "Synthesizing system calls...", 52 "Mounting deweydecimalfs...", 53 "Moving files to filing cabinet...", 54 "Digging up root...", 55 "Constructing home...", 56 "Segmenting fault lines...", 57 "Creating bureaucratic processes...", 58 "Searching for needles in stacks...", 59 "Preparing for the zombie uprising...", 60 "Feeding the init monster...", 61 "Creating cloned children...", 62 "Daemonizing children...", 63 "Waiting for children...", 64 "Gathering forks...", 65 "Committing treasure map to memory...", 66 "Reading process obituaries...", 67 "Searching for socket adapter...", 68 "Creating process schedule...", 69 "Generating random numbers by fair dice roll...", 70 "Rewriting operating system in Javascript...", 71 "Reticulating splines...", 72 "Consulting tar man page...", 73 "Forking spaghetti code...", 74 "Checking naughty and nice process list...", 75 "Checking naughty and nice process list...", // Check it up to twice. 76 "Granting licence to kill(2)...", // British spelling for British movie. 77 "Letting the watchdogs out...", 78 "Conjuring /dev/null black hole...", 79 "Adversarially training Redcode AI...", 80 "Singleplexing /dev/ptmx...", 81 "Recruiting cron-ies...", 82 "Verifying that no non-zero bytes made their way into /dev/zero...", 83 "Accelerating teletypewriter to 9600 baud...", 84 } 85 86 selectMessage := func() string { 87 i := rand.Intn(len(allMessages)) 88 m := allMessages[i] 89 90 // Delete the selected message. 91 allMessages[i] = allMessages[len(allMessages)-1] 92 allMessages = allMessages[:len(allMessages)-1] 93 94 return m 95 } 96 97 const format = "<6>[%11.6f] %s\n" 98 99 s.msg = append(s.msg, []byte(fmt.Sprintf(format, 0.0, "Starting gVisor..."))...) 100 101 time := 0.1 102 for i := 0; i < 10; i++ { 103 time += rand.Float64() / 2 104 s.msg = append(s.msg, []byte(fmt.Sprintf(format, time, selectMessage()))...) 105 } 106 107 time += rand.Float64() / 2 108 s.msg = append(s.msg, []byte(fmt.Sprintf(format, time, "Setting up VFS..."))...) 109 time += rand.Float64() / 2 110 s.msg = append(s.msg, []byte(fmt.Sprintf(format, time, "Setting up FUSE..."))...) 111 112 time += rand.Float64() / 2 113 s.msg = append(s.msg, []byte(fmt.Sprintf(format, time, "Ready!"))...) 114 115 // Return a copy. 116 o := make([]byte, len(s.msg)) 117 copy(o, s.msg) 118 return o 119 }