Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon: Always close the ready channel on error #264

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cmd/authd-oidc/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,26 @@ func New(name string) *App {
// serve creates new dbus service on the system bus. This call is blocking until we quit it.
func (a *App) serve(config daemonConfig) error {
ctx := context.Background()
// Ensure that the a.ready channel is closed when the function returns, which is what Quit() waits for before exiting.
readyPtr := &a.ready
3v1n0 marked this conversation as resolved.
Show resolved Hide resolved
closeFunc := func() {
if readyPtr == nil {
return
}
close(*readyPtr)
readyPtr = nil
}
defer closeFunc()

// When the data directory is SNAP_DATA, it has permission 0755, else we want to create it with 0700.
if err := ensureDirWithPerms(config.Paths.DataDir, 0700, os.Geteuid()); err != nil {
if err := ensureDirWithPerms(config.Paths.DataDir, 0755, os.Geteuid()); err != nil {
close(a.ready)
return fmt.Errorf("error initializing data directory %q: %v", config.Paths.DataDir, err)
}
}

brokerConfigDir := broker.GetDropInDir(config.Paths.BrokerConf)
if err := ensureDirWithPerms(brokerConfigDir, 0700, os.Geteuid()); err != nil {
close(a.ready)
return fmt.Errorf("error initializing broker configuration directory %q: %v", brokerConfigDir, err)
}

Expand All @@ -142,20 +150,18 @@ func (a *App) serve(config daemonConfig) error {

s, err := dbusservice.New(ctx, b)
if err != nil {
close(a.ready)
return err
}

var daemonopts []daemon.Option
daemon, err := daemon.New(ctx, s, daemonopts...)
if err != nil {
_ = s.Stop()
close(a.ready)
return err
}

a.daemon = daemon
close(a.ready)
closeFunc()
adombeck marked this conversation as resolved.
Show resolved Hide resolved

return daemon.Serve(ctx)
}
Expand Down
Loading