Skip to content

Commit

Permalink
try to create rundir and lockdir before using them
Browse files Browse the repository at this point in the history
Runtime dir changed from /run to /run/pppd in commit 66a8c74 ("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.

Lockdir has a similar problem depending on the configuration, which is
even more important as failure to create a lock file leads to pppd not
starting.

Return code of mkdir does not need to be checked as the following open
will fail anyway if mkdir failed.

See: #419 (lock directory moved in ppp-2.5.0)
Signed-off-by: Dominique Martinet <[email protected]>
  • Loading branch information
martinetd committed Aug 30, 2023
1 parent db5f15a commit 5bfd754
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pppd/tdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,12 @@ TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
goto internal;
}

again:
if ((tdb->fd = open(name, open_flags, mode)) == -1) {
if ((open_flags & O_CREAT) && errno == ENOENT &&
mkdir_recursive(PPP_PATH_VARRUN) == 0)
goto again;

TDB_LOG((tdb, 5, "tdb_open_ex: could not open file %s: %s\n",
name, strerror(errno)));
goto fail; /* errno set by open(2) */
Expand Down
4 changes: 4 additions & 0 deletions pppd/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,10 @@ lock(char *dev)
#endif

while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) {
if (errno == ENOENT && mkdir_recursive(PPP_PATH_LOCKDIR) == 0) {
/* parent dir was missing, retry now */
continue;
}
if (errno != EEXIST) {
error("Can't create lock file %s: %m", lock_file);
break;
Expand Down

0 comments on commit 5bfd754

Please sign in to comment.