-fixes
[oweals/gnunet.git] / src / fs / gnunet-fs.c
index 9025b71daae8a3851b32c67c94c09cfb5e8efa20..0b28923712487f4e46ffc707cf4b0b1e127f1abc 100644 (file)
@@ -46,20 +46,6 @@ static int list_indexed_files;
 static int verbose;
 
 
-/**
- * Shutdown this process.
- *
- * @param cls unused
- * @param tc unused
- */
-static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  GNUNET_FS_stop (fs);
-  fs = NULL;
-}
-
-
 /**
  * Print indexed filenames to stdout.
  *
@@ -71,10 +57,16 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static int
 print_indexed (void *cls, const char *filename, const GNUNET_HashCode * file_id)
 {
+  if (NULL == filename)
+  {
+    GNUNET_FS_stop (fs);
+    fs = NULL;
+    return GNUNET_OK;
+  }
   if (verbose)
-    fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
+    FPRINTF (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
   else
-    fprintf (stdout, "%s\n", filename);
+    FPRINTF (stdout, "%s\n", filename);
   return GNUNET_OK;
 }
 
@@ -93,13 +85,20 @@ run (void *cls, char *const *args, const char *cfgfile,
 {
   if (list_indexed_files)
   {
-    fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+    fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE,
+                          GNUNET_FS_OPTIONS_END);
     if (NULL == fs)
     {
       ret = 1;
       return;
     }
-    GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL, &do_shutdown, NULL);
+    if (NULL == GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL))
+    {
+      ret = 2;
+      GNUNET_FS_stop (fs);
+      fs = NULL;
+      return;
+    }
   }
 }