summaryrefslogtreecommitdiff
diff options
authorMichael Vogt <mvo@ubuntu.com>2020-10-28 13:13:27 +0100
committerMichael Vogt <mvo@ubuntu.com>2020-10-28 13:13:27 +0100
commit417b03103a73d1f961703abc128b9f27bcf119ac (patch)
treee32302be09b499ba8b6204a52b6610d6f3d55288
parentc4b329fa3a17a338d433afb192c6ab2f1d0179ee (diff)
interface: retry gpio export for up to 30sslow-gpio-retry
This commit changes the generated systemd service from the gpio interface so that they will retry exporting a gpio pin for up to 30s. This should fix the issues that some devices are slow at loading/initializing the gpio kernel modules.
-rw-r--r--interfaces/builtin/gpio.go2
-rw-r--r--interfaces/builtin/gpio_test.go2
2 files changed, 2 insertions, 2 deletions
diff --git a/interfaces/builtin/gpio.go b/interfaces/builtin/gpio.go
index ee05c1ffb4..9faa4da884 100644
--- a/interfaces/builtin/gpio.go
+++ b/interfaces/builtin/gpio.go
@@ -116,7 +116,7 @@ func (iface *gpioInterface) SystemdConnectedSlot(spec *systemd.Specification, pl
service := &systemd.Service{
Type: "oneshot",
RemainAfterExit: true,
- ExecStart: fmt.Sprintf("/bin/sh -c 'test -e /sys/class/gpio/gpio%d || echo %d > /sys/class/gpio/export'", gpioNum, gpioNum),
+ ExecStart: fmt.Sprintf(`/bin/sh -c 'i=0; while ! (test -e /sys/class/gpio/gpio%d || echo %d > /sys/class/gpio/export ); do if [ "$i" = 30 ]; then exit 1; fi; i=$((i+1)); sleep 1; done'`, gpioNum, gpioNum),
ExecStop: fmt.Sprintf("/bin/sh -c 'test ! -e /sys/class/gpio/gpio%d || echo %d > /sys/class/gpio/unexport'", gpioNum, gpioNum),
}
return spec.AddService(serviceName, service)
diff --git a/interfaces/builtin/gpio_test.go b/interfaces/builtin/gpio_test.go
index 423eb65928..f72693f1f9 100644
--- a/interfaces/builtin/gpio_test.go
+++ b/interfaces/builtin/gpio_test.go
@@ -134,7 +134,7 @@ func (s *GpioInterfaceSuite) TestSystemdConnectedSlot(c *C) {
"snap.my-device.interface.gpio-100.service": {
Type: "oneshot",
RemainAfterExit: true,
- ExecStart: `/bin/sh -c 'test -e /sys/class/gpio/gpio100 || echo 100 > /sys/class/gpio/export'`,
+ ExecStart: `/bin/sh -c 'i=0; while ! (test -e /sys/class/gpio/gpio100 || echo 100 > /sys/class/gpio/export ); do if [ "$i" = 30 ]; then exit 1; fi; i=$((i+1)); sleep 1; done'`,
ExecStop: `/bin/sh -c 'test ! -e /sys/class/gpio/gpio100 || echo 100 > /sys/class/gpio/unexport'`,
},
})