mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
interfaces/udev: add udev support code
This patch adds a function for reloading the udev database. Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
This commit is contained in:
37
interfaces/udev/udev.go
Normal file
37
interfaces/udev/udev.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// -*- Mode: Go; indent-tabs-mode: t -*-
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Canonical Ltd
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 3 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package udev
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// ReloadRules runs two commands that reload udev rule database.
|
||||
//
|
||||
// The commands are: udevadm control --reload-rules
|
||||
// udevadm trigger
|
||||
func ReloadRules() error {
|
||||
err := exec.Command("udevadm", "control", "--reload-rules").Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = exec.Command("udevadm", "trigger").Run()
|
||||
return err
|
||||
}
|
||||
57
interfaces/udev/udev_test.go
Normal file
57
interfaces/udev/udev_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
// -*- Mode: Go; indent-tabs-mode: t -*-
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Canonical Ltd
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 3 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package udev_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
|
||||
"github.com/ubuntu-core/snappy/interfaces/udev"
|
||||
"github.com/ubuntu-core/snappy/testutil"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) {
|
||||
TestingT(t)
|
||||
}
|
||||
|
||||
type uDevSuite struct {
|
||||
testutil.ExecTest
|
||||
}
|
||||
|
||||
var _ = Suite(&uDevSuite{})
|
||||
|
||||
// Tests for ReloadRules()
|
||||
|
||||
func (s *uDevSuite) TestReloadUDevRulesRunsUDevAdm(c *C) {
|
||||
s.ExecTest.MockExecutable(c, "udevadm")
|
||||
err := udev.ReloadRules()
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(s.CallsToExecutable(c, "udevadm"), DeepEquals, []string{
|
||||
"control --reload-rules",
|
||||
"trigger",
|
||||
})
|
||||
}
|
||||
|
||||
func (s *uDevSuite) TestReloadUDevRulesReportsErrors(c *C) {
|
||||
s.ExecTest.MockFailingExecutable(c, "udevadm", 42)
|
||||
err := udev.ReloadRules()
|
||||
c.Assert(err, ErrorMatches, "exit status 42")
|
||||
}
|
||||
Reference in New Issue
Block a user