Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NETCONFIG override by environment variable. #304

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ntirpc/netconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#endif
#define NETPATH "NETPATH"

/* Environment variable to override the location of NETCONFIG */
#define ENV_NETCONFIG_OVERRIDE "NETCONFIG_OVERRIDE"

struct netconfig {
char *nc_netid; /* Network ID */
unsigned long nc_semantics; /* Semantics (see below) */
Expand Down
11 changes: 9 additions & 2 deletions src/getnetconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ __nc_error(void)
return (nc_addr);
}

static inline const char* getnetconfig_path(void)
{
/* Overriding netconfig path is used for unit testing */
const char *const override = getenv(ENV_NETCONFIG_OVERRIDE);
return override != NULL ? override : NETCONFIG;
}

#define nc_error (*(__nc_error()))
/*
* A call to setnetconfig() establishes a /etc/netconfig "session". A session
Expand Down Expand Up @@ -196,7 +203,7 @@ setnetconfig(void)
ni.ref++;

if (!nc_file) {
nc_file = fopen(NETCONFIG, "r");
nc_file = fopen(getnetconfig_path(), "r");
if (!nc_file) {
ni.ref--;
mutex_unlock(&nc_mtx);
Expand Down Expand Up @@ -436,7 +443,7 @@ getnetconfigent(const char *netid)
}
}

file = fopen(NETCONFIG, "r");
file = fopen(getnetconfig_path(), "r");
if (!file) {
nc_error = NC_NONETCONFIG;
mutex_unlock(&nc_mtx);
Expand Down