From: Andre Noll Date: Mon, 24 Mar 2008 14:20:28 +0000 (+0100) Subject: make send_callback_request() and friends take a result handler. X-Git-Tag: v0.3.2~58 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=0a3b9b83;p=paraslash.git make send_callback_request() and friends take a result handler. This is a first step to overcome a design flaw in the afs callback code: The output of the commands is currently stored in an osl object that is copied to a shared memory area whose shmid is passed back to the command handler via the local socket. This method limits the size of the command output to the maximal size that can be stored in a shared memory area which is not enough to hold large outputs like that of ls -c. This patch allows the command handlers to pass a result handler function instead of an osl object. This result handler is called for each shared memory area that gets sent through the local socket. Further patches will change the callbacks so that they pass multiple result buffers instead of returning a single buffer. This has the additional advantage that partial command output produced by the callback can be sent even before the callback returns. This parital output is seen immediately by the command handler. --- diff --git a/afs.c b/afs.c index 05c2c213..9b6cd0c4 100644 --- a/afs.c +++ b/afs.c @@ -157,11 +157,11 @@ struct callback_result { * \sa send_option_arg_callback_request(), send_standard_callback_request(). */ int send_callback_request(callback_function *f, struct osl_object *query, - struct osl_object *result) + callback_result_handler *result_handler, + void *private_result_data) { struct callback_query *cq; - struct callback_result *cr; - int ret, fd = -1, query_shmid, result_shmid; + int num_results = 0, ret, fd = -1, query_shmid, result_shmid; void *query_shm, *result_shm; char buf[sizeof(afs_socket_cookie) + sizeof(int)]; size_t query_shm_size = sizeof(*cq); @@ -195,37 +195,45 @@ int send_callback_request(callback_function *f, struct osl_object *query, ret = send_bin_buffer(fd, buf, sizeof(buf)); if (ret < 0) goto out; - ret = recv_bin_buffer(fd, buf, sizeof(buf)); - if (ret < 0) - goto out; - if (ret != sizeof(int)) { - ret = -E_AFS_SHORT_READ; - goto out; - } - ret = *(int *) buf; - if (ret <= 0) - goto out; - result_shmid = ret; - ret = shm_attach(result_shmid, ATTACH_RO, &result_shm); - if (ret >= 0) { - assert(result); - cr = result_shm; - result->size = cr->result_size; - result->data = para_malloc(result->size); - memcpy(result->data, result_shm + sizeof(*cr), result->size); - ret = shm_detach(result_shm); + for (;;) { + ret = recv_bin_buffer(fd, buf, sizeof(int)); + if (ret <= 0) + goto out; + if (ret != sizeof(int)) { + ret = -E_AFS_SHORT_READ; + goto out; + } + ret = *(int *) buf; + if (ret <= 0) + goto out; + result_shmid = ret; + ret = shm_attach(result_shmid, ATTACH_RO, &result_shm); + if (ret >= 0) { + struct callback_result *cr = result_shm; + struct osl_object result; + num_results++; + result.size = cr->result_size; + result.data = result_shm + sizeof(*cr); + if (result.size) { + assert(result_handler); + ret = result_handler(&result, private_result_data); + if (shm_detach(result_shm) < 0) + PARA_ERROR_LOG("can not detach result\n"); + } + } else + PARA_ERROR_LOG("attach result failed: %d\n", ret); + if (shm_destroy(result_shmid) < 0) + PARA_ERROR_LOG("destroy result failed\n"); if (ret < 0) - PARA_ERROR_LOG("can not detach result\n"); - } else - PARA_ERROR_LOG("attach result failed: %d\n", ret); - if (shm_destroy(result_shmid) < 0) - PARA_ERROR_LOG("destroy result failed\n"); - ret = 1; + break; + } out: if (shm_destroy(query_shmid) < 0) PARA_ERROR_LOG("%s\n", "shm destroy error"); if (fd >= 0) close(fd); + if (ret >= 0) + ret = num_results; // PARA_DEBUG_LOG("callback_ret: %d\n", ret); return ret; } @@ -248,7 +256,8 @@ out: */ int send_option_arg_callback_request(struct osl_object *options, int argc, char * const * const argv, callback_function *f, - struct osl_object *result) + callback_result_handler *result_handler, + void *private_result_data) { char *p; int i, ret; @@ -266,7 +275,8 @@ int send_option_arg_callback_request(struct osl_object *options, strcpy(p, argv[i]); /* OK */ p += strlen(argv[i]) + 1; } - ret = send_callback_request(f, &query, result); + ret = send_callback_request(f, &query, result_handler, + private_result_data); free(query.data); return ret; } @@ -286,9 +296,11 @@ int send_option_arg_callback_request(struct osl_object *options, * send_option_arg_callback_request(). */ int send_standard_callback_request(int argc, char * const * const argv, - callback_function *f, struct osl_object *result) + callback_function *f, callback_result_handler *result_handler, + void *private_result_data) { - return send_option_arg_callback_request(NULL, argc, argv, f, result); + return send_option_arg_callback_request(NULL, argc, argv, f, result_handler, + private_result_data); } static int action_if_pattern_matches(struct osl_row *row, void *data) @@ -407,7 +419,8 @@ static int fd2buf(int fd, unsigned max_size, struct osl_object *obj) * send_callback_request() otherwise. */ int stdin_command(int fd, struct osl_object *arg_obj, callback_function *f, - unsigned max_len, struct osl_object *result) + unsigned max_len, callback_result_handler *result_handler, + void *private_result_data) { struct osl_object query, stdin_obj; int ret; @@ -423,7 +436,7 @@ int stdin_command(int fd, struct osl_object *arg_obj, callback_function *f, memcpy(query.data, arg_obj->data, arg_obj->size); memcpy((char *)query.data + arg_obj->size, stdin_obj.data, stdin_obj.size); free(stdin_obj.data); - ret = send_callback_request(f, &query, result); + ret = send_callback_request(f, &query, result_handler, private_result_data); free(query.data); return ret; } @@ -588,26 +601,28 @@ static int com_select_callback(const struct osl_object *query, para_printf(&pb, "activated %s (%d admissible files)\n", current_mop? current_mop : "dummy mood", num_admissible); result->data = pb.buf; - result->size = pb.size; + result->size = pb.offset; return 1; } +int send_result(struct osl_object *result, void *private_result_data) +{ + int fd = *(int *)private_result_data; + if (!result->size) + return 1; + return send_bin_buffer(fd, result->data, result->size); +} + int com_select(int fd, int argc, char * const * const argv) { - int ret; - struct osl_object query, result; + struct osl_object query; if (argc != 2) return -E_AFS_SYNTAX; query.data = argv[1]; query.size = strlen(argv[1]) + 1; - ret = send_callback_request(com_select_callback, &query, - &result); - if (ret > 0 && result.data && result.size) { - ret = send_va_buffer(fd, "%s", (char *)result.data); - free(result.data); - } - return ret; + return send_callback_request(com_select_callback, &query, + &send_result, &fd); } static void init_admissible_files(char *arg) @@ -1047,7 +1062,7 @@ int com_init(int fd, int argc, char * const * const argv) return -E_BAD_TABLE_NAME; } } - ret = send_callback_request(create_tables_callback, &query, NULL); + ret = send_callback_request(create_tables_callback, &query, NULL, NULL); if (ret < 0) return ret; return send_va_buffer(fd, "successfully created afs table(s)\n"); @@ -1071,7 +1086,6 @@ int com_check(int fd, int argc, char * const * const argv) { unsigned flags = 0; int i, ret; - struct osl_object result; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -1100,37 +1114,19 @@ int com_check(int fd, int argc, char * const * const argv) if (!flags) flags = ~0U; if (flags & CHECK_AFT) { - ret = send_callback_request(aft_check_callback, NULL, &result); + ret = send_callback_request(aft_check_callback, NULL, send_result, &fd); if (ret < 0) return ret; - if (ret > 0) { - ret = send_buffer(fd, (char *) result.data); - free(result.data); - if (ret < 0) - return ret; - } } if (flags & CHECK_PLAYLISTS) { - ret = send_callback_request(playlist_check_callback, NULL, &result); + ret = send_callback_request(playlist_check_callback, NULL, send_result, &fd); if (ret < 0) return ret; - if (ret > 0) { - ret = send_buffer(fd, (char *) result.data); - free(result.data); - if (ret < 0) - return ret; - } } if (flags & CHECK_MOODS) { - ret = send_callback_request(mood_check_callback, NULL, &result); + ret = send_callback_request(mood_check_callback, NULL, send_result, &fd); if (ret < 0) return ret; - if (ret > 0) { - ret = send_buffer(fd, (char *) result.data); - free(result.data); - if (ret < 0) - return ret; - } } return 1; } diff --git a/afs.h b/afs.h index 52d37673..56979845 100644 --- a/afs.h +++ b/afs.h @@ -169,18 +169,25 @@ struct pattern_match_data { * \sa send_callback_request(). */ typedef int callback_function(const struct osl_object *, struct osl_object *); +typedef int callback_result_handler(struct osl_object *result, void *private); +int send_result(struct osl_object *result, void *private_result_data); + __noreturn void afs_init(uint32_t cookie, int socket_fd); void afs_event(enum afs_events event, struct para_buffer *pb, void *data); int send_callback_request(callback_function *f, struct osl_object *query, - struct osl_object *result); -int send_standard_callback_request(int argc, char * const * const argv, - callback_function *f, struct osl_object *result); + callback_result_handler *result_handler, + void *private_result_data); int send_option_arg_callback_request(struct osl_object *options, - int argc, char * const * const argv, callback_function *f, - struct osl_object *result); + int argc, char * const * const argv, callback_function *f, + callback_result_handler *result_handler, + void *private_result_data); +int send_standard_callback_request(int argc, char * const * const argv, + callback_function *f, callback_result_handler *result_handler, + void *private_result_data); int stdin_command(int fd, struct osl_object *arg_obj, callback_function *f, - unsigned max_len, struct osl_object *result); + unsigned max_len, callback_result_handler *result_handler, + void *private_result_data); int string_compare(const struct osl_object *obj1, const struct osl_object *obj2); int for_each_matching_row(struct pattern_match_data *pmd); diff --git a/aft.c b/aft.c index 51e36c8e..d6abc13d 100644 --- a/aft.c +++ b/aft.c @@ -1284,7 +1284,7 @@ static int com_ls_callback(const struct osl_object *query, ret = 1; out: ls_output->data = b.buf; - ls_output->size = b.size; + ls_output->size = b.offset; free(opts->data); free(opts->data_ptr); free(opts->patterns); @@ -1301,8 +1301,7 @@ int com_ls(int fd, int argc, char * const * const argv) enum ls_sorting_method sort = LS_SORT_BY_PATH; enum ls_listing_mode mode = LS_MODE_SHORT; struct ls_options opts = {.patterns = NULL}; - struct osl_object query = {.data = &opts, .size = sizeof(opts)}, - ls_output; + struct osl_object query = {.data = &opts, .size = sizeof(opts)}; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -1400,11 +1399,7 @@ int com_ls(int fd, int argc, char * const * const argv) opts.mode = mode; opts.num_patterns = argc - i; ret = send_option_arg_callback_request(&query, opts.num_patterns, - argv + i, com_ls_callback, &ls_output); - if (ret > 0) { - ret = send_buffer(fd, (char *)ls_output.data); - free(ls_output.data); - } + argv + i, com_ls_callback, send_result, &fd); return ret; } @@ -1671,7 +1666,7 @@ out: if (!msg.buf) return 0; result->data = msg.buf; - result->size = msg.size; + result->size = msg.offset; return 1; } @@ -1712,14 +1707,21 @@ static int hash_sister_callback(const struct osl_object *query, return 1; } -static int add_one_audio_file(const char *path, const void *private_data) +int get_row_pointer_from_result(struct osl_object *result, void *private) +{ + struct osl_row **row = private; + *row = result->data; + return 1; +} + +static int add_one_audio_file(const char *path, void *private_data) { int ret, send_ret = 1; uint8_t format_num = -1; - const struct private_add_data *pad = private_data; + struct private_add_data *pad = private_data; struct afh_info afhi, *afhi_ptr = NULL; struct osl_row *pb = NULL, *hs = NULL; /* path brother/hash sister */ - struct osl_object map, obj = {.data = NULL}, query, result = {.data = NULL}; + struct osl_object map, obj = {.data = NULL}, query; HASH_TYPE hash[HASH_SIZE]; ret = guess_audio_format(path); @@ -1727,13 +1729,10 @@ static int add_one_audio_file(const char *path, const void *private_data) goto out_free; query.data = (char *)path; query.size = strlen(path) + 1; - ret = send_callback_request(path_brother_callback, &query, &result); + ret = send_callback_request(path_brother_callback, &query, + get_row_pointer_from_result, &pb); if (ret < 0 && ret != -E_RB_KEY_NOT_FOUND) goto out_free; - if (ret >= 0) { - pb = *(struct osl_row **)result.data; - free(result.data); - } ret = 1; if (pb && (pad->flags & ADD_FLAG_LAZY)) { /* lazy is really cheap */ if (pad->flags & ADD_FLAG_VERBOSE) @@ -1749,13 +1748,10 @@ static int add_one_audio_file(const char *path, const void *private_data) /* Check whether the database contains a file with the same hash. */ query.data = hash; query.size = HASH_SIZE; - ret = send_callback_request(hash_sister_callback, &query, &result); + ret = send_callback_request(hash_sister_callback, &query, + get_row_pointer_from_result, &hs); if (ret < 0 && ret != -E_RB_KEY_NOT_FOUND) goto out_unmap; - if (ret >= 0) { - hs = *(struct osl_row **)result.data; - free(result.data); - } /* Return success if we already know this file. */ ret = 1; if (pb && hs && hs == pb && !(pad->flags & ADD_FLAG_FORCE)) { @@ -1783,11 +1779,7 @@ static int add_one_audio_file(const char *path, const void *private_data) } save_add_callback_buffer(hash, path, afhi_ptr, pad->flags, format_num, &obj); /* Ask afs to consider this entry for adding. */ - ret = send_callback_request(com_add_callback, &obj, &result); - if (ret > 0) { - send_ret = send_va_buffer(pad->fd, "%s", (char *)result.data); - free(result.data); - } + ret = send_callback_request(com_add_callback, &obj, send_result, &pad->fd); goto out_free; out_unmap: @@ -1979,7 +1971,7 @@ static int com_touch_callback(const struct osl_object *query, para_printf(&tad.pb, "no matches\n"); if (tad.pb.buf) { result->data = tad.pb.buf; - result->size = tad.pb.size; + result->size = tad.pb.offset; return 1; } return ret < 0? ret : 0; @@ -1993,8 +1985,7 @@ int com_touch(int fd, int argc, char * const * const argv) .lyrics_id = -1, .image_id = -1 }; - struct osl_object query = {.data = &cto, .size = sizeof(cto)}, - result; + struct osl_object query = {.data = &cto, .size = sizeof(cto)}; int i, ret; @@ -2043,15 +2034,9 @@ int com_touch(int fd, int argc, char * const * const argv) if (i >= argc) return -E_AFT_SYNTAX; ret = send_option_arg_callback_request(&query, argc - i, - argv + i, com_touch_callback, &result); - if (!ret) - return 0; - if (ret < 0) { + argv + i, com_touch_callback, send_result, &fd); + if (ret < 0) send_va_buffer(fd, "%s\n", para_strerror(-ret)); - return ret; - } - ret = send_buffer(fd, (char *)result.data); - free(result.data); return ret; } @@ -2093,7 +2078,7 @@ static int remove_audio_file(__a_unused struct osl_table *table, } static int com_rm_callback(const struct osl_object *query, - __a_unused struct osl_object *result) + struct osl_object *result) { struct com_rm_action_data crd = {.flags = *(uint32_t *)query->data}; int ret; @@ -2119,7 +2104,7 @@ static int com_rm_callback(const struct osl_object *query, } if (crd.pb.buf) { result->data = crd.pb.buf; - result->size = crd.pb.size; + result->size = crd.pb.offset; return 1; } return ret < 0? ret : 0; @@ -2129,8 +2114,7 @@ static int com_rm_callback(const struct osl_object *query, int com_rm(int fd, int argc, char * const * const argv) { uint32_t flags = 0; - struct osl_object query = {.data = &flags, .size = sizeof(flags)}, - result; + struct osl_object query = {.data = &flags, .size = sizeof(flags)}; int i, ret; for (i = 1; i < argc; i++) { @@ -2158,15 +2142,9 @@ int com_rm(int fd, int argc, char * const * const argv) if (i >= argc) return -E_AFT_SYNTAX; ret = send_option_arg_callback_request(&query, argc - i, argv + i, - com_rm_callback, &result); - if (!ret) - return 0; - if (ret < 0) { + com_rm_callback, send_result, &fd); + if (ret < 0) send_va_buffer(fd, "%s\n", para_strerror(-ret)); - return ret; - } - ret = send_buffer(fd, (char *)result.data); - free(result.data); return ret; } @@ -2270,7 +2248,7 @@ out: } if (cad.pb.buf) { result->data = cad.pb.buf; - result->size = cad.pb.size; + result->size = cad.pb.offset; return 1; } return ret < 0? ret : 0; @@ -2280,8 +2258,7 @@ int com_cpsi(int fd, int argc, char * const * const argv) { unsigned flags = 0; int i, ret; - struct osl_object options = {.data = &flags, .size = sizeof(flags)}, - result; + struct osl_object options = {.data = &flags, .size = sizeof(flags)}; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -2322,15 +2299,9 @@ int com_cpsi(int fd, int argc, char * const * const argv) if (!(flags & ~CPSI_FLAG_VERBOSE)) /* no copy flags given */ flags = ~(unsigned)CPSI_FLAG_VERBOSE | flags; ret = send_option_arg_callback_request(&options, argc - i, argv + i, - com_cpsi_callback, &result); - if (!ret) - return 0; - if (ret < 0) { + com_cpsi_callback, send_result, &fd); + if (ret < 0) send_va_buffer(fd, "%s\n", para_strerror(-ret)); - return ret; - } - ret = send_buffer(fd, (char *)result.data); - free(result.data); return ret; } @@ -2387,7 +2358,7 @@ int aft_check_callback(__a_unused const struct osl_object *query, struct osl_obj para_printf(&pb, "checking audio file table...\n"); audio_file_loop(&pb, check_audio_file); result->data = pb.buf; - result->size = pb.size; + result->size = pb.offset; return 1; } diff --git a/attribute.c b/attribute.c index c4bc0bca..acbb8f4d 100644 --- a/attribute.c +++ b/attribute.c @@ -168,15 +168,14 @@ static int com_lsatt_callback(const struct osl_object *query, if (!laad.pb.buf) return 0; result->data = laad.pb.buf; - result->size = laad.pb.size; + result->size = laad.pb.offset; return 1; } int com_lsatt(int fd, int argc, char * const * const argv) { unsigned flags = 0; - struct osl_object options = {.data = &flags, .size = sizeof(flags)}, - result; + struct osl_object options = {.data = &flags, .size = sizeof(flags)}; int ret, i; for (i = 1; i < argc; i++) { @@ -201,18 +200,12 @@ int com_lsatt(int fd, int argc, char * const * const argv) } } ret = send_option_arg_callback_request(&options, argc - i, argv + i, - com_lsatt_callback, &result); + com_lsatt_callback, send_result, &fd); if (!ret) { if (argc > 1) ret = send_va_buffer(fd, "no matches\n"); - return ret; - } - if (ret < 0) { + } else if (ret < 0) send_va_buffer(fd, "%s\n", para_strerror(-ret)); - return ret; - } - ret = send_buffer(fd, (char *)result.data); - free(result.data); return ret; } @@ -282,7 +275,7 @@ int com_setatt(__a_unused int fd, int argc, char * const * const argv) if (argc < 3) return -E_ATTR_SYNTAX; return send_standard_callback_request(argc - 1, argv + 1, com_setatt_callback, - NULL); + NULL, NULL); } struct addatt_event_data { @@ -347,27 +340,20 @@ out: if (ret < 0) para_printf(&pb, "%s: %s\n", p, para_strerror(-ret)); result->data = pb.buf; - result->size = pb.size; + result->size = pb.offset; return result->data? 0 : 1; } int com_addatt(int fd, int argc, char * const * const argv) { - struct osl_object result; int ret; if (argc < 2) return -E_ATTR_SYNTAX; ret = send_standard_callback_request(argc - 1, argv + 1, com_addatt_callback, - &result); - if (!ret) - return 1; + send_result, &fd); if (ret < 0) - return ret; - if (!result.data || !result.size) - return 1; - ret = send_va_buffer(fd, "%s", (char *) result.data); - free(result.data); + send_va_buffer(fd, "%s\n", para_strerror(-ret)); return ret; } @@ -396,27 +382,20 @@ out: if (!pb.buf) return 0; result->data = pb.buf; - result->size = pb.size; + result->size = pb.offset; return 1; } int com_mvatt(int fd, int argc, char * const * const argv) { - struct osl_object result; int ret; if (argc != 3) return -E_ATTR_SYNTAX; ret = send_standard_callback_request(argc - 1, argv + 1, com_mvatt_callback, - &result); - if (!ret) - return 1; + send_result, &fd); if (ret < 0) - return ret; - if (!result.data || !result.size) - return 1; - ret = send_va_buffer(fd, "%s", (char *) result.data); - free(result.data); + send_va_buffer(fd, "%s\n", para_strerror(-ret)); return ret; } @@ -473,27 +452,20 @@ static int com_rmatt_callback(const struct osl_object *query, if (!raad.num_removed) para_printf(&raad.pb, "no match -- nothing removed\n"); result->data = raad.pb.buf; - result->size = raad.pb.size; + result->size = raad.pb.offset; return 1; } int com_rmatt(int fd, int argc, char * const * const argv) { int ret; - struct osl_object result; if (argc < 2) return -E_ATTR_SYNTAX; ret = send_standard_callback_request(argc - 1, argv + 1, com_rmatt_callback, - &result); - if (!ret) - return 0; - if (ret < 0) { + send_result, &fd); + if (ret < 0) send_va_buffer(fd, "%s\n", para_strerror(-ret)); - return ret; - } - ret = send_buffer(fd, (char *)result.data); - free(result.data); return ret; } diff --git a/blob.c b/blob.c index c42a5f7a..899bd5a3 100644 --- a/blob.c +++ b/blob.c @@ -109,16 +109,15 @@ static int com_lsblob_callback(struct osl_table *table, if (!lbad.pb.buf) return 0; result->data = lbad.pb.buf; - result->size = lbad.pb.size; + result->size = lbad.pb.offset; return 1; } static int com_lsblob(callback_function *f, int fd, int argc, char * const * const argv) { uint32_t flags = 0; - struct osl_object options = {.data = &flags, .size = sizeof(flags)}, - result; - int i, ret; + struct osl_object options = {.data = &flags, .size = sizeof(flags)}; + int i; for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -144,17 +143,8 @@ static int com_lsblob(callback_function *f, int fd, int argc, char * const * con } // if (argc > i) // return -E_BLOB_SYNTAX; - ret = send_option_arg_callback_request(&options, argc - i, - argv + i, f, &result); - if (!ret) - return 0; - if (ret < 0) { - send_va_buffer(fd, "%s\n", para_strerror(-ret)); - return ret; - } - ret = send_buffer(fd, (char *)result.data); - free(result.data); - return ret; + return send_option_arg_callback_request(&options, argc - i, + argv + i, f, send_result, &fd); } static int cat_blob(struct osl_table *table, struct osl_row *row, @@ -198,17 +188,9 @@ static int com_catblob_callback(struct osl_table *table, static int com_catblob(callback_function *f, int fd, int argc, char * const * const argv) { - struct osl_object result; - int ret; - if (argc < 2) return -E_BLOB_SYNTAX; - ret = send_standard_callback_request(argc - 1, argv + 1, f, &result); - if (ret > 0) { - ret = send_bin_buffer(fd, (char *)result.data, result.size); - free(result.data); - } - return ret; + return send_standard_callback_request(argc - 1, argv + 1, f, send_result, &fd); } /** Used for removing rows from a blob table. */ @@ -258,25 +240,17 @@ static int com_rmblob_callback(struct osl_table *table, afs_event(BLOB_RENAME, NULL, table); } result->data = rmbd.pb.buf; - result->size = rmbd.pb.size; + result->size = rmbd.pb.offset; return 1; } static int com_rmblob(callback_function *f, int fd, int argc, char * const * const argv) { - int ret; - struct osl_object result; - if (argc < 2) return -E_MOOD_SYNTAX; - ret = send_option_arg_callback_request(NULL, argc - 1, argv + 1, f, - &result); - if (ret > 0) { - send_buffer(fd, (char *)result.data); - free(result.data); - } - return ret; + return send_option_arg_callback_request(NULL, argc - 1, argv + 1, f, + send_result, &fd); } static int com_addblob_callback(struct osl_table *table, @@ -358,7 +332,7 @@ static int com_addblob(callback_function *f, int fd, int argc, PARA_NOTICE_LOG("argv[1]: %s\n", argv[1]); arg_obj.size = strlen(argv[1]) + 1; arg_obj.data = (char *)argv[1]; - return stdin_command(fd, &arg_obj, f, 10 * 1024 * 1024, NULL); + return stdin_command(fd, &arg_obj, f, 10 * 1024 * 1024, NULL, NULL); } static int com_mvblob_callback(struct osl_table *table, @@ -388,7 +362,7 @@ static int com_mvblob(callback_function *f, __a_unused int fd, if (argc != 3) return -E_MOOD_SYNTAX; return send_option_arg_callback_request(NULL, argc - 1, argv + 1, f, - NULL); + NULL, NULL); } #define DEFINE_BLOB_COMMAND(cmd_name, table_name, cmd_prefix) \ diff --git a/fsck.c b/fsck.c index 60bd2702..ee7f4ee2 100644 --- a/fsck.c +++ b/fsck.c @@ -474,7 +474,7 @@ static int dummy_compare(const struct osl_object *obj1, const struct osl_object static unsigned files_pruned; -int prune_disk_storage_file(const char *path, const void *private_data) +int prune_disk_storage_file(const char *path, void *private_data) { HASH_TYPE hash[HASH_SIZE]; unsigned flags = *(unsigned *)private_data; @@ -534,7 +534,8 @@ static int prune_disk_storage_files(struct osl_table *t) PARA_INFO_LOG("looking for unreferenced disk storage files\n"); FOR_EACH_DISK_STORAGE_COLUMN(i, t, cd) { char *dirname = column_filename(t, i); - ret = for_each_file_in_dir(dirname, prune_disk_storage_file, &t->desc->flags); + ret = for_each_file_in_dir(dirname, prune_disk_storage_file, + (unsigned *)&t->desc->flags); free(dirname); } if (files_pruned) diff --git a/mood.c b/mood.c index 98bbb8d9..2e562f4f 100644 --- a/mood.c +++ b/mood.c @@ -569,7 +569,7 @@ int mood_check_callback(__a_unused const struct osl_object *query, osl_rbtree_loop(moods_table, BLOBCOL_ID, &pb, check_mood); result->data = pb.buf; - result->size = pb.size; + result->size = pb.offset; return 1; } diff --git a/osl.c b/osl.c index c5f48945..bc6956e9 100644 --- a/osl.c +++ b/osl.c @@ -171,7 +171,7 @@ out: * \return Standard. */ int for_each_file_in_dir(const char *dirname, - int (*func)(const char *, const void *), const void *private_data) + int (*func)(const char *, void *), void *private_data) { DIR *dir; struct dirent *entry; diff --git a/osl.h b/osl.h index 7ddf7e98..58969a43 100644 --- a/osl.h +++ b/osl.h @@ -180,7 +180,7 @@ int osl_get_rank(const struct osl_table *t, struct osl_row *r, unsigned col_num, unsigned *rank); int for_each_file_in_dir(const char *dirname, - int (*func)(const char *, const void *), const void *private_data); + int (*func)(const char *, void *), void *private_data); ssize_t para_write_all(int fd, const void *buf, size_t size); int para_lseek(int fd, off_t *offset, int whence); int para_write_file(const char *filename, const void *buf, size_t size); diff --git a/playlist.c b/playlist.c index 5dcac73c..19a91314 100644 --- a/playlist.c +++ b/playlist.c @@ -133,7 +133,7 @@ int playlist_check_callback(__a_unused const struct osl_object *query, osl_rbtree_loop(playlists_table, BLOBCOL_ID, &pb, check_playlist); result->data = pb.buf; - result->size = pb.size; + result->size = pb.offset; return 1; }