Esempio n. 1
0
func snapRunApp(snapApp, command string, args []string) error {
	snapName, appName := snap.SplitSnapApp(snapApp)
	info, err := getSnapInfo(snapName, snap.R(0))
	if err != nil {
		return err
	}

	app := info.Apps[appName]
	if app == nil {
		return fmt.Errorf(i18n.G("cannot find app %q in %q"), appName, snapName)
	}

	return runSnapConfine(info, app.SecurityTag(), snapApp, command, "", args)
}
Esempio n. 2
0
func (s *infoSuite) TestSplitSnapApp(c *C) {
	for _, t := range []struct {
		in  string
		out []string
	}{
		// normal cases
		{"foo.bar", []string{"foo", "bar"}},
		{"foo.bar.baz", []string{"foo", "bar.baz"}},
		// special case, snapName == appName
		{"foo", []string{"foo", "foo"}},
	} {
		snap, app := snap.SplitSnapApp(t.in)
		c.Check([]string{snap, app}, DeepEquals, t.out)
	}
}
Esempio n. 3
0
func snapExecApp(snapApp, revision, command string, args []string) error {
	rev, err := snap.ParseRevision(revision)
	if err != nil {
		return fmt.Errorf("cannot parse revision %q: %s", revision, err)
	}

	snapName, appName := snap.SplitSnapApp(snapApp)
	info, err := snap.ReadInfo(snapName, &snap.SideInfo{
		Revision: rev,
	})
	if err != nil {
		return fmt.Errorf("cannot read info for %q: %s", snapName, err)
	}

	app := info.Apps[appName]
	if app == nil {
		return fmt.Errorf("cannot find app %q in %q", appName, snapName)
	}

	cmdAndArgs, err := findCommand(app, command)
	if err != nil {
		return err
	}
	// strings.Split() is ok here because we validate all app fields
	// and the whitelist is pretty strict (see
	// snap/validate.go:appContentWhitelist)
	cmdArgv := strings.Split(cmdAndArgs, " ")
	cmd := cmdArgv[0]
	cmdArgs := cmdArgv[1:]

	// build the environment from the yaml
	env := append(os.Environ(), app.Env()...)

	// run the command
	fullCmd := filepath.Join(app.Snap.MountDir(), cmd)
	if command == "shell" {
		fullCmd = "/bin/bash"
		cmdArgs = nil
	}
	fullCmdArgs := []string{fullCmd}
	fullCmdArgs = append(fullCmdArgs, cmdArgs...)
	fullCmdArgs = append(fullCmdArgs, args...)
	if err := syscallExec(fullCmd, fullCmdArgs, env); err != nil {
		return fmt.Errorf("cannot exec %q: %s", fullCmd, err)
	}
	// this is never reached except in tests
	return nil
}
Esempio n. 4
0
func ExampleSpltiSnapAppShort() {
	fmt.Println(snap.SplitSnapApp("hello-world"))
	// Output: hello-world hello-world
}
Esempio n. 5
0
func ExampleSpltiSnapApp() {
	fmt.Println(snap.SplitSnapApp("hello-world.env"))
	// Output: hello-world env
}