From c2882d0223530d1f2ac84f9675f23bda11270d08 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 14 Sep 2013 13:51:27 +0000 Subject: -fixing #3034 --- src/fs/fs_file_information.c | 30 +++++++-------- src/fs/fs_publish.c | 72 +++++++++++++++++++++--------------- src/fs/gnunet-helper-fs-publish.c | 66 +++++++++++++++++++++++++-------- src/fs/test_fs_publish_persistence.c | 15 +++++--- 4 files changed, 119 insertions(+), 64 deletions(-) (limited to 'src/fs') diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c index 3e6d53af6..da4e85b78 100644 --- a/src/fs/fs_file_information.c +++ b/src/fs/fs_file_information.c @@ -37,8 +37,7 @@ * * @param s structure to get the filename for * @return NULL on error, otherwise filename that - * can be passed to "GNUNET_FS_file_information_recover" - * to read this fi-struct from disk. + * can be used to read this fi-struct from disk. */ const char * GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s) @@ -80,6 +79,7 @@ GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s, s->filename = NULL; } + /** * Create an entry for a file in a publish-structure. * @@ -89,8 +89,8 @@ GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s, * @param keywords under which keywords should this file be available * directly; can be NULL * @param meta metadata for the file - * @param do_index GNUNET_YES for index, GNUNET_NO for insertion, - * GNUNET_SYSERR for simulation + * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion, + * #GNUNET_SYSERR for simulation * @param bo block options * @return publish structure entry for the file */ @@ -215,8 +215,8 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, * @param keywords under which keywords should this file be available * directly; can be NULL * @param meta metadata for the file - * @param do_index GNUNET_YES for index, GNUNET_NO for insertion, - * GNUNET_SYSERR for simulation + * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion, + * #GNUNET_SYSERR for simulation * @param bo block options * @return publish structure entry for the file */ @@ -316,13 +316,13 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, /** * Add an entry to a directory in a publish-structure. Clients * should never modify publish structures that were passed to - * "GNUNET_FS_publish_start" already. + * #GNUNET_FS_publish_start already. * * @param dir the directory * @param ent the entry to add; the entry must not have been * added to any other directory at this point and - * must not include "dir" in its structure - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * must not include @a dir in its structure + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, @@ -344,16 +344,16 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, /** * Inspect a file or directory in a publish-structure. Clients * should never modify publish structures that were passed to - * "GNUNET_FS_publish_start" already. When called on a directory, - * this function will FIRST call "proc" with information about + * #GNUNET_FS_publish_start already. When called on a directory, + * this function will FIRST call @a proc with information about * the directory itself and then for each of the files in the * directory (but not for files in subdirectories). When called - * on a file, "proc" will be called exactly once (with information + * on a file, @a proc will be called exactly once (with information * about the specific file). * * @param dir the directory * @param proc function to call on each entry - * @param proc_cls closure for proc + * @param proc_cls closure for @a proc */ void GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, @@ -392,13 +392,13 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, /** * Destroy publish-structure. Clients should never destroy publish - * structures that were passed to "GNUNET_FS_publish_start" already. + * structures that were passed to #GNUNET_FS_publish_start already. * * @param fi structure to destroy * @param cleaner function to call on each entry in the structure * (useful to clean up client_info); can be NULL; return * values are ignored - * @param cleaner_cls closure for cleaner + * @param cleaner_cls closure for @a cleaner */ void GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 9483ec36a..c554c8bb2 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c @@ -106,8 +106,8 @@ publish_cleanup (struct GNUNET_FS_PublishContext *pc) * Function called by the datastore API with * the result from the PUT request. * - * @param cls the 'struct GNUNET_FS_PublishContext' - * @param success GNUNET_OK on success + * @param cls the `struct GNUNET_FS_PublishContext *` + * @param success #GNUNET_OK on success * @param min_expiration minimum expiration time required for content to be stored * @param msg error message (or NULL) */ @@ -200,7 +200,7 @@ signal_publish_error (struct GNUNET_FS_FileInformation *p, /** * Datastore returns from reservation cancel request. * - * @param cls the 'struct GNUNET_FS_PublishContext' + * @param cls the `struct GNUNET_FS_PublishContext *` * @param success success code (not used) * @param min_expiration minimum expiration time required for content to be stored * @param msg error message (typically NULL, not used) @@ -284,7 +284,7 @@ publish_sblock (struct GNUNET_FS_PublishContext *pc) * We've finished publishing a KBlock as part of a larger upload. * Check the result and continue the larger upload. * - * @param cls the "struct GNUNET_FS_PublishContext*" + * @param cls the `struct GNUNET_FS_PublishContext *` * of the larger upload * @param uri URI of the published blocks * @param emsg NULL on success, otherwise error message @@ -399,6 +399,7 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished with tree encoder\n"); p = pc->fi_pos; + GNUNET_FS_file_information_sync_ (p); GNUNET_FS_tree_encoder_finish (p->te, &p->chk_uri, &emsg); p->te = NULL; if (NULL != emsg) @@ -423,8 +424,7 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth (flen); p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, flen); } - GNUNET_FS_file_information_sync_ (p); - /* continue with main */ + /* continue with main */ /* continue with main */ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); pc->upload_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, @@ -444,7 +444,7 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @param depth depth of the block in the file, 0 for DBLOCK * @param type type of the block (IBLOCK or DBLOCK) * @param block the (encrypted) block - * @param block_size size of block (in bytes) + * @param block_size size of @a block (in bytes) */ static void block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset, @@ -508,7 +508,7 @@ block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset, * @param cls closure * @param offset where are we in the file * @param pt_block plaintext of the currently processed block - * @param pt_size size of pt_block + * @param pt_size size of @a pt_block * @param depth depth of the block in the tree, 0 for DBLOCK */ static void @@ -611,11 +611,12 @@ publish_content (struct GNUNET_FS_PublishContext *pc) * Process the response (or lack thereof) from * the "fs" service to our 'start index' request. * - * @param cls closure (of type "struct GNUNET_FS_PublishContext*"_) + * @param cls closure (of type `struct GNUNET_FS_PublishContext *`) * @param msg the response we got */ static void -process_index_start_response (void *cls, const struct GNUNET_MessageHeader *msg) +process_index_start_response (void *cls, + const struct GNUNET_MessageHeader *msg) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; @@ -668,7 +669,8 @@ process_index_start_response (void *cls, const struct GNUNET_MessageHeader *msg) * @param res resulting hash, NULL on error */ static void -hash_for_index_cb (void *cls, const struct GNUNET_HashCode * res) +hash_for_index_cb (void *cls, + const struct GNUNET_HashCode *res) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_FileInformation *p; @@ -773,7 +775,7 @@ hash_for_index_cb (void *cls, const struct GNUNET_HashCode * res) /** * Main function that performs the upload. * - * @param cls "struct GNUNET_FS_PublishContext" identifies the upload + * @param cls `struct GNUNET_FS_PublishContext *` identifies the upload * @param tc task context */ void @@ -799,8 +801,10 @@ GNUNET_FS_publish_main_ (void *cls, return; } /* find starting position */ - while ((p->is_directory == GNUNET_YES) && (NULL != p->data.dir.entries) && (NULL == p->emsg) - && (NULL == p->data.dir.entries->chk_uri)) + while ( (GNUNET_YES == p->is_directory) && + (NULL != p->data.dir.entries) && + (NULL == p->emsg) && + (NULL == p->data.dir.entries->chk_uri) ) { p = p->data.dir.entries; pc->fi_pos = p; @@ -809,7 +813,9 @@ GNUNET_FS_publish_main_ (void *cls, /* abort on error */ if (NULL != p->emsg) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error uploading: %s\n", p->emsg); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Error uploading: %s\n", + p->emsg); /* error with current file, abort all * related files as well! */ while (NULL != p->dir) @@ -897,7 +903,7 @@ GNUNET_FS_publish_main_ (void *cls, * Signal the FS's progress function that we are starting * an upload. * - * @param cls closure (of type "struct GNUNET_FS_PublishContext*") + * @param cls closure (of type `struct GNUNET_FS_PublishContext *`) * @param fi the entry in the publish-structure * @param length length of the file or directory * @param meta metadata for the file or directory (can be modified) @@ -905,13 +911,17 @@ GNUNET_FS_publish_main_ (void *cls, * @param bo block options * @param do_index should we index? * @param client_info pointer to client context set upon creation (can be modified) - * @return GNUNET_OK to continue (always) + * @return #GNUNET_OK to continue (always) */ static int -fip_signal_start (void *cls, struct GNUNET_FS_FileInformation *fi, - uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, - struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, - int *do_index, void **client_info) +fip_signal_start (void *cls, + struct GNUNET_FS_FileInformation *fi, + uint64_t length, + struct GNUNET_CONTAINER_MetaData *meta, + struct GNUNET_FS_Uri **uri, + struct GNUNET_FS_BlockOptions *bo, + int *do_index, + void **client_info) { struct GNUNET_FS_PublishContext *pc = cls; struct GNUNET_FS_ProgressInfo pi; @@ -1024,13 +1034,16 @@ suspend_operation (struct GNUNET_FS_FileInformation *fi, * @param bo block options * @param do_index should we index? * @param client_info pointer to client context set upon creation (can be modified) - * @return GNUNET_OK to continue (always) + * @return #GNUNET_OK to continue (always) */ static int -fip_signal_suspend (void *cls, struct GNUNET_FS_FileInformation *fi, - uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, +fip_signal_suspend (void *cls, + struct GNUNET_FS_FileInformation *fi, + uint64_t length, + struct GNUNET_CONTAINER_MetaData *meta, struct GNUNET_FS_Uri **uri, - struct GNUNET_FS_BlockOptions *bo, int *do_index, + struct GNUNET_FS_BlockOptions *bo, + int *do_index, void **client_info) { struct GNUNET_FS_PublishContext *pc = cls; @@ -1081,7 +1094,7 @@ GNUNET_FS_publish_signal_suspend_ (void *cls) * We have gotten a reply for our space reservation request. * Either fail (insufficient space) or start publishing for good. * - * @param cls the 'struct GNUNET_FS_PublishContext*' + * @param cls the `struct GNUNET_FS_PublishContext *` * @param success positive reservation ID on success * @param min_expiration minimum expiration time required for content to be stored * @param msg error message on error, otherwise NULL @@ -1097,7 +1110,8 @@ finish_reserve (void *cls, int success, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reservation complete (%d)!\n", success); if ((msg != NULL) || (success <= 0)) { - GNUNET_asprintf (&pc->fi->emsg, _("Insufficient space for publishing: %s"), + GNUNET_asprintf (&pc->fi->emsg, + _("Insufficient space for publishing: %s"), msg); signal_publish_error (pc->fi, pc, pc->fi->emsg); return; @@ -1193,7 +1207,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, * Signal the FS's progress function that we are stopping * an upload. * - * @param cls closure (of type "struct GNUNET_FS_PublishContext*") + * @param cls closure (of type `struct GNUNET_FS_PublishContext *`) * @param fi the entry in the publish-structure * @param length length of the file or directory * @param meta metadata for the file or directory (can be modified) @@ -1201,7 +1215,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, * @param bo block options (can be modified) * @param do_index should we index? * @param client_info pointer to client context set upon creation (can be modified) - * @return GNUNET_OK to continue (always) + * @return #GNUNET_OK to continue (always) */ static int fip_signal_stop (void *cls, struct GNUNET_FS_FileInformation *fi, diff --git a/src/fs/gnunet-helper-fs-publish.c b/src/fs/gnunet-helper-fs-publish.c index 7ea94998d..2aa9df0e4 100644 --- a/src/fs/gnunet-helper-fs-publish.c +++ b/src/fs/gnunet-helper-fs-publish.c @@ -87,6 +87,11 @@ struct ScanTreeNode */ static struct EXTRACTOR_PluginList *plugins; +/** + * File descriptor we use for IPC with the parent. + */ +static int output_stream; + /** * Add meta data that libextractor finds to our meta data @@ -140,11 +145,11 @@ free_tree (struct ScanTreeNode *tree) /** - * Write 'size' bytes from 'buf' into 'out'. + * Write @a size bytes from @a buf into the #output_stream. * * @param buf buffer with data to write * @param size number of bytes to write - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int write_all (const void *buf, @@ -157,7 +162,7 @@ write_all (const void *buf, total = 0; do { - wr = write (1, + wr = write (output_stream, &cbuf[total], size - total); if (wr > 0) @@ -176,8 +181,8 @@ write_all (const void *buf, * * @param message_type message type to use * @param data data to append, NULL for none - * @param data_length number of bytes in data - * @return GNUNET_SYSERR to stop scanning (the pipe was broken somehow) + * @param data_length number of bytes in @a data + * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) */ static int write_message (uint16_t message_type, @@ -187,7 +192,8 @@ write_message (uint16_t message_type, struct GNUNET_MessageHeader hdr; #if 0 - fprintf (stderr, "Helper sends %u-byte message of type %u\n", + fprintf (stderr, + "Helper sends %u-byte message of type %u\n", (unsigned int) (sizeof (struct GNUNET_MessageHeader) + data_length), (unsigned int) message_type); #endif @@ -211,8 +217,8 @@ write_message (uint16_t message_type, * * @param filename file or directory to scan * @param dst where to store the resulting share tree item; - * NULL is stored in 'dst' upon recoverable errors (GNUNET_OK is returned) - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * NULL is stored in @a dst upon recoverable errors (#GNUNET_OK is returned) + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int preprocess_file (const char *filename, @@ -241,9 +247,9 @@ struct RecursionContext * of the files in the directory to the tree. Called by the directory * scanner to initiate the scan. Does NOT yet add any metadata. * - * @param cls the 'struct RecursionContext' + * @param cls the `struct RecursionContext` * @param filename file or directory to scan - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int scan_callback (void *cls, @@ -276,8 +282,8 @@ scan_callback (void *cls, * * @param filename file or directory to scan * @param dst where to store the resulting share tree item; - * NULL is stored in 'dst' upon recoverable errors (GNUNET_OK is returned) - * @return GNUNET_OK on success, GNUNET_SYSERR on error + * NULL is stored in @a dst upon recoverable errors (#GNUNET_OK is returned) + * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int preprocess_file (const char *filename, @@ -340,7 +346,7 @@ preprocess_file (const char *filename, * Extract metadata from files. * * @param item entry we are processing - * @return GNUNET_OK on success, GNUNET_SYSERR on fatal errors + * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors */ static int extract_files (struct ScanTreeNode *item) @@ -428,6 +434,29 @@ ignore_sigpipe () fprintf (stderr, "Failed to install SIGPIPE handler: %s\n", strerror (errno)); } + + +/** + * Turn the given file descriptor in to '/dev/null'. + * + * @param fd fd to bind to /dev/null + * @param flags flags to use (O_RDONLY or O_WRONLY) + */ +static void +make_dev_zero (int fd, + int flags) +{ + int z; + + GNUNET_assert (0 == close (fd)); + z = open ("/dev/null", flags); + GNUNET_assert (-1 != z); + if (z == fd) + return; + dup2 (z, fd); + GNUNET_assert (0 == close (z)); +} + #endif @@ -441,8 +470,9 @@ ignore_sigpipe () * otherwise custom plugins to load from LE * @return 0 on success */ -int main(int argc, - char *const *argv) +int +main (int argc, + char *const *argv) { const char *filename_expanded; const char *ex; @@ -456,8 +486,14 @@ int main(int argc, /* Get utf-8-encoded arguments */ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 5; + output_stream = 1; /* stdout */ #else ignore_sigpipe (); + /* move stdout to some other FD for IPC, bind + stdout/stderr to /dev/null */ + output_stream = dup (1); + make_dev_zero (1, O_WRONLY); + make_dev_zero (2, O_WRONLY); #endif /* parse command line */ diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 1dc8c43aa..e3bbc77a1 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c @@ -93,8 +93,10 @@ restart_fs_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { rtask = GNUNET_SCHEDULER_NO_TASK; GNUNET_FS_stop (fs); - fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL, - GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); + fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", + &progress_cb, NULL, + GNUNET_FS_FLAGS_PERSISTENCE, + GNUNET_FS_OPTIONS_END); } @@ -123,7 +125,8 @@ consider_restart (int ev) static void * -progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) +progress_cb (void *cls, + const struct GNUNET_FS_ProgressInfo *event) { void *ret; @@ -138,7 +141,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us) / 1024)); - if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) + if ( (NULL != event->value.publish.cctx) && + (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) ) GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); break; case GNUNET_FS_STATUS_PUBLISH_PROGRESS: @@ -206,7 +210,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) break; case GNUNET_FS_STATUS_PUBLISH_STOPPED: consider_restart (event->status); - if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) + if ( (NULL != event->value.publish.cctx) && + (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) ) GNUNET_assert (publish == event->value.publish.pc); break; default: -- cgit v1.2.3