Skip to contentSkip to conversation

tc class names: Ignore if default file does not exist

PATCH Superseded Vadim Kochan 2 participants 4 messages Mar 17, 2015 – Mar 24, 2015

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover tc class names: Ignore if default file does not exist

1) Split lib/names.c:db_names_alloc to 2 funcs for allocate and load names from file. Also added checking for malloc failing.

2) Ignore if default class names file does not exist if '-nm' option was specified, so it will be possible to create alias:

alias tc='tc -nm'

Changed default class name file cls_names -> tc_cls.

v2:
Get rid of pointless 'ret' initialization
in tc/tc_util.c - noticed by Sergei Shtylyov <[email protected]>

Vadim Kochan (2):
lib names: Split to db_names_alloc and db_names_load tc class: Ignore if default class name file does not exist

 include/names.h |  3 ++-
 lib/names.c     | 59 +++++++++++++++++++++++++++++++++++++++++----------------
 tc/tc_util.c    | 19 +++++++++++++++----
 3 files changed, 60 insertions(+), 21 deletions(-)
Signature · 1 line
2.3.1
#1 lore raw

PATCH v2 1/2 lib names: Split to db_names_alloc and db_names_load

From: Vadim Kochan <[email protected]>

Also added checking for malloc failing

---
 include/names.h |  3 ++-
 lib/names.c     | 59 +++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 45 insertions(+), 17 deletions(-)
include/names.h +2 -1
index 4123d0b..6fed581 100644
@@ -16,7 +16,8 @@ struct db_names {
 	int max;
 };
 
-struct db_names *db_names_alloc(const char *path);
+struct db_names *db_names_alloc(void);
+int db_names_load(struct db_names *db, const char *path);
 void db_names_free(struct db_names *db);
 
 char *id_to_name(struct db_names *db, int id, char *name);
lib/names.c +43 -16

119 lines not on this page · raw message

Signature · 1 line
2.3.1
#2 lore raw

Re: [PATCH iproute2 v2 1/2] lib names: Split to db_names_alloc and db_names_load

Quoted 5 lines · On Tue, 17 Mar 2015 22:15:41 +0200 Vadim Kochan <[email protected]> wrote:

From: Vadim Kochan <[email protected]>

Also added checking for malloc failing

Conceptually I am fine with this, but it doesn't build:

tc_util.c: In function ‘cls_names_init’:
tc_util.c:40:14: error: too many arguments to function ‘db_names_alloc’

  cls_names = db_names_alloc(path ?: NAMES_DB);
              ^
In file included from tc_util.c:26:0:
../include/names.h:19:18: note: declared here
 struct db_names *db_names_alloc(void);
                  ^

<builtin>: recipe for target 'tc_util.o' failed
make[1]: *** [tc_util.o] Error 1

All patches must build (even if split into two pieces).

#3 lore raw

PATCH v2 2/2 tc class: Ignore if default class name file does not exist

In reply to Vadim Kochan

From: Vadim Kochan <[email protected]>

If '-nm' specified that do not fail if there is no default class names file in /etc/iproute2.

Changed default class name file cls_names -> tc_cls.

---
 tc/tc_util.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
tc/tc_util.c +15 -4
index feae439..1d3153d 100644
@@ -21,6 +21,7 @@
 #include <arpa/inet.h>
 #include <string.h>
 #include <math.h>
+#include <errno.h>
 
 #include "utils.h"
 #include "names.h"
@@ -33,15 +34,25 @@
 
 static struct db_names *cls_names = NULL;
 
-#define NAMES_DB "/etc/iproute2/cls_names"
+#define NAMES_DB "/etc/iproute2/tc_cls"
 
 int cls_names_init(char *path)
 {
-	cls_names = db_names_alloc(path ?: NAMES_DB);
-	if (!cls_names) {
-		fprintf(stderr, "Error while opening class names file\n");
+	int ret;
+
+	cls_names = db_names_alloc();
+	if (!cls_names)
+		return -1;
+
+	ret = db_names_load(cls_names, path ?: NAMES_DB);
+	if (ret == -ENOENT && path) {
+		fprintf(stderr, "Can't open class names file: %s\n", path);
 		return -1;
 	}
+	if (ret) {
+		db_names_free(cls_names);
+		cls_names = NULL;
+	}
 
 	return 0;
 }
Signature · 1 line
2.3.1