From: Andre Noll Date: Sat, 5 May 2012 09:18:58 +0000 (+0200) Subject: Simplify pass_buffer_as_shm(). X-Git-Tag: v0.4.11~14^2~4 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=d5a9e8c8eefe170b6fb62be563c079c818bd3bf8;hp=3667d75edd30f45f6b909bcf5203689c866a77b5;ds=sidebyside Simplify pass_buffer_as_shm(). Currently, this function takes a pointer to the file descriptor. For no good reason, we may as well pass the fd directly. This patch also adds a comment about the callers of this function. --- diff --git a/afs.c b/afs.c index 9cef049b..f76da3dc 100644 --- a/afs.c +++ b/afs.c @@ -580,7 +580,7 @@ static void com_select_callback(int fd, const struct osl_object *query) 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); } @@ -786,20 +786,23 @@ static void command_pre_select(struct sched *s, struct task *t) /** * 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; @@ -1022,7 +1025,7 @@ out: 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); } diff --git a/afs.h b/afs.h index 73c46648..d30621a7 100644 --- a/afs.h +++ b/afs.h @@ -207,7 +207,7 @@ typedef void callback_function(int fd, const struct osl_object *); */ 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 { @@ -233,7 +233,7 @@ 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); diff --git a/aft.c b/aft.c index fb40a7be..c7246703 100644 --- a/aft.c +++ b/aft.c @@ -1399,7 +1399,7 @@ static void com_ls_callback(int fd, const struct osl_object *query) } 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); @@ -1807,7 +1807,7 @@ out: 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); } @@ -1826,7 +1826,7 @@ static void path_brother_callback(int fd, const struct osl_object *query) 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) @@ -1837,7 +1837,7 @@ 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) @@ -2115,7 +2115,7 @@ static void com_touch_callback(int fd, const struct osl_object *query) 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); } @@ -2262,7 +2262,7 @@ static void com_rm_callback(int fd, const struct osl_object *query) 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); } @@ -2408,7 +2408,7 @@ out: 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); } @@ -2471,7 +2471,7 @@ static void afs_stat_callback(int fd, const struct osl_object *query) if (!buf) return; - pass_buffer_as_shm(buf, strlen(buf), &fd); + pass_buffer_as_shm(fd, buf, strlen(buf)); } /** @@ -2562,7 +2562,7 @@ void aft_check_callback(int fd, __a_unused const struct osl_object *query) 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); } diff --git a/attribute.c b/attribute.c index edf3baf5..8dcfa28f 100644 --- a/attribute.c +++ b/attribute.c @@ -175,7 +175,7 @@ static void com_lsatt_callback(int fd, const struct osl_object *query) 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); } @@ -359,7 +359,7 @@ out: 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); } @@ -404,7 +404,7 @@ out: 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); } @@ -478,7 +478,7 @@ static void com_rmatt_callback(int fd, const struct osl_object *query) 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); } diff --git a/blob.c b/blob.c index bc898699..5c70f04f 100644 --- a/blob.c +++ b/blob.c @@ -163,7 +163,7 @@ static void com_lsblob_callback(struct osl_table *table, 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); } @@ -204,14 +204,14 @@ static int com_lsblob(callback_function *f, struct command_context *cc) 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; } @@ -231,7 +231,7 @@ static void com_catblob_callback(struct osl_table *table, int fd, 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)); } } @@ -297,7 +297,7 @@ static void com_rmblob_callback(struct osl_table *table, int fd, } 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); } diff --git a/mood.c b/mood.c index c892ff5c..6046137d 100644 --- a/mood.c +++ b/mood.c @@ -437,7 +437,7 @@ void mood_check_callback(int fd, __a_unused const struct osl_object *query) 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); } diff --git a/playlist.c b/playlist.c index dd437157..efd27476 100644 --- a/playlist.c +++ b/playlist.c @@ -144,7 +144,7 @@ void playlist_check_callback(int fd, __a_unused const struct osl_object *query) 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); }