Module Name:    src
Committed By:   pho
Date:           Sat Jan 22 08:02:50 UTC 2022

Modified Files:
        src/lib/librefuse: Makefile fuse.h refuse.c
Added Files:
        src/lib/librefuse: refuse_compat.c

Log Message:
Correct the wrong prototype of fuse_daemonize(3) while retaining ABI 
compatibility


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/librefuse/Makefile
cvs rdiff -u -r1.30 -r1.31 src/lib/librefuse/fuse.h
cvs rdiff -u -r1.109 -r1.110 src/lib/librefuse/refuse.c
cvs rdiff -u -r0 -r1.1 src/lib/librefuse/refuse_compat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librefuse/Makefile
diff -u src/lib/librefuse/Makefile:1.15 src/lib/librefuse/Makefile:1.16
--- src/lib/librefuse/Makefile:1.15	Sat Jan 22 07:58:32 2022
+++ src/lib/librefuse/Makefile	Sat Jan 22 08:02:49 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.15 2022/01/22 07:58:32 pho Exp $
+# $NetBSD: Makefile,v 1.16 2022/01/22 08:02:49 pho Exp $
 
 USE_FORT?=	yes	# data driven bugs?
 
@@ -12,7 +12,7 @@ FUSE_OPT_DEBUG_FLAGS=	-g -DFUSE_OPT_DEBU
 
 CFLAGS+=	${FUSE_OPT_DEBUG_FLAGS}
 CPPFLAGS+=	-I${.CURDIR}
-SRCS=		refuse.c refuse_log.c refuse_lowlevel.c
+SRCS=		refuse.c refuse_compat.c refuse_log.c refuse_lowlevel.c
 SRCS+=		refuse_opt.c refuse_signals.c
 MAN=		refuse.3
 WARNS?=		6

Index: src/lib/librefuse/fuse.h
diff -u src/lib/librefuse/fuse.h:1.30 src/lib/librefuse/fuse.h:1.31
--- src/lib/librefuse/fuse.h:1.30	Sat Jan 22 08:01:50 2022
+++ src/lib/librefuse/fuse.h	Sat Jan 22 08:02:49 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: fuse.h,v 1.30 2022/01/22 08:01:50 pho Exp $ */
+/* $NetBSD: fuse.h,v 1.31 2022/01/22 08:02:49 pho Exp $ */
 
 /*
  * Copyright © 2007 Alistair Crooks.  All rights reserved.
@@ -201,13 +201,20 @@ int fuse_invalidate_path(struct fuse *fu
 int fuse_mount(struct fuse *, const char *);
 void fuse_unmount(struct fuse *);
 
-int fuse_daemonize(struct fuse *);
-
 int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
+/* Functions that have existed since the beginning and have never
+ * changed between API versions. */
 int fuse_loop(struct fuse *);
 struct fuse_context *fuse_get_context(void);
 void fuse_exit(struct fuse *);
 void fuse_destroy(struct fuse *);
+
+/* Daemonize the calling process. Appeared on FUSE 2.6.
+ *
+ * NOTE: This function used to have a wrong prototype in librefuse at
+ * the time when FUSE_H_ < 20211204. */
+int fuse_daemonize(int foreground) __RENAME(fuse_daemonize_rev1);
+
 int fuse_version(void);
 
 #if FUSE_USE_VERSION == 22

Index: src/lib/librefuse/refuse.c
diff -u src/lib/librefuse/refuse.c:1.109 src/lib/librefuse/refuse.c:1.110
--- src/lib/librefuse/refuse.c:1.109	Sat Jan 22 08:01:12 2022
+++ src/lib/librefuse/refuse.c	Sat Jan 22 08:02:49 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: refuse.c,v 1.109 2022/01/22 08:01:12 pho Exp $	*/
+/*	$NetBSD: refuse.c,v 1.110 2022/01/22 08:02:49 pho Exp $	*/
 
 /*
  * Copyright © 2007 Alistair Crooks.  All rights reserved.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: refuse.c,v 1.109 2022/01/22 08:01:12 pho Exp $");
+__RCSID("$NetBSD: refuse.c,v 1.110 2022/01/22 08:02:49 pho Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -1248,9 +1248,23 @@ int fuse_mount(struct fuse *fuse, const 
 	return 0;
 }
 
-int fuse_daemonize(struct fuse *fuse)
+int fuse_daemonize(int foreground)
 {
-	return puffs_daemon(fuse->pu, 0, 0);
+	/* There is an impedance mismatch here: FUSE wants to
+	 * daemonize the process without any contexts but puffs wants
+	 * one. */
+	struct fuse *fuse = fuse_get_context()->fuse;
+
+	if (!fuse)
+		/* FUSE would probably allow this, but we cannot. */
+		errx(EXIT_FAILURE,
+		     "%s: librefuse doesn't allow calling"
+		     " this function before fuse_new().", __func__);
+
+	if (!foreground)
+		return puffs_daemon(fuse->pu, 0, 0);
+
+	return 0;
 }
 
 /* ARGSUSED1 */

Added files:

Index: src/lib/librefuse/refuse_compat.c
diff -u /dev/null src/lib/librefuse/refuse_compat.c:1.1
--- /dev/null	Sat Jan 22 08:02:50 2022
+++ src/lib/librefuse/refuse_compat.c	Sat Jan 22 08:02:49 2022
@@ -0,0 +1,60 @@
+/* $NetBSD: refuse_compat.c,v 1.1 2022/01/22 08:02:49 pho Exp $ */
+
+/*
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if !defined(lint)
+__RCSID("$NetBSD: refuse_compat.c,v 1.1 2022/01/22 08:02:49 pho Exp $");
+#endif /* !lint */
+
+#include <fuse_internal.h>
+
+/*
+ * Compatibility symbols that had existed in old versions of
+ * librefuse.
+ */
+
+int fuse_daemonize_rev0(struct fuse* fuse) __RENAME(fuse_daemonize);
+
+/* librefuse once had a function fuse_daemonize() with an incompatible
+ * prototype with that of FUSE. We keep ABI compatibility with
+ * executables compiled against old librefuse by having this shim
+ * function as a symbol "fuse_daemonize". However, we can NOT keep API
+ * compatibility with old code expecting the wrong prototype. The only
+ * way to work around the problem is to put "#if FUSE_H_ < 20211204"
+ * into old user code. pho@ really regrets this mistake... */
+__warn_references(
+    fuse_daemonize,
+    "warning: reference to compatibility fuse_daemonize();"
+    " include <fuse.h> for correct reference")
+int
+fuse_daemonize_rev0(struct fuse* fuse __attribute__((__unused__))) {
+    return fuse_daemonize(1);
+}

Reply via email to