]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Introduce send_strerror().
authorAndre Noll <maan@systemlinux.org>
Sat, 5 May 2012 10:10:08 +0000 (12:10 +0200)
committerAndre Noll <maan@systemlinux.org>
Mon, 7 May 2012 09:27:37 +0000 (11:27 +0200)
There are many places in various command handlers where the error path
contains code like

sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));

to send an error message to the client.  This patch simplifies all
these places by introducing the public function send_strerror() which
takes a command context structure and an error code, and executes the
above statement. All places where this was open-coded are changed
to call the new function instead.

aft.c
attribute.c
command.c
command.h

diff --git a/aft.c b/aft.c
index c724670391bcbdde581d6cfc6c45342ef1f57650..2c123ce3e480f8b1d8d9e19cb4825fc2e0f664c0 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -2189,7 +2189,7 @@ int com_touch(struct command_context *cc)
        ret = send_option_arg_callback_request(&query, cc->argc - i,
                cc->argv + i, com_touch_callback, afs_cb_result_handler, cc);
        if (ret < 0)
        ret = send_option_arg_callback_request(&query, cc->argc - i,
                cc->argv + i, com_touch_callback, afs_cb_result_handler, cc);
        if (ret < 0)
-               sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));
+               send_strerror(cc, -ret);
        return ret;
 }
 
        return ret;
 }
 
@@ -2300,7 +2300,7 @@ int com_rm(struct command_context *cc)
        ret = send_option_arg_callback_request(&query, cc->argc - i,
                cc->argv + i, com_rm_callback, afs_cb_result_handler, cc);
        if (ret < 0)
        ret = send_option_arg_callback_request(&query, cc->argc - i,
                cc->argv + i, com_rm_callback, afs_cb_result_handler, cc);
        if (ret < 0)
-               sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));
+               send_strerror(cc, -ret);
        return ret;
 }
 
        return ret;
 }
 
@@ -2459,7 +2459,7 @@ int com_cpsi(struct command_context *cc)
        ret = send_option_arg_callback_request(&options, cc->argc - i,
                cc->argv + i, com_cpsi_callback, afs_cb_result_handler, cc);
        if (ret < 0)
        ret = send_option_arg_callback_request(&options, cc->argc - i,
                cc->argv + i, com_cpsi_callback, afs_cb_result_handler, cc);
        if (ret < 0)
-               sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));
+               send_strerror(cc, -ret);
        return ret;
 }
 
        return ret;
 }
 
index 8dcfa28fa6c5f77e4ae8f02cfc045ee0ec401bf6..f4e2012044ecb20c20333fe5a2d294131140b149 100644 (file)
@@ -208,11 +208,12 @@ int com_lsatt(struct command_context *cc)
        }
        ret = send_option_arg_callback_request(&options, cc->argc - i, cc->argv + i,
                com_lsatt_callback, afs_cb_result_handler, cc);
        }
        ret = send_option_arg_callback_request(&options, cc->argc - i, cc->argv + i,
                com_lsatt_callback, afs_cb_result_handler, cc);
+
        if (!ret) {
                if (cc->argc > 1)
                        ret = sc_send_va_buffer(&cc->scc, "no matches\n");
        } else if (ret < 0)
        if (!ret) {
                if (cc->argc > 1)
                        ret = sc_send_va_buffer(&cc->scc, "no matches\n");
        } else if (ret < 0)
-               sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));
+               send_strerror(cc, -ret);
        return ret;
 }
 
        return ret;
 }
 
@@ -372,7 +373,7 @@ int com_addatt(struct command_context *cc)
        ret = send_standard_callback_request(cc->argc - 1, cc->argv + 1,
                com_addatt_callback, afs_cb_result_handler, cc);
        if (ret < 0)
        ret = send_standard_callback_request(cc->argc - 1, cc->argv + 1,
                com_addatt_callback, afs_cb_result_handler, cc);
        if (ret < 0)
-               sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));
+               send_strerror(cc, -ret);
        return ret;
 }
 
        return ret;
 }
 
@@ -417,7 +418,7 @@ int com_mvatt(struct command_context *cc)
        ret = send_standard_callback_request(cc->argc - 1, cc->argv + 1,
                com_mvatt_callback, afs_cb_result_handler, cc);
        if (ret < 0)
        ret = send_standard_callback_request(cc->argc - 1, cc->argv + 1,
                com_mvatt_callback, afs_cb_result_handler, cc);
        if (ret < 0)
-               sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));
+               send_strerror(cc, -ret);
        return ret;
 }
 
        return ret;
 }
 
@@ -491,7 +492,7 @@ int com_rmatt(struct command_context *cc)
        ret = send_standard_callback_request(cc->argc - 1, cc->argv + 1,
                com_rmatt_callback, afs_cb_result_handler, cc);
        if (ret < 0)
        ret = send_standard_callback_request(cc->argc - 1, cc->argv + 1,
                com_rmatt_callback, afs_cb_result_handler, cc);
        if (ret < 0)
-               sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));
+               send_strerror(cc, -ret);
        return ret;
 }
 
        return ret;
 }
 
index 9c175f35ec45087325db2ef3dbb3249689de0708..82194adf8b0c4568427b38f35a1eb1a7cadf70ae 100644 (file)
--- a/command.c
+++ b/command.c
@@ -256,6 +256,11 @@ __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band,
        return send_sb(scc, msg, ret, band, false);
 }
 
        return send_sb(scc, msg, ret, band, false);
 }
 
+int send_strerror(struct command_context *cc, int err)
+{
+       return sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(err));
+}
+
 /**
  * Send a sideband packet through a blocking file descriptor.
  *
 /**
  * Send a sideband packet through a blocking file descriptor.
  *
@@ -1054,7 +1059,7 @@ __noreturn void handle_connect(int fd, const char *peername)
        if (ret >= 0)
                goto out;
 err_out:
        if (ret >= 0)
                goto out;
 err_out:
-       sc_send_va_buffer(&cc->scc, "%s\n", para_strerror(-ret));
+       send_strerror(cc, -ret);
 net_err:
        PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
 out:
 net_err:
        PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
 out:
index 851b8f13485a042f8747031ebed1a3bb2e0e3128..e4159e6bda00131bf4a1ef6b5a46627c9f7d88b1 100644 (file)
--- a/command.h
+++ b/command.h
@@ -40,6 +40,7 @@ int send_sb(struct stream_cipher_context *scc, void *buf, size_t numbytes,
                int band, bool dont_free);
 __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band,
                const char *fmt, ...);
                int band, bool dont_free);
 __printf_3_4 int send_sb_va(struct stream_cipher_context *scc, int band,
                const char *fmt, ...);
+int send_strerror(struct command_context *cc, int err);
 int recv_sb(struct stream_cipher_context *scc,
                enum sb_designator expected_band,
                size_t max_size, struct iovec *result);
 int recv_sb(struct stream_cipher_context *scc,
                enum sb_designator expected_band,
                size_t max_size, struct iovec *result);