This kills some code which is duplicated in all command handlers.
return send_sb(&cc->scc, result->data, result->size, band, true);
}
+void flush_and_free_pb(struct para_buffer *pb)
+{
+ int ret;
+ struct afs_max_size_handler_data *amshd = pb->private_data;
+
+ if (pb->buf && pb->size > 0) {
+ ret = pass_buffer_as_shm(amshd->fd, amshd->band, pb->buf,
+ pb->offset);
+ if (ret < 0)
+ PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+ }
+ free(pb->buf);
+}
+
static void com_select_callback(int fd, const struct osl_object *query)
{
struct para_buffer pb = {
current_mop? current_mop : "dummy mood",
num_admissible);
out:
- if (pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
- free(pb.buf);
+ flush_and_free_pb(&pb);
}
int com_select(struct command_context *cc)
out:
if (ret < 0)
para_printf(&pb, "%s\n", para_strerror(-ret));
- if (pb.buf)
- pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
- free(pb.buf);
+ flush_and_free_pb(&pb);
}
int com_init(struct command_context *cc)
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);
+void flush_and_free_pb(struct para_buffer *pb);
/* score */
void score_init(struct afs_table *t);
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);
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);
+ flush_and_free_pb(&msg);
}
/** Used by com_add(). */
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);
+ flush_and_free_pb(&tad.pb);
}
int com_touch(struct command_context *cc)
para_printf(&crd.pb, "no matches -- nothing removed\n");
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);
+ flush_and_free_pb(&crd.pb);
}
/* TODO options: -r (recursive) */
"to %u files\n", source_path, 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);
+ flush_and_free_pb(&cad.pb);
}
int com_cpsi(struct command_context *cc)
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);
}
int com_setatt(struct command_context *cc)
};
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);
}
/**
if (laad.flags & LSATT_FLAG_REVERSE)
pmd.pm_flags |= PM_REVERSE_LOOP;
for_each_matching_row(&pmd);
- if (laad.pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, laad.pb.buf, laad.pb.offset);
- free(laad.pb.buf);
+ flush_and_free_pb(&laad.pb);
}
int com_lsatt(struct command_context *cc)
out:
if (ret < 0)
para_printf(&pb, "%s: %s\n", p, para_strerror(-ret));
- if (pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
- free(pb.buf);
+ flush_and_free_pb(&pb);
}
int com_addatt(struct command_context *cc)
para_printf(&pb, "%s\n", para_strerror(-ret));
else
afs_event(ATTRIBUTE_RENAME, &pb, NULL);
- if (pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
- free(pb.buf);
+ flush_and_free_pb(&pb);
}
int com_mvatt(struct command_context *cc)
para_printf(&raad.pb, "%s\n", para_strerror(-ret));
else if (!raad.num_removed)
para_printf(&raad.pb, "no match -- nothing removed\n");
- if (raad.pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, raad.pb.buf, raad.pb.offset);
- free(raad.pb.buf);
+ flush_and_free_pb(&raad.pb);
}
int com_rmatt(struct command_context *cc)
para_printf(&lbad.pb, "%s\n", para_strerror(-ret));
else if (pmd.num_matches == 0 && pmd.patterns.size > 0)
para_printf(&lbad.pb, "no matches\n");
- if (lbad.pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, lbad.pb.buf, lbad.pb.offset);
- free(lbad.pb.buf);
+ flush_and_free_pb(&lbad.pb);
}
static int com_lsblob(callback_function *f, struct command_context *cc)
para_printf(&rmbd.pb, "removed %d blobs\n", pmd.num_matches);
afs_event(BLOB_RENAME, NULL, table);
}
- if (rmbd.pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, rmbd.pb.buf, rmbd.pb.offset);
- free(rmbd.pb.buf);
+ flush_and_free_pb(&rmbd.pb);
}
static int com_rmblob(callback_function *f, struct command_context *cc)
}
afs_event(BLOB_RENAME, NULL, table);
out:
- if (pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
- free(pb.buf);
+ flush_and_free_pb(&pb);
}
static int com_mvblob(callback_function *f, struct command_context *cc)
para_printf(&pb, "checking moods...\n");
osl_rbtree_loop(moods_table, BLOBCOL_ID, &pb,
check_mood);
- if (pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
- free(pb.buf);
+ flush_and_free_pb(&pb);
}
static int64_t normalized_value(int64_t x, int64_t n, int64_t sum, int64_t qd)
para_printf(&pb, "checking playlists...\n");
osl_rbtree_loop(playlists_table, BLOBCOL_ID, &pb,
check_playlist);
- if (pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
- free(pb.buf);
+ flush_and_free_pb(&pb);
}
/**