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
PR #435 makes lockdir default go back to /var/lock, but runtime dir
still 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.

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 <[email protected]>
  • Loading branch information
martinetd committed Aug 3, 2023
1 parent 091e69b commit b621730
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pppd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions pppd/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b621730

Please sign in to comment.