Skip to content
Snippets Groups Projects
Commit b600d3e9 authored by Zygmunt Krynicki's avatar Zygmunt Krynicki
Browse files

ota/raucinterface,rauc/installhandler: convey install handler process ID


RAUC install handlers execute in a mount namespace which sees the mounted
bundle file. Add HandlerContext.HandlerPID which tracks the process
which was responsible for the request.

This allows sysotad to, receive the request, complete the request using
the file system as the handler process sees it, before responding to the
handler process.

The Service.{Pre,Post}Install methods are extended to take the special
dbus.Sender argument. The service calls org.freedesktop.DBus method
GetConnectionUnixProcessID to find the process corresponding to the sender.

Signed-off-by: default avatarZygmunt Krynicki <zygmunt.krynicki@huawei.com>
parent 01bb4ac0
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ package raucinterface_test
import (
"encoding/xml"
"errors"
"os"
"testing"
"github.com/godbus/dbus/v5"
......@@ -283,7 +284,8 @@ func (s *clientSuite) TestPreInstallSuccess(c *C) {
s.EnsureService(c)
client := raucinterface.NewClient(s.EnsureConn(c))
ctx := &installhandler.HandlerContext{
SystemConfig: "foo",
SystemConfig: "foo",
InitialHandlerPID: os.Getpid(), // we self-send the D-Bus message.
}
called := false
s.installParticipant.PreInstallHandlerFn = func(ctx2 *installhandler.HandlerContext) error {
......@@ -323,7 +325,8 @@ func (s *clientSuite) TestPostInstallSuccess(c *C) {
s.EnsureService(c)
client := raucinterface.NewClient(s.EnsureConn(c))
ctx := &installhandler.HandlerContext{
SystemConfig: "foo",
SystemConfig: "foo",
InitialHandlerPID: os.Getpid(), // we self-send the D-Bus message.
}
called := false
s.installParticipant.PostInstallHandlerFn = func(ctx2 *installhandler.HandlerContext) error {
......
......@@ -38,6 +38,8 @@ const (
type Service struct {
bootHandler boothandler.Handler
installHandler installhandler.Participant
conn *dbus.Conn
}
// NewService returns a service with the given boot backend.
......@@ -47,6 +49,8 @@ func NewService(bootHandler boothandler.Handler, installHandler installhandler.P
// JoinServiceHost integrates with dbusutil.ServiceHost.
func (svc *Service) JoinServiceHost(reg dbusutil.ServiceRegistration) error {
svc.conn = reg.DBusConn()
methods := map[string]interface{}{
getPrimaryDBusName: svc.GetPrimary,
setPrimaryDBusName: svc.SetPrimary,
......@@ -200,13 +204,31 @@ func (svc *Service) SetState(slotName string, stateName string) (dbusErr *dbus.E
return nil
}
func (svc *Service) populateHandlerPID(ctx *installhandler.HandlerContext, sender dbus.Sender) error {
// Find the pid of the sender and store it int the handler context.
// See https://dbus.freedesktop.org/doc/dbus-specification.html
var pid uint32
if err := svc.conn.BusObject().Call("org.freedesktop.DBus.GetConnectionUnixProcessID", 0, sender).Store(&pid); err != nil {
return err
}
ctx.InitialHandlerPID = int(pid)
return nil
}
// PreInstall maps installhandler.Participant.PreInstallHandler to D-Bus.
func (svc *Service) PreInstall(env []string) (dbusErr *dbus.Error) {
func (svc *Service) PreInstall(sender dbus.Sender, env []string) (dbusErr *dbus.Error) {
ctx, err := installhandler.NewHandlerContext(env)
if err != nil {
return dbus.MakeFailedError(err)
}
if err := svc.populateHandlerPID(ctx, sender); err != nil {
return dbus.MakeFailedError(err)
}
if err := svc.installHandler.PreInstallHandler(ctx); err != nil {
return dbus.MakeFailedError(err)
}
......@@ -215,12 +237,16 @@ func (svc *Service) PreInstall(env []string) (dbusErr *dbus.Error) {
}
// PostInstall maps installhandler.Participant.PostInstallHandler to D-Bus.
func (svc *Service) PostInstall(env []string) (dbusErr *dbus.Error) {
func (svc *Service) PostInstall(sender dbus.Sender, env []string) (dbusErr *dbus.Error) {
ctx, err := installhandler.NewHandlerContext(env)
if err != nil {
return dbus.MakeFailedError(err)
}
if err := svc.populateHandlerPID(ctx, sender); err != nil {
return dbus.MakeFailedError(err)
}
if err := svc.installHandler.PostInstallHandler(ctx); err != nil {
return dbus.MakeFailedError(err)
}
......
......@@ -51,6 +51,10 @@ type HandlerContext struct {
// Images correspond to data collected from a number of variables. See the
// documentation of the Image type for details.
Images map[string]*Image
// InitialHandlerPID is the PID of initial handler process. The handler may be in a
// special mount namespace, distinct from the rest of the system.
InitialHandlerPID int
}
// Slot contains information about RAUC slots provided to install handlers.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment