Simplify pass_buffer_as_shm().
authorAndre Noll <maan@systemlinux.org>
Sat, 5 May 2012 09:18:58 +0000 (11:18 +0200)
committerAndre Noll <maan@systemlinux.org>
Mon, 7 May 2012 09:22:41 +0000 (11:22 +0200)
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.

afs.c
afs.h
aft.c
attribute.c
blob.c
mood.c
playlist.c

diff --git a/afs.c b/afs.c
index 9cef049bdfff719c95aa8a4e0357da16fc926712..f76da3dc17a398e2b273ec3a12b5b166520b6d56 100644 (file)
--- 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)
                        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);
 }
 
        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.
  *
 /**
  * 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 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.
  *
  *
  * 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.
  */
  * \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;
 
        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)
        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);
 }
 
        free(pb.buf);
 }
 
diff --git a/afs.h b/afs.h
index 73c466480c7319929c5a103d14c73fbfb5934c4a..d30621a7ddfcbd519cad7873065335b47bce1598 100644 (file)
--- 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);
  */
 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 {
 
 /** 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;
 _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);
 }
 
 __noreturn void afs_init(uint32_t cookie, int socket_fd);
diff --git a/aft.c b/aft.c
index fb40a7be164232cf884a0a409272e5f34dedc3b9..c724670391bcbdde581d6cfc6c45342ef1f57650 100644 (file)
--- 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)
                }
 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);
        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)
        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);
 }
 
        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;
        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)
 }
 
 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;
        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)
 }
 
 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)
        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);
 }
 
        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)
                        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);
 }
 
        free(crd.pb.buf);
 }
 
@@ -2408,7 +2408,7 @@ out:
                        para_printf(&cad.pb, "nothing copied\n");
        }
        if (cad.pb.offset)
                        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);
 }
 
        free(cad.pb.buf);
 }
 
@@ -2471,7 +2471,7 @@ static void afs_stat_callback(int fd, const struct osl_object *query)
 
        if (!buf)
                return;
 
        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)
                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);
 }
 
        free(pb.buf);
 }
 
index edf3baf51fa376708785eaa014f321eaff827aa4..8dcfa28fa6c5f77e4ae8f02cfc045ee0ec401bf6 100644 (file)
@@ -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)
                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);
 }
 
        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)
        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);
 }
 
        free(pb.buf);
 }
 
@@ -404,7 +404,7 @@ out:
        else
                afs_event(ATTRIBUTE_RENAME, &pb, NULL);
        if (pb.offset)
        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);
 }
 
        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)
        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);
 }
 
        free(raad.pb.buf);
 }
 
diff --git a/blob.c b/blob.c
index bc8986990a76793962c1759b7d882ac69ab1f5a3..5c70f04fc6ec95b197c37170d581f58b27810c98 100644 (file)
--- 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)
        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);
 }
 
        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)
 {
 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);
        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;
 }
        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";
        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)
        }
 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);
 }
 
        free(rmbd.pb.buf);
 }
 
diff --git a/mood.c b/mood.c
index c892ff5c15fcfb8abfe8a11fe0a85911f073c740..6046137d31b63bc8406182b01ef650e2eafa5f0f 100644 (file)
--- 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)
        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);
 }
 
        free(pb.buf);
 }
 
index dd4371578179031403ed04274f0a0e7f872294c5..efd27476f2199cb1dd82a3af50ee9f26aaded8af 100644 (file)
@@ -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)
        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);
 }
 
        free(pb.buf);
 }