aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-helper-fs-publish.c
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/gnunet-helper-fs-publish.c
parente5ba359af49fac05185f5ec0b4dbb47c7060167a (diff)
downloadgnunet-c2882d0223530d1f2ac84f9675f23bda11270d08.tar.gz
gnunet-c2882d0223530d1f2ac84f9675f23bda11270d08.zip
-fixing #3034
Diffstat (limited to 'src/fs/gnunet-helper-fs-publish.c')
-rw-r--r--src/fs/gnunet-helper-fs-publish.c66
1 files changed, 51 insertions, 15 deletions
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 */