current_mop : "dummy mood", num_admissible);
out:
if (ret2 >= 0 && pb.offset)
- pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+ pass_buffer_as_shm(fd, pb.buf, pb.offset);
free(pb.buf);
}
/**
* Send data as shared memory to a file descriptor.
*
+ * \param fd File descriptor to send the shmid to.
* \param buf The buffer holding the data to be sent.
* \param size The size of \a buf.
- * \param fd_ptr A pointer to the file descriptor.
*
* This function creates a shared memory area large enough to hold
* the content given by \a buf and \a size and sends the identifier
* of this area to the file descriptor given by \a fd_ptr.
*
+ * It is called by the AFS max_size handler as well as directly by the AFS
+ * command callbacks to send command output to the command handlers.
+ *
* \return Zero if \a buf is \p NULL or \a size is zero. Negative on errors,
* and positive on success.
*/
-int pass_buffer_as_shm(char *buf, size_t size, void *fd_ptr)
+int pass_buffer_as_shm(int fd, char *buf, size_t size)
{
- int ret, shmid, fd = *(int *)fd_ptr;
+ int ret, shmid;
void *shm;
struct callback_result *cr;
if (ret < 0)
para_printf(&pb, "%s\n", para_strerror(-ret));
if (pb.buf)
- pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+ pass_buffer_as_shm(fd, pb.buf, pb.offset);
free(pb.buf);
}
*/
typedef int callback_result_handler(struct osl_object *result, void *private);
int afs_cb_result_handler(struct osl_object *result, void *private);
-int pass_buffer_as_shm(char *buf, size_t size, void *fd_ptr);
+int pass_buffer_as_shm(int fd, char *buf, size_t size);
/** Structure passed to the AFS max_size handler. */
struct afs_max_size_handler_data {
_static_inline_ int afs_max_size_handler(char *buf, size_t size, void *private)
{
struct afs_max_size_handler_data *amshd = private;
- return pass_buffer_as_shm(buf, size, &amshd->fd);
+ return pass_buffer_as_shm(amshd->fd, buf, size);
}
__noreturn void afs_init(uint32_t cookie, int socket_fd);
}
out:
if (b.offset)
- pass_buffer_as_shm(b.buf, b.offset, &fd);
+ pass_buffer_as_shm(fd, b.buf, b.offset);
free(b.buf);
free(opts->data);
free(opts->data_ptr);
if (ret < 0)
para_printf(&msg, "%s\n", para_strerror(-ret));
if (msg.offset)
- pass_buffer_as_shm(msg.buf, msg.offset, &fd);
+ pass_buffer_as_shm(fd, msg.buf, msg.offset);
free(msg.buf);
}
int ret = aft_get_row_of_path(path, &path_brother);
if (ret < 0)
return;
- pass_buffer_as_shm((char *)&path_brother, sizeof(path_brother), &fd);
+ pass_buffer_as_shm(fd, (char *)&path_brother, sizeof(path_brother));
}
static void hash_sister_callback(int fd, const struct osl_object *query)
hash_sister = find_hash_sister(hash);
if (!hash_sister)
return;
- pass_buffer_as_shm((char *)&hash_sister, sizeof(hash_sister), &fd);
+ pass_buffer_as_shm(fd, (char *)&hash_sister, sizeof(hash_sister));
}
static int get_row_pointer_from_result(struct osl_object *result, void *private)
else if (pmd.num_matches == 0)
ret2 = para_printf(&tad.pb, "no matches\n");
if (ret2 >= 0 && tad.pb.offset)
- pass_buffer_as_shm(tad.pb.buf, tad.pb.offset, &fd);
+ pass_buffer_as_shm(fd, tad.pb.buf, tad.pb.offset);
free(tad.pb.buf);
}
pmd.num_matches);
}
if (ret >= 0 && crd.pb.offset)
- pass_buffer_as_shm(crd.pb.buf, crd.pb.offset, &fd);
+ pass_buffer_as_shm(fd, crd.pb.buf, crd.pb.offset);
free(crd.pb.buf);
}
para_printf(&cad.pb, "nothing copied\n");
}
if (cad.pb.offset)
- pass_buffer_as_shm(cad.pb.buf, cad.pb.offset, &fd);
+ pass_buffer_as_shm(fd, cad.pb.buf, cad.pb.offset);
free(cad.pb.buf);
}
if (!buf)
return;
- pass_buffer_as_shm(buf, strlen(buf), &fd);
+ pass_buffer_as_shm(fd, buf, strlen(buf));
}
/**
return;
audio_file_loop(&pb, check_audio_file);
if (pb.offset)
- pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+ pass_buffer_as_shm(fd, pb.buf, pb.offset);
free(pb.buf);
}
pmd.pm_flags |= PM_REVERSE_LOOP;
for_each_matching_row(&pmd);
if (laad.pb.offset)
- pass_buffer_as_shm(laad.pb.buf, laad.pb.offset, &fd);
+ pass_buffer_as_shm(fd, laad.pb.buf, laad.pb.offset);
free(laad.pb.buf);
}
if (ret < 0 && ret2 >= 0)
para_printf(&pb, "%s: %s\n", p, para_strerror(-ret));
if (pb.offset)
- pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+ pass_buffer_as_shm(fd, pb.buf, pb.offset);
free(pb.buf);
}
else
afs_event(ATTRIBUTE_RENAME, &pb, NULL);
if (pb.offset)
- pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+ pass_buffer_as_shm(fd, pb.buf, pb.offset);
free(pb.buf);
}
else if (!raad.num_removed)
ret2 = para_printf(&raad.pb, "no match -- nothing removed\n");
if (ret2 >= 0 && raad.pb.offset)
- pass_buffer_as_shm(raad.pb.buf, raad.pb.offset, &fd);
+ pass_buffer_as_shm(fd, raad.pb.buf, raad.pb.offset);
free(raad.pb.buf);
}
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(lbad.pb.buf, lbad.pb.offset, &fd);
+ pass_buffer_as_shm(fd, lbad.pb.buf, lbad.pb.offset);
free(lbad.pb.buf);
}
static int cat_blob(struct osl_table *table, struct osl_row *row,
__a_unused const char *name, void *data)
{
- int ret = 0, ret2;
+ int ret = 0, ret2, fd = *(int *)data;
struct osl_object obj;
ret = osl(osl_open_disk_object(table, row, BLOBCOL_DEF, &obj));
if (ret < 0)
return (ret == osl(-E_OSL_EMPTY))? 0 : ret;
assert(obj.size > 0);
- ret = pass_buffer_as_shm(obj.data, obj.size, data);
+ ret = pass_buffer_as_shm(fd, obj.data, obj.size);
ret2 = osl(osl_close_disk_object(&obj));
return (ret < 0)? ret : ret2;
}
for_each_matching_row(&pmd);
if (pmd.num_matches == 0) {
char err_msg[] = "no matches\n";
- pass_buffer_as_shm(err_msg, sizeof(err_msg), &fd);
+ pass_buffer_as_shm(fd, err_msg, sizeof(err_msg));
}
}
}
out:
if (ret2 >= 0 && rmbd.pb.offset)
- pass_buffer_as_shm(rmbd.pb.buf, rmbd.pb.offset, &fd);
+ pass_buffer_as_shm(fd, rmbd.pb.buf, rmbd.pb.offset);
free(rmbd.pb.buf);
}
osl_rbtree_loop(moods_table, BLOBCOL_ID, &pb,
check_mood);
if (pb.offset)
- pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+ pass_buffer_as_shm(fd, pb.buf, pb.offset);
free(pb.buf);
}
osl_rbtree_loop(playlists_table, BLOBCOL_ID, &pb,
check_playlist);
if (pb.offset)
- pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+ pass_buffer_as_shm(fd, pb.buf, pb.offset);
free(pb.buf);
}