usr.sbin/autofs: Fix absolute path when creating a mountpoint

taken-from freebsd 63640b2f552c0476f50484635eb9888eafcd22dc
bouyer-sunxi-drm
tkusumi 2022-05-04 11:27:54 +00:00
parent 2dc6aafac8
commit 5628820aad
2 changed files with 5 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: automount.c,v 1.3 2018/01/15 14:38:06 christos Exp $ */
/* $NetBSD: automount.c,v 1.4 2022/05/04 11:27:54 tkusumi Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@ -34,7 +34,7 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: automount.c,v 1.3 2018/01/15 14:38:06 christos Exp $");
__RCSID("$NetBSD: automount.c,v 1.4 2022/05/04 11:27:54 tkusumi Exp $");
#include <sys/types.h>
#include <sys/mount.h>
@ -83,18 +83,8 @@ mount_autofs(const char *from, const char *fspath, const char *options,
{
struct autofs_args args;
int error;
char *cwd;
/*
* There is no guarantee we are at /, so chdir to /.
*/
cwd = getcwd(NULL, 0);
if (chdir("/") != 0)
log_warn("failed to chdir to /");
create_directory(fspath);
if (chdir(cwd) != 0)
log_warn("failed to restore cwd");
free(cwd);
log_debugx("mounting %s on %s, prefix \"%s\", options \"%s\"",
from, fspath, prefix, options);

View File

@ -1,4 +1,4 @@
/* $NetBSD: common.c,v 1.4 2021/09/14 20:40:55 rillig Exp $ */
/* $NetBSD: common.c,v 1.5 2022/05/04 11:27:54 tkusumi Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@ -36,7 +36,7 @@
* $FreeBSD: head/usr.sbin/autofs/common.c 303527 2016-07-30 01:10:05Z bapt $
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: common.c,v 1.4 2021/09/14 20:40:55 rillig Exp $");
__RCSID("$NetBSD: common.c,v 1.5 2022/05/04 11:27:54 tkusumi Exp $");
#include <sys/types.h>
#include <sys/stat.h>
@ -132,7 +132,7 @@ create_directory(const char *path)
*/
copy = tofree = checked_strdup(path + 1);
partial = checked_strdup("");
partial = checked_strdup("/");
for (;;) {
component = strsep(&copy, "/");
if (component == NULL)