mvblob: Improve error diagnostics.
authorAndre Noll <maan@systemlinux.org>
Sun, 29 Jun 2014 13:49:45 +0000 (15:49 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 13 Jul 2014 11:10:40 +0000 (13:10 +0200)
On errors the mvblob commands (mvmood, mvlyr, mvimg, mvpl) fail
silently. They do write an error message to the server log, but nobody
might notice the error there. This commit changes these commands to
send the message to the client instead.

blob.c

diff --git a/blob.c b/blob.c
index dc71b8e3feb61323279b770effbab33b7c6d4978..9973de9544486e4df2f1d9d0a381db9978c4dc6d 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -482,35 +482,51 @@ static int com_addblob(callback_function *f, struct command_context *cc)
        return stdin_command(cc, &arg_obj, f, afs_cb_result_handler, cc);
 }
 
        return stdin_command(cc, &arg_obj, f, afs_cb_result_handler, cc);
 }
 
-/* FIXME: Print output to client, not to log file */
-static void com_mvblob_callback(struct osl_table *table, __a_unused int fd,
+static void com_mvblob_callback(struct osl_table *table, int fd,
                const struct osl_object *query)
 {
        char *src = (char *) query->data;
        struct osl_object obj = {.data = src, .size = strlen(src) + 1};
        char *dest = src + obj.size;
        struct osl_row *row;
                const struct osl_object *query)
 {
        char *src = (char *) query->data;
        struct osl_object obj = {.data = src, .size = strlen(src) + 1};
        char *dest = src + obj.size;
        struct osl_row *row;
+       struct para_buffer pb = {
+               .max_size = shm_get_shmmax(),
+               .private_data = &fd,
+               .max_size_handler = afs_max_size_handler
+       };
        int ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
 
        int ret = osl(osl_get_row(table, BLOBCOL_NAME, &obj, &row));
 
-       if (ret < 0)
+       if (ret < 0) {
+               para_printf(&pb, "could not locate %s: %s\n", src,
+                       para_strerror(-ret));
                goto out;
                goto out;
+       }
        obj.data = dest;
        obj.size = strlen(dest) + 1;
        ret = osl(osl_update_object(table, row, BLOBCOL_NAME, &obj));
        obj.data = dest;
        obj.size = strlen(dest) + 1;
        ret = osl(osl_update_object(table, row, BLOBCOL_NAME, &obj));
-       if (ret < 0)
+       if (ret < 0) {
+               para_printf(&pb, "failed to update object %s: %s\n", dest,
+                       para_strerror(-ret));
                goto out;
                goto out;
+       }
        afs_event(BLOB_RENAME, NULL, table);
 out:
        afs_event(BLOB_RENAME, NULL, table);
 out:
-       if (ret < 0)
-               PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
+       if (pb.offset)
+               pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
+       free(pb.buf);
 }
 
 static int com_mvblob(callback_function *f, struct command_context *cc)
 {
 }
 
 static int com_mvblob(callback_function *f, struct command_context *cc)
 {
+       int ret;
+
        if (cc->argc != 3)
                return -E_MOOD_SYNTAX;
        if (cc->argc != 3)
                return -E_MOOD_SYNTAX;
-       return send_option_arg_callback_request(NULL, cc->argc - 1,
-               cc->argv + 1, f, NULL, NULL);
+       ret = send_option_arg_callback_request(NULL, cc->argc - 1,
+               cc->argv + 1, f, afs_cb_result_handler, cc);
+       if (ret < 0)
+               send_strerror(cc, -ret);
+       return ret;
 }
 
 #define DEFINE_BLOB_COMMAND(cmd_name, table_name, cmd_prefix) \
 }
 
 #define DEFINE_BLOB_COMMAND(cmd_name, table_name, cmd_prefix) \