Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dirs,interfaces,overlord,snap,snapenv,test: export per-snap XDG_RUNTIME_DIR per user (LP: #1620442) #2281

Merged
merged 11 commits into from
Nov 17, 2016

Conversation

jdstrand
Copy link

@jdstrand jdstrand commented Nov 15, 2016

  • interfaces: allow access to snap-specific XDG_RUNTIME_DIR
  • snapenv: export XDG_RUNTIME_DIR as part of snapenv
  • dirs,overlord,snap: cleanup XdgRuntimeDir for all users on removal

In support of Ubuntu Personal and xdg-aware snaps, this PR exports XDG_RUNTIME_DIR as a snap and user-specific directory. AppArmor rules are added to allow creating and using the directory. Note: the location of this directory follows the current convention of /run/user/$UID except that it creates a snap-specific subdirectory under it which follows the typical snappy file naming conventions. Eg, for a snap named 'foo', XDG_RUNTIME_DIR=/run/user/$UID/snap.foo. $UID is set to os.Geteuid() to ensure the proper uid is used when invoked with sudo.

A separate PR for snap-confine will create this directory on behalf of the user. These PR can land independently of each other.

Copy link
Contributor

@mvo5 mvo5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, looks like one (trivial) test is missing but once that is there its good to go.

@@ -475,6 +475,7 @@ func (s *infoSuite) TestDirAndFileMethods(c *C) {
c.Check(info.UserDataDir("/home/bob"), Equals, "/home/bob/snap/name/1")
c.Check(info.UserCommonDataDir("/home/bob"), Equals, "/home/bob/snap/name/common")
c.Check(info.CommonDataDir(), Equals, "/var/snap/name/common")
c.Check(info.UserXdgRuntimeDir(12345), Equals, "/run/user/12345/snap.name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we want to test XdgRuntimeDir here has well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks! Added.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Copy link
Contributor

@zyga zyga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments, mostly about naming. I pushed one spread test to this branch to have some idea of what we're setting now.

@@ -319,6 +319,10 @@ var defaultTemplate = []byte(`
# access in /dev/shm for shm_open() and files in subdirectories for open()
/{dev,run}/shm/snap.@{SNAP_NAME}.** mrwlkix,

# Snap-specific XDG_RUNTIME_DIR that is based on the UID of the user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use + rather than *, just to ensure that component exists please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zyga - I don't understand this comment: "Can we use + rather than *, just to ensure that component exists please." in the context of where you put the comment. Can you elaborate? (the apparmor rule is correct)

@@ -56,6 +56,9 @@ type PlaceInfo interface {

// CommonDataHomeDir returns the per user data directory common across revisions of the snap.
CommonDataHomeDir() string

// XdgRuntimeDir returns the XDG_RUNTIME_DIR directories of the snap.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One directory or many directories? Code wise it looks like just one. If someone please adjust the comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah if this is supposed to be a glob it should be more explicit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zyga - this is one directory per user, but cleanup will be a glob since multiple users might have used the snap and have the directory. Ie:

  • I launch a snap 'foo' and need XDG_RUNTIME_DIR=/run/user/1000/snap.foo (ie UserXdgRuntimeDir())
  • you launch a snap 'foo' and need XDG_RUNTIME_DIR=/run/user/1001/snap.foo (ie UserXdgRuntimeDir())
  • the sysadmin does 'snap remove foo' (ie XdgRuntimeDir() glob for /run/user/*/snap.foo

I'll improve the comments and function names.

@jdstrand
Copy link
Author

jdstrand commented Nov 16, 2016

It looks like the XDG_SESSION_ID check that @zyga added is causing the autopkgtests to fail. This variable wasn't added as part of this commit so removing from the spread test.

@mvo5
Copy link
Contributor

mvo5 commented Nov 17, 2016

Looks good, please feel free to merge once the travis tests are green. The autopkgtests have some known issue (after merging master it should be much better) so its ok to ignore them for now.

@jdstrand jdstrand merged commit 81bb592 into canonical:master Nov 17, 2016
@jdstrand jdstrand deleted the per-snap-xdg-runtime-dir branch November 17, 2016 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants