Skip to content

Commit 4f411d9

Browse files
committed
Address review comments
Signed-off-by: Mark Yen <mark.yen@suse.com>
1 parent f4e48e3 commit 4f411d9

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/rd-init/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func run(ctx context.Context) error {
6161
// Notify ready before we reload the other units; otherwise we end up
6262
// blocking startup due to a loop with systemd-networkd.
6363
if _, err := daemon.SdNotify(true, daemon.SdNotifyReady); err != nil {
64-
return err
64+
return fmt.Errorf("failed to notify systemd: %w", err)
6565
}
6666

6767
seenUnits := make(map[string]bool)
@@ -75,7 +75,12 @@ func run(ctx context.Context) error {
7575
if err != nil {
7676
return fmt.Errorf("failed to start unit %s: %w", unit, err)
7777
}
78-
slog.InfoContext(ctx, "restarted systemd unit", "unit", unit, "result", <-ch)
78+
select {
79+
case result := <-ch:
80+
slog.InfoContext(ctx, "restarted systemd unit", "unit", unit, "result", result)
81+
case <-ctx.Done():
82+
return fmt.Errorf("context closed while waiting for systemd unit %s: %w", unit, ctx.Err())
83+
}
7984
}
8085

8186
return nil

src/rd-init/metadata.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import (
1010
"golang.org/x/sys/unix"
1111
)
1212

13+
const (
14+
// Path to cloud-config style metadata file provided by Lima.
15+
metadataPath = "/mnt/lima-cidata/meta-data"
16+
)
17+
1318
// Load /mnt/lima-cidata/meta-data
1419
func LoadMetadata(ctx context.Context) ([]string, error) {
1520
var metaData struct {
1621
LocalHostName string `yaml:"local-hostname"`
1722
}
1823

19-
file, err := os.Open("/mnt/lima-cidata/meta-data")
24+
file, err := os.Open(metadataPath)
2025
if err != nil {
2126
return nil, fmt.Errorf("failed to load meta-data file: %w", err)
2227
}

src/rd-init/network.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111
"github.com/goccy/go-yaml"
1212
)
1313

14+
const (
15+
// Path to cloud-config style networking configuration file provided by Lima.
16+
networkConfigPath = "/mnt/lima-cidata/network-config"
17+
)
18+
1419
var networkConfig struct {
1520
Version uint `yaml:"version"`
1621
Ethernets map[string]struct {
@@ -31,7 +36,7 @@ var networkConfig struct {
3136

3237
func LoadNetworkConfig(ctx context.Context) ([]string, error) {
3338
hasChanges := false
34-
file, err := os.Open("/mnt/lima-cidata/network-config")
39+
file, err := os.Open(networkConfigPath)
3540
if err != nil {
3641
return nil, fmt.Errorf("failed to read network-config: %w", err)
3742
}

src/rd-init/userdata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func LoadUserData(ctx context.Context) ([]string, error) {
115115
err := os.WriteFile(
116116
fmt.Sprintf("/etc/sudoers.d/90-lima-user-%s", userEntry.Name),
117117
[]byte(userEntry.Name + " " + userEntry.Sudo),
118-
0o644)
118+
0o400)
119119
if err != nil {
120120
return nil, fmt.Errorf("failed to create sudoers file for %q: %w", userEntry.Name, err)
121121
}
@@ -185,7 +185,7 @@ func LoadUserData(ctx context.Context) ([]string, error) {
185185
if err := os.WriteFile(writeFile.Path, []byte(writeFile.Content), os.FileMode(fileMode)); err != nil {
186186
return nil, fmt.Errorf("failed to write file %s: %w", writeFile.Path, err)
187187
}
188-
uid := int64(-1)
188+
var uid int64
189189
gid := int64(-1)
190190
userName, groupName, _ := strings.Cut(writeFile.Owner, ":")
191191
if u, err := user.Lookup(userName); err != nil {

0 commit comments

Comments
 (0)