Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librefuse Correct the wrong prototype of fuse_daemonize(...



details:   https://anonhg.NetBSD.org/src/rev/6e811f92b232
branches:  trunk
changeset: 359767:6e811f92b232
user:      pho <pho%NetBSD.org@localhost>
date:      Sat Jan 22 08:02:49 2022 +0000

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

diffstat:

 lib/librefuse/Makefile        |   4 +-
 lib/librefuse/fuse.h          |  13 +++++++--
 lib/librefuse/refuse.c        |  22 ++++++++++++--
 lib/librefuse/refuse_compat.c |  60 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 90 insertions(+), 9 deletions(-)

diffs (158 lines):

diff -r a58a7cbe9176 -r 6e811f92b232 lib/librefuse/Makefile
--- a/lib/librefuse/Makefile    Sat Jan 22 08:01:50 2022 +0000
+++ b/lib/librefuse/Makefile    Sat Jan 22 08:02:49 2022 +0000
@@ -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 @@
 
 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
diff -r a58a7cbe9176 -r 6e811f92b232 lib/librefuse/fuse.h
--- a/lib/librefuse/fuse.h      Sat Jan 22 08:01:50 2022 +0000
+++ b/lib/librefuse/fuse.h      Sat Jan 22 08:02:49 2022 +0000
@@ -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_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
diff -r a58a7cbe9176 -r 6e811f92b232 lib/librefuse/refuse.c
--- a/lib/librefuse/refuse.c    Sat Jan 22 08:01:50 2022 +0000
+++ b/lib/librefuse/refuse.c    Sat Jan 22 08:02:49 2022 +0000
@@ -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 @@
        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 */
diff -r a58a7cbe9176 -r 6e811f92b232 lib/librefuse/refuse_compat.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/librefuse/refuse_compat.c     Sat Jan 22 08:02:49 2022 +0000
@@ -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);
+}



Home | Main Index | Thread Index | Old Index