* [PATCH iproute2 0/2] lib names: Refactoring and cleanups
@ 2014-12-06 2:05 Vadim Kochan
2014-12-06 2:05 ` [PATCH iproute2 1/2] lib names: Use CONFDIR for specify 'group' file path Vadim Kochan
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Vadim Kochan @ 2014-12-06 2:05 UTC (permalink / raw)
To: netdev; +Cc: Vadim Kochan
Some cleanups and refactoring in lib/rt_names.c:
#1 Replaced using of /etc/iproute2 path by CONFDIR define
when initializing tables of group names.
#2 Added helper to have one func for parsing id and names from
db files.
Vadim Kochan (2):
lib names: Use CONFDIR for specify 'group' file path
lib names: Add helper func for parse id and name from file
lib/rt_names.c | 70 +++++++++++++++++++++++++++++++++-------------------------
1 file changed, 40 insertions(+), 30 deletions(-)
--
2.1.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH iproute2 1/2] lib names: Use CONFDIR for specify 'group' file path
2014-12-06 2:05 [PATCH iproute2 0/2] lib names: Refactoring and cleanups Vadim Kochan
@ 2014-12-06 2:05 ` Vadim Kochan
2014-12-06 2:05 ` [PATCH iproute2 2/2] lib names: Add helper func for parse id and name from file Vadim Kochan
2014-12-10 4:38 ` [PATCH iproute2 0/2] lib names: Refactoring and cleanups Stephen Hemminger
2 siblings, 0 replies; 6+ messages in thread
From: Vadim Kochan @ 2014-12-06 2:05 UTC (permalink / raw)
To: netdev; +Cc: Vadim Kochan
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
lib/rt_names.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/rt_names.c b/lib/rt_names.c
index 369e0f4..e6a1e01 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -469,7 +469,7 @@ static int rtnl_group_init;
static void rtnl_group_initialize(void)
{
rtnl_group_init = 1;
- rtnl_hash_initialize("/etc/iproute2/group",
+ rtnl_hash_initialize(CONFDIR "/group",
rtnl_group_hash, 256);
}
--
2.1.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH iproute2 2/2] lib names: Add helper func for parse id and name from file
2014-12-06 2:05 [PATCH iproute2 0/2] lib names: Refactoring and cleanups Vadim Kochan
2014-12-06 2:05 ` [PATCH iproute2 1/2] lib names: Use CONFDIR for specify 'group' file path Vadim Kochan
@ 2014-12-06 2:05 ` Vadim Kochan
2014-12-10 4:38 ` [PATCH iproute2 0/2] lib names: Refactoring and cleanups Stephen Hemminger
2 siblings, 0 replies; 6+ messages in thread
From: Vadim Kochan @ 2014-12-06 2:05 UTC (permalink / raw)
To: netdev; +Cc: Vadim Kochan
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
lib/rt_names.c | 68 +++++++++++++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 29 deletions(-)
diff --git a/lib/rt_names.c b/lib/rt_names.c
index e6a1e01..2f14723 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -27,43 +27,62 @@
#define CONFDIR "/etc/iproute2"
#endif
+#define NAME_MAX_LEN 512
+
struct rtnl_hash_entry {
struct rtnl_hash_entry *next;
const char * name;
unsigned int id;
};
+static int fread_id_name(FILE *fp, int *id, char *namebuf)
+{
+ char buf[NAME_MAX_LEN];
+ while (fgets(buf, sizeof(buf), fp)) {
+ char *p = buf;
+
+ while (*p == ' ' || *p == '\t')
+ p++;
+
+ if (*p == '#' || *p == '\n' || *p == 0)
+ continue;
+
+ if (sscanf(p, "0x%x %s\n", id, namebuf) != 2 &&
+ sscanf(p, "0x%x %s #", id, namebuf) != 2 &&
+ sscanf(p, "%d %s\n", id, namebuf) != 2 &&
+ sscanf(p, "%d %s #", id, namebuf) != 2) {
+ strcpy(namebuf, p);
+ return -1;
+ }
+ return 1;
+ }
+ return 0;
+}
+
static void
rtnl_hash_initialize(const char *file, struct rtnl_hash_entry **hash, int size)
{
struct rtnl_hash_entry *entry;
- char buf[512];
FILE *fp;
+ int id;
+ char namebuf[NAME_MAX_LEN] = {0};
+ int ret;
fp = fopen(file, "r");
if (!fp)
return;
- while (fgets(buf, sizeof(buf), fp)) {
- char *p = buf;
- int id;
- char namebuf[512];
- while (*p == ' ' || *p == '\t')
- p++;
- if (*p == '#' || *p == '\n' || *p == 0)
- continue;
- if (sscanf(p, "0x%x %s\n", &id, namebuf) != 2 &&
- sscanf(p, "0x%x %s #", &id, namebuf) != 2 &&
- sscanf(p, "%d %s\n", &id, namebuf) != 2 &&
- sscanf(p, "%d %s #", &id, namebuf) != 2) {
+ while ((ret = fread_id_name(fp, &id, &namebuf[0]))) {
+ if (ret == -1) {
fprintf(stderr, "Database %s is corrupted at %s\n",
- file, p);
+ file, namebuf);
fclose(fp);
return;
}
if (id<0)
continue;
+
entry = malloc(sizeof(*entry));
entry->id = id;
entry->name = strdup(namebuf);
@@ -75,31 +94,22 @@ rtnl_hash_initialize(const char *file, struct rtnl_hash_entry **hash, int size)
static void rtnl_tab_initialize(const char *file, char **tab, int size)
{
- char buf[512];
FILE *fp;
+ int id;
+ char namebuf[NAME_MAX_LEN] = {0};
+ int ret;
fp = fopen(file, "r");
if (!fp)
return;
- while (fgets(buf, sizeof(buf), fp)) {
- char *p = buf;
- int id;
- char namebuf[512];
- while (*p == ' ' || *p == '\t')
- p++;
- if (*p == '#' || *p == '\n' || *p == 0)
- continue;
- if (sscanf(p, "0x%x %s\n", &id, namebuf) != 2 &&
- sscanf(p, "0x%x %s #", &id, namebuf) != 2 &&
- sscanf(p, "%d %s\n", &id, namebuf) != 2 &&
- sscanf(p, "%d %s #", &id, namebuf) != 2) {
+ while ((ret = fread_id_name(fp, &id, &namebuf[0]))) {
+ if (ret == -1) {
fprintf(stderr, "Database %s is corrupted at %s\n",
- file, p);
+ file, namebuf);
fclose(fp);
return;
}
-
if (id<0 || id>size)
continue;
--
2.1.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH iproute2 0/2] lib names: Refactoring and cleanups
2014-12-06 2:05 [PATCH iproute2 0/2] lib names: Refactoring and cleanups Vadim Kochan
2014-12-06 2:05 ` [PATCH iproute2 1/2] lib names: Use CONFDIR for specify 'group' file path Vadim Kochan
2014-12-06 2:05 ` [PATCH iproute2 2/2] lib names: Add helper func for parse id and name from file Vadim Kochan
@ 2014-12-10 4:38 ` Stephen Hemminger
2014-12-10 15:10 ` vadim4j
2 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2014-12-10 4:38 UTC (permalink / raw)
To: Vadim Kochan; +Cc: netdev
On Sat, 6 Dec 2014 04:05:10 +0200
Vadim Kochan <vadim4j@gmail.com> wrote:
> Some cleanups and refactoring in lib/rt_names.c:
>
> #1 Replaced using of /etc/iproute2 path by CONFDIR define
> when initializing tables of group names.
>
> #2 Added helper to have one func for parsing id and names from
> db files.
>
> Vadim Kochan (2):
> lib names: Use CONFDIR for specify 'group' file path
> lib names: Add helper func for parse id and name from file
>
> lib/rt_names.c | 70 +++++++++++++++++++++++++++++++++-------------------------
> 1 file changed, 40 insertions(+), 30 deletions(-)
>
Both applied
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH iproute2 0/2] lib names: Refactoring and cleanups
2014-12-10 4:38 ` [PATCH iproute2 0/2] lib names: Refactoring and cleanups Stephen Hemminger
@ 2014-12-10 15:10 ` vadim4j
2014-12-10 23:46 ` Stephen Hemminger
0 siblings, 1 reply; 6+ messages in thread
From: vadim4j @ 2014-12-10 15:10 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Vadim Kochan, netdev
On Tue, Dec 09, 2014 at 08:38:56PM -0800, Stephen Hemminger wrote:
> On Sat, 6 Dec 2014 04:05:10 +0200
> Vadim Kochan <vadim4j@gmail.com> wrote:
>
> > Some cleanups and refactoring in lib/rt_names.c:
> >
> > #1 Replaced using of /etc/iproute2 path by CONFDIR define
> > when initializing tables of group names.
> >
> > #2 Added helper to have one func for parsing id and names from
> > db files.
> >
> > Vadim Kochan (2):
> > lib names: Use CONFDIR for specify 'group' file path
> > lib names: Add helper func for parse id and name from file
> >
> > lib/rt_names.c | 70 +++++++++++++++++++++++++++++++++-------------------------
> > 1 file changed, 40 insertions(+), 30 deletions(-)
> >
>
> Both applied
Hi Stephen,
I see a warning (after 'make clean && make') about using 'const' in lib/rt_names.c:
static const char * rtnl_rtscope_tab[256] = {
"global",
};
which came with PATCH with a subject:
"lib names: Add helper func for parse id and name from file" (f00073e8b)
but in the PATCH version which was sent by me in email I did not see this.
Why it was needed ?
Regards,
Vadim
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH iproute2 0/2] lib names: Refactoring and cleanups
2014-12-10 15:10 ` vadim4j
@ 2014-12-10 23:46 ` Stephen Hemminger
0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2014-12-10 23:46 UTC (permalink / raw)
To: vadim4j; +Cc: netdev
On Wed, 10 Dec 2014 17:10:29 +0200
vadim4j@gmail.com wrote:
> On Tue, Dec 09, 2014 at 08:38:56PM -0800, Stephen Hemminger wrote:
> > On Sat, 6 Dec 2014 04:05:10 +0200
> > Vadim Kochan <vadim4j@gmail.com> wrote:
> >
> > > Some cleanups and refactoring in lib/rt_names.c:
> > >
> > > #1 Replaced using of /etc/iproute2 path by CONFDIR define
> > > when initializing tables of group names.
> > >
> > > #2 Added helper to have one func for parsing id and names from
> > > db files.
> > >
> > > Vadim Kochan (2):
> > > lib names: Use CONFDIR for specify 'group' file path
> > > lib names: Add helper func for parse id and name from file
> > >
> > > lib/rt_names.c | 70 +++++++++++++++++++++++++++++++++-------------------------
> > > 1 file changed, 40 insertions(+), 30 deletions(-)
> > >
> >
> > Both applied
>
> Hi Stephen,
>
> I see a warning (after 'make clean && make') about using 'const' in lib/rt_names.c:
>
> static const char * rtnl_rtscope_tab[256] = {
> "global",
> };
>
> which came with PATCH with a subject:
>
> "lib names: Add helper func for parse id and name from file" (f00073e8b)
>
> but in the PATCH version which was sent by me in email I did not see this.
>
> Why it was needed ?
>
> Regards,
> Vadim
My gaff. Fixed but not pushed, holding of until include snafu is fixed
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-12-10 23:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-06 2:05 [PATCH iproute2 0/2] lib names: Refactoring and cleanups Vadim Kochan
2014-12-06 2:05 ` [PATCH iproute2 1/2] lib names: Use CONFDIR for specify 'group' file path Vadim Kochan
2014-12-06 2:05 ` [PATCH iproute2 2/2] lib names: Add helper func for parse id and name from file Vadim Kochan
2014-12-10 4:38 ` [PATCH iproute2 0/2] lib names: Refactoring and cleanups Stephen Hemminger
2014-12-10 15:10 ` vadim4j
2014-12-10 23:46 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox