Beispiel #1
0
// WaitOnDevices waits for the devices named in devs to be plugged before returning.
func WaitOnDevices(devs []string, stage string) error {
	conn, err := dbus.NewSystemdConnection()
	if err != nil {
		return err
	}

	devUnits := []string{}
	for _, d := range devs {
		devUnits = append(devUnits, unit.UnitNamePathEscape(d)+".device")
	}

	unitName := unit.UnitNameEscape(fmt.Sprintf("ignition_%s.service", stage))
	props := []dbus.Property{
		dbus.PropExecStart([]string{"/bin/true"}, false), // XXX(vc): we apparently are required to ExecStart _something_
		dbus.PropAfter(devUnits...),
		dbus.PropRequires(devUnits...),
	}

	res := make(chan string)
	if _, err = conn.StartTransientUnit(unitName, "replace", props, res); err != nil {
		return fmt.Errorf("failed creating transient unit %s: %v", unitName, err)
	}
	s := <-res

	if s != "done" {
		return fmt.Errorf("transient unit %s %s", unitName, s)
	}

	return nil
}
Beispiel #2
0
// WaitOnDevices waits for the devices named in devs to be plugged before returning.
func WaitOnDevices(devs []string, stage string) error {
	conn, err := dbus.NewSystemdConnection()
	if err != nil {
		return err
	}

	results := map[string]chan string{}
	for _, dev := range devs {
		unitName := unit.UnitNamePathEscape(dev + ".device")
		results[unitName] = make(chan string)

		if _, err = conn.StartUnit(unitName, "replace", results[unitName]); err != nil {
			return fmt.Errorf("failed starting device unit %s: %v", unitName, err)
		}
	}

	for unitName, result := range results {
		s := <-result

		if s != "done" {
			return fmt.Errorf("device unit %s %s", unitName, s)
		}
	}

	return nil
}