netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Max Gautier <mg@max.gautier.name>
To: Meiyong Yu <meiyong.yu@126.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2-next v2] arpd: create /var/lib/arpd on first use
Date: Sun, 17 Mar 2024 18:23:05 +0100	[thread overview]
Message-ID: <0EE20B22-A0C2-4ECC-A1C0-CD52C5A478A6@max.gautier.name> (raw)
In-Reply-To: <09BB339D-A57C-4F67-BE67-2859F0262C86@126.com>

Le 17 mars 2024 17:03:32 GMT+01:00, Meiyong Yu <meiyong.yu@126.com> a écrit :
>
>
>> On Mar 17, 2024, at 17:04, Max Gautier <mg@max.gautier.name> 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
>> Signed-off-by: Max Gautier <mg@max.gautier.name>
>> ---
>> Makefile    |  2 +-
>> misc/arpd.c | 12 +++++++++++-
>> 2 files changed, 12 insertions(+), 2 deletions(-)
>> 
>> diff --git a/Makefile b/Makefile
>> index 8024d45e..2b2c3dec 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -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)
>> diff --git a/misc/arpd.c b/misc/arpd.c
>> index 1ef837c6..a64888aa 100644
>> --- a/misc/arpd.c
>> +++ b/misc/arpd.c
>> @@ -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");
>> --
>> 2.44.0
>> 
>
>if (strcmp(default_dbname, dbname) == 0
>
>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.

  parent reply	other threads:[~2024-03-17 17:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240313093856.17fc459e@hermes.local>
2024-03-16  9:06 ` [PATCH iproute2-next] arpd: create /var/lib/arpd on first use Max Gautier
2024-03-16 15:07   ` Stephen Hemminger
2024-03-16 19:56     ` Jay Vosburgh
2024-03-17  0:14       ` Max Gautier
2024-03-17  9:01   ` [PATCH iproute2-next v2] " Max Gautier
2024-03-17 15:39     ` Stephen Hemminger
     [not found]     ` <09BB339D-A57C-4F67-BE67-2859F0262C86@126.com>
2024-03-17 17:23       ` Max Gautier [this message]
2024-03-18  2:56     ` Ratheesh Kannoth
2024-03-18  8:37       ` Max Gautier
2024-03-18  8:51         ` [EXTERNAL] " Ratheesh Kannoth
2024-03-18  8:59           ` Max Gautier
2024-03-18  9:18             ` Ratheesh Kannoth
2024-03-18  9:26               ` Max Gautier
2024-03-18  9:37                 ` Denis Kirjanov
2024-03-18  9:43                 ` Ratheesh Kannoth
2024-03-18 15:49   ` [PATCH iproute2-next v3] " Max Gautier
2024-03-28 20:40     ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0EE20B22-A0C2-4ECC-A1C0-CD52C5A478A6@max.gautier.name \
    --to=mg@max.gautier.name \
    --cc=meiyong.yu@126.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).