<div class="gmail_quote">That is perfect!</div><div class="gmail_quote">Many thanks.</div><div class="gmail_quote"><br></div><div class="gmail_quote">2011/3/24 Thomas Graf <span dir="ltr"><<a href="mailto:tgraf@infradead.org">tgraf@infradead.org</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">On Thu, Mar 24, 2011 at 06:40:54PM +0100, nicolas sitbon wrote:<br>
> Le jeudi 24 mars 2011, Thomas Graf <<a href="mailto:tgraf@infradead.org">tgraf@infradead.org</a>> a écrit :<br>
> > On Thu, Mar 24, 2011 at 05:02:11PM +0100, Sitbon Nicolas wrote:<br>
> >> I'm currently looking for potential issues for migrating my<br>
> >> application from libnl 2.0 to the newest 3.0.<br>
> >><br>
> >> It seems libnl try to read the file /etc/libnl/classid, /etc/libnl<br>
> >> comes from SYSCONFDIR (lib/route/classid.c:313) which is a compile<br>
> >> time constant. My problem is that I don't know where my clients will<br>
> >> install my application (libnl is shipped with it and it's a closed<br>
> >> source application) so I can't configure (--sysconfdir) the path at<br>
> >> compile time. Do you think it might be possible to add a way to<br>
> >> modify the path to classid at runtime (environment variable)?<br>
> ><br>
> > I guess adding support for recognizing an environment variable<br>
> > NLSYSCONFDIR would solve your problem?<br>
<br>
</div></div>commit f523f297f7fed8b64fe4c2a6e3791d31b2d2448b<br>
Author: Thomas Graf <<a href="mailto:tgraf@suug.ch">tgraf@suug.ch</a>><br>
Date: Thu Mar 24 21:14:52 2011 +0100<br>
<br>
Allow NLSYSCONFDIR environment variable to overwrite built-in sysconfdir<br>
<br>
diff --git a/include/netlink-local.h b/include/netlink-local.h<br>
index 32e8302..9acc0e4 100644<br>
--- a/include/netlink-local.h<br>
+++ b/include/netlink-local.h<br>
@@ -186,4 +186,16 @@ static inline int wait_for_ack(struct nl_sock *sk)<br>
return nl_wait_for_ack(sk);<br>
}<br>
<br>
+static inline int build_sysconf_path(char **strp, const char *filename)<br>
+{<br>
+ char *sysconfdir;<br>
+<br>
+ sysconfdir = getenv("NLSYSCONFDIR");<br>
+<br>
+ if (!sysconfdir)<br>
+ sysconfdir = SYSCONFDIR;<br>
+<br>
+ return asprintf(strp, "%s/%s", sysconfdir, filename);<br>
+}<br>
+<br>
#endif<br>
diff --git a/lib/route/classid.c b/lib/route/classid.c<br>
index 35cafe6..6af0ee3 100644<br>
--- a/lib/route/classid.c<br>
+++ b/lib/route/classid.c<br>
@@ -310,7 +310,8 @@ int rtnl_tc_read_classid_file(void)<br>
FILE *fd;<br>
int err;<br>
<br>
- asprintf(&path, "%s/classid", SYSCONFDIR);<br>
+ if (build_sysconf_path(&path, "classid") < 0)<br>
+ return -NLE_NOMEM;<br>
<br>
/* if stat fails, just (re-)read the file */<br>
if (stat(path, &st) == 0) {<br>
@@ -392,7 +393,7 @@ int rtnl_classid_generate(const char *name, uint32_t *result, uint32_t parent)<br>
<br>
NL_DBG(2, "Generated new classid %#x\n", classid);<br>
<br>
- if (asprintf(&path, "%s/classid", SYSCONFDIR) < 0)<br>
+ if (build_sysconf_path(&path, "classid") < 0)<br>
return -NLE_NOMEM;<br>
<br>
if (!(fd = fopen(path, "a"))) {<br>
diff --git a/lib/route/pktloc.c b/lib/route/pktloc.c<br>
index 4d7d9dd..b677ab5 100644<br>
--- a/lib/route/pktloc.c<br>
+++ b/lib/route/pktloc.c<br>
@@ -94,7 +94,8 @@ static int read_pktlocs(void)<br>
int i, err;<br>
FILE *fd;<br>
<br>
- asprintf(&path, "%s/pktloc", SYSCONFDIR);<br>
+ if (build_sysconf_path(&path, "pktloc") < 0)<br>
+ return -NLE_NOMEM;<br>
<br>
/* if stat fails, just try to read the file */<br>
if (stat(path, &st) == 0) {<br>
diff --git a/src/Makefile.am b/src/Makefile.am<br>
index 64d1cce..e196b58 100644<br>
--- a/src/Makefile.am<br>
+++ b/src/Makefile.am<br>
@@ -2,7 +2,7 @@<br>
<br>
SUBDIRS = lib<br>
<br>
-AM_CPPFLAGS = -Wall -I${top_srcdir}/include -I${top_builddir}/include -D_GNU_SOURCE<br>
+AM_CPPFLAGS = -Wall -I${top_srcdir}/include -I${top_builddir}/include -D_GNU_SOURCE -DSYSCONFDIR<br>
AM_LDFLAGS = -L${top_builddir}/lib -L${top_builddir}/src/lib -lnl-cli -lnl -lnl-nf -lnl-genl -lnl<br>
<br>
sbin_PROGRAMS = \<br>
<br>
</blockquote></div><br>