Skip to content
Snippets Groups Projects
Commit fed4bb2c authored by Nicolas Dumazet's avatar Nicolas Dumazet
Browse files

inotify: raise correct error if server is already started in a deep repository

When path is too long to be an Unix socket address, we create a socket in a
temporary directory and link from the long path to the shorter one.
But checks in server code at startup were insufficient in this case, and used
to raise an unclear "tried linking .hg/inotify.sock to a temporary socket but
.hg/inotify.sock already exists"
parent 6c0e1aee
No related branches found
No related tags found
No related merge requests found
...@@ -332,5 +332,12 @@ ...@@ -332,5 +332,12 @@
self.repowatcher = repowatcher self.repowatcher = repowatcher
self.sock = socket.socket(socket.AF_UNIX) self.sock = socket.socket(socket.AF_UNIX)
self.sockpath = join(root, '.hg/inotify.sock') self.sockpath = join(root, '.hg/inotify.sock')
self.realsockpath = None
self.realsockpath = self.sockpath
if os.path.islink(self.sockpath):
if os.path.exists(self.sockpath):
self.realsockpath = os.readlink(self.sockpath)
else:
raise util.Abort('inotify-server: cannot start: '
'.hg/inotify.sock is a broken symlink')
try: try:
...@@ -336,7 +343,7 @@ ...@@ -336,7 +343,7 @@
try: try:
self.sock.bind(self.sockpath) self.sock.bind(self.realsockpath)
except socket.error, err: except socket.error, err:
if err.args[0] == errno.EADDRINUSE: if err.args[0] == errno.EADDRINUSE:
raise AlreadyStartedException(_('cannot start: socket is ' raise AlreadyStartedException(_('cannot start: socket is '
'already bound')) 'already bound'))
if err.args[0] == "AF_UNIX path too long": if err.args[0] == "AF_UNIX path too long":
...@@ -338,12 +345,8 @@ ...@@ -338,12 +345,8 @@
except socket.error, err: except socket.error, err:
if err.args[0] == errno.EADDRINUSE: if err.args[0] == errno.EADDRINUSE:
raise AlreadyStartedException(_('cannot start: socket is ' raise AlreadyStartedException(_('cannot start: socket is '
'already bound')) 'already bound'))
if err.args[0] == "AF_UNIX path too long": if err.args[0] == "AF_UNIX path too long":
if os.path.islink(self.sockpath) and \
not os.path.exists(self.sockpath):
raise util.Abort('inotify-server: cannot start: '
'.hg/inotify.sock is a broken symlink')
tempdir = tempfile.mkdtemp(prefix="hg-inotify-") tempdir = tempfile.mkdtemp(prefix="hg-inotify-")
self.realsockpath = os.path.join(tempdir, "inotify.sock") self.realsockpath = os.path.join(tempdir, "inotify.sock")
try: try:
......
...@@ -26,4 +26,11 @@ ...@@ -26,4 +26,11 @@
$ hg status $ hg status
? hg.pid ? hg.pid
if we try to start twice the server, make sure we get a correct error
$ hg inserve -d --pid-file=hg2.pid
abort: inotify-server: cannot start: socket is already bound
abort: child process failed to start
[255]
$ kill `cat hg.pid` $ kill `cat hg.pid`
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment