From b6217301f7ad3ee038af1bc04bb6df37826f18b6 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Thu, 3 Aug 2023 16:37:27 +0900 Subject: [PATCH] try to create rundir and lockdir before using them PR #435 makes lockdir default go back to /var/lock, but runtime dir still changed from /run to /run/pppd in commit 66a8c74c3f73 ("Let ./configure control the paths for pppd") and is likely to not exist on some distros, in which case the pppdb will not be created. This is not a big problem but might as well just try to create the directory if it is missing. Return code of mkdir does not need to be checked as the following open will fail anyway if mkdir failed. See: #419 Signed-off-by: Dominique Martinet --- pppd/main.c | 3 +++ pppd/utils.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pppd/main.c b/pppd/main.c index c207d1038..7bd58cb8b 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -494,6 +494,9 @@ main(int argc, char *argv[]) */ sys_init(); + if (access(PPP_PATH_VARRUN, F_OK)) + mkdir(PPP_PATH_VARRUN, 0755); + #ifdef PPP_WITH_TDB pppdb = tdb_open(PPP_PATH_PPPDB, 0, 0, O_RDWR|O_CREAT, 0644); if (pppdb != NULL) { diff --git a/pppd/utils.c b/pppd/utils.c index c1bdbbbfe..26be98e3a 100644 --- a/pppd/utils.c +++ b/pppd/utils.c @@ -843,6 +843,9 @@ lock(char *dev) slprintf(lock_file, sizeof(lock_file), "%s/LCK..%s", PPP_PATH_LOCKDIR, dev); #endif + if (access(PPP_PATH_LOCKDIR, F_OK)) + mkdir(PPP_PATH_LOCKDIR, 0755); + while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) { if (errno != EEXIST) { error("Can't create lock file %s: %m", lock_file);