summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/exec.c7
-rw-r--r--lib/libnetlink.c4
-rw-r--r--lib/mnl_utils.c2
-rw-r--r--lib/rt_names.c43
-rw-r--r--lib/utils.c14
5 files changed, 48 insertions, 22 deletions
diff --git a/lib/exec.c b/lib/exec.c
index 9b1c8f4..8939375 100644
--- a/lib/exec.c
+++ b/lib/exec.c
@@ -36,8 +36,13 @@ int cmd_exec(const char *cmd, char **argv, bool do_fork,
}
}
- if (setup && setup(arg))
+ if (setup && setup(arg)) {
+ if (do_fork) {
+ /* In child, nothing to do */
+ _exit(1);
+ }
return -1;
+ }
if (execvp(cmd, argv) < 0)
fprintf(stderr, "exec of \"%s\" failed: %s\n",
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 0164822..e2b284e 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -111,6 +111,10 @@ int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
err_nlh = &err->msg;
}
+ if (tb[NLMSGERR_ATTR_MISS_TYPE])
+ fprintf(stderr, "Missing required attribute type %u\n",
+ mnl_attr_get_u32(tb[NLMSGERR_ATTR_MISS_TYPE]));
+
if (errfn)
return errfn(msg, off, err_nlh);
diff --git a/lib/mnl_utils.c b/lib/mnl_utils.c
index af5aa4f..6c8f527 100644
--- a/lib/mnl_utils.c
+++ b/lib/mnl_utils.c
@@ -193,6 +193,8 @@ int mnlu_gen_socket_open(struct mnlu_gen_socket *nlg, const char *family_name,
if (!nlg->nl)
goto err_socket_open;
+ nlg->version = version;
+
err = family_get(nlg, family_name);
if (err)
goto err_socket;
diff --git a/lib/rt_names.c b/lib/rt_names.c
index dafef3f..e967e0c 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -160,7 +160,7 @@ struct tabhash {
static void
rtnl_tabhash_readdir(const char *dirpath_base, const char *dirpath_overload,
- const struct tabhash tabhash, const int size)
+ const struct tabhash tabhash, const int size)
{
struct dirent *de;
DIR *d;
@@ -216,14 +216,15 @@ rtnl_tabhash_initialize_dir(const char *ddir, const struct tabhash tabhash, cons
}
static void
-rtnl_tab_initialize_dir(const char *ddir, char **tab, const int size) {
+rtnl_tab_initialize_dir(const char *ddir, char **tab, const int size)
+{
struct tabhash tab_data = {.type = TAB, .data.tab = tab};
rtnl_tabhash_initialize_dir(ddir, tab_data, size);
}
static void
rtnl_hash_initialize_dir(const char *ddir, struct rtnl_hash_entry **hash,
- const int size) {
+ const int size) {
struct tabhash hash_data = {.type = HASH, .data.hash = hash};
rtnl_tabhash_initialize_dir(ddir, hash_data, size);
}
@@ -236,10 +237,10 @@ static void rtnl_rtprot_initialize(void)
rtnl_rtprot_init = 1;
ret = rtnl_tab_initialize(CONF_ETC_DIR "/rt_protos",
- rtnl_rtprot_tab, 256);
+ rtnl_rtprot_tab, 256);
if (ret == -ENOENT)
rtnl_tab_initialize(CONF_USR_DIR "/rt_protos",
- rtnl_rtprot_tab, 256);
+ rtnl_rtprot_tab, 256);
rtnl_tab_initialize_dir("rt_protos.d", rtnl_rtprot_tab, 256);
}
@@ -308,12 +309,12 @@ static void rtnl_addrprot_initialize(void)
rtnl_addrprot_tab_initialized = true;
ret = rtnl_tab_initialize(CONF_ETC_DIR "/rt_addrprotos",
- rtnl_addrprot_tab,
- ARRAY_SIZE(rtnl_addrprot_tab));
+ rtnl_addrprot_tab,
+ ARRAY_SIZE(rtnl_addrprot_tab));
if (ret == -ENOENT)
ret = rtnl_tab_initialize(CONF_USR_DIR "/rt_addrprotos",
- rtnl_addrprot_tab,
- ARRAY_SIZE(rtnl_addrprot_tab));
+ rtnl_addrprot_tab,
+ ARRAY_SIZE(rtnl_addrprot_tab));
}
const char *rtnl_addrprot_n2a(__u8 id, char *buf, int len)
@@ -370,7 +371,7 @@ static void rtnl_rtscope_initialize(void)
rtnl_rtscope_init = 1;
ret = rtnl_tab_initialize(CONF_ETC_DIR "/rt_scopes",
- rtnl_rtscope_tab, 256);
+ rtnl_rtscope_tab, 256);
if (ret == -ENOENT)
rtnl_tab_initialize(CONF_USR_DIR "/rt_scopes",
rtnl_rtscope_tab, 256);
@@ -440,10 +441,10 @@ static void rtnl_rtrealm_initialize(void)
rtnl_rtrealm_init = 1;
ret = rtnl_tab_initialize(CONF_ETC_DIR "/rt_realms",
- rtnl_rtrealm_tab, 256);
+ rtnl_rtrealm_tab, 256);
if (ret == -ENOENT)
rtnl_tab_initialize(CONF_USR_DIR "/rt_realms",
- rtnl_rtrealm_tab, 256);
+ rtnl_rtrealm_tab, 256);
}
const char *rtnl_rtrealm_n2a(int id, char *buf, int len)
@@ -519,10 +520,10 @@ static void rtnl_rttable_initialize(void)
rtnl_rttable_hash[i]->id = i;
}
ret = rtnl_hash_initialize(CONF_ETC_DIR "/rt_tables",
- rtnl_rttable_hash, 256);
+ rtnl_rttable_hash, 256);
if (ret == -ENOENT)
rtnl_hash_initialize(CONF_USR_DIR "/rt_tables",
- rtnl_rttable_hash, 256);
+ rtnl_rttable_hash, 256);
rtnl_hash_initialize_dir("rt_tables.d", rtnl_rttable_hash, 256);
}
@@ -590,10 +591,10 @@ static void rtnl_rtdsfield_initialize(void)
rtnl_rtdsfield_init = 1;
ret = rtnl_tab_initialize(CONF_ETC_DIR "/rt_dsfield",
- rtnl_rtdsfield_tab, 256);
+ rtnl_rtdsfield_tab, 256);
if (ret == -ENOENT)
rtnl_tab_initialize(CONF_USR_DIR "/rt_dsfield",
- rtnl_rtdsfield_tab, 256);
+ rtnl_rtdsfield_tab, 256);
}
const char *rtnl_dsfield_n2a(int id, char *buf, int len)
@@ -674,10 +675,10 @@ static void rtnl_group_initialize(void)
rtnl_group_init = 1;
ret = rtnl_hash_initialize(CONF_ETC_DIR "/group",
- rtnl_group_hash, 256);
+ rtnl_group_hash, 256);
if (ret == -ENOENT)
rtnl_hash_initialize(CONF_USR_DIR "/group",
- rtnl_group_hash, 256);
+ rtnl_group_hash, 256);
}
int rtnl_group_a2n(int *id, const char *arg)
@@ -769,10 +770,10 @@ static void nl_proto_initialize(void)
nl_proto_init = 1;
ret = rtnl_tab_initialize(CONF_ETC_DIR "/nl_protos",
- nl_proto_tab, 256);
+ nl_proto_tab, 256);
if (ret == -ENOENT)
rtnl_tab_initialize(CONF_USR_DIR "/nl_protos",
- nl_proto_tab, 256);
+ nl_proto_tab, 256);
}
const char *nl_proto_n2a(int id, char *buf, int len)
@@ -835,7 +836,7 @@ static void protodown_reason_initialize(void)
protodown_reason_init = 1;
rtnl_tab_initialize_dir("protodown_reasons.d", protodown_reason_tab,
- PROTODOWN_REASON_NUM_BITS);
+ PROTODOWN_REASON_NUM_BITS);
}
int protodown_reason_n2a(int id, char *buf, int len)
diff --git a/lib/utils.c b/lib/utils.c
index 6c1c1a8..deb7654 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -2003,3 +2003,17 @@ int proto_a2n(unsigned short *id, const char *buf,
return 0;
}
+
+FILE *generic_proc_open(const char *env, const char *name)
+{
+ const char *p = getenv(env);
+ char store[128];
+
+ if (!p) {
+ p = getenv("PROC_ROOT") ? : "/proc";
+ snprintf(store, sizeof(store) - 1, "%s/%s", p, name);
+ p = store;
+ }
+
+ return fopen(p, "r");
+}