summaryrefslogtreecommitdiff
path: root/libfshelp
diff options
context:
space:
mode:
authorJustus Winter <justus@gnupg.org>2016-10-05 15:38:58 +0200
committerJustus Winter <justus@gnupg.org>2017-09-12 10:41:35 +0200
commit5fef1b7f22ec0ee3730b80bbf972dbf9a8995091 (patch)
tree29890aef362b5a8ebffb4721a1967b818a22a3af /libfshelp
parent116552c075abf1d22057a608fee9d27684bcbbe5 (diff)
libfshelp: Add function to map over all active translators.
* libdiskfs/file-syncfs.c (diskfs_S_file_syncfs): Use the new function. * libdiskfs/fsys-options.c (diskfs_S_fsys_set_options): Likewise. * libdiskfs/fsys-syncfs.c (diskfs_S_fsys_syncfs): Likewise. * libdiskfs/shutdown.c (diskfs_shutdown): Likewise. * libfshelp/fshelp.h (fshelp_map_active_translators): New declaration. * libfshelp/translator-list.c (fshelp_map_active_translators): New function. * libnetfs/file-syncfs.c (netfs_S_file_syncfs): Use the new function. * libnetfs/fsys-set-options.c (netfs_S_fsys_set_options): Likewise. * libnetfs/fsys-syncfs.c (netfs_S_fsys_syncfs): Likewise. * libnetfs/shutdown.c (netfs_shutdown): Likewise.
Diffstat (limited to 'libfshelp')
-rw-r--r--libfshelp/fshelp.h10
-rw-r--r--libfshelp/translator-list.c26
2 files changed, 36 insertions, 0 deletions
diff --git a/libfshelp/fshelp.h b/libfshelp/fshelp.h
index ecd9335d..d1dd49c4 100644
--- a/libfshelp/fshelp.h
+++ b/libfshelp/fshelp.h
@@ -71,6 +71,16 @@ fshelp_get_active_translators (char **translators,
fshelp_filter filter,
const char *prefix);
+/* Call FUN for each active translator. If FUN returns non-zero, the
+ iteration immediately stops, and returns that value. FUN is called
+ with COOKIE, the name of the translator, and the translators
+ control port. */
+error_t
+fshelp_map_active_translators (error_t (*fun)(void *cookie,
+ const char *name,
+ mach_port_t control),
+ void *cookie);
+
/* Passive translator linkage */
/* These routines are self-contained and start passive translators,
diff --git a/libfshelp/translator-list.c b/libfshelp/translator-list.c
index b8fe3f94..c64e1747 100644
--- a/libfshelp/translator-list.c
+++ b/libfshelp/translator-list.c
@@ -229,3 +229,29 @@ fshelp_get_active_translators (char **translators,
pthread_mutex_unlock (&translator_ihash_lock);
return err;
}
+
+/* Call FUN for each active translator. If FUN returns non-zero, the
+ iteration immediately stops, and returns that value. FUN is called
+ with COOKIE, the name of the translator, and the translators
+ control port. */
+error_t
+fshelp_map_active_translators (error_t (*fun)(void *cookie,
+ const char *name,
+ mach_port_t control),
+ void *cookie)
+{
+ error_t err = 0;
+ pthread_mutex_lock (&translator_ihash_lock);
+
+ HURD_IHASH_ITERATE (&translator_ihash, value)
+ {
+ struct translator *t = value;
+
+ err = fun (cookie, t->name, t->active);
+ if (err)
+ break;
+ }
+
+ pthread_mutex_unlock (&translator_ihash_lock);
+ return err;
+}