Merge lp:~axwalk/juju-core/lp1212916-hook-unix-socket-namespace into lp:~go-bot/juju-core/trunk

Proposed by Andrew Wilkins
Status: Merged
Approved by: Andrew Wilkins
Approved revision: no longer in the source branch.
Merged at revision: 1690
Proposed branch: lp:~axwalk/juju-core/lp1212916-hook-unix-socket-namespace
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 57 lines (+10/-6)
2 files modified
worker/uniter/jujuc/server.go (+8/-6)
worker/uniter/uniter.go (+2/-0)
To merge this branch: bzr merge lp:~axwalk/juju-core/lp1212916-hook-unix-socket-namespace
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+181191@code.launchpad.net

Commit message

uniter: Use abstract namespace for unix sockets

Also, don't attempt to remove the socket after
closing the server. It's not necessary to do this
anyway; the Close method on the socket already
does an Unlink if not using the abstract namespace
(hence tests don't need changing).

Abstract namespaces are a Linux extension, so this
will break if we ever support Unixes. I've purposely
not checked the OS, so that it'll be obviously broken
and we can revisit this issue.

Fixes bug #1212916

https://codereview.appspot.com/12742045/

Description of the change

uniter: Use abstract namespace for unix sockets

Also, don't attempt to remove the socket after
closing the server. It's not necessary to do this
anyway; the Close method on the socket already
does an Unlink if not using the abstract namespace
(hence tests don't need changing).

Abstract namespaces are a Linux extension, so this
will break if we ever support Unixes. I've purposely
not checked the OS, so that it'll be obviously broken
and we can revisit this issue.

Fixes bug #1212916

https://codereview.appspot.com/12742045/

To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote :

Reviewers: mp+181191_code.launchpad.net,

Message:
Please take a look.

Description:
uniter: Use abstract namespace for unix sockets

Also, don't attempt to remove the socket after
closing the server. It's not necessary to do this
anyway; the Close method on the socket already
does an Unlink if not using the abstract namespace
(hence tests don't need changing).

Abstract namespaces are a Linux extension, so this
will break if we ever support Unixes. I've purposely
not checked the OS, so that it'll be obviously broken
and we can revisit this issue.

Fixes bug #1212916

https://code.launchpad.net/~axwalk/juju-core/lp1212916-hook-unix-socket-namespace/+merge/181191

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/12742045/

Affected files:
   A [revision details]
   M worker/uniter/jujuc/server.go
   M worker/uniter/uniter.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20130820022554-t4r3stekgq56x0ih
+New revision: <email address hidden>

Index: worker/uniter/uniter.go
=== modified file 'worker/uniter/uniter.go'
--- worker/uniter/uniter.go 2013-08-06 01:42:16 +0000
+++ worker/uniter/uniter.go 2013-08-21 03:27:47 +0000
@@ -338,6 +338,8 @@
    return jujuc.NewCommand(hctx, cmdName)
   }
   socketPath := filepath.Join(u.baseDir, "agent.socket")
+ // Use abstract namespace so we don't get stale socket files.
+ socketPath = "@" + socketPath
   srv, err := jujuc.NewServer(getCmd, socketPath)
   if err != nil {
    return err

Index: worker/uniter/jujuc/server.go
=== modified file 'worker/uniter/jujuc/server.go'
--- worker/uniter/jujuc/server.go 2013-05-02 15:55:42 +0000
+++ worker/uniter/jujuc/server.go 2013-08-21 03:27:47 +0000
@@ -9,16 +9,19 @@
  import (
   "bytes"
   "fmt"
- "launchpad.net/juju-core/cmd"
- "launchpad.net/juju-core/log"
   "net"
   "net/rpc"
- "os"
   "path/filepath"
   "sort"
   "sync"
+
+ "launchpad.net/loggo"
+
+ "launchpad.net/juju-core/cmd"
  )

+var logger = loggo.GetLogger("worker.uniter.jujuc")
+
  // newCommands maps Command names to initializers.
  var newCommands = map[string]func(Context) cmd.Command{
   "close-port": NewClosePortCommand,
@@ -102,8 +105,8 @@
   }
   j.mu.Lock()
   defer j.mu.Unlock()
- log.Infof("worker/uniter/jujuc: running hook tool %q %q",
req.CommandName, req.Args)
- log.Debugf("worker/uniter/jujuc: hook context id %q; dir %q",
req.ContextId, req.Dir)
+ logger.Infof("running hook tool %q %q", req.CommandName, req.Args)
+ logger.Debugf("hook context id %q; dir %q", req.ContextId, req.Dir)
   resp.Code = cmd.Main(c, ctx, req.Args)
   resp.Stdout = stdout.Bytes()
   resp.Stderr = stderr.Bytes()
@@ -176,6 +179,5 @@
  func (s *Server) Close() {
   close(s.closing)
   s.listener.Close()
- os.Remove(s.socketPath)
   <-s.closed
  }

Revision history for this message
Roger Peppe (rogpeppe) wrote :

On 2013/08/21 03:59:21, dfc wrote:
> On 2013/08/21 03:46:31, axw wrote:
> > Please take a look.

> LGTM. Thanks for fixing this, I'm surprised none of the tests needed
to change.

LGTM

https://codereview.appspot.com/12742045/

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2013-08-21 7:46, Andrew Wilkins wrote:
> uniter: Use abstract namespace for unix sockets
>
> Also, don't attempt to remove the socket after closing the server.
> It's not necessary to do this anyway; the Close method on the
> socket already does an Unlink if not using the abstract namespace
> (hence tests don't need changing).

This comment confuses me. You say "lets switch to the abstract
namespace" and then "we don't need to delete if we aren't using the
abstract namespace". Doesn't that mean we *do* need to delete?

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13 (Cygwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlIUl/oACgkQJdeBCYSNAAN6QgCgg0sq6bYo3PbTSRlxYdAAnpGh
zdUAnRtfwP5D/DmqLBaUaCpAp1mDXDXv
=TKs0
-----END PGP SIGNATURE-----

Revision history for this message
Andrew Wilkins (axwalk) wrote :

> > Also, don't attempt to remove the socket after closing the server.
> > It's not necessary to do this anyway; the Close method on the
> > socket already does an Unlink if not using the abstract namespace
> > (hence tests don't need changing).
>
> This comment confuses me. You say "lets switch to the abstract
> namespace" and then "we don't need to delete if we aren't using the
> abstract namespace". Doesn't that mean we *do* need to delete?

That paragraph refers to the removal of the os.Remove from jujuc.Server.Close. While we've moved to the abstract namespace in the normal runtime code, some tests call jujuc.NewServer directly with filesystem paths. What I was trying to get at was that the os.Remove was never necessary (unless the Go standard library changed behaviour?), which explains why the tests don't need to change. Let me know if I'm still not being clear.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'worker/uniter/jujuc/server.go'
2--- worker/uniter/jujuc/server.go 2013-05-02 15:55:42 +0000
3+++ worker/uniter/jujuc/server.go 2013-08-21 03:45:36 +0000
4@@ -9,16 +9,19 @@
5 import (
6 "bytes"
7 "fmt"
8- "launchpad.net/juju-core/cmd"
9- "launchpad.net/juju-core/log"
10 "net"
11 "net/rpc"
12- "os"
13 "path/filepath"
14 "sort"
15 "sync"
16+
17+ "launchpad.net/loggo"
18+
19+ "launchpad.net/juju-core/cmd"
20 )
21
22+var logger = loggo.GetLogger("worker.uniter.jujuc")
23+
24 // newCommands maps Command names to initializers.
25 var newCommands = map[string]func(Context) cmd.Command{
26 "close-port": NewClosePortCommand,
27@@ -102,8 +105,8 @@
28 }
29 j.mu.Lock()
30 defer j.mu.Unlock()
31- log.Infof("worker/uniter/jujuc: running hook tool %q %q", req.CommandName, req.Args)
32- log.Debugf("worker/uniter/jujuc: hook context id %q; dir %q", req.ContextId, req.Dir)
33+ logger.Infof("running hook tool %q %q", req.CommandName, req.Args)
34+ logger.Debugf("hook context id %q; dir %q", req.ContextId, req.Dir)
35 resp.Code = cmd.Main(c, ctx, req.Args)
36 resp.Stdout = stdout.Bytes()
37 resp.Stderr = stderr.Bytes()
38@@ -176,6 +179,5 @@
39 func (s *Server) Close() {
40 close(s.closing)
41 s.listener.Close()
42- os.Remove(s.socketPath)
43 <-s.closed
44 }
45
46=== modified file 'worker/uniter/uniter.go'
47--- worker/uniter/uniter.go 2013-08-06 01:42:16 +0000
48+++ worker/uniter/uniter.go 2013-08-21 03:45:36 +0000
49@@ -338,6 +338,8 @@
50 return jujuc.NewCommand(hctx, cmdName)
51 }
52 socketPath := filepath.Join(u.baseDir, "agent.socket")
53+ // Use abstract namespace so we don't get stale socket files.
54+ socketPath = "@" + socketPath
55 srv, err := jujuc.NewServer(getCmd, socketPath)
56 if err != nil {
57 return err

Subscribers

People subscribed via source and target branches

to status/vote changes: