aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-14 13:51:27 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-14 13:51:27 +0000
commitc2882d0223530d1f2ac84f9675f23bda11270d08 (patch)
tree77c5a7973735a93e58e482d1a21ecd62bf6d08bf /src/fs
parente5ba359af49fac05185f5ec0b4dbb47c7060167a (diff)
downloadgnunet-c2882d0223530d1f2ac84f9675f23bda11270d08.tar.gz
gnunet-c2882d0223530d1f2ac84f9675f23bda11270d08.zip
-fixing #3034
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs_file_information.c30
-rw-r--r--src/fs/fs_publish.c72
-rw-r--r--src/fs/gnunet-helper-fs-publish.c66
-rw-r--r--src/fs/test_fs_publish_persistence.c15
4 files changed, 119 insertions, 64 deletions
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 @@
37 * 37 *
38 * @param s structure to get the filename for 38 * @param s structure to get the filename for
39 * @return NULL on error, otherwise filename that 39 * @return NULL on error, otherwise filename that
40 * can be passed to "GNUNET_FS_file_information_recover" 40 * can be used to read this fi-struct from disk.
41 * to read this fi-struct from disk.
42 */ 41 */
43const char * 42const char *
44GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s) 43GNUNET_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,
80 s->filename = NULL; 79 s->filename = NULL;
81} 80}
82 81
82
83/** 83/**
84 * Create an entry for a file in a publish-structure. 84 * Create an entry for a file in a publish-structure.
85 * 85 *
@@ -89,8 +89,8 @@ GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
89 * @param keywords under which keywords should this file be available 89 * @param keywords under which keywords should this file be available
90 * directly; can be NULL 90 * directly; can be NULL
91 * @param meta metadata for the file 91 * @param meta metadata for the file
92 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion, 92 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
93 * GNUNET_SYSERR for simulation 93 * #GNUNET_SYSERR for simulation
94 * @param bo block options 94 * @param bo block options
95 * @return publish structure entry for the file 95 * @return publish structure entry for the file
96 */ 96 */
@@ -215,8 +215,8 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
215 * @param keywords under which keywords should this file be available 215 * @param keywords under which keywords should this file be available
216 * directly; can be NULL 216 * directly; can be NULL
217 * @param meta metadata for the file 217 * @param meta metadata for the file
218 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion, 218 * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
219 * GNUNET_SYSERR for simulation 219 * #GNUNET_SYSERR for simulation
220 * @param bo block options 220 * @param bo block options
221 * @return publish structure entry for the file 221 * @return publish structure entry for the file
222 */ 222 */
@@ -316,13 +316,13 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
316/** 316/**
317 * Add an entry to a directory in a publish-structure. Clients 317 * Add an entry to a directory in a publish-structure. Clients
318 * should never modify publish structures that were passed to 318 * should never modify publish structures that were passed to
319 * "GNUNET_FS_publish_start" already. 319 * #GNUNET_FS_publish_start already.
320 * 320 *
321 * @param dir the directory 321 * @param dir the directory
322 * @param ent the entry to add; the entry must not have been 322 * @param ent the entry to add; the entry must not have been
323 * added to any other directory at this point and 323 * added to any other directory at this point and
324 * must not include "dir" in its structure 324 * must not include @a dir in its structure
325 * @return GNUNET_OK on success, GNUNET_SYSERR on error 325 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
326 */ 326 */
327int 327int
328GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, 328GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
@@ -344,16 +344,16 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
344/** 344/**
345 * Inspect a file or directory in a publish-structure. Clients 345 * Inspect a file or directory in a publish-structure. Clients
346 * should never modify publish structures that were passed to 346 * should never modify publish structures that were passed to
347 * "GNUNET_FS_publish_start" already. When called on a directory, 347 * #GNUNET_FS_publish_start already. When called on a directory,
348 * this function will FIRST call "proc" with information about 348 * this function will FIRST call @a proc with information about
349 * the directory itself and then for each of the files in the 349 * the directory itself and then for each of the files in the
350 * directory (but not for files in subdirectories). When called 350 * directory (but not for files in subdirectories). When called
351 * on a file, "proc" will be called exactly once (with information 351 * on a file, @a proc will be called exactly once (with information
352 * about the specific file). 352 * about the specific file).
353 * 353 *
354 * @param dir the directory 354 * @param dir the directory
355 * @param proc function to call on each entry 355 * @param proc function to call on each entry
356 * @param proc_cls closure for proc 356 * @param proc_cls closure for @a proc
357 */ 357 */
358void 358void
359GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, 359GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
@@ -392,13 +392,13 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
392 392
393/** 393/**
394 * Destroy publish-structure. Clients should never destroy publish 394 * Destroy publish-structure. Clients should never destroy publish
395 * structures that were passed to "GNUNET_FS_publish_start" already. 395 * structures that were passed to #GNUNET_FS_publish_start already.
396 * 396 *
397 * @param fi structure to destroy 397 * @param fi structure to destroy
398 * @param cleaner function to call on each entry in the structure 398 * @param cleaner function to call on each entry in the structure
399 * (useful to clean up client_info); can be NULL; return 399 * (useful to clean up client_info); can be NULL; return
400 * values are ignored 400 * values are ignored
401 * @param cleaner_cls closure for cleaner 401 * @param cleaner_cls closure for @a cleaner
402 */ 402 */
403void 403void
404GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, 404GNUNET_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)
106 * Function called by the datastore API with 106 * Function called by the datastore API with
107 * the result from the PUT request. 107 * the result from the PUT request.
108 * 108 *
109 * @param cls the 'struct GNUNET_FS_PublishContext' 109 * @param cls the `struct GNUNET_FS_PublishContext *`
110 * @param success GNUNET_OK on success 110 * @param success #GNUNET_OK on success
111 * @param min_expiration minimum expiration time required for content to be stored 111 * @param min_expiration minimum expiration time required for content to be stored
112 * @param msg error message (or NULL) 112 * @param msg error message (or NULL)
113 */ 113 */
@@ -200,7 +200,7 @@ signal_publish_error (struct GNUNET_FS_FileInformation *p,
200/** 200/**
201 * Datastore returns from reservation cancel request. 201 * Datastore returns from reservation cancel request.
202 * 202 *
203 * @param cls the 'struct GNUNET_FS_PublishContext' 203 * @param cls the `struct GNUNET_FS_PublishContext *`
204 * @param success success code (not used) 204 * @param success success code (not used)
205 * @param min_expiration minimum expiration time required for content to be stored 205 * @param min_expiration minimum expiration time required for content to be stored
206 * @param msg error message (typically NULL, not used) 206 * @param msg error message (typically NULL, not used)
@@ -284,7 +284,7 @@ publish_sblock (struct GNUNET_FS_PublishContext *pc)
284 * We've finished publishing a KBlock as part of a larger upload. 284 * We've finished publishing a KBlock as part of a larger upload.
285 * Check the result and continue the larger upload. 285 * Check the result and continue the larger upload.
286 * 286 *
287 * @param cls the "struct GNUNET_FS_PublishContext*" 287 * @param cls the `struct GNUNET_FS_PublishContext *`
288 * of the larger upload 288 * of the larger upload
289 * @param uri URI of the published blocks 289 * @param uri URI of the published blocks
290 * @param emsg NULL on success, otherwise error message 290 * @param emsg NULL on success, otherwise error message
@@ -399,6 +399,7 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
399 399
400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished with tree encoder\n"); 400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished with tree encoder\n");
401 p = pc->fi_pos; 401 p = pc->fi_pos;
402 GNUNET_FS_file_information_sync_ (p);
402 GNUNET_FS_tree_encoder_finish (p->te, &p->chk_uri, &emsg); 403 GNUNET_FS_tree_encoder_finish (p->te, &p->chk_uri, &emsg);
403 p->te = NULL; 404 p->te = NULL;
404 if (NULL != emsg) 405 if (NULL != emsg)
@@ -423,8 +424,7 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
423 pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth (flen); 424 pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth (flen);
424 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, flen); 425 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, flen);
425 } 426 }
426 GNUNET_FS_file_information_sync_ (p); 427 /* continue with main */ /* continue with main */
427 /* continue with main */
428 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task); 428 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == pc->upload_task);
429 pc->upload_task = 429 pc->upload_task =
430 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 430 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
@@ -444,7 +444,7 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
444 * @param depth depth of the block in the file, 0 for DBLOCK 444 * @param depth depth of the block in the file, 0 for DBLOCK
445 * @param type type of the block (IBLOCK or DBLOCK) 445 * @param type type of the block (IBLOCK or DBLOCK)
446 * @param block the (encrypted) block 446 * @param block the (encrypted) block
447 * @param block_size size of block (in bytes) 447 * @param block_size size of @a block (in bytes)
448 */ 448 */
449static void 449static void
450block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset, 450block_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,
508 * @param cls closure 508 * @param cls closure
509 * @param offset where are we in the file 509 * @param offset where are we in the file
510 * @param pt_block plaintext of the currently processed block 510 * @param pt_block plaintext of the currently processed block
511 * @param pt_size size of pt_block 511 * @param pt_size size of @a pt_block
512 * @param depth depth of the block in the tree, 0 for DBLOCK 512 * @param depth depth of the block in the tree, 0 for DBLOCK
513 */ 513 */
514static void 514static void
@@ -611,11 +611,12 @@ publish_content (struct GNUNET_FS_PublishContext *pc)
611 * Process the response (or lack thereof) from 611 * Process the response (or lack thereof) from
612 * the "fs" service to our 'start index' request. 612 * the "fs" service to our 'start index' request.
613 * 613 *
614 * @param cls closure (of type "struct GNUNET_FS_PublishContext*"_) 614 * @param cls closure (of type `struct GNUNET_FS_PublishContext *`)
615 * @param msg the response we got 615 * @param msg the response we got
616 */ 616 */
617static void 617static void
618process_index_start_response (void *cls, const struct GNUNET_MessageHeader *msg) 618process_index_start_response (void *cls,
619 const struct GNUNET_MessageHeader *msg)
619{ 620{
620 struct GNUNET_FS_PublishContext *pc = cls; 621 struct GNUNET_FS_PublishContext *pc = cls;
621 struct GNUNET_FS_FileInformation *p; 622 struct GNUNET_FS_FileInformation *p;
@@ -668,7 +669,8 @@ process_index_start_response (void *cls, const struct GNUNET_MessageHeader *msg)
668 * @param res resulting hash, NULL on error 669 * @param res resulting hash, NULL on error
669 */ 670 */
670static void 671static void
671hash_for_index_cb (void *cls, const struct GNUNET_HashCode * res) 672hash_for_index_cb (void *cls,
673 const struct GNUNET_HashCode *res)
672{ 674{
673 struct GNUNET_FS_PublishContext *pc = cls; 675 struct GNUNET_FS_PublishContext *pc = cls;
674 struct GNUNET_FS_FileInformation *p; 676 struct GNUNET_FS_FileInformation *p;
@@ -773,7 +775,7 @@ hash_for_index_cb (void *cls, const struct GNUNET_HashCode * res)
773/** 775/**
774 * Main function that performs the upload. 776 * Main function that performs the upload.
775 * 777 *
776 * @param cls "struct GNUNET_FS_PublishContext" identifies the upload 778 * @param cls `struct GNUNET_FS_PublishContext *` identifies the upload
777 * @param tc task context 779 * @param tc task context
778 */ 780 */
779void 781void
@@ -799,8 +801,10 @@ GNUNET_FS_publish_main_ (void *cls,
799 return; 801 return;
800 } 802 }
801 /* find starting position */ 803 /* find starting position */
802 while ((p->is_directory == GNUNET_YES) && (NULL != p->data.dir.entries) && (NULL == p->emsg) 804 while ( (GNUNET_YES == p->is_directory) &&
803 && (NULL == p->data.dir.entries->chk_uri)) 805 (NULL != p->data.dir.entries) &&
806 (NULL == p->emsg) &&
807 (NULL == p->data.dir.entries->chk_uri) )
804 { 808 {
805 p = p->data.dir.entries; 809 p = p->data.dir.entries;
806 pc->fi_pos = p; 810 pc->fi_pos = p;
@@ -809,7 +813,9 @@ GNUNET_FS_publish_main_ (void *cls,
809 /* abort on error */ 813 /* abort on error */
810 if (NULL != p->emsg) 814 if (NULL != p->emsg)
811 { 815 {
812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error uploading: %s\n", p->emsg); 816 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
817 "Error uploading: %s\n",
818 p->emsg);
813 /* error with current file, abort all 819 /* error with current file, abort all
814 * related files as well! */ 820 * related files as well! */
815 while (NULL != p->dir) 821 while (NULL != p->dir)
@@ -897,7 +903,7 @@ GNUNET_FS_publish_main_ (void *cls,
897 * Signal the FS's progress function that we are starting 903 * Signal the FS's progress function that we are starting
898 * an upload. 904 * an upload.
899 * 905 *
900 * @param cls closure (of type "struct GNUNET_FS_PublishContext*") 906 * @param cls closure (of type `struct GNUNET_FS_PublishContext *`)
901 * @param fi the entry in the publish-structure 907 * @param fi the entry in the publish-structure
902 * @param length length of the file or directory 908 * @param length length of the file or directory
903 * @param meta metadata for the file or directory (can be modified) 909 * @param meta metadata for the file or directory (can be modified)
@@ -905,13 +911,17 @@ GNUNET_FS_publish_main_ (void *cls,
905 * @param bo block options 911 * @param bo block options
906 * @param do_index should we index? 912 * @param do_index should we index?
907 * @param client_info pointer to client context set upon creation (can be modified) 913 * @param client_info pointer to client context set upon creation (can be modified)
908 * @return GNUNET_OK to continue (always) 914 * @return #GNUNET_OK to continue (always)
909 */ 915 */
910static int 916static int
911fip_signal_start (void *cls, struct GNUNET_FS_FileInformation *fi, 917fip_signal_start (void *cls,
912 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, 918 struct GNUNET_FS_FileInformation *fi,
913 struct GNUNET_FS_Uri **uri, struct GNUNET_FS_BlockOptions *bo, 919 uint64_t length,
914 int *do_index, void **client_info) 920 struct GNUNET_CONTAINER_MetaData *meta,
921 struct GNUNET_FS_Uri **uri,
922 struct GNUNET_FS_BlockOptions *bo,
923 int *do_index,
924 void **client_info)
915{ 925{
916 struct GNUNET_FS_PublishContext *pc = cls; 926 struct GNUNET_FS_PublishContext *pc = cls;
917 struct GNUNET_FS_ProgressInfo pi; 927 struct GNUNET_FS_ProgressInfo pi;
@@ -1024,13 +1034,16 @@ suspend_operation (struct GNUNET_FS_FileInformation *fi,
1024 * @param bo block options 1034 * @param bo block options
1025 * @param do_index should we index? 1035 * @param do_index should we index?
1026 * @param client_info pointer to client context set upon creation (can be modified) 1036 * @param client_info pointer to client context set upon creation (can be modified)
1027 * @return GNUNET_OK to continue (always) 1037 * @return #GNUNET_OK to continue (always)
1028 */ 1038 */
1029static int 1039static int
1030fip_signal_suspend (void *cls, struct GNUNET_FS_FileInformation *fi, 1040fip_signal_suspend (void *cls,
1031 uint64_t length, struct GNUNET_CONTAINER_MetaData *meta, 1041 struct GNUNET_FS_FileInformation *fi,
1042 uint64_t length,
1043 struct GNUNET_CONTAINER_MetaData *meta,
1032 struct GNUNET_FS_Uri **uri, 1044 struct GNUNET_FS_Uri **uri,
1033 struct GNUNET_FS_BlockOptions *bo, int *do_index, 1045 struct GNUNET_FS_BlockOptions *bo,
1046 int *do_index,
1034 void **client_info) 1047 void **client_info)
1035{ 1048{
1036 struct GNUNET_FS_PublishContext *pc = cls; 1049 struct GNUNET_FS_PublishContext *pc = cls;
@@ -1081,7 +1094,7 @@ GNUNET_FS_publish_signal_suspend_ (void *cls)
1081 * We have gotten a reply for our space reservation request. 1094 * We have gotten a reply for our space reservation request.
1082 * Either fail (insufficient space) or start publishing for good. 1095 * Either fail (insufficient space) or start publishing for good.
1083 * 1096 *
1084 * @param cls the 'struct GNUNET_FS_PublishContext*' 1097 * @param cls the `struct GNUNET_FS_PublishContext *`
1085 * @param success positive reservation ID on success 1098 * @param success positive reservation ID on success
1086 * @param min_expiration minimum expiration time required for content to be stored 1099 * @param min_expiration minimum expiration time required for content to be stored
1087 * @param msg error message on error, otherwise NULL 1100 * @param msg error message on error, otherwise NULL
@@ -1097,7 +1110,8 @@ finish_reserve (void *cls, int success,
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reservation complete (%d)!\n", success); 1110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reservation complete (%d)!\n", success);
1098 if ((msg != NULL) || (success <= 0)) 1111 if ((msg != NULL) || (success <= 0))
1099 { 1112 {
1100 GNUNET_asprintf (&pc->fi->emsg, _("Insufficient space for publishing: %s"), 1113 GNUNET_asprintf (&pc->fi->emsg,
1114 _("Insufficient space for publishing: %s"),
1101 msg); 1115 msg);
1102 signal_publish_error (pc->fi, pc, pc->fi->emsg); 1116 signal_publish_error (pc->fi, pc, pc->fi->emsg);
1103 return; 1117 return;
@@ -1193,7 +1207,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1193 * Signal the FS's progress function that we are stopping 1207 * Signal the FS's progress function that we are stopping
1194 * an upload. 1208 * an upload.
1195 * 1209 *
1196 * @param cls closure (of type "struct GNUNET_FS_PublishContext*") 1210 * @param cls closure (of type `struct GNUNET_FS_PublishContext *`)
1197 * @param fi the entry in the publish-structure 1211 * @param fi the entry in the publish-structure
1198 * @param length length of the file or directory 1212 * @param length length of the file or directory
1199 * @param meta metadata for the file or directory (can be modified) 1213 * @param meta metadata for the file or directory (can be modified)
@@ -1201,7 +1215,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1201 * @param bo block options (can be modified) 1215 * @param bo block options (can be modified)
1202 * @param do_index should we index? 1216 * @param do_index should we index?
1203 * @param client_info pointer to client context set upon creation (can be modified) 1217 * @param client_info pointer to client context set upon creation (can be modified)
1204 * @return GNUNET_OK to continue (always) 1218 * @return #GNUNET_OK to continue (always)
1205 */ 1219 */
1206static int 1220static int
1207fip_signal_stop (void *cls, struct GNUNET_FS_FileInformation *fi, 1221fip_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
87 */ 87 */
88static struct EXTRACTOR_PluginList *plugins; 88static struct EXTRACTOR_PluginList *plugins;
89 89
90/**
91 * File descriptor we use for IPC with the parent.
92 */
93static int output_stream;
94
90 95
91/** 96/**
92 * Add meta data that libextractor finds to our meta data 97 * Add meta data that libextractor finds to our meta data
@@ -140,11 +145,11 @@ free_tree (struct ScanTreeNode *tree)
140 145
141 146
142/** 147/**
143 * Write 'size' bytes from 'buf' into 'out'. 148 * Write @a size bytes from @a buf into the #output_stream.
144 * 149 *
145 * @param buf buffer with data to write 150 * @param buf buffer with data to write
146 * @param size number of bytes to write 151 * @param size number of bytes to write
147 * @return GNUNET_OK on success, GNUNET_SYSERR on error 152 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
148 */ 153 */
149static int 154static int
150write_all (const void *buf, 155write_all (const void *buf,
@@ -157,7 +162,7 @@ write_all (const void *buf,
157 total = 0; 162 total = 0;
158 do 163 do
159 { 164 {
160 wr = write (1, 165 wr = write (output_stream,
161 &cbuf[total], 166 &cbuf[total],
162 size - total); 167 size - total);
163 if (wr > 0) 168 if (wr > 0)
@@ -176,8 +181,8 @@ write_all (const void *buf,
176 * 181 *
177 * @param message_type message type to use 182 * @param message_type message type to use
178 * @param data data to append, NULL for none 183 * @param data data to append, NULL for none
179 * @param data_length number of bytes in data 184 * @param data_length number of bytes in @a data
180 * @return GNUNET_SYSERR to stop scanning (the pipe was broken somehow) 185 * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow)
181 */ 186 */
182static int 187static int
183write_message (uint16_t message_type, 188write_message (uint16_t message_type,
@@ -187,7 +192,8 @@ write_message (uint16_t message_type,
187 struct GNUNET_MessageHeader hdr; 192 struct GNUNET_MessageHeader hdr;
188 193
189#if 0 194#if 0
190 fprintf (stderr, "Helper sends %u-byte message of type %u\n", 195 fprintf (stderr,
196 "Helper sends %u-byte message of type %u\n",
191 (unsigned int) (sizeof (struct GNUNET_MessageHeader) + data_length), 197 (unsigned int) (sizeof (struct GNUNET_MessageHeader) + data_length),
192 (unsigned int) message_type); 198 (unsigned int) message_type);
193#endif 199#endif
@@ -211,8 +217,8 @@ write_message (uint16_t message_type,
211 * 217 *
212 * @param filename file or directory to scan 218 * @param filename file or directory to scan
213 * @param dst where to store the resulting share tree item; 219 * @param dst where to store the resulting share tree item;
214 * NULL is stored in 'dst' upon recoverable errors (GNUNET_OK is returned) 220 * NULL is stored in @a dst upon recoverable errors (#GNUNET_OK is returned)
215 * @return GNUNET_OK on success, GNUNET_SYSERR on error 221 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
216 */ 222 */
217static int 223static int
218preprocess_file (const char *filename, 224preprocess_file (const char *filename,
@@ -241,9 +247,9 @@ struct RecursionContext
241 * of the files in the directory to the tree. Called by the directory 247 * of the files in the directory to the tree. Called by the directory
242 * scanner to initiate the scan. Does NOT yet add any metadata. 248 * scanner to initiate the scan. Does NOT yet add any metadata.
243 * 249 *
244 * @param cls the 'struct RecursionContext' 250 * @param cls the `struct RecursionContext`
245 * @param filename file or directory to scan 251 * @param filename file or directory to scan
246 * @return GNUNET_OK on success, GNUNET_SYSERR on error 252 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
247 */ 253 */
248static int 254static int
249scan_callback (void *cls, 255scan_callback (void *cls,
@@ -276,8 +282,8 @@ scan_callback (void *cls,
276 * 282 *
277 * @param filename file or directory to scan 283 * @param filename file or directory to scan
278 * @param dst where to store the resulting share tree item; 284 * @param dst where to store the resulting share tree item;
279 * NULL is stored in 'dst' upon recoverable errors (GNUNET_OK is returned) 285 * NULL is stored in @a dst upon recoverable errors (#GNUNET_OK is returned)
280 * @return GNUNET_OK on success, GNUNET_SYSERR on error 286 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
281 */ 287 */
282static int 288static int
283preprocess_file (const char *filename, 289preprocess_file (const char *filename,
@@ -340,7 +346,7 @@ preprocess_file (const char *filename,
340 * Extract metadata from files. 346 * Extract metadata from files.
341 * 347 *
342 * @param item entry we are processing 348 * @param item entry we are processing
343 * @return GNUNET_OK on success, GNUNET_SYSERR on fatal errors 349 * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors
344 */ 350 */
345static int 351static int
346extract_files (struct ScanTreeNode *item) 352extract_files (struct ScanTreeNode *item)
@@ -428,6 +434,29 @@ ignore_sigpipe ()
428 fprintf (stderr, 434 fprintf (stderr,
429 "Failed to install SIGPIPE handler: %s\n", strerror (errno)); 435 "Failed to install SIGPIPE handler: %s\n", strerror (errno));
430} 436}
437
438
439/**
440 * Turn the given file descriptor in to '/dev/null'.
441 *
442 * @param fd fd to bind to /dev/null
443 * @param flags flags to use (O_RDONLY or O_WRONLY)
444 */
445static void
446make_dev_zero (int fd,
447 int flags)
448{
449 int z;
450
451 GNUNET_assert (0 == close (fd));
452 z = open ("/dev/null", flags);
453 GNUNET_assert (-1 != z);
454 if (z == fd)
455 return;
456 dup2 (z, fd);
457 GNUNET_assert (0 == close (z));
458}
459
431#endif 460#endif
432 461
433 462
@@ -441,8 +470,9 @@ ignore_sigpipe ()
441 * otherwise custom plugins to load from LE 470 * otherwise custom plugins to load from LE
442 * @return 0 on success 471 * @return 0 on success
443 */ 472 */
444int main(int argc, 473int
445 char *const *argv) 474main (int argc,
475 char *const *argv)
446{ 476{
447 const char *filename_expanded; 477 const char *filename_expanded;
448 const char *ex; 478 const char *ex;
@@ -456,8 +486,14 @@ int main(int argc,
456 /* Get utf-8-encoded arguments */ 486 /* Get utf-8-encoded arguments */
457 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 487 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
458 return 5; 488 return 5;
489 output_stream = 1; /* stdout */
459#else 490#else
460 ignore_sigpipe (); 491 ignore_sigpipe ();
492 /* move stdout to some other FD for IPC, bind
493 stdout/stderr to /dev/null */
494 output_stream = dup (1);
495 make_dev_zero (1, O_WRONLY);
496 make_dev_zero (2, O_WRONLY);
461#endif 497#endif
462 498
463 /* parse command line */ 499 /* 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)
93{ 93{
94 rtask = GNUNET_SCHEDULER_NO_TASK; 94 rtask = GNUNET_SCHEDULER_NO_TASK;
95 GNUNET_FS_stop (fs); 95 GNUNET_FS_stop (fs);
96 fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence", &progress_cb, NULL, 96 fs = GNUNET_FS_start (cfg, "test-fs-publish-persistence",
97 GNUNET_FS_FLAGS_PERSISTENCE, GNUNET_FS_OPTIONS_END); 97 &progress_cb, NULL,
98 GNUNET_FS_FLAGS_PERSISTENCE,
99 GNUNET_FS_OPTIONS_END);
98} 100}
99 101
100 102
@@ -123,7 +125,8 @@ consider_restart (int ev)
123 125
124 126
125static void * 127static void *
126progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 128progress_cb (void *cls,
129 const struct GNUNET_FS_ProgressInfo *event)
127{ 130{
128 void *ret; 131 void *ret;
129 132
@@ -138,7 +141,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
138 (1 + 141 (1 +
139 GNUNET_TIME_absolute_get_duration 142 GNUNET_TIME_absolute_get_duration
140 (start).rel_value_us) / 1024)); 143 (start).rel_value_us) / 1024));
141 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) 144 if ( (NULL != event->value.publish.cctx) &&
145 (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) )
142 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 146 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL);
143 break; 147 break;
144 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 148 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
@@ -206,7 +210,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event)
206 break; 210 break;
207 case GNUNET_FS_STATUS_PUBLISH_STOPPED: 211 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
208 consider_restart (event->status); 212 consider_restart (event->status);
209 if (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) 213 if ( (NULL != event->value.publish.cctx) &&
214 (0 == strcmp ("publish-context-dir", event->value.publish.cctx)) )
210 GNUNET_assert (publish == event->value.publish.pc); 215 GNUNET_assert (publish == event->value.publish.pc);
211 break; 216 break;
212 default: 217 default: