* copied. It then notifies the afs process that the callback function \a f
* should be executed by sending the shared memory identifier (shmid) to the
* socket.
-
+ *
* If the callback produces a result, it sends any number of shared memory
* identifiers back via the socket. For each such identifier received, \a
* result_handler is called. The contents of the sma identified by the received
if (ret < 0)
goto out;
- *(uint32_t *) buf = afs_socket_cookie;
- *(int *) (buf + sizeof(afs_socket_cookie)) = query_shmid;
+ *(uint32_t *)buf = afs_socket_cookie;
+ *(int *)(buf + sizeof(afs_socket_cookie)) = query_shmid;
ret = connect_local_socket(conf.afs_socket_arg);
if (ret < 0)
name = (char *)name_obj.data;
if ((!name || !*name) && (pmd->pm_flags & PM_SKIP_EMPTY_NAME))
return 1;
- if (!pmd->patterns.size && (pmd->pm_flags & PM_NO_PATTERN_MATCHES_EVERYTHING))
+ if (pmd->patterns.size == 0 &&
+ (pmd->pm_flags & PM_NO_PATTERN_MATCHES_EVERYTHING)) {
+ pmd->num_matches++;
return pmd->action(pmd->table, row, name, pmd->data);
+ }
for (p = pattern_txt; p < pattern_txt + pmd->patterns.size;
p += strlen(p) + 1) {
ret = fnmatch(p, name, pmd->fnmatch_flags);
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 = {
.max_size_handler = afs_max_size_handler,
};
char *arg = query->data;
- int num_admissible, ret, ret2;
+ int num_admissible, ret;
ret = clear_score_table();
if (ret < 0) {
- ret2 = para_printf(&pb, "%s\n", para_strerror(-ret));
+ para_printf(&pb, "%s\n", para_strerror(-ret));
goto out;
}
if (current_play_mode == PLAY_MODE_MOOD)
playlist_close();
ret = activate_mood_or_playlist(arg, &num_admissible);
if (ret < 0) {
- ret2 = para_printf(&pb, "%s\nswitching back to %s\n",
+ para_printf(&pb, "%s\nswitching back to %s\n",
para_strerror(-ret), current_mop?
current_mop : "dummy");
ret = activate_mood_or_playlist(current_mop, &num_admissible);
if (ret < 0) {
- if (ret2 >= 0)
- ret2 = para_printf(&pb, "failed, switching to dummy\n");
+ para_printf(&pb, "failed (%s), switching to dummy\n",
+ para_strerror(-ret));
activate_mood_or_playlist(NULL, &num_admissible);
}
} else
- ret2 = para_printf(&pb, "activated %s (%d admissible files)\n", current_mop?
- current_mop : "dummy mood", num_admissible);
+ para_printf(&pb, "activated %s (%d admissible files)\n",
+ current_mop? current_mop : "dummy mood",
+ num_admissible);
out:
- if (ret2 >= 0 && 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)
return ret;
}
-/*
- * On errors, negative value is written to fd.
- * On success: If query produced a result, the result_shmid is written to fd.
- * Otherwise, zero is written.
- */
static int call_callback(int fd, int query_shmid)
{
void *query_shm;
{
uint32_t table_mask = *(uint32_t *)query->data;
int i, ret;
- struct para_buffer pb = {.buf = NULL};
+ struct para_buffer pb = {
+ .max_size = shm_get_shmmax(),
+ .private_data = &(struct afs_max_size_handler_data) {
+ .fd = fd,
+ .band = SBD_OUTPUT
+ }
+ };
close_afs_tables();
for (i = 0; i < NUM_AFS_TABLES; i++) {
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)
return -E_BAD_TABLE_NAME;
}
}
- ret = send_callback_request(create_tables_callback, &query,
+ return send_callback_request(create_tables_callback, &query,
afs_cb_result_handler, cc);
- return ret;
}
/**