com_setatt(): Return negative on errors
[paraslash.git] / aft.c
diff --git a/aft.c b/aft.c
index 206be9e38630d3c8ebfe4ce8e07fc28de74073b9..c255b245fdf0209f0c8b09ba0b28310fddcb8fa5 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -748,62 +748,50 @@ static int write_attribute_items(struct para_buffer *b,
        char *att_text;
        int ret;
 
-       ret = WRITE_STATUS_ITEM(b, SI_ATTRIBUTES_BITMAP, "%s\n", att_bitmap);
-       if (ret < 0)
-               return ret;
+       WRITE_STATUS_ITEM(b, SI_ATTRIBUTES_BITMAP, "%s\n", att_bitmap);
        ret = get_attribute_text(&afsi->attributes, " ", &att_text);
        if (ret < 0)
                return ret;
-       ret = WRITE_STATUS_ITEM(b, SI_ATTRIBUTES_TXT, "%s\n", att_text);
+       WRITE_STATUS_ITEM(b, SI_ATTRIBUTES_TXT, "%s\n", att_text);
        free(att_text);
        return ret;
 }
 
-static int write_lyrics_items(struct para_buffer *b, struct afs_info *afsi)
+static void write_lyrics_items(struct para_buffer *b, struct afs_info *afsi)
 {
        char *lyrics_name;
-       int ret;
 
-       ret = WRITE_STATUS_ITEM(b, SI_LYRICS_ID, "%u\n", afsi->lyrics_id);
-       if (ret < 0)
-               return ret;
+       WRITE_STATUS_ITEM(b, SI_LYRICS_ID, "%u\n", afsi->lyrics_id);
        lyr_get_name_by_id(afsi->lyrics_id, &lyrics_name);
-       return WRITE_STATUS_ITEM(b, SI_LYRICS_NAME, "%s\n", lyrics_name?
+       WRITE_STATUS_ITEM(b, SI_LYRICS_NAME, "%s\n", lyrics_name?
                lyrics_name : "(none)");
 }
 
-static int write_image_items(struct para_buffer *b, struct afs_info *afsi)
+static void write_image_items(struct para_buffer *b, struct afs_info *afsi)
 {
        char *image_name;
-       int ret;
 
-       ret = WRITE_STATUS_ITEM(b, SI_IMAGE_ID, "%u\n", afsi->image_id);
-       if (ret < 0)
-               return ret;
+       WRITE_STATUS_ITEM(b, SI_IMAGE_ID, "%u\n", afsi->image_id);
        img_get_name_by_id(afsi->image_id, &image_name);
-       return WRITE_STATUS_ITEM(b, SI_IMAGE_NAME, "%s\n", image_name?
+       WRITE_STATUS_ITEM(b, SI_IMAGE_NAME, "%s\n", image_name?
                image_name : "(none)");
 }
 
-static int write_filename_items(struct para_buffer *b, const char *path,
+static void write_filename_items(struct para_buffer *b, const char *path,
                unsigned flags)
 {
        char *val;
-       int ret;
 
-       if (!(flags & LS_FLAG_FULL_PATH))
-               return WRITE_STATUS_ITEM(b, SI_BASENAME, "%s\n", path);
-       ret = WRITE_STATUS_ITEM(b, SI_PATH, "%s\n", path);
-       if (ret < 0)
-               return ret;
+       if (!(flags & LS_FLAG_FULL_PATH)) {
+               WRITE_STATUS_ITEM(b, SI_BASENAME, "%s\n", path);
+               return;
+       }
+       WRITE_STATUS_ITEM(b, SI_PATH, "%s\n", path);
        val = para_basename(path);
-       ret = WRITE_STATUS_ITEM(b, SI_BASENAME, "%s\n", val? val : "");
-       if (ret < 0)
-               return ret;
+       WRITE_STATUS_ITEM(b, SI_BASENAME, "%s\n", val? val : "");
        val = para_dirname(path);
-       ret = WRITE_STATUS_ITEM(b, SI_DIRECTORY, "%s\n", val? val : "");
+       WRITE_STATUS_ITEM(b, SI_DIRECTORY, "%s\n", val? val : "");
        free(val);
-       return ret;
 }
 
 static int print_chunk_table(struct ls_data *d, struct para_buffer *b)
@@ -835,12 +823,12 @@ static int print_chunk_table(struct ls_data *d, struct para_buffer *b)
        return ret;
 }
 
-static int write_score(struct para_buffer *b, struct ls_data *d,
+static void write_score(struct para_buffer *b, struct ls_data *d,
                struct ls_options *opts)
 {
        if (!(opts->flags & LS_FLAG_ADMISSIBLE_ONLY)) /* no score*/
-               return 0;
-       return WRITE_STATUS_ITEM(b, SI_SCORE, "%li\n", d->score);
+               return;
+       WRITE_STATUS_ITEM(b, SI_SCORE, "%li\n", d->score);
 }
 
 static int print_list_item(struct ls_data *d, struct ls_options *opts,
@@ -919,80 +907,33 @@ static int print_list_item(struct ls_data *d, struct ls_options *opts,
                        last_played_time,
                        bn? bn : "?");
        }
-       ret = write_filename_items(b, d->path, opts->flags);
-       if (ret < 0)
-               goto out;
-       ret = write_score(b, d, opts);
-       if (ret < 0)
-               goto out;
+       write_filename_items(b, d->path, opts->flags);
+       write_score(b, d, opts);
        ret = write_attribute_items(b, att_buf, afsi);
        if (ret < 0)
                goto out;
-       ret = write_image_items(b, afsi);
-       if (ret < 0)
-               goto out;
-       ret = write_lyrics_items(b, afsi);
-       if (ret < 0)
-               goto out;
+       write_image_items(b, afsi);
+       write_lyrics_items(b, afsi);
        hash_to_asc(d->hash, asc_hash);
-       ret = WRITE_STATUS_ITEM(b, SI_HASH, "%s\n", asc_hash);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_BITRATE, "%dkbit/s\n", afhi->bitrate);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_FORMAT, "%s\n",
+       WRITE_STATUS_ITEM(b, SI_HASH, "%s\n", asc_hash);
+       WRITE_STATUS_ITEM(b, SI_BITRATE, "%dkbit/s\n", afhi->bitrate);
+       WRITE_STATUS_ITEM(b, SI_FORMAT, "%s\n",
                audio_format_name(afsi->audio_format_id));
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_FREQUENCY, "%dHz\n", afhi->frequency);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_CHANNELS, "%d\n", afhi->channels);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_DURATION, "%s\n", duration_buf);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_SECONDS_TOTAL, "%lu\n",
-               afhi->seconds_total);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_LAST_PLAYED, "%s\n", last_played_time);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%d\n", afsi->num_played);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_AMPLIFICATION, "%u\n", afsi->amp);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_CHUNK_TIME, "%lu\n",
-               tv2ms(&afhi->chunk_tv));
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%lu\n",
-               afhi->chunks_total);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_TECHINFO, "%s\n", afhi->techinfo);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_ARTIST, "%s\n", afhi->tags.artist);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_TITLE, "%s\n", afhi->tags.title);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_YEAR, "%s\n", afhi->tags.year);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_ALBUM, "%s\n", afhi->tags.album);
-       if (ret < 0)
-               goto out;
-       ret = WRITE_STATUS_ITEM(b, SI_COMMENT, "%s\n", afhi->tags.comment);
-       if (ret < 0)
-               goto out;
+       WRITE_STATUS_ITEM(b, SI_FREQUENCY, "%dHz\n", afhi->frequency);
+       WRITE_STATUS_ITEM(b, SI_CHANNELS, "%d\n", afhi->channels);
+       WRITE_STATUS_ITEM(b, SI_DURATION, "%s\n", duration_buf);
+       WRITE_STATUS_ITEM(b, SI_SECONDS_TOTAL, "%lu\n", afhi->seconds_total);
+       WRITE_STATUS_ITEM(b, SI_LAST_PLAYED, "%s\n", last_played_time);
+       WRITE_STATUS_ITEM(b, SI_NUM_PLAYED, "%d\n", afsi->num_played);
+       WRITE_STATUS_ITEM(b, SI_AMPLIFICATION, "%u\n", afsi->amp);
+       WRITE_STATUS_ITEM(b, SI_CHUNK_TIME, "%lu\n", tv2ms(&afhi->chunk_tv));
+       WRITE_STATUS_ITEM(b, SI_NUM_CHUNKS, "%lu\n", afhi->chunks_total);
+       WRITE_STATUS_ITEM(b, SI_TECHINFO, "%s\n", afhi->techinfo);
+       WRITE_STATUS_ITEM(b, SI_ARTIST, "%s\n", afhi->tags.artist);
+       WRITE_STATUS_ITEM(b, SI_TITLE, "%s\n", afhi->tags.title);
+       WRITE_STATUS_ITEM(b, SI_YEAR, "%s\n", afhi->tags.year);
+       WRITE_STATUS_ITEM(b, SI_ALBUM, "%s\n", afhi->tags.album);
+       WRITE_STATUS_ITEM(b, SI_COMMENT, "%s\n", afhi->tags.comment);
        if (opts->mode == LS_MODE_MBOX) {
                struct osl_object lyrics_def;
                lyr_get_def_by_id(afsi->lyrics_id, &lyrics_def);
@@ -1026,9 +967,8 @@ static void make_inode_status_items(struct para_buffer *pb)
        ret = strftime(mtime_str, 29, "%b %d %Y", &mtime_tm);
        assert(ret > 0); /* number of bytes placed in mtime_str */
 out:
-       /* We don't care too much about errors here */
-       (void)WRITE_STATUS_ITEM(pb, SI_MTIME, "%s\n", mtime_str);
-       (void)WRITE_STATUS_ITEM(pb, SI_FILE_SIZE, "%ld\n", statbuf.st_size / 1024);
+       WRITE_STATUS_ITEM(pb, SI_MTIME, "%s\n", mtime_str);
+       WRITE_STATUS_ITEM(pb, SI_FILE_SIZE, "%ld\n", statbuf.st_size / 1024);
 }
 
 static int make_status_items(void)
@@ -1351,7 +1291,7 @@ err:
        return ret;
 }
 
-static void com_ls_callback(int fd, const struct osl_object *query)
+static int com_ls_callback(int fd, const struct osl_object *query)
 {
        struct ls_options *opts = query->data;
        char *p, *pattern_start = (char *)query->data + sizeof(*opts);
@@ -1383,8 +1323,7 @@ static void com_ls_callback(int fd, const struct osl_object *query)
        if (ret < 0)
                goto out;
        if (opts->num_matching_paths == 0) {
-               if (opts->num_patterns > 0)
-                       para_printf(&b, "no matches\n");
+               ret = opts->num_patterns > 0? -E_NO_MATCH : 0;
                goto out;
        }
        ret = sort_matching_paths(opts);
@@ -1404,12 +1343,11 @@ static void com_ls_callback(int fd, const struct osl_object *query)
                                goto out;
                }
 out:
-       if (b.offset)
-               pass_buffer_as_shm(fd, SBD_OUTPUT, b.buf, b.offset);
-       free(b.buf);
+       flush_and_free_pb(&b);
        free(opts->data);
        free(opts->data_ptr);
        free(opts->patterns);
+       return ret;
 }
 
 /*
@@ -1417,7 +1355,7 @@ out:
  */
 int com_ls(struct command_context *cc)
 {
-       int i, ret;
+       int i;
        unsigned flags = 0;
        enum ls_sorting_method sort = LS_SORT_BY_PATH;
        enum ls_listing_mode mode = LS_MODE_SHORT;
@@ -1526,9 +1464,8 @@ int com_ls(struct command_context *cc)
        opts.sorting = sort;
        opts.mode = mode;
        opts.num_patterns = cc->argc - i;
-       ret = send_option_arg_callback_request(&query, opts.num_patterns,
+       return send_option_arg_callback_request(&query, opts.num_patterns,
                cc->argv + i, com_ls_callback, afs_cb_result_handler, cc);
-       return ret;
 }
 
 /**
@@ -1674,7 +1611,7 @@ enum com_add_flags {
        ADD_FLAG_ALL = 8,
 };
 
-static void com_add_callback(int fd, const struct osl_object *query)
+static int com_add_callback(int fd, const struct osl_object *query)
 {
        char *buf = query->data, *path;
        struct osl_row *pb, *aft_row;
@@ -1798,10 +1735,9 @@ static void com_add_callback(int fd, const struct osl_object *query)
        afs_event(AUDIO_FILE_ADD, &msg, aft_row);
 out:
        if (ret < 0)
-               para_printf(&msg, "%s\n", para_strerror(-ret));
-       if (msg.offset)
-               pass_buffer_as_shm(fd, SBD_OUTPUT, msg.buf, msg.offset);
-       free(msg.buf);
+               para_printf(&msg, "could not add %s\n", path);
+       flush_and_free_pb(&msg);
+       return ret;
 }
 
 /** Used by com_add(). */
@@ -1812,26 +1748,26 @@ struct private_add_data {
        uint32_t flags;
 };
 
-static void path_brother_callback(int fd, const struct osl_object *query)
+static int path_brother_callback(int fd, const struct osl_object *query)
 {
        char *path = query->data;
        struct osl_row *path_brother;
        int ret = aft_get_row_of_path(path, &path_brother);
        if (ret < 0)
-               return;
-       pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&path_brother,
+               return ret;
+       return pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&path_brother,
                sizeof(path_brother));
 }
 
-static void hash_sister_callback(int fd, const struct osl_object *query)
+static int hash_sister_callback(int fd, const struct osl_object *query)
 {
        unsigned char *hash = query->data;
        struct osl_row *hash_sister;
 
        hash_sister = find_hash_sister(hash);
        if (!hash_sister)
-               return;
-       pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&hash_sister,
+               return 0;
+       return pass_buffer_as_shm(fd, SBD_OUTPUT, (char *)&hash_sister,
                sizeof(hash_sister));
 }
 
@@ -1839,7 +1775,9 @@ static int get_row_pointer_from_result(struct osl_object *result,
                __a_unused uint8_t band, void *private)
 {
        struct osl_row **row = private;
-       *row = *(struct osl_row **)(result->data);
+
+       if (band == SBD_OUTPUT)
+               *row = *(struct osl_row **)(result->data);
        return 1;
 }
 
@@ -2036,12 +1974,12 @@ static int touch_audio_file(__a_unused struct osl_table *table,
 
        ret = get_afsi_object_of_row(row, &obj);
        if (ret < 0) {
-               para_printf(&tad->pb, "%s: %s\n", name, para_strerror(-ret));
+               para_printf(&tad->pb, "cannot touch %s\n", name);
                return ret;
        }
        ret = load_afsi(&old_afsi, &obj);
        if (ret < 0) {
-               para_printf(&tad->pb, "%s: %s\n", name, para_strerror(-ret));
+               para_printf(&tad->pb, "cannot touch %s\n", name);
                return ret;
        }
        new_afsi = old_afsi;
@@ -2073,7 +2011,7 @@ static int touch_audio_file(__a_unused struct osl_table *table,
        return 1;
 }
 
-static void com_touch_callback(int fd, const struct osl_object *query)
+static int com_touch_callback(int fd, const struct osl_object *query)
 {
        struct touch_action_data tad = {.cto = query->data,
                .pb = {
@@ -2098,13 +2036,10 @@ static void com_touch_callback(int fd, const struct osl_object *query)
        if (tad.cto->flags & TOUCH_FLAG_FNM_PATHNAME)
                pmd.fnmatch_flags |= FNM_PATHNAME;
        ret = for_each_matching_row(&pmd);
-       if (ret < 0)
-               para_printf(&tad.pb, "%s\n", para_strerror(-ret));
-       else if (pmd.num_matches == 0)
-               para_printf(&tad.pb, "no matches\n");
-       if (tad.pb.offset)
-               pass_buffer_as_shm(fd, SBD_OUTPUT, tad.pb.buf, tad.pb.offset);
-       free(tad.pb.buf);
+       if (ret >= 0 && pmd.num_matches == 0)
+               ret = -E_NO_MATCH;
+       flush_and_free_pb(&tad.pb);
+       return ret;
 }
 
 int com_touch(struct command_context *cc)
@@ -2174,11 +2109,8 @@ int com_touch(struct command_context *cc)
        }
        if (i >= cc->argc)
                return -E_AFT_SYNTAX;
-       ret = send_option_arg_callback_request(&query, cc->argc - i,
+       return send_option_arg_callback_request(&query, cc->argc - i,
                cc->argv + i, com_touch_callback, afs_cb_result_handler, cc);
-       if (ret < 0)
-               send_strerror(cc, -ret);
-       return ret;
 }
 
 /** Flags for com_rm(). */
@@ -2210,11 +2142,11 @@ static int remove_audio_file(__a_unused struct osl_table *table,
        afs_event(AUDIO_FILE_REMOVE, &crd->pb, row);
        ret = osl(osl_del_row(audio_file_table, row));
        if (ret < 0)
-               para_printf(&crd->pb, "%s: %s\n", name, para_strerror(-ret));
+               para_printf(&crd->pb, "cannot remove %s\n", name);
        return ret;
 }
 
-static void com_rm_callback(int fd, const struct osl_object *query)
+static int com_rm_callback(int fd, const struct osl_object *query)
 {
        struct com_rm_action_data crd = {.flags = *(uint32_t *)query->data,
                .pb = {
@@ -2239,17 +2171,15 @@ static void com_rm_callback(int fd, const struct osl_object *query)
        if (crd.flags & RM_FLAG_FNM_PATHNAME)
                pmd.fnmatch_flags |= FNM_PATHNAME;
        ret = for_each_matching_row(&pmd);
-       if (ret < 0) {
-               para_printf(&crd.pb, "%s\n", para_strerror(-ret));
-               return;
-       }
-       if ((pmd.num_matches == 0) && !(crd.flags & RM_FLAG_FORCE))
-               para_printf(&crd.pb, "no matches -- nothing removed\n");
+       if (ret < 0)
+               goto out;
+       if (pmd.num_matches == 0)
+               ret = -E_NO_MATCH;
        else if (crd.flags & RM_FLAG_VERBOSE)
-               para_printf(&crd.pb, "removed %u files\n", pmd.num_matches);
-       if (ret >= 0 && crd.pb.offset)
-               pass_buffer_as_shm(fd, SBD_OUTPUT, crd.pb.buf, crd.pb.offset);
-       free(crd.pb.buf);
+               para_printf(&crd.pb, "removed %u file(s)\n", pmd.num_matches);
+out:
+       flush_and_free_pb(&crd.pb);
+       return ret;
 }
 
 /* TODO options: -r (recursive) */
@@ -2257,7 +2187,7 @@ int com_rm(struct command_context *cc)
 {
        uint32_t flags = 0;
        struct osl_object query = {.data = &flags, .size = sizeof(flags)};
-       int i, ret;
+       int i;
 
        for (i = 1; i < cc->argc; i++) {
                const char *arg = cc->argv[i];
@@ -2283,11 +2213,8 @@ int com_rm(struct command_context *cc)
        }
        if (i >= cc->argc)
                return -E_AFT_SYNTAX;
-       ret = send_option_arg_callback_request(&query, cc->argc - i,
+       return send_option_arg_callback_request(&query, cc->argc - i,
                cc->argv + i, com_rm_callback, afs_cb_result_handler, cc);
-       if (ret < 0)
-               send_strerror(cc, -ret);
-       return ret;
 }
 
 /**
@@ -2353,7 +2280,7 @@ static int copy_selector_info(__a_unused struct osl_table *table,
        return 1;
 }
 
-static void com_cpsi_callback(int fd, const struct osl_object *query)
+static int com_cpsi_callback(int fd, const struct osl_object *query)
 {
        struct cpsi_action_data cad = {
                .flags = *(unsigned *)query->data,
@@ -2383,24 +2310,23 @@ static void com_cpsi_callback(int fd, const struct osl_object *query)
        if (ret < 0)
                goto out;
        ret = for_each_matching_row(&pmd);
-out:
        if (ret < 0)
-               para_printf(&cad.pb, "%s\n", para_strerror(-ret));
-       else if (pmd.num_matches > 0) {
+               goto out;
+       if (pmd.num_matches > 0) {
                if (cad.flags & CPSI_FLAG_VERBOSE)
-                       para_printf(&cad.pb, "copied requested afsi from %s "
-                               "to %u files\n", source_path, pmd.num_matches);
+                       para_printf(&cad.pb, "updated afsi of %u file(s)\n",
+                               pmd.num_matches);
        } else
-               para_printf(&cad.pb, "no matches - nothing copied\n");
-       if (cad.pb.offset)
-               pass_buffer_as_shm(fd, SBD_OUTPUT, cad.pb.buf, cad.pb.offset);
-       free(cad.pb.buf);
+               ret = -E_NO_MATCH;
+out:
+       flush_and_free_pb(&cad.pb);
+       return ret;
 }
 
 int com_cpsi(struct command_context *cc)
 {
        unsigned flags = 0;
-       int i, ret;
+       int i;
        struct osl_object options = {.data = &flags, .size = sizeof(flags)};
 
        for (i = 1; i < cc->argc; i++) {
@@ -2441,11 +2367,8 @@ int com_cpsi(struct command_context *cc)
                return -E_AFT_SYNTAX;
        if (!(flags & ~CPSI_FLAG_VERBOSE)) /* no copy flags given */
                flags = ~(unsigned)CPSI_FLAG_VERBOSE | flags;
-       ret = send_option_arg_callback_request(&options, cc->argc - i,
+       return send_option_arg_callback_request(&options, cc->argc - i,
                cc->argv + i, com_cpsi_callback, afs_cb_result_handler, cc);
-       if (ret < 0)
-               send_strerror(cc, -ret);
-       return ret;
 }
 
 struct change_atts_data {
@@ -2479,7 +2402,7 @@ static int change_atts(__a_unused struct osl_table *table,
        return 1;
 }
 
-static void com_setatt_callback(int fd, const struct osl_object *query)
+static int com_setatt_callback(int fd, const struct osl_object *query)
 {
        char *p;
        int ret;
@@ -2535,13 +2458,10 @@ static void com_setatt_callback(int fd, const struct osl_object *query)
        if (ret < 0)
                goto out;
        if (pmd.num_matches == 0)
-               para_printf(&cad.pb, "no matches\n");
+               ret = -E_NO_MATCH;
 out:
-       if (ret < 0)
-               para_printf(&cad.pb, "%s\n", para_strerror(-ret));
-       if (cad.pb.offset)
-               pass_buffer_as_shm(fd, SBD_OUTPUT, cad.pb.buf, cad.pb.offset);
-       free(cad.pb.buf);
+       flush_and_free_pb(&cad.pb);
+       return ret;
 }
 
 int com_setatt(struct command_context *cc)
@@ -2552,15 +2472,15 @@ int com_setatt(struct command_context *cc)
                com_setatt_callback, afs_cb_result_handler, cc);
 }
 
-static void afs_stat_callback(int fd, const struct osl_object *query)
+static int afs_stat_callback(int fd, const struct osl_object *query)
 {
        int *parser_friendly = query->data;
        char *buf = *parser_friendly?
                parser_friendly_status_items : status_items;
 
        if (!buf)
-               return;
-       pass_buffer_as_shm(fd, SBD_OUTPUT, buf, strlen(buf));
+               return 0;
+       return pass_buffer_as_shm(fd, SBD_OUTPUT, buf, strlen(buf));
 }
 
 /**
@@ -2626,11 +2546,11 @@ static int check_audio_file(struct osl_row *row, void *data)
  * \param fd The afs socket.
  * \param query Unused.
  *
- * This function always succeeds.
+ * \return This function always returns zero.
  *
  * \sa com_check().
  */
-void aft_check_callback(int fd, __a_unused const struct osl_object *query)
+int aft_check_callback(int fd, __a_unused const struct osl_object *query)
 {
        struct para_buffer pb = {
                .max_size = shm_get_shmmax(),
@@ -2642,9 +2562,8 @@ void aft_check_callback(int fd, __a_unused const struct osl_object *query)
        };
        para_printf(&pb, "checking audio file table...\n");
        audio_file_loop(&pb, check_audio_file);
-       if (pb.offset)
-               pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
-       free(pb.buf);
+       flush_and_free_pb(&pb);
+       return 0;
 }
 
 /**