Skip to contentSkip to conversation

arpd: create /var/lib/arpd on first use

PATCH Superseded Max Gautier 6 participants 17 messages Mar 16, 2024 – Mar 28, 2024 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 arpd: create /var/lib/arpd on first use

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

Links: https://0pointer.net/blog/projects/stateless.html
---
Instead of modifying the default location, I opted to create it at runtime, but only for the default location and assuming that /var/lib exists. My thinking is that not changing defaults is somewhat better, plus using /var/tmp directly might cause security concerns (I don't know that it does, but at least someone could create a db file which the root user would then open by default. Not sure what that could cause, so I'd rather avoid it).

 Makefile    |  2 +-
 misc/arpd.c | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
Makefile +1 -1
index 8024d45e..2b2c3dec 100644
@@ -42,6 +42,7 @@ DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
          -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
          -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
          -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
          -DCONF_COLOR=$(CONF_COLOR)
 
 #options for AX.25
@@ -104,7 +105,6 @@ config.mk:
 install: all
 	install -m 0755 -d $(DESTDIR)$(SBINDIR)
 	install -m 0755 -d $(DESTDIR)$(CONF_USR_DIR)
-	install -m 0755 -d $(DESTDIR)$(ARPDDIR)
 	install -m 0755 -d $(DESTDIR)$(HDRDIR)
 	@for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
 	install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONF_USR_DIR)
misc/arpd.c +11 -1
index 1ef837c6..a133226c 100644
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
@@ -35,7 +36,8 @@
 #include "rt_names.h"
 
 DB	*dbase;
-char	*dbname = "/var/lib/arpd/arpd.db";
+char const * const	default_dbname = ARPDDIR "/arpd.db";
+char const	*dbname = default_dbname;
 
 int	ifnum;
 int	*ifvec;
@@ -668,6 +670,14 @@ int main(int argc, char **argv)
 		}
 	}
 
+	if (default_dbname == dbname
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}
+
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
 	if (dbase == NULL) {
 		perror("db_open");
Signature · 1 line
2.44.0
#2 lore raw
Quoted 54 lines · On Sat, 16 Mar 2024 10:06:44 +0100 Max Gautier <[email protected]> wrote:

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

Links: https://0pointer.net/blog/projects/stateless.html
---
Instead of modifying the default location, I opted to create it at runtime, but only for the default location and assuming that /var/lib exists. My thinking is that not changing defaults is somewhat better, plus using /var/tmp directly might cause security concerns (I don't know that it does, but at least someone could create a db file which the root user would then open by default. Not sure what that could cause, so I'd rather avoid it).

 Makefile    |  2 +-
 misc/arpd.c | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
Makefile +1 -1
index 8024d45e..2b2c3dec 100644
@@ -42,6 +42,7 @@ DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
          -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
          -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
          -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
          -DCONF_COLOR=$(CONF_COLOR)
 
 #options for AX.25
@@ -104,7 +105,6 @@ config.mk:
 install: all
 	install -m 0755 -d $(DESTDIR)$(SBINDIR)
 	install -m 0755 -d $(DESTDIR)$(CONF_USR_DIR)
-	install -m 0755 -d $(DESTDIR)$(ARPDDIR)
 	install -m 0755 -d $(DESTDIR)$(HDRDIR)
 	@for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
 	install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONF_USR_DIR)
misc/arpd.c +1 -0
index 1ef837c6..a133226c 100644
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>

misc/arpd.c line 39

Quoted 5 lines
misc/arpd.c +1 -1
@@ -35,7 +36,8 @@
 #include "rt_names.h"
 
 DB	*dbase;
-char	*dbname = "/var/lib/arpd/arpd.db";
+char const * const	default_dbname = ARPDDIR "/arpd.db";

Make this an array.
const char *default_dbname[] = ARPDDIR "/arpd.db";

Quoted 9 lines
misc/arpd.c +2 -0
+char const	*dbname = default_dbname;
 
 int	ifnum;
 int	*ifvec;
@@ -668,6 +670,14 @@ int main(int argc, char **argv)
 		}
 	}
 
+	if (default_dbname == dbname

misc/arpd.c int main(int argc, char **argv) · line 683

Quoted 10 lines
misc/arpd.c +7 -0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}
+
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
 	if (dbase == NULL) {
 		perror("db_open");

Missing signed-off-by

#3 lore raw
Quoted 59 lines · Stephen Hemminger
Quoted 56 lines · On Sat, 16 Mar 2024 10:06:44 +0100 Max Gautier <[email protected]> wrote:

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

Links: https://0pointer.net/blog/projects/stateless.html
---
Instead of modifying the default location, I opted to create it at runtime, but only for the default location and assuming that /var/lib exists. My thinking is that not changing defaults is somewhat better, plus using /var/tmp directly might cause security concerns (I don't know that it does, but at least someone could create a db file which the root user would then open by default. Not sure what that could cause, so I'd rather avoid it).

 Makefile    |  2 +-
 misc/arpd.c | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
Makefile +1 -1
index 8024d45e..2b2c3dec 100644
@@ -42,6 +42,7 @@ DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
          -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
          -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
          -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
          -DCONF_COLOR=$(CONF_COLOR)
 
 #options for AX.25
@@ -104,7 +105,6 @@ config.mk:
 install: all
 	install -m 0755 -d $(DESTDIR)$(SBINDIR)
 	install -m 0755 -d $(DESTDIR)$(CONF_USR_DIR)
-	install -m 0755 -d $(DESTDIR)$(ARPDDIR)
 	install -m 0755 -d $(DESTDIR)$(HDRDIR)
 	@for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
 	install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONF_USR_DIR)
misc/arpd.c +1 -0
index 1ef837c6..a133226c 100644
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
@@ -35,7 +36,8 @@
 #include "rt_names.h"
 
Quoted 6 lines

misc/arpd.c line 39

Quoted 3 lines
misc/arpd.c +1 -1
 DB	*dbase;
-char	*dbname = "/var/lib/arpd/arpd.db";
+char const * const	default_dbname = ARPDDIR "/arpd.db";

Make this an array.
const char *default_dbname[] = ARPDDIR "/arpd.db";

I suspect this should be

const char default_dbname[] = ARPDDIR "/arpd.db";

i.e., no "*" before "default_dbname", to match the type of
dbname (below).

Quoted 8 lines
Quoted 8 lines
misc/arpd.c +1 -0
+char const	*dbname = default_dbname;
 
 int	ifnum;
 int	*ifvec;
@@ -668,6 +670,14 @@ int main(int argc, char **argv)
 		}
 	}
 
Quoted 8 lines

misc/arpd.c int main(int argc, char **argv) · line 680

Quoted 8 lines
misc/arpd.c +8 -0
+	if (default_dbname == dbname
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}
+

Should this be a string comparison? I don't think the pointer
comparison "default_dbname == dbname" will do what you expect if a user specifies "-b" with the default value of ARPDIR "/arpd.db" as its argument (i.e., the pointers won't match, but the actual text is the same).

	-J
Quoted 6 lines

misc/arpd.c int main(int argc, char **argv) · line 683

Quoted 3 lines
misc/arpd.c +0 -0
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
 	if (dbase == NULL) {
 		perror("db_open");

Missing signed-off-by

---
-Jay Vosburgh, [email protected]

#4 lore raw

Le 16 mars 2024 20:56:37 GMT+01:00, Jay Vosburgh <[email protected]> a écrit :

Quoted 68 lines
Quoted 59 lines · Stephen Hemminger
Quoted 56 lines · On Sat, 16 Mar 2024 10:06:44 +0100 Max Gautier <[email protected]> wrote:

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

Links: https://0pointer.net/blog/projects/stateless.html
---
Instead of modifying the default location, I opted to create it at runtime, but only for the default location and assuming that /var/lib exists. My thinking is that not changing defaults is somewhat better, plus using /var/tmp directly might cause security concerns (I don't know that it does, but at least someone could create a db file which the root user would then open by default. Not sure what that could cause, so I'd rather avoid it).

 Makefile    |  2 +-
 misc/arpd.c | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
Makefile +1 -1
index 8024d45e..2b2c3dec 100644
@@ -42,6 +42,7 @@ DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
          -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
          -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
          -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
          -DCONF_COLOR=$(CONF_COLOR)
 
 #options for AX.25
@@ -104,7 +105,6 @@ config.mk:
 install: all
 	install -m 0755 -d $(DESTDIR)$(SBINDIR)
 	install -m 0755 -d $(DESTDIR)$(CONF_USR_DIR)
-	install -m 0755 -d $(DESTDIR)$(ARPDDIR)
 	install -m 0755 -d $(DESTDIR)$(HDRDIR)
 	@for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
 	install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONF_USR_DIR)
misc/arpd.c +1 -0
index 1ef837c6..a133226c 100644
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
@@ -35,7 +36,8 @@
 #include "rt_names.h"
 
Quoted 6 lines

misc/arpd.c line 39

Quoted 3 lines
misc/arpd.c +1 -1
 DB	*dbase;
-char	*dbname = "/var/lib/arpd/arpd.db";
+char const * const	default_dbname = ARPDDIR "/arpd.db";

Make this an array.
const char *default_dbname[] = ARPDDIR "/arpd.db";

Quoted 6 lines

I suspect this should be

const char default_dbname[] = ARPDDIR "/arpd.db";

i.e., no "*" before "default_dbname", to match the type of
dbname (below).

Yeah, does not compile otherwise, that was my guess as well.

Quoted 24 lines
Quoted 9 lines
Quoted 9 lines
misc/arpd.c +1 -0
+char const	*dbname = default_dbname;
 
 int	ifnum;
 int	*ifvec;
@@ -668,6 +670,14 @@ int main(int argc, char **argv)
 		}
 	}
 
Quoted 8 lines

misc/arpd.c int main(int argc, char **argv) · line 680

Quoted 8 lines
misc/arpd.c +8 -0
+	if (default_dbname == dbname
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}
+

Should this be a string comparison? I don't think the pointer
comparison "default_dbname == dbname" will do what you expect if a user specifies "-b" with the default value of ARPDIR "/arpd.db" as its argument (i.e., the pointers won't match, but the actual text is the same).

Quoted 1 line
	-J

I did consider that, the reasoning was mostly something like "if you specify a custom location, you're on your own". But a string compare is probably best, it preserve the observable behavior of arpd and is overall less surprising.

I'll send a v2 shortly.

Quoted 10 lines
Quoted 7 lines

misc/arpd.c int main(int argc, char **argv) · line 683

Quoted 4 lines
misc/arpd.c +0 -0
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
 	if (dbase == NULL) {
 		perror("db_open");

Missing signed-off-by

---
-Jay Vosburgh, [email protected]

#5 lore raw

PATCH v2 1/1 arpd: create /var/lib/arpd on first use

In reply to Max Gautier

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

Links: https://0pointer.net/blog/projects/stateless.html

---
 Makefile    |  2 +-
 misc/arpd.c | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
Makefile +1 -1
index 8024d45e..2b2c3dec 100644
@@ -42,6 +42,7 @@ DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
          -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
          -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
          -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
          -DCONF_COLOR=$(CONF_COLOR)
 
 #options for AX.25
@@ -104,7 +105,6 @@ config.mk:
 install: all
 	install -m 0755 -d $(DESTDIR)$(SBINDIR)
 	install -m 0755 -d $(DESTDIR)$(CONF_USR_DIR)
-	install -m 0755 -d $(DESTDIR)$(ARPDDIR)
 	install -m 0755 -d $(DESTDIR)$(HDRDIR)
 	@for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
 	install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONF_USR_DIR)
misc/arpd.c +11 -1
index 1ef837c6..a64888aa 100644
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
@@ -35,7 +36,8 @@
 #include "rt_names.h"
 
 DB	*dbase;
-char	*dbname = "/var/lib/arpd/arpd.db";
+char const	default_dbname[] = ARPDDIR "/arpd.db";
+char const	*dbname = default_dbname;
 
 int	ifnum;
 int	*ifvec;
@@ -668,6 +670,14 @@ int main(int argc, char **argv)
 		}
 	}
 
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}
+
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
 	if (dbase == NULL) {
 		perror("db_open");
Signature · 1 line
2.44.0
#6 lore raw

misc/arpd.c int main(int argc, char **argv) · line 679

Quoted 7 lines · On Sun, 17 Mar 2024 10:01:24 +0100 Max Gautier <[email protected]> wrote:
misc/arpd.c +7 -0
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}

Please put closing paren on same line after EEXIST

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Le 17 mars 2024 17:03:32 GMT+01:00, Meiyong Yu <[email protected]> a écrit :

Quoted 81 lines
Quoted 76 lines · Max Gautier

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

Links: https://0pointer.net/blog/projects/stateless.html

---
Makefile | 2 +-
misc/arpd.c | 12 +++++++++++-

2 files changed, 12 insertions(+), 2 deletions(-)
Makefile +1 -0
index 8024d45e..2b2c3dec 100644
@@ -42,6 +42,7 @@ DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
         -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
         -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
         -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
         -DCONF_COLOR=$(CONF_COLOR)
 
 #options for AX.25
@@ -104,7 +105,6 @@ config.mk:

install: all
install -m 0755 -d $(DESTDIR)$(SBINDIR)
install -m 0755 -d $(DESTDIR)$(CONF_USR_DIR)

Makefile +0 -1
-    install -m 0755 -d $(DESTDIR)$(ARPDDIR)
   install -m 0755 -d $(DESTDIR)$(HDRDIR)
   @for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
   install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONF_USR_DIR)
misc/arpd.c +11 -2
index 1ef837c6..a64888aa 100644
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
@@ -35,7 +36,8 @@
 #include "rt_names.h"
 
 DB    *dbase;
-char    *dbname = "/var/lib/arpd/arpd.db";
+char const    default_dbname[] = ARPDDIR "/arpd.db";
+char const    *dbname = default_dbname;
 
 int    ifnum;
 int    *ifvec;
@@ -668,6 +670,14 @@ int main(int argc, char **argv)
       }
   }
 
+    if (strcmp(default_dbname, dbname) == 0
+            && mkdir(ARPDDIR, 0755) != 0
+            && errno != EEXIST
+            ) {
+        perror("create_db_dir");
+        exit(-1);
+    }
+
   dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
   if (dbase == NULL) {
       perror("db_open");
--
Quoted 2 lines

2.44.0

if (strcmp(default_dbname, dbname) == 0

Quoted 1 line

Do you consider when the input dbname is relative path, for example: ../../var/lib/arpd/arpd.db, anther example: //var//lib//arpd//arpd.db

I don't. IMO this is a corner case which isn't worth doing path normalization. Symlinks are not considered either.

#9 lore raw
In reply to Max Gautier
Quoted 57 lines · Max Gautier

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

Links: https://0pointer.net/blog/projects/stateless.html

---
 Makefile    |  2 +-
 misc/arpd.c | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
Makefile +1 -1
index 8024d45e..2b2c3dec 100644
@@ -42,6 +42,7 @@ DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
          -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
          -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
          -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
          -DCONF_COLOR=$(CONF_COLOR)
 
 #options for AX.25
@@ -104,7 +105,6 @@ config.mk:
 install: all
 	install -m 0755 -d $(DESTDIR)$(SBINDIR)
 	install -m 0755 -d $(DESTDIR)$(CONF_USR_DIR)
-	install -m 0755 -d $(DESTDIR)$(ARPDDIR)
 	install -m 0755 -d $(DESTDIR)$(HDRDIR)
 	@for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
 	install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONF_USR_DIR)
misc/arpd.c +3 -1
index 1ef837c6..a64888aa 100644
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
@@ -35,7 +36,8 @@
 #include "rt_names.h"
 
 DB	*dbase;
-char	*dbname = "/var/lib/arpd/arpd.db";
+char const	default_dbname[] = ARPDDIR "/arpd.db";
+char const	*dbname = default_dbname;
 
 int	ifnum;
 int	*ifvec;

misc/arpd.c int main(int argc, char **argv) · line 675

Quoted 6 lines
misc/arpd.c +3 -0
@@ -668,6 +670,14 @@ int main(int argc, char **argv)
 		}
 	}
 
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST

why do you need errno != EEXIST case ? mkdir() will return error in this case as well.

Quoted 11 lines
misc/arpd.c +5 -1
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}
+
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
 	if (dbase == NULL) {
 		perror("db_open");
--

2.44.0

#10 lore raw
Quoted 61 lines · Ratheesh Kannoth
Quoted 60 lines · Max Gautier

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

Links: https://0pointer.net/blog/projects/stateless.html

---
 Makefile    |  2 +-
 misc/arpd.c | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
Makefile +1 -1
index 8024d45e..2b2c3dec 100644
@@ -42,6 +42,7 @@ DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
          -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
          -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
          -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
          -DCONF_COLOR=$(CONF_COLOR)
 
 #options for AX.25
@@ -104,7 +105,6 @@ config.mk:
 install: all
 	install -m 0755 -d $(DESTDIR)$(SBINDIR)
 	install -m 0755 -d $(DESTDIR)$(CONF_USR_DIR)
-	install -m 0755 -d $(DESTDIR)$(ARPDDIR)
 	install -m 0755 -d $(DESTDIR)$(HDRDIR)
 	@for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
 	install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONF_USR_DIR)
misc/arpd.c +3 -1
index 1ef837c6..a64888aa 100644
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
@@ -35,7 +36,8 @@
 #include "rt_names.h"
 
 DB	*dbase;
-char	*dbname = "/var/lib/arpd/arpd.db";
+char const	default_dbname[] = ARPDDIR "/arpd.db";
+char const	*dbname = default_dbname;
 
 int	ifnum;
 int	*ifvec;
@@ -668,6 +670,14 @@ int main(int argc, char **argv)
 		}
 	}
 
Quoted 4 lines

misc/arpd.c int main(int argc, char **argv) · line 675

Quoted 3 lines
misc/arpd.c +3 -0
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST

why do you need errno != EEXIST case ? mkdir() will return error in this case as well.

EEXIST is not an error in this case: if the default location already exist, all is good. mkdir would still return -1 in this case, so we need to exclude it manually.

Quoted 11 lines
Quoted 11 lines
misc/arpd.c +5 -1
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}
+
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
 	if (dbase == NULL) {
 		perror("db_open");
--

2.44.0

Signature · 1 line
Max Gautier
#11 lore raw
Quoted 11 lines

From: Max Gautier <[email protected]>
Sent: Monday, March 18, 2024 2:07 PM
To: Ratheesh Kannoth <[email protected]>
Cc: [email protected]
Subject: [EXTERNAL] Re: [PATCH iproute2-next v2] arpd: create /var/lib/arpd on first use

Quoted 4 lines

misc/arpd.c int main(int argc, char **argv) · line 675

Quoted 3 lines
misc/arpd.c +3 -0
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST

why do you need errno != EEXIST case ? mkdir() will return error in this case

Quoted 5 lines

as well.

EEXIST is not an error in this case: if the default location already exist, all is good. mkdir would still return -1 in this case, so we need to exclude it manually.

ACK. IMO, it would make a more readable code if you consider splitting the "if" loop.

Quoted 16 lines
Quoted 7 lines

misc/arpd.c int main(int argc, char **argv)

Quoted 7 lines
misc/arpd.c +5 -0
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}
+
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH,

NULL);

Quoted 5 lines
Quoted 5 lines
misc/arpd.c +0 -1
 	if (dbase == NULL) {
 		perror("db_open");
--

2.44.0

--
Max Gautier

#12 lore raw
Quoted 11 lines · Ratheesh Kannoth
Quoted 11 lines

From: Max Gautier <[email protected]>
Sent: Monday, March 18, 2024 2:07 PM
To: Ratheesh Kannoth <[email protected]>
Cc: [email protected]
Subject: [EXTERNAL] Re: [PATCH iproute2-next v2] arpd: create /var/lib/arpd on first use

Quoted 4 lines

misc/arpd.c int main(int argc, char **argv) · line 675

Quoted 3 lines
misc/arpd.c +3 -0
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST

why do you need errno != EEXIST case ? mkdir() will return error in this case

Quoted 7 lines
Quoted 5 lines

as well.

EEXIST is not an error in this case: if the default location already exist, all is good. mkdir would still return -1 in this case, so we need to exclude it manually.

ACK. IMO, it would make a more readable code if you consider splitting the "if" loop.

Something like this ? I tend to pack conditions unless branching is necessary, but no problem if this form is preferred.

if (strcmp(default_dbname, dbname) == 0) {
    if (mkdir(ARPDDIR, 0755) != 0 && errno != EEXIST) {

...
}
}

Quoted 19 lines
Quoted 19 lines
Quoted 10 lines

misc/arpd.c int main(int argc, char **argv)

Quoted 10 lines
misc/arpd.c +5 -0
+			) {
+		perror("create_db_dir");
+		exit(-1);
+	}
+
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH,

NULL);

Quoted 5 lines
Quoted 5 lines
misc/arpd.c +0 -1
 	if (dbase == NULL) {
 		perror("db_open");
--

2.44.0

--
Max Gautier

Signature · 1 line
Max Gautier
#13 lore raw
Quoted 29 lines

From: Max Gautier <[email protected]>
Sent: Monday, March 18, 2024 2:29 PM
To: Ratheesh Kannoth <[email protected]>
Cc: [email protected]
Subject: Re: [EXTERNAL] Re: [PATCH iproute2-next v2] arpd: create /var/lib/arpd on first use

Quoted 12 lines · Ratheesh Kannoth
Quoted 12 lines

From: Max Gautier <[email protected]>
Sent: Monday, March 18, 2024 2:07 PM
To: Ratheesh Kannoth <[email protected]>
Cc: [email protected]
Subject: [EXTERNAL] Re: [PATCH iproute2-next v2] arpd: create /var/lib/arpd on first use

Quoted 5 lines

misc/arpd.c int main(int argc, char **argv) · line 675

Quoted 3 lines
misc/arpd.c +3 -0
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST

why do you need errno != EEXIST case ? mkdir() will return error in this case

Quoted 7 lines
Quoted 5 lines

as well.

EEXIST is not an error in this case: if the default location already exist, all is good. mkdir would still return -1 in this case, so we need to exclude it manually.

ACK. IMO, it would make a more readable code if you consider splitting the

"if" loop.

Quoted 8 lines

Something like this ? I tend to pack conditions unless branching is necessary, but no problem if this form is preferred.

if (strcmp(default_dbname, dbname) == 0) {
    if (mkdir(ARPDDIR, 0755) != 0 && errno != EEXIST) {

...
}
}

ACK.
instead of errno != EXIST , you may consider stat() before mkdir() call. Just my way thinking(please ignore it, if you don't like). My thinking is --> you need to execute mkdir () only first time, second time onwards, stat() call will return 0.

#14 lore raw
Quoted 17 lines · Ratheesh Kannoth
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

misc/arpd.c int main(int argc, char **argv) · line 675

Quoted 3 lines
misc/arpd.c +3 -0
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST

why do you need errno != EEXIST case ? mkdir() will return error in this case

Quoted 7 lines
Quoted 5 lines

as well.

EEXIST is not an error in this case: if the default location already exist, all is good. mkdir would still return -1 in this case, so we need to exclude it manually.

ACK. IMO, it would make a more readable code if you consider splitting the

"if" loop.

Something like this ? I tend to pack conditions unless branching is necessary, but no problem if this form is preferred.

Quoted 8 lines
Quoted 5 lines
if (strcmp(default_dbname, dbname) == 0) {
    if (mkdir(ARPDDIR, 0755) != 0 && errno != EEXIST) {

...
}
}

ACK.
instead of errno != EXIST , you may consider stat() before mkdir() call. Just my way thinking(please ignore it, if you don't like). My thinking is --> you need to execute mkdir () only first time, second time onwards, stat() call will return 0.

That's racy: we can stat and have a non existing folder, then have another arpd instance (or anything else, really) create the directory, and we would hit EEXIST anyway when we call mkdir.
Also, that needs two syscalls instead of one.

Signature · 1 line
Max Gautier
#15 lore raw
Quoted 23 lines · Max Gautier
Quoted 22 lines · Ratheesh Kannoth
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST

why do you need errno != EEXIST case ? mkdir() will return error in this case

Quoted 7 lines
Quoted 5 lines

as well.

EEXIST is not an error in this case: if the default location already exist, all is good. mkdir would still return -1 in this case, so we need to exclude it manually.

ACK. IMO, it would make a more readable code if you consider splitting the

"if" loop.

Something like this ? I tend to pack conditions unless branching is necessary, but no problem if this form is preferred.

if (strcmp(default_dbname, dbname) == 0) {
    if (mkdir(ARPDDIR, 0755) != 0 && errno != EEXIST) {

...
}
}

Quoted 6 lines
Quoted 3 lines

ACK.
instead of errno != EXIST , you may consider stat() before mkdir() call. Just my way thinking(please ignore it, if you don't like). My thinking is --> you need to execute mkdir () only first time, second time onwards, stat() call will return 0.

That's racy: we can stat and have a non existing folder, then have another arpd instance (or anything else, really) create the directory,

Agreed ^^

Quoted 3 lines

and we would hit EEXIST anyway when we call mkdir. Also, that needs two syscalls instead of one.

#16 lore raw
In reply to Max Gautier
Quoted 33 lines

From: Max Gautier <[email protected]>
Sent: Monday, March 18, 2024 2:57 PM
To: Ratheesh Kannoth <[email protected]>
Cc: [email protected]
Subject: Re: [EXTERNAL] Re: [PATCH iproute2-next v2] arpd: create /var/lib/arpd on first use

Quoted 18 lines · Ratheesh Kannoth
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	if (strcmp(default_dbname, dbname) == 0
+			&& mkdir(ARPDDIR, 0755) != 0
+			&& errno != EEXIST

why do you need errno != EEXIST case ? mkdir() will return error in this case

Quoted 8 lines
Quoted 5 lines

as well.

EEXIST is not an error in this case: if the default location already exist, all is good. mkdir would still return -1 in this case, so we need to exclude it manually.

ACK. IMO, it would make a more readable code if you consider splitting the

"if" loop.

Something like this ? I tend to pack conditions unless branching is necessary, but no problem if this form is preferred.

Quoted 7 lines
Quoted 5 lines
if (strcmp(default_dbname, dbname) == 0) {
    if (mkdir(ARPDDIR, 0755) != 0 && errno != EEXIST) {

...
}
}

ACK.
instead of errno != EXIST , you may consider stat() before mkdir() call. Just

Quoted 7 lines

my way thinking(please ignore it, if you don't like).

Quoted 1 line

My thinking is --> you need to execute mkdir () only first time, second time

onwards, stat() call will return 0.

That's racy: we can stat and have a non existing folder, then have another arpd instance (or anything else, really) create the directory, and we would hit EEXIST anyway when we call mkdir.

ACK.

Quoted 4 lines

Also, that needs two syscalls instead of one.

--
Max Gautier

#17 lore raw

PATCH v3 1/1 arpd: create /var/lib/arpd on first use

In reply to Max Gautier

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

Links: https://0pointer.net/blog/projects/stateless.html

---
Some slight syntax changes from list feedback.

 Makefile    |  2 +-
 misc/arpd.c | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
Makefile +1 -1
index 8024d45e..2b2c3dec 100644
@@ -42,6 +42,7 @@ DEFINES+=-DCONF_USR_DIR=\"$(CONF_USR_DIR)\" \
          -DCONF_ETC_DIR=\"$(CONF_ETC_DIR)\" \
          -DNETNS_RUN_DIR=\"$(NETNS_RUN_DIR)\" \
          -DNETNS_ETC_DIR=\"$(NETNS_ETC_DIR)\" \
+         -DARPDDIR=\"$(ARPDDIR)\" \
          -DCONF_COLOR=$(CONF_COLOR)
 
 #options for AX.25
@@ -104,7 +105,6 @@ config.mk:
 install: all
 	install -m 0755 -d $(DESTDIR)$(SBINDIR)
 	install -m 0755 -d $(DESTDIR)$(CONF_USR_DIR)
-	install -m 0755 -d $(DESTDIR)$(ARPDDIR)
 	install -m 0755 -d $(DESTDIR)$(HDRDIR)
 	@for i in $(SUBDIRS);  do $(MAKE) -C $$i install; done
 	install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONF_USR_DIR)
misc/arpd.c +10 -1
index 1ef837c6..65ac6a38 100644
@@ -19,6 +19,7 @@
 #include <fcntl.h>
 #include <sys/uio.h>
 #include <sys/socket.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
@@ -35,7 +36,8 @@
 #include "rt_names.h"
 
 DB	*dbase;
-char	*dbname = "/var/lib/arpd/arpd.db";
+char const	default_dbname[] = ARPDDIR "/arpd.db";
+char const	*dbname = default_dbname;
 
 int	ifnum;
 int	*ifvec;
@@ -668,6 +670,13 @@ int main(int argc, char **argv)
 		}
 	}
 
+	if (strcmp(default_dbname, dbname) == 0) {
+		if (mkdir(ARPDDIR, 0755) != 0 && errno != EEXIST) {
+			perror("create_db_dir");
+			exit(-1);
+		}
+	}
+
 	dbase = dbopen(dbname, O_CREAT|O_RDWR, 0644, DB_HASH, NULL);
 	if (dbase == NULL) {
 		perror("db_open");
Signature · 1 line
2.44.0
#18 lore raw
This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 8 lines · On Mon, 18 Mar 2024 16:49:13 +0100 you wrote:

The motivation is to build distributions packages without /var to go towards stateless systems, see link below (TL;DR: provisionning anything outside of /usr on boot).

We only try do create the database directory when it's in the default location, and assume its parent (/var/lib in the usual case) exists.

[...]

Here is the summary with links:
- [iproute2-next,v3] arpd: create /var/lib/arpd on first use

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f740f5a165eb

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html