Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
server/debug-flags.c: Refactor construction of name from debug flag.
Neutral refactoring.
  • Loading branch information
rwmjones committed Dec 12, 2019
1 parent 3b45db2 commit 5317291
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions server/debug-flags.c
Expand Up @@ -40,6 +40,22 @@

#include "internal.h"

/* Synthesize the name of the *_debug_* variable from the plugin name
* and flag.
*/
static char *
name_of_debug_flag (const char *name, const char *flag)
{
char *var;

if (asprintf (&var, "%s_debug_%s", name, flag) == -1) {
perror ("asprintf");
exit (EXIT_FAILURE);
}

return var; /* caller frees */
}

/* Apply all debug flags applicable to this backend. */
void
apply_debug_flags (void *dl, const char *name)
Expand All @@ -48,14 +64,8 @@ apply_debug_flags (void *dl, const char *name)

for (flag = debug_flags; flag != NULL; flag = flag->next) {
if (!flag->used && strcmp (name, flag->name) == 0) {
CLEANUP_FREE char *var = NULL;
int *sym;

/* Synthesize the name of the variable. */
if (asprintf (&var, "%s_debug_%s", name, flag->flag) == -1) {
perror ("asprintf");
exit (EXIT_FAILURE);
}
CLEANUP_FREE char *var = name_of_debug_flag (name, flag->flag);

/* Find the symbol. */
sym = dlsym (dl, var);
Expand Down

0 comments on commit 5317291

Please sign in to comment.