message: rename NewMsg to New
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Test / Create distribution (push) Successful in 34s
				
			
		
			
				
	
				Test / Sandbox (push) Successful in 2m13s
				
			
		
			
				
	
				Test / Hakurei (push) Successful in 3m15s
				
			
		
			
				
	
				Test / Hpkg (push) Successful in 4m7s
				
			
		
			
				
	
				Test / Sandbox (race detector) (push) Successful in 4m14s
				
			
		
			
				
	
				Test / Hakurei (race detector) (push) Successful in 5m7s
				
			
		
			
				
	
				Test / Flake checks (push) Successful in 1m37s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Test / Create distribution (push) Successful in 34s
				
			Test / Sandbox (push) Successful in 2m13s
				
			Test / Hakurei (push) Successful in 3m15s
				
			Test / Hpkg (push) Successful in 4m7s
				
			Test / Sandbox (race detector) (push) Successful in 4m14s
				
			Test / Hakurei (race detector) (push) Successful in 5m7s
				
			Test / Flake checks (push) Successful in 1m37s
				
			Should have done this when relocating this from container. Now is a good time to rename it before v0.3.x. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
		
							parent
							
								
									149bc3671a
								
							
						
					
					
						commit
						ae66b3d2fb
					
				@ -77,7 +77,7 @@ Flags:
 | 
			
		||||
			t.Parallel()
 | 
			
		||||
 | 
			
		||||
			out := new(bytes.Buffer)
 | 
			
		||||
			c := buildCommand(t.Context(), message.NewMsg(nil), new(earlyHardeningErrs), out)
 | 
			
		||||
			c := buildCommand(t.Context(), message.New(nil), new(earlyHardeningErrs), out)
 | 
			
		||||
			if err := c.Parse(tc.args); !errors.Is(err, command.ErrHelp) && !errors.Is(err, flag.ErrHelp) {
 | 
			
		||||
				t.Errorf("Parse: error = %v; want %v",
 | 
			
		||||
					err, command.ErrHelp)
 | 
			
		||||
 | 
			
		||||
@ -32,7 +32,7 @@ func main() {
 | 
			
		||||
 | 
			
		||||
	log.SetPrefix("hakurei: ")
 | 
			
		||||
	log.SetFlags(0)
 | 
			
		||||
	msg := message.NewMsg(log.Default())
 | 
			
		||||
	msg := message.New(log.Default())
 | 
			
		||||
 | 
			
		||||
	early := earlyHardeningErrs{
 | 
			
		||||
		yamaLSM:  container.SetPtracer(0),
 | 
			
		||||
 | 
			
		||||
@ -28,7 +28,7 @@ func TestShortIdentifier(t *testing.T) {
 | 
			
		||||
func TestTryIdentifier(t *testing.T) {
 | 
			
		||||
	t.Parallel()
 | 
			
		||||
 | 
			
		||||
	msg := message.NewMsg(nil)
 | 
			
		||||
	msg := message.New(nil)
 | 
			
		||||
	id := hst.ID{
 | 
			
		||||
		0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
 | 
			
		||||
		0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
 | 
			
		||||
 | 
			
		||||
@ -761,7 +761,7 @@ func TestPrintPs(t *testing.T) {
 | 
			
		||||
			t.Parallel()
 | 
			
		||||
 | 
			
		||||
			var printBuf, logBuf bytes.Buffer
 | 
			
		||||
			msg := message.NewMsg(log.New(&logBuf, "check: ", 0))
 | 
			
		||||
			msg := message.New(log.New(&logBuf, "check: ", 0))
 | 
			
		||||
			msg.SwapVerbose(true)
 | 
			
		||||
			printPs(msg, &printBuf, testTime, s, tc.short, tc.json)
 | 
			
		||||
			if got := printBuf.String(); got != tc.want {
 | 
			
		||||
 | 
			
		||||
@ -24,7 +24,7 @@ var (
 | 
			
		||||
func main() {
 | 
			
		||||
	log.SetPrefix("hpkg: ")
 | 
			
		||||
	log.SetFlags(0)
 | 
			
		||||
	msg := message.NewMsg(log.Default())
 | 
			
		||||
	msg := message.New(log.Default())
 | 
			
		||||
 | 
			
		||||
	if err := os.Setenv("SHELL", pathShell.String()); err != nil {
 | 
			
		||||
		log.Fatalf("cannot set $SHELL: %v", err)
 | 
			
		||||
 | 
			
		||||
@ -404,7 +404,7 @@ func (p *Container) ProcessState() *os.ProcessState {
 | 
			
		||||
// New returns the address to a new instance of [Container] that requires further initialisation before use.
 | 
			
		||||
func New(ctx context.Context, msg message.Msg) *Container {
 | 
			
		||||
	if msg == nil {
 | 
			
		||||
		msg = message.NewMsg(nil)
 | 
			
		||||
		msg = message.New(nil)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	p := &Container{ctx: ctx, msg: msg, Params: Params{Ops: new(Ops)}}
 | 
			
		||||
 | 
			
		||||
@ -556,7 +556,7 @@ func testContainerCancel(
 | 
			
		||||
 | 
			
		||||
func TestContainerString(t *testing.T) {
 | 
			
		||||
	t.Parallel()
 | 
			
		||||
	msg := message.NewMsg(nil)
 | 
			
		||||
	msg := message.New(nil)
 | 
			
		||||
	c := container.NewCommand(t.Context(), msg, check.MustAbs("/run/current-system/sw/bin/ldd"), "ldd", "/usr/bin/env")
 | 
			
		||||
	c.SeccompFlags |= seccomp.AllowMultiarch
 | 
			
		||||
	c.SeccompRules = seccomp.Preset(
 | 
			
		||||
@ -721,7 +721,7 @@ func TestMain(m *testing.M) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func helperNewContainerLibPaths(ctx context.Context, libPaths *[]*check.Absolute, args ...string) (c *container.Container) {
 | 
			
		||||
	msg := message.NewMsg(nil)
 | 
			
		||||
	msg := message.New(nil)
 | 
			
		||||
	c = container.NewCommand(ctx, msg, absHelperInnerPath, "helper", args...)
 | 
			
		||||
	c.Env = append(c.Env, envDoCheck+"=1")
 | 
			
		||||
	c.Bind(check.MustAbs(os.Args[0]), absHelperInnerPath, 0)
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ import (
 | 
			
		||||
func TestExecutable(t *testing.T) {
 | 
			
		||||
	t.Parallel()
 | 
			
		||||
	for i := 0; i < 16; i++ {
 | 
			
		||||
		if got := container.MustExecutable(message.NewMsg(nil)); got != os.Args[0] {
 | 
			
		||||
		if got := container.MustExecutable(message.New(nil)); got != os.Args[0] {
 | 
			
		||||
			t.Errorf("MustExecutable: %q, want %q", got, os.Args[0])
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -461,7 +461,7 @@ func TryArgv0(msg message.Msg) {
 | 
			
		||||
	if msg == nil {
 | 
			
		||||
		log.SetPrefix(initName + ": ")
 | 
			
		||||
		log.SetFlags(0)
 | 
			
		||||
		msg = message.NewMsg(log.Default())
 | 
			
		||||
		msg = message.New(log.Default())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(os.Args) > 0 && path.Base(os.Args[0]) == initName {
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ import (
 | 
			
		||||
 | 
			
		||||
func TestOutcomeMain(t *testing.T) {
 | 
			
		||||
	t.Parallel()
 | 
			
		||||
	msg := message.NewMsg(nil)
 | 
			
		||||
	msg := message.New(nil)
 | 
			
		||||
	msg.SwapVerbose(testing.Verbose())
 | 
			
		||||
 | 
			
		||||
	testCases := []struct {
 | 
			
		||||
@ -40,7 +40,7 @@ func TestOutcomeMain(t *testing.T) {
 | 
			
		||||
		wantSys    *system.I
 | 
			
		||||
		wantParams *container.Params
 | 
			
		||||
	}{
 | 
			
		||||
		{"template", new(stubNixOS), hst.Template(), checkExpectInstanceId, system.New(panicMsgContext{}, message.NewMsg(nil), 1000009).
 | 
			
		||||
		{"template", new(stubNixOS), hst.Template(), checkExpectInstanceId, system.New(panicMsgContext{}, message.New(nil), 1000009).
 | 
			
		||||
			// spParamsOp
 | 
			
		||||
			Ensure(m("/tmp/hakurei.0"), 0711).
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -78,7 +78,7 @@ const shimName = "shim"
 | 
			
		||||
// Shim does not return.
 | 
			
		||||
func Shim(msg message.Msg) {
 | 
			
		||||
	if msg == nil {
 | 
			
		||||
		msg = message.NewMsg(log.Default())
 | 
			
		||||
		msg = message.New(log.Default())
 | 
			
		||||
	}
 | 
			
		||||
	shimEntrypoint(direct{msg})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -80,7 +80,7 @@ func TestSpDBusOp(t *testing.T) {
 | 
			
		||||
				"--broadcast=org.freedesktop.portal.*=@/org/freedesktop/portal/*",
 | 
			
		||||
			)}}, nil, nil),
 | 
			
		||||
		}, func() *system.I {
 | 
			
		||||
			sys := system.New(panicMsgContext{}, message.NewMsg(nil), checkExpectUid)
 | 
			
		||||
			sys := system.New(panicMsgContext{}, message.New(nil), checkExpectUid)
 | 
			
		||||
			sys.Ephemeral(system.Process, m(wantInstancePrefix), 0711)
 | 
			
		||||
			if err := sys.ProxyDBus(
 | 
			
		||||
				dbus.NewConfig(config.ID, true, true), nil,
 | 
			
		||||
@ -162,7 +162,7 @@ func TestSpDBusOp(t *testing.T) {
 | 
			
		||||
				"--talk=org.freedesktop.UPower",
 | 
			
		||||
			)}}, nil, nil),
 | 
			
		||||
		}, func() *system.I {
 | 
			
		||||
			sys := system.New(panicMsgContext{}, message.NewMsg(nil), checkExpectUid)
 | 
			
		||||
			sys := system.New(panicMsgContext{}, message.New(nil), checkExpectUid)
 | 
			
		||||
			sys.Ephemeral(system.Process, m(wantInstancePrefix), 0711)
 | 
			
		||||
			if err := sys.ProxyDBus(
 | 
			
		||||
				config.SessionBus, config.SystemBus,
 | 
			
		||||
 | 
			
		||||
@ -52,7 +52,7 @@ type Msg interface {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// defaultMsg is the default implementation of the [Msg] interface.
 | 
			
		||||
// The zero value is not safe for use. Callers should use the [NewMsg] function instead.
 | 
			
		||||
// The zero value is not safe for use. Callers should use the [New] function instead.
 | 
			
		||||
type defaultMsg struct {
 | 
			
		||||
	verbose atomic.Bool
 | 
			
		||||
 | 
			
		||||
@ -60,10 +60,10 @@ type defaultMsg struct {
 | 
			
		||||
	Suspendable
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewMsg initialises a downstream [log.Logger] for a new [Msg].
 | 
			
		||||
// The [log.Logger] should no longer be configured after NewMsg returns.
 | 
			
		||||
// New initialises a downstream [log.Logger] for a new [Msg].
 | 
			
		||||
// The [log.Logger] should no longer be configured after [New] returns.
 | 
			
		||||
// If downstream is nil, a new logger is initialised in its place.
 | 
			
		||||
func NewMsg(downstream *log.Logger) Msg {
 | 
			
		||||
func New(downstream *log.Logger) Msg {
 | 
			
		||||
	if downstream == nil {
 | 
			
		||||
		downstream = log.New(log.Writer(), "container: ", 0)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -51,7 +51,7 @@ func TestDefaultMsg(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	t.Run("logger", func(t *testing.T) {
 | 
			
		||||
		t.Run("nil", func(t *testing.T) {
 | 
			
		||||
			got := message.NewMsg(nil).GetLogger()
 | 
			
		||||
			got := message.New(nil).GetLogger()
 | 
			
		||||
 | 
			
		||||
			if out := got.Writer().(*message.Suspendable).Downstream; out != log.Writer() {
 | 
			
		||||
				t.Errorf("GetLogger: Downstream = %#v", out)
 | 
			
		||||
@ -64,7 +64,7 @@ func TestDefaultMsg(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
		t.Run("takeover", func(t *testing.T) {
 | 
			
		||||
			l := log.New(io.Discard, "\x00", 0xdeadbeef)
 | 
			
		||||
			got := message.NewMsg(l)
 | 
			
		||||
			got := message.New(l)
 | 
			
		||||
 | 
			
		||||
			if logger := got.GetLogger(); logger != l {
 | 
			
		||||
				t.Errorf("GetLogger: %#v, want %#v", logger, l)
 | 
			
		||||
@ -169,7 +169,7 @@ func TestDefaultMsg(t *testing.T) {
 | 
			
		||||
		}},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	msg := message.NewMsg(log.New(&dw, "test: ", 0))
 | 
			
		||||
	msg := message.New(log.New(&dw, "test: ", 0))
 | 
			
		||||
	for _, step := range steps {
 | 
			
		||||
		// these share the same writer, so cannot be subtests
 | 
			
		||||
		t.Logf("running step %q", step.name)
 | 
			
		||||
 | 
			
		||||
@ -93,9 +93,9 @@ func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
 | 
			
		||||
 | 
			
		||||
	t.Run("invalid start", func(t *testing.T) {
 | 
			
		||||
		if !useSandbox {
 | 
			
		||||
			p = dbus.NewDirect(t.Context(), message.NewMsg(nil), nil, nil)
 | 
			
		||||
			p = dbus.NewDirect(t.Context(), message.New(nil), nil, nil)
 | 
			
		||||
		} else {
 | 
			
		||||
			p = dbus.New(t.Context(), message.NewMsg(nil), nil, nil)
 | 
			
		||||
			p = dbus.New(t.Context(), message.New(nil), nil, nil)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err := p.Start(); !errors.Is(err, syscall.ENOTRECOVERABLE) {
 | 
			
		||||
@ -125,9 +125,9 @@ func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
 | 
			
		||||
			defer cancel()
 | 
			
		||||
			output := new(strings.Builder)
 | 
			
		||||
			if !useSandbox {
 | 
			
		||||
				p = dbus.NewDirect(ctx, message.NewMsg(nil), final, output)
 | 
			
		||||
				p = dbus.NewDirect(ctx, message.New(nil), final, output)
 | 
			
		||||
			} else {
 | 
			
		||||
				p = dbus.New(ctx, message.NewMsg(nil), final, output)
 | 
			
		||||
				p = dbus.New(ctx, message.New(nil), final, output)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			{ // check invalid wait behaviour
 | 
			
		||||
 | 
			
		||||
@ -82,7 +82,7 @@ func TestNew(t *testing.T) {
 | 
			
		||||
					t.Errorf("recover: %v, want %v", r, want)
 | 
			
		||||
				}
 | 
			
		||||
			}()
 | 
			
		||||
			New(nil, message.NewMsg(nil), 0)
 | 
			
		||||
			New(nil, message.New(nil), 0)
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
		t.Run("msg", func(t *testing.T) {
 | 
			
		||||
@ -102,11 +102,11 @@ func TestNew(t *testing.T) {
 | 
			
		||||
					t.Errorf("recover: %v, want %v", r, want)
 | 
			
		||||
				}
 | 
			
		||||
			}()
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), -1)
 | 
			
		||||
			New(t.Context(), message.New(nil), -1)
 | 
			
		||||
		})
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	sys := New(t.Context(), message.NewMsg(nil), 0xdeadbeef)
 | 
			
		||||
	sys := New(t.Context(), message.New(nil), 0xdeadbeef)
 | 
			
		||||
	if sys.ctx == nil {
 | 
			
		||||
		t.Error("New: ctx = nil")
 | 
			
		||||
	}
 | 
			
		||||
@ -125,51 +125,51 @@ func TestEqual(t *testing.T) {
 | 
			
		||||
		want bool
 | 
			
		||||
	}{
 | 
			
		||||
		{"simple UID",
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150),
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150),
 | 
			
		||||
			New(t.Context(), message.New(nil), 150),
 | 
			
		||||
			New(t.Context(), message.New(nil), 150),
 | 
			
		||||
			true},
 | 
			
		||||
 | 
			
		||||
		{"simple UID differ",
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150),
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 151),
 | 
			
		||||
			New(t.Context(), message.New(nil), 150),
 | 
			
		||||
			New(t.Context(), message.New(nil), 151),
 | 
			
		||||
			false},
 | 
			
		||||
 | 
			
		||||
		{"simple UID nil",
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150),
 | 
			
		||||
			New(t.Context(), message.New(nil), 150),
 | 
			
		||||
			nil,
 | 
			
		||||
			false},
 | 
			
		||||
 | 
			
		||||
		{"op length mismatch",
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150).
 | 
			
		||||
			New(t.Context(), message.New(nil), 150).
 | 
			
		||||
				ChangeHosts("chronos"),
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150).
 | 
			
		||||
			New(t.Context(), message.New(nil), 150).
 | 
			
		||||
				ChangeHosts("chronos").
 | 
			
		||||
				Ensure(m("/run"), 0755),
 | 
			
		||||
			false},
 | 
			
		||||
 | 
			
		||||
		{"op value mismatch",
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150).
 | 
			
		||||
			New(t.Context(), message.New(nil), 150).
 | 
			
		||||
				ChangeHosts("chronos").
 | 
			
		||||
				Ensure(m("/run"), 0644),
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150).
 | 
			
		||||
			New(t.Context(), message.New(nil), 150).
 | 
			
		||||
				ChangeHosts("chronos").
 | 
			
		||||
				Ensure(m("/run"), 0755),
 | 
			
		||||
			false},
 | 
			
		||||
 | 
			
		||||
		{"op type mismatch",
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150).
 | 
			
		||||
			New(t.Context(), message.New(nil), 150).
 | 
			
		||||
				ChangeHosts("chronos").
 | 
			
		||||
				Wayland(m("/proc/nonexistent/dst"), m("/proc/nonexistent/src"), "\x00", "\x00"),
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150).
 | 
			
		||||
			New(t.Context(), message.New(nil), 150).
 | 
			
		||||
				ChangeHosts("chronos").
 | 
			
		||||
				Ensure(m("/run"), 0755),
 | 
			
		||||
			false},
 | 
			
		||||
 | 
			
		||||
		{"op equals",
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150).
 | 
			
		||||
			New(t.Context(), message.New(nil), 150).
 | 
			
		||||
				ChangeHosts("chronos").
 | 
			
		||||
				Ensure(m("/run"), 0755),
 | 
			
		||||
			New(t.Context(), message.NewMsg(nil), 150).
 | 
			
		||||
			New(t.Context(), message.New(nil), 150).
 | 
			
		||||
				ChangeHosts("chronos").
 | 
			
		||||
				Ensure(m("/run"), 0755),
 | 
			
		||||
			true},
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user