aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-10-22 16:59:41 +0200
committerChristian Grothoff <christian@grothoff.org>2022-10-22 16:59:41 +0200
commit16e78046530c204f2d349a13752fd8f8c30f7482 (patch)
treebd9323eac86cb99c6a79d11d9346cb07d965ff9a
parent1436e4266673df53f1a692e4c9c9a74d621b0a8e (diff)
downloadgnunet-16e78046530c204f2d349a13752fd8f8c30f7482.tar.gz
gnunet-16e78046530c204f2d349a13752fd8f8c30f7482.zip
-fix gnunet-fs shutdown
m---------contrib/sphinx0
-rw-r--r--src/fs/gnunet-fs.c90
-rw-r--r--src/include/gnunet_fs_service.h3
3 files changed, 66 insertions, 27 deletions
diff --git a/contrib/sphinx b/contrib/sphinx
Subproject c0e1c1d1cc7531130ba9de8e74520fd21c3aa57 Subproject 4e5c8c6d4a0befd55fba632b8b1bed482ea2bac
diff --git a/src/fs/gnunet-fs.c b/src/fs/gnunet-fs.c
index 70a0034a0..f9d63e101 100644
--- a/src/fs/gnunet-fs.c
+++ b/src/fs/gnunet-fs.c
@@ -36,6 +36,11 @@ static int ret;
36static struct GNUNET_FS_Handle *fs; 36static struct GNUNET_FS_Handle *fs;
37 37
38/** 38/**
39 * Handle for the index listing operation.
40 */
41static struct GNUNET_FS_GetIndexedContext *gic;
42
43/**
39 * Option -i given? 44 * Option -i given?
40 */ 45 */
41static int list_indexed_files; 46static int list_indexed_files;
@@ -54,26 +59,53 @@ static unsigned int verbose;
54 * @param file_id hash of the contents of the indexed file 59 * @param file_id hash of the contents of the indexed file
55 * @return GNUNET_OK to continue iteration 60 * @return GNUNET_OK to continue iteration
56 */ 61 */
57static int 62static enum GNUNET_GenericReturnValue
58print_indexed (void *cls, 63print_indexed (void *cls,
59 const char *filename, 64 const char *filename,
60 const struct GNUNET_HashCode *file_id) 65 const struct GNUNET_HashCode *file_id)
61{ 66{
62 if (NULL == filename) 67 if (NULL == filename)
63 { 68 {
64 GNUNET_FS_stop (fs); 69 gic = NULL;
65 fs = NULL; 70 GNUNET_SCHEDULER_shutdown ();
66 return GNUNET_OK; 71 return GNUNET_OK;
67 } 72 }
68 if (verbose) 73 if (verbose)
69 fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename); 74 fprintf (stdout,
75 "%s: %s\n",
76 GNUNET_h2s (file_id),
77 filename);
70 else 78 else
71 fprintf (stdout, "%s\n", filename); 79 fprintf (stdout,
80 "%s\n",
81 filename);
72 return GNUNET_OK; 82 return GNUNET_OK;
73} 83}
74 84
75 85
76/** 86/**
87 * Function run on shutdown.
88 *
89 * @param cls NULL
90 */
91static void
92do_shutdown (void *cls)
93{
94 (void) cls;
95 if (NULL != gic)
96 {
97 GNUNET_FS_get_indexed_files_cancel (gic);
98 gic = NULL;
99 }
100 if (NULL != fs)
101 {
102 GNUNET_FS_stop (fs);
103 fs = NULL;
104 }
105}
106
107
108/**
77 * Main function that will be run by the scheduler. 109 * Main function that will be run by the scheduler.
78 * 110 *
79 * @param cls closure 111 * @param cls closure
@@ -87,26 +119,29 @@ run (void *cls,
87 const char *cfgfile, 119 const char *cfgfile,
88 const struct GNUNET_CONFIGURATION_Handle *cfg) 120 const struct GNUNET_CONFIGURATION_Handle *cfg)
89{ 121{
90 if (list_indexed_files) 122 if (! list_indexed_files)
123 return;
124 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
125 NULL);
126 fs = GNUNET_FS_start (cfg,
127 "gnunet-fs",
128 NULL,
129 NULL,
130 GNUNET_FS_FLAGS_NONE,
131 GNUNET_FS_OPTIONS_END);
132 if (NULL == fs)
133 {
134 ret = 1;
135 return;
136 }
137 gic = GNUNET_FS_get_indexed_files (fs,
138 &print_indexed,
139 NULL);
140 if (NULL == gic)
91 { 141 {
92 fs = GNUNET_FS_start (cfg, 142 ret = 2;
93 "gnunet-fs", 143 GNUNET_SCHEDULER_shutdown ();
94 NULL, 144 return;
95 NULL,
96 GNUNET_FS_FLAGS_NONE,
97 GNUNET_FS_OPTIONS_END);
98 if (NULL == fs)
99 {
100 ret = 1;
101 return;
102 }
103 if (NULL == GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL))
104 {
105 ret = 2;
106 GNUNET_FS_stop (fs);
107 fs = NULL;
108 return;
109 }
110 } 145 }
111} 146}
112 147
@@ -119,7 +154,8 @@ run (void *cls,
119 * @return 0 ok, 1 on error 154 * @return 0 ok, 1 on error
120 */ 155 */
121int 156int
122main (int argc, char *const *argv) 157main (int argc,
158 char *const *argv)
123{ 159{
124 struct GNUNET_GETOPT_CommandLineOption options[] = { 160 struct GNUNET_GETOPT_CommandLineOption options[] = {
125 GNUNET_GETOPT_option_flag ('i', 161 GNUNET_GETOPT_option_flag ('i',
@@ -132,7 +168,9 @@ main (int argc, char *const *argv)
132 GNUNET_GETOPT_OPTION_END 168 GNUNET_GETOPT_OPTION_END
133 }; 169 };
134 170
135 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 171 if (GNUNET_OK !=
172 GNUNET_STRINGS_get_utf8_args (argc, argv,
173 &argc, &argv))
136 return 2; 174 return 2;
137 ret = (GNUNET_OK == 175 ret = (GNUNET_OK ==
138 GNUNET_PROGRAM_run (argc, 176 GNUNET_PROGRAM_run (argc,
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index 8ae826380..d9f2ee563 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -1732,7 +1732,8 @@ GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1732 * @return "filename" field of the structure (can be NULL) 1732 * @return "filename" field of the structure (can be NULL)
1733 */ 1733 */
1734const char * 1734const char *
1735GNUNET_FS_file_information_get_filename (const struct GNUNET_FS_FileInformation *s); 1735GNUNET_FS_file_information_get_filename (const struct
1736 GNUNET_FS_FileInformation *s);
1736 1737
1737 1738
1738/** 1739/**