forked from docker-archive/runc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@kolyshkin: documentation nits] Signed-off-by: Shiming Zhang <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
- Loading branch information
Showing
4 changed files
with
70 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// +build linux | ||
|
||
package systemd | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
systemdDbus "github.com/coreos/go-systemd/v22/dbus" | ||
) | ||
|
||
type dbusConnManager struct { | ||
conn *systemdDbus.Conn | ||
rootless bool | ||
sync.RWMutex | ||
} | ||
|
||
// newDbusConnManager initializes systemd dbus connection manager. | ||
func newDbusConnManager(rootless bool) *dbusConnManager { | ||
return &dbusConnManager{ | ||
rootless: rootless, | ||
} | ||
} | ||
|
||
// getConnection lazily initializes and returns systemd dbus connection. | ||
func (d *dbusConnManager) getConnection() (*systemdDbus.Conn, error) { | ||
// In the case where d.conn != nil | ||
// Use the read lock the first time to ensure | ||
// that Conn can be acquired at the same time. | ||
d.RLock() | ||
if conn := d.conn; conn != nil { | ||
d.RUnlock() | ||
return conn, nil | ||
} | ||
d.RUnlock() | ||
|
||
// In the case where d.conn == nil | ||
// Use write lock to ensure that only one | ||
// will be created | ||
d.Lock() | ||
defer d.Unlock() | ||
if conn := d.conn; conn != nil { | ||
return conn, nil | ||
} | ||
|
||
conn, err := d.newConnection() | ||
if err != nil { | ||
return nil, err | ||
} | ||
d.conn = conn | ||
return conn, nil | ||
} | ||
|
||
func (d *dbusConnManager) newConnection() (*systemdDbus.Conn, error) { | ||
if d.rootless { | ||
return NewUserSystemdDbus() | ||
} | ||
return systemdDbus.NewWithContext(context.TODO()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters