From 1aa01910957e967e87e46b86f1e67844148703e3 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Thu, 15 Aug 2013 17:10:56 -0700 Subject: [PATCH] ceph.in: --admin-daemon was not returning EINVAL on bad command Fix by restructuring code to hoist common code and have only one place where admin_socket is actually called. Signed-off-by: Dan Mick (cherry picked from commit 266460e97ec9ef9711e9eaa4bd954f3188d8da69) --- src/ceph.in | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/ceph.in b/src/ceph.in index fa79a720656f9..e4fd6eb3d6530 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -506,35 +506,36 @@ def main(): format = parsed_args.output_format + sockpath = None if parsed_args.admin_socket: - try: - print admin_socket(parsed_args.admin_socket, childargs, format) - except Exception as e: - print >> sys.stderr, 'admin_socket: {0}'.format(e) - return 0 - - if len(childargs) > 0 and childargs[0] == "daemon": + sockpath = parsed_args.admin_socket + elif len(childargs) > 0 and childargs[0] == "daemon": + # Treat "daemon " or "daemon " like --admin_daemon if len(childargs) > 2: if childargs[1].find('/') >= 0: - try: - print admin_socket(childargs[1], childargs[2:], format) - except Exception as e: - print >> sys.stderr, 'admin_socket: {0}'.format(e) - return errno.EINVAL - return 0 + sockpath = childargs[1] else: # try resolve daemon name - path = ceph_conf('admin_socket', childargs[1]) try: - print admin_socket(path, childargs[2:], format) + sockpath = ceph_conf('admin_socket', childargs[1]) except Exception as e: - print >> sys.stderr, 'admin_socket: {0}'.format(e) + print >> sys.stderr, \ + 'Can\'t get admin socket path: ' + str(e) return errno.EINVAL - return 0 + # for both: + childargs = childargs[2:] else: - print >> sys.stderr, 'Daemon requires at least 2 arguments' + print >> sys.stderr, 'daemon requires at least 3 arguments' return errno.EINVAL + if sockpath: + try: + print admin_socket(sockpath, childargs, format) + except Exception as e: + print >> sys.stderr, 'admin_socket: {0}'.format(e) + return errno.EINVAL + return 0 + # handle any 'generic' ceph arguments that we didn't parse here global cluster_handle -- 2.39.5