summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hostmux/hostmux.c5
-rw-r--r--hostmux/hostmux.h10
-rw-r--r--hostmux/mux.c15
3 files changed, 22 insertions, 8 deletions
diff --git a/hostmux/hostmux.c b/hostmux/hostmux.c
index 3778613c..5296527b 100644
--- a/hostmux/hostmux.c
+++ b/hostmux/hostmux.c
@@ -45,6 +45,9 @@ static const struct argp_option options[] =
"The string to replace in the translator specification with the hostname;"
" if empty, or doesn't occur, the hostname is appended as additional"
" argument instead (default `" DEFAULT_HOST_PAT "')" },
+ { "canonicalize", 'C', 0, 0,
+ "Canonicalize hostname before passing it to TRANSLATOR, aliases will"
+ " show up as symbolic links to the canonicalized entry" },
{ 0 }
};
static const char args_doc[] = "TRANSLATOR [ARG...]";
@@ -97,6 +100,8 @@ main (int argc, char **argv)
{
case 'H':
mux.host_pat = arg; break;
+ case 'C':
+ mux.canonicalize = 1; break;
case ARGP_KEY_NO_ARGS:
argp_usage (state);
case ARGP_KEY_ARGS:
diff --git a/hostmux/hostmux.h b/hostmux/hostmux.h
index e6cfb767..4f971473 100644
--- a/hostmux/hostmux.h
+++ b/hostmux/hostmux.h
@@ -55,6 +55,9 @@ struct hostmux
argument. */
char *host_pat;
+ /* Whether we should canonicalize host names or not. */
+ boolean_t canonicalize;
+
/* Constant fields for host stat entries. */
struct stat stat_template;
@@ -69,9 +72,10 @@ struct hostmux_name
const char *name; /* Looked up name (may be a number). */
const char *canon; /* The canonical (fq) host name. */
- /* A filesystem node associated with NAME. If NAME = CANON, then this will
- refer to a node with a translator for that host, otherwise, the node
- will be a symbolic link to the canonical name. */
+ /* A filesystem node associated with NAME. If canonicalize is 0 or
+ NAME = CANON, then this will refer to a node with a translator for that
+ host, otherwise, the node will be a symbolic link to the canonical name.
+ */
struct node *node;
ino_t fileno; /* The inode number for this entry. */
diff --git a/hostmux/mux.c b/hostmux/mux.c
index 737240af..81d3961f 100644
--- a/hostmux/mux.c
+++ b/hostmux/mux.c
@@ -283,7 +283,7 @@ lookup_addrinfo (struct hostmux *mux, const char *host, struct addrinfo *he,
return ENOMEM;
nm->name = strdup (host);
- if (strcmp (host, he->ai_canonname) == 0)
+ if (!he || strcmp (host, he->ai_canonname) == 0)
nm->canon = nm->name;
else
nm->canon = strdup (he->ai_canonname);
@@ -340,12 +340,17 @@ lookup_host (struct hostmux *mux, const char *host, struct node **node)
if (was_cached)
return 0;
- h_err = getaddrinfo (host, NULL, &hints, &ai);
- if (! h_err)
+ if (mux->canonicalize)
{
- h_err = lookup_addrinfo (mux, host, ai, node);
- freeaddrinfo (ai);
+ h_err = getaddrinfo (host, NULL, &hints, &ai);
+ if (! h_err)
+ {
+ h_err = lookup_addrinfo (mux, host, ai, node);
+ freeaddrinfo (ai);
+ }
}
+ else
+ h_err = lookup_addrinfo (mux, host, NULL, node);
return h_err;
}