From 6b4b841a403380eeadd39ab0fdec50c73cd4d342 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arkadiusz=20Mi=C5=9Bkiewicz?= Date: Sun, 11 Sep 2005 14:33:38 +0000 Subject: [PATCH] - command to dump locks data into log file - unlock can fail when tree is already unlocked Changed files: modules/cmds.py -> 1.13 modules/ftpio.py -> 1.8 --- modules/cmds.py | 15 +++++++++++++-- modules/ftpio.py | 13 +++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/cmds.py b/modules/cmds.py index 7f4b809..580fa44 100644 --- a/modules/cmds.py +++ b/modules/cmds.py @@ -49,6 +49,9 @@ def lock(con, arg, hard): def cmd_unlock(con, arg): if arg in locks: del locks[arg] + con.sock.send("OK") + else: + con.sock.send("FAIL") def cmd_lock_soft(con, arg): lock(con, arg, False) @@ -56,6 +59,15 @@ def cmd_lock_soft(con, arg): def cmd_lock_hard(con, arg): lock(con, arg, True) +def cmd_show_locks(con): + cmd_log(con, "Dumping locks data:"); + if len(locks): + for lockdata in locks.iteritems(): + tree, data = lockdata + cmd_log(con, "Tree: %s, Conn name: %s, Hard Lock: %s, Time: %s" + % (tree, data['name'], data['hard'], time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data['time'])))) + else: + cmd_log(con, "No locks found."); def cmd_log(con, msg): logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), @@ -65,7 +77,6 @@ def cmd_log(con, msg): def cmd_name(con, name): con.name=name - def load_creds(): global users, cookies users={} @@ -161,7 +172,7 @@ cmdlist_args={'lcks':cmd_lock_soft, 'lckh':cmd_lock_hard, 'ulck':cmd_unlock, 'log1':cmd_log, 'name':cmd_name, 'linp':cmd_login_passwd, 'linc':cmd_login_cookie} -cmdlist_noargs={'lout':cmd_logout, 'gett':cmd_gettree} +cmdlist_noargs={'lout':cmd_logout, 'gett':cmd_gettree, 'slck':cmd_show_locks} # Global stuff and initializations diff --git a/modules/ftpio.py b/modules/ftpio.py index 194d2a5..1adf5e4 100644 --- a/modules/ftpio.py +++ b/modules/ftpio.py @@ -1,6 +1,7 @@ # vi: encoding=utf-8 ts=8 sts=4 sw=4 et import os +import sys import socket import time import config @@ -17,8 +18,9 @@ def connect(name=None): global sock sock=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(socketname) - if name: - sock.send('name %s\0' % name) + if not name: + name = "pid_%d_name_%s" % (os.getpid(), sys.argv[0]) + sock.send('name %s\0' % name) def login_passwd(login, passwd): 'Return cookie if ok' @@ -60,10 +62,17 @@ def lock(path, hard=False): def unlock(path): sock.send('ulck %s\0' % path) + ret = sock.recv(20) + if ret == "OK": + return True + return False def log(msg): sock.send('log1 %s\0' % msg) +def locks_dump(): + sock.send('slck\0') + def gettree(): sock.send('gett\0') pkgs=[] -- 2.44.0