diff options
302 files changed, 2120 insertions, 568 deletions
@@ -1,4 +1,5 @@ *.o +*.pyc Makefile libpseudo.so pseudo_wrapfuncs.* @@ -14,3 +15,5 @@ pseudo_ports.h templatefile.pyc func_deps.mk port_deps.mk +test/test-* +!test/test-*.* @@ -457,48 +457,10 @@ DAMAGES. END OF TERMS AND CONDITIONS - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - <one line to give the library's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - <signature of Ty Coon>, 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! +Note: +Individual files contain the following tag instead of the full license text. + SPDX-License-Identifier: LGPL-2.1-only +This enables machine processing of license information based on the SPDX +License Identifiers that are here available: http://spdx.org/licenses/ diff --git a/ChangeLog.txt b/ChangeLog.txt index 60666e5..f681596 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,13 @@ +2019-08-02: + * (seebs) Pass flags & O_NOFOLLOW, also use that to influence + stat types. Note. &. Not |. + +2019-08-01: + * (seebs) Pass flags|O_NOFOLLOW on when resolving paths with openat. + +2019-05-15: + * (RP) Add SDPX license headers to source files. + 2019-04-10: * (seebs) Experimental workaround for special non-blocking open case. diff --git a/Makefile.in b/Makefile.in index ad6541b..48fdbd2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -3,18 +3,7 @@ # # Copyright (c) 2008-2015 Wind River Systems, Inc. # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the Lesser GNU General Public License version 2.1 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the Lesser GNU General Public License for more details. -# -# You should have received a copy of the Lesser GNU General Public License -# version 2.1 along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# SPDX-License-Identifier: LGPL-2.1-only # # configuration flags @@ -53,7 +42,7 @@ LOCALSTATE=var/pseudo BINDIR=$(PREFIX)/$(BIN) LOCALSTATEDIR=$(PREFIX)/$(LOCALSTATE) -CFLAGS_BASE=-pipe -std=gnu99 -Wall -W -Wextra +CFLAGS_BASE=-pipe -std=gnu99 -Wall -W -Wextra -Wno-deprecated-declarations CFLAGS_CODE=-fPIC -D_LARGEFILE64_SOURCE -D_ATFILE_SOURCE $(ARCH_FLAGS) CFLAGS_DEFS=-DPSEUDO_PREFIX='"$(PREFIX)"' -DPSEUDO_SUFFIX='"$(SUFFIX)"' -DPSEUDO_BINDIR='"$(BIN)"' -DPSEUDO_LIBDIR='"$(LIB)"' -DPSEUDO_LOCALSTATEDIR='"$(LOCALSTATE)"' -DPSEUDO_VERSION='"$(VERSION)"' $(SQLITE_MEMORY) $(FORCE_ASYNC) -DPSEUDO_PASSWD_FALLBACK='$(PASSWD_FALLBACK)' $(OPTDEFS) $(EPOLL) CFLAGS_DEBUG=-O2 -g @@ -66,6 +55,7 @@ GUTS=$(filter-out "$(GLOB_PATTERN)",$(wildcard $(GLOB_PATTERN))) SOURCES=$(wildcard *.c) OBJS=$(subst .c,.o,$(SOURCES)) +TESTS=$(patsubst %.c,%,$(wildcard test/*.c)) SHOBJS=pseudo_tables.o pseudo_util.o DBOBJS=pseudo_db.o @@ -85,8 +75,11 @@ TABLES=table_templates/pseudo_tables.c table_templates/pseudo_tables.h all: $(LIBPSEUDO) $(PSEUDO) $(PSEUDODB) $(PSEUDOLOG) $(PSEUDO_PROFILE) -test: all | $(BIN) $(LIB) $(LOCALSTATE) - @./run_tests.sh -v +test: all $(TESTS) | $(BIN) $(LIB) + ./run_tests.sh -v + +test/%: test/%.c + $(CC) $(CFLAGS) $(CFLAGS_PSEUDO) -o $@ $< install-lib: $(LIBPSEUDO) mkdir -p $(DESTDIR)$(LIBDIR) @@ -102,7 +95,7 @@ install-data: install: all install-lib install-bin install-data -$(BIN) $(LIB) $(LOCALSTATE): +$(BIN) $(LIB): mkdir -p $@ pseudo: $(PSEUDO) @@ -176,7 +169,8 @@ pseudo_profile: Makefile pseudo_profile.c tables wrappers $(CC) $(CFLAGS) $(CFLAGS_PSEUDO) -o pseudo_profile pseudo_profile.c clean: - rm -f *.o *.so $(PSEUDO) $(PSEUDODB) $(PSEUDOLOG) \ + rm -f *.o $(LIBPSEUDO) $(PSEUDO) $(PSEUDODB) $(PSEUDOLOG) \ + $(TESTS) \ pseudo_wrapfuncs.h pseudo_wrapfuncs.c \ pseudo_wrapper_table.c \ pseudo_tables.c pseudo_tables.h \ @@ -187,8 +181,8 @@ clean: touch port_deps.mk func_deps.mk distclean: clean - rm -f Makefile - rm -rf ./$(BIN) ./$(LIB) ./$(LOCALSTATE) + rm -f Makefile port_deps.mk func_deps.mk + rm -rf ./$(BIN) ./$(LIB) ./$(LOCALSTATE) ./__pycache__ @echo "WARNING: Makefile has been removed. You must reconfigure to do anything else." nuke: distclean @@ -1,16 +1,8 @@ -pseudo -- an analogue to sudo +pseudo -- an analogue to sudo and an alternative to fakeroot -IMPORTANT NOTE: +The official home for pseudo's git repository is: -As of this writing, the official home for pseudo's git repository has -changed to: - git://git.yoctoproject.org/pseudo - -The old site at: - https://github.com/wrpseudo/pseudo - -is no longer the "real" master, although I'll probably try to keep it in -sync. + https://git.yoctoproject.org/pseudo OVERVIEW: @@ -78,6 +70,7 @@ commentary. ACKNOWLEDGEMENTS: +Peter Seebach: My various coworkers, both engineering and management, made this possible. While I did most of the actual typing, this code has benefitted greatly from detailed code reviews, excellent reproducers for bugs, and the @@ -86,9 +79,19 @@ deal of fun, and I'm pretty happy that we're finally ready to make it available for other people to look at. +MAINTAINERS: + +Richard Purdie +Mark Hatle + + CONTACT: -Discussions and patches should be directed at the openembedded-core mailing -list at openembedded-core at lists.openembedded.org. More information at -https://www.openembedded.org/wiki/Mailing_lists. Bugs should be filed with -the Yocto project at https://bugzilla.yoctoproject.org/. +Patches should be directed at the yocto-patches mailing list at yocto-patches +at lists.yoctoproject.org with [pseudo] in the subject line. Bugs should be +filed with the Yocto project at https://bugzilla.yoctoproject.org/. + +The repository can be configured to do this correctly with: + + git config format.subjectprefix "pseudo] [PATCH" + git config sendemail.to yocto-patches@lists.yoctoproject.org diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..7ccecc1 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,13 @@ +How to Report a Potential Vulnerability? +======================================== + +If you would like to report a public issue (for example, one with a released +CVE number), please report it using the +[https://bugzilla.yoctoproject.org/enter_bug.cgi?product=Security Security Bugzilla]. +If you have a patch ready, submit it following the same procedure as any other +patch as described in README.md. + +If you are dealing with a not-yet released or urgent issue, please send a +message to security AT yoctoproject DOT org, including as many details as +possible: the layer or software module affected, the recipe and its version, +and any example code, if available. @@ -4,18 +4,7 @@ # # Copyright (c) 2008-2014 Wind River Systems, Inc. # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the Lesser GNU General Public License version 2.1 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the Lesser GNU General Public License for more details. -# -# You should have received a copy of the Lesser GNU General Public License -# version 2.1 along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# SPDX-License-Identifier: LGPL-2.1-only # # not a real configure script... opt_prefix= diff --git a/enums/op.in b/enums/op.in index 61ee666..5b5e21b 100644 --- a/enums/op.in +++ b/enums/op.in @@ -27,3 +27,4 @@ remove-xattr, 1 set-xattr, 0 create-xattr, 1 replace-xattr, 1 +closefrom, 0 diff --git a/enums/res.in b/enums/res.in index 435338f..b0096b4 100644 --- a/enums/res.in +++ b/enums/res.in @@ -2,3 +2,4 @@ res: RESULT succeed fail error +abort diff --git a/guts/COPYRIGHT b/guts/COPYRIGHT index 06188b2..1b478d1 100644 --- a/guts/COPYRIGHT +++ b/guts/COPYRIGHT @@ -1,17 +1,6 @@ /* * Copyright (c) 2008-2014 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ @@ -1,19 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (c) 2008-2010, 2013 Wind River Systems, Inc. # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the Lesser GNU General Public License version 2.1 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the Lesser GNU General Public License for more details. -# -# You should have received a copy of the Lesser GNU General Public License -# version 2.1 along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# SPDX-License-Identifier: LGPL-2.1-only # """convert tables.in files to enums, tables, and support code. diff --git a/makewrappers b/makewrappers index fa514ba..cf5ad60 100755 --- a/makewrappers +++ b/makewrappers @@ -1,19 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (c) 2008-2011,2013 Wind River Systems, Inc. # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the Lesser GNU General Public License version 2.1 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the Lesser GNU General Public License for more details. -# -# You should have received a copy of the Lesser GNU General Public License -# version 2.1 along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# SPDX-License-Identifier: LGPL-2.1-only # """convert wrapfuncs.in to wrapper function stubs and tables""" @@ -22,6 +11,7 @@ import glob import sys import re import os.path +import platform import string import subprocess from templatefile import TemplateFile @@ -239,6 +229,8 @@ class Function: self.real_func = None self.paths_to_munge = [] self.specific_dirfds = {} + self.fd_arg = False + self.noignore_path = False self.hand_wrapped = None self.async_skip = None # used for the copyright date when creating stub functions @@ -278,6 +270,11 @@ class Function: self.flags = '(flags & AT_SYMLINK_NOFOLLOW)' elif arg.name.endswith('path'): self.paths_to_munge.append(arg.name) + elif arg.name == 'fd': + self.fd_arg = "fd" + elif arg.name == 'filedes': + self.fd_arg = "filedes" + # pick default values if self.type == 'void': @@ -294,10 +291,18 @@ class Function: # handle special comments, such as flags=AT_SYMLINK_NOFOLLOW if self.comments: - modifiers = self.comments.split(', ') - for mod in modifiers: - key, value = mod.split('=') - value = value.rstrip() + # Build a dictionary of key=value, key=value pairs + modifiers = dict(mod.split("=") for mod in self.comments.split(',')) + # Strip all leading/trailing whitespace + modifiers = {k.strip():v.strip() for k, v in modifiers.items()} + + arch = "-" + platform.machine() + # Sorted so that versions-foo appear after versions, so overrides are easy + for key in sorted(modifiers): + value = modifiers[key] + # If the key is version-arm64 and we're on arm64 then rename this to version + if key.endswith(arch): + key = key.replace(arch, "") setattr(self, key, value) def maybe_inode64(self): @@ -367,11 +372,39 @@ class Function: prefix = path[:-4] if prefix not in self.specific_dirfds: prefix = '' + if self.dirfd != "AT_FDCWD" and "flags" in self.flags \ + and "AT_SYMLINK_NOFOLLOW" in self.flags: + fix_paths.append( + # Reference the variable inside a noop inline-asm to stop + # the compiler from eliminating the null pointer check + # on parameters marked nonnull + "asm(\"\" : \"+r\"(%s));" + "if (%s && !*%s && (flags & AT_EMPTY_PATH))\n" + "\t\t\tflags |= AT_SYMLINK_NOFOLLOW;" % (path, path, path)) fix_paths.append( "%s = pseudo_root_path(__func__, __LINE__, %s%s, %s, %s);" % (path, prefix, self.dirfd, path, self.flags)) return "\n\t\t".join(fix_paths) + def ignore_paths(self): + if self.noignore_path: + return "0" + + mainpath = None + if "oldpath" in self.paths_to_munge: + mainpath = "oldpath" + elif "newpath" in self.paths_to_munge: + mainpath = "newpath" + elif "path" in self.paths_to_munge: + mainpath = "path" + + if mainpath: + return "pseudo_client_ignore_path(%s)" % mainpath + if self.fd_arg: + return "pseudo_client_ignore_fd(%s)" % self.fd_arg + + return "0" + def real_predecl(self): if self.real_func: return self.decl().replace(self.name, self.real_func, 1) + ";" @@ -578,7 +611,7 @@ def process_wrapfuncs(port): func.directory = directory funcs[func.name] = func sys.stdout.write(".") - except Exception(e): + except Exception as e: print("Parsing failed:", e) exit(1) funclist.close() @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ #ifndef _LARGEFILE64_SOURCE @@ -1,4 +1,8 @@ #!/bin/sh +# +# SPDX-License-Identifier: LGPL-2.1-only +# + # do a quick performance test of pseudo opt_f=false flag_f= diff --git a/ports/common/guts/execl.c b/ports/common/guts/execl.c index be86b49..21a18cc 100644 --- a/ports/common/guts/execl.c +++ b/ports/common/guts/execl.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int execl(const char *file, const char *arg, va_list ap) * int rc = -1; */ diff --git a/ports/common/guts/execle.c b/ports/common/guts/execle.c index a3bc3ca..0b15e91 100644 --- a/ports/common/guts/execle.c +++ b/ports/common/guts/execle.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int execle(const char *file, const char *arg, va_list ap) * int rc = -1; */ diff --git a/ports/common/guts/execlp.c b/ports/common/guts/execlp.c index 3cf2889..93f85d0 100644 --- a/ports/common/guts/execlp.c +++ b/ports/common/guts/execlp.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int execlp(const char *file, const char *arg, va_list ap) * int rc = -1; */ diff --git a/ports/common/guts/execv.c b/ports/common/guts/execv.c index c071626..7819911 100644 --- a/ports/common/guts/execv.c +++ b/ports/common/guts/execv.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_execv(const char *file, char *const *argv) { * int rc = -1; diff --git a/ports/common/guts/execve.c b/ports/common/guts/execve.c index 24cc177..1144f7c 100644 --- a/ports/common/guts/execve.c +++ b/ports/common/guts/execve.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_execve(const char *file, char *const *argv, char *const *envp) { * int rc = -1; diff --git a/ports/common/guts/execvp.c b/ports/common/guts/execvp.c index e6bf09f..acc9fdc 100644 --- a/ports/common/guts/execvp.c +++ b/ports/common/guts/execvp.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_execvp(const char *file, char *const *argv) { * int rc = -1; diff --git a/ports/common/guts/fork.c b/ports/common/guts/fork.c index bebe3b0..4f5f4e4 100644 --- a/ports/common/guts/fork.c +++ b/ports/common/guts/fork.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_fork(void) { * int rc = -1; diff --git a/ports/common/pseudo_wrappers.c b/ports/common/pseudo_wrappers.c index 81be635..92dfaa8 100644 --- a/ports/common/pseudo_wrappers.c +++ b/ports/common/pseudo_wrappers.c @@ -1,3 +1,8 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + /* these aren't used, but the wrapper table isn't happy unless they * exist */ diff --git a/ports/common/subports b/ports/common/subports index e2aac56..4a47252 100755 --- a/ports/common/subports +++ b/ports/common/subports @@ -1,4 +1,8 @@ #!/bin/sh +# +# SPDX-License-Identifier: LGPL-2.1-only +# + case $(uname -s) in Linux) echo "linux";; Darwin) echo "darwin";; diff --git a/ports/darwin/guts/COPYRIGHT b/ports/darwin/guts/COPYRIGHT index c96e1b1..b860a36 100644 --- a/ports/darwin/guts/COPYRIGHT +++ b/ports/darwin/guts/COPYRIGHT @@ -1,17 +1,6 @@ /* * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ diff --git a/ports/darwin/guts/fcntl.c b/ports/darwin/guts/fcntl.c index c0b142b..917d5e2 100644 --- a/ports/darwin/guts/fcntl.c +++ b/ports/darwin/guts/fcntl.c @@ -2,6 +2,8 @@ * Copyright (c) 2011, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fcntl(int fd, int cmd, ... { struct flock *lock }) * int rc = -1; */ diff --git a/ports/darwin/guts/fgetgrent_r.c b/ports/darwin/guts/fgetgrent_r.c index e760cdd..eec3d3a 100644 --- a/ports/darwin/guts/fgetgrent_r.c +++ b/ports/darwin/guts/fgetgrent_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fgetgrent_r(FILE *fp, struct group*gbuf, char *buf, size_t buflen, struct group **gbufp) * int rc = -1; */ diff --git a/ports/darwin/guts/fgetpwent_r.c b/ports/darwin/guts/fgetpwent_r.c index cfea5b8..b935616 100644 --- a/ports/darwin/guts/fgetpwent_r.c +++ b/ports/darwin/guts/fgetpwent_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fgetpwent_r(FILE *fp, struct passwd *pbuf, char *buf, size_t buflen, struct passwd **pbufp) * int rc = -1; */ diff --git a/ports/darwin/guts/fgetxattr.c b/ports/darwin/guts/fgetxattr.c index dbb3681..56b09d0 100644 --- a/ports/darwin/guts/fgetxattr.c +++ b/ports/darwin/guts/fgetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size, u_int32_t position, int options) * ssize_t rc = -1; */ diff --git a/ports/darwin/guts/flistxattr.c b/ports/darwin/guts/flistxattr.c index bfaa4e9..de95906 100644 --- a/ports/darwin/guts/flistxattr.c +++ b/ports/darwin/guts/flistxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t flistxattr(int filedes, char *list, size_t size, int options) * ssize_t rc = -1; */ diff --git a/ports/darwin/guts/fremovexattr.c b/ports/darwin/guts/fremovexattr.c index 4edc38c..125c77c 100644 --- a/ports/darwin/guts/fremovexattr.c +++ b/ports/darwin/guts/fremovexattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fremovexattr(int filedes, const char *name, int options) * int rc = -1; */ diff --git a/ports/darwin/guts/fsetxattr.c b/ports/darwin/guts/fsetxattr.c index d707595..8f29ac9 100644 --- a/ports/darwin/guts/fsetxattr.c +++ b/ports/darwin/guts/fsetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fsetxattr(int filedes, const char *name, const void *value, size_t size, u_int32_t position, int options) * int rc = -1; */ diff --git a/ports/darwin/guts/fstat.c b/ports/darwin/guts/fstat.c index 7695147..12e2233 100644 --- a/ports/darwin/guts/fstat.c +++ b/ports/darwin/guts/fstat.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fstat(int fd, struct stat *buf) * int rc = -1; */ diff --git a/ports/darwin/guts/getgrent_r.c b/ports/darwin/guts/getgrent_r.c index 9d5db5a..ffc4796 100644 --- a/ports/darwin/guts/getgrent_r.c +++ b/ports/darwin/guts/getgrent_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int getgrent_r(struct group *gbuf, char *buf, size_t buflen, struct group **gbufp) * int rc = -1; */ diff --git a/ports/darwin/guts/getgrouplist.c b/ports/darwin/guts/getgrouplist.c index c5950bd..2988387 100644 --- a/ports/darwin/guts/getgrouplist.c +++ b/ports/darwin/guts/getgrouplist.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getgrouplist(const char *name, int basegid, int *groups, int *ngroups) { * int rc = -1; diff --git a/ports/darwin/guts/getgroups.c b/ports/darwin/guts/getgroups.c index 3cbeb76..7aba660 100644 --- a/ports/darwin/guts/getgroups.c +++ b/ports/darwin/guts/getgroups.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getgroups(int size, gid_t *list) { * int rc = -1; diff --git a/ports/darwin/guts/getpwent_r.c b/ports/darwin/guts/getpwent_r.c index 3de41b9..da0f797 100644 --- a/ports/darwin/guts/getpwent_r.c +++ b/ports/darwin/guts/getpwent_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) * int rc = -1; */ diff --git a/ports/darwin/guts/getxattr.c b/ports/darwin/guts/getxattr.c index ecef9cf..f67bf2c 100644 --- a/ports/darwin/guts/getxattr.c +++ b/ports/darwin/guts/getxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t getxattr(const char *path, const char *name, void *value, size_t size, u_int32_t position, int options) * ssize_t rc = -1; */ diff --git a/ports/darwin/guts/listxattr.c b/ports/darwin/guts/listxattr.c index 5a8a7a8..59151b1 100644 --- a/ports/darwin/guts/listxattr.c +++ b/ports/darwin/guts/listxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t listxattr(const char *path, char *list, size_t size, int options) * ssize_t rc = -1; */ diff --git a/ports/darwin/guts/lstat.c b/ports/darwin/guts/lstat.c index 01e0f30..480dc50 100644 --- a/ports/darwin/guts/lstat.c +++ b/ports/darwin/guts/lstat.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int lstat(const char *path, struct stat *buf) * int rc = -1; */ diff --git a/ports/darwin/guts/open.c b/ports/darwin/guts/open.c index 307bcc9..da23316 100644 --- a/ports/darwin/guts/open.c +++ b/ports/darwin/guts/open.c @@ -2,6 +2,8 @@ * Copyright (c) 2011-2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int open(const char *path, int flags, ... { int mode }) * int rc = -1; */ diff --git a/ports/darwin/guts/removexattr.c b/ports/darwin/guts/removexattr.c index c125b1a..18a1480 100644 --- a/ports/darwin/guts/removexattr.c +++ b/ports/darwin/guts/removexattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int removexattr(const char *path, const char *name, int options) * int rc = -1; */ diff --git a/ports/darwin/guts/scandir.c b/ports/darwin/guts/scandir.c index 6492b1b..b6a5d8f 100644 --- a/ports/darwin/guts/scandir.c +++ b/ports/darwin/guts/scandir.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_scandir(const char *path, struct dirent ***namelist, int (*filter)(struct dirent *), int (*compar)(const void *, const void *)) { * int rc = -1; diff --git a/ports/darwin/guts/setxattr.c b/ports/darwin/guts/setxattr.c index 10ffba4..3346605 100644 --- a/ports/darwin/guts/setxattr.c +++ b/ports/darwin/guts/setxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int setxattr(const char *path, const char *name, const void *value, size_t size, u_int32_t position, int options) * int rc = -1; */ diff --git a/ports/darwin/guts/stat.c b/ports/darwin/guts/stat.c index 8a0742c..4df9670 100644 --- a/ports/darwin/guts/stat.c +++ b/ports/darwin/guts/stat.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int stat(const char *path, struct stat *buf) * int rc = -1; */ diff --git a/ports/darwin/guts/sync_file_range.c b/ports/darwin/guts/sync_file_range.c index e0a31a4..229ccaa 100644 --- a/ports/darwin/guts/sync_file_range.c +++ b/ports/darwin/guts/sync_file_range.c @@ -2,6 +2,8 @@ * Copyright (c) 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int sync_file_range(int fd, off_t offset, off_t nbytes, unsigned int flags) * int rc = -1; */ diff --git a/ports/darwin/portdefs.h b/ports/darwin/portdefs.h index 900d98e..07fd39c 100644 --- a/ports/darwin/portdefs.h +++ b/ports/darwin/portdefs.h @@ -1,3 +1,7 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ #define PRELINK_LIBRARIES "DYLD_INSERT_LIBRARIES" #define PRELINK_PATH "DYLD_LIBRARY_PATH" #define PSEUDO_STATBUF_64 0 diff --git a/ports/darwin/pseudo_wrappers.c b/ports/darwin/pseudo_wrappers.c index e33533e..3f05936 100644 --- a/ports/darwin/pseudo_wrappers.c +++ b/ports/darwin/pseudo_wrappers.c @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2011 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ /* we need XATTR_NOFOLLOW in scope */ diff --git a/ports/linux/guts/COPYRIGHT b/ports/linux/guts/COPYRIGHT index c96e1b1..b860a36 100644 --- a/ports/linux/guts/COPYRIGHT +++ b/ports/linux/guts/COPYRIGHT @@ -1,17 +1,6 @@ /* * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ diff --git a/ports/linux/guts/__fxstat.c b/ports/linux/guts/__fxstat.c index db9716b..0a34320 100644 --- a/ports/linux/guts/__fxstat.c +++ b/ports/linux/guts/__fxstat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int * wrap___fxstat(int ver, int fd, struct stat *buf) { * int rc = -1; diff --git a/ports/linux/guts/__fxstat64.c b/ports/linux/guts/__fxstat64.c index 8601904..aa734b5 100644 --- a/ports/linux/guts/__fxstat64.c +++ b/ports/linux/guts/__fxstat64.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int * wrap___fxstat64(int ver, int fd, struct stat64 *buf) { * int rc = -1; diff --git a/ports/linux/guts/__fxstatat.c b/ports/linux/guts/__fxstatat.c index 94c5ff6..23dfa73 100644 --- a/ports/linux/guts/__fxstatat.c +++ b/ports/linux/guts/__fxstatat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___fxstatat(int ver, int dirfd, const char *path, struct stat *buf, int flags) { * int rc = -1; diff --git a/ports/linux/guts/__fxstatat64.c b/ports/linux/guts/__fxstatat64.c index 62fc3f1..ecf2952 100644 --- a/ports/linux/guts/__fxstatat64.c +++ b/ports/linux/guts/__fxstatat64.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___fxstatat64(int ver, int dirfd, const char *path, struct stat64 *buf, int flags) { * int rc = -1; diff --git a/ports/linux/guts/__lxstat.c b/ports/linux/guts/__lxstat.c index 32b0301..1307eb7 100644 --- a/ports/linux/guts/__lxstat.c +++ b/ports/linux/guts/__lxstat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___lxstat(int ver, const char *path, struct stat *buf) { * int rc = -1; diff --git a/ports/linux/guts/__lxstat64.c b/ports/linux/guts/__lxstat64.c index ac1f782..1d3cf32 100644 --- a/ports/linux/guts/__lxstat64.c +++ b/ports/linux/guts/__lxstat64.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___lxstat64(int ver, const char *path, struct stat64 *buf) { * int rc = -1; diff --git a/ports/linux/guts/__openat64_2.c b/ports/linux/guts/__openat64_2.c index e970df7..f9e9cf0 100644 --- a/ports/linux/guts/__openat64_2.c +++ b/ports/linux/guts/__openat64_2.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010,2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___openat64_2(int dirfd, const char *path, int flags) { * int rc = -1; diff --git a/ports/linux/guts/__openat_2.c b/ports/linux/guts/__openat_2.c index 33ed620..e9a1f7e 100644 --- a/ports/linux/guts/__openat_2.c +++ b/ports/linux/guts/__openat_2.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___openat_2(int dirfd, const char *path, int flags) { * int rc = -1; diff --git a/ports/linux/guts/__xmknod.c b/ports/linux/guts/__xmknod.c index fa31b66..bbf486b 100644 --- a/ports/linux/guts/__xmknod.c +++ b/ports/linux/guts/__xmknod.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___xmknod(int ver, const char *path, mode_t mode, dev_t *dev) { * int rc = -1; diff --git a/ports/linux/guts/__xmknodat.c b/ports/linux/guts/__xmknodat.c index 4fa021b..8c34427 100644 --- a/ports/linux/guts/__xmknodat.c +++ b/ports/linux/guts/__xmknodat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___xmknodat(int ver, int dirfd, const char *path, mode_t mode, dev_t *dev) { * int rc = -1; diff --git a/ports/linux/guts/__xstat.c b/ports/linux/guts/__xstat.c index ec10abb..fed6955 100644 --- a/ports/linux/guts/__xstat.c +++ b/ports/linux/guts/__xstat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___xstat(int ver, const char *path, struct stat *buf) { * int rc = -1; diff --git a/ports/linux/guts/__xstat64.c b/ports/linux/guts/__xstat64.c index ed62e7e..ec74c02 100644 --- a/ports/linux/guts/__xstat64.c +++ b/ports/linux/guts/__xstat64.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap___xstat64(int ver, const char *path, struct stat64 *buf) { * int rc = -1; diff --git a/ports/linux/guts/canonicalize_file_name.c b/ports/linux/guts/canonicalize_file_name.c index 9a04f33..a36cfbd 100644 --- a/ports/linux/guts/canonicalize_file_name.c +++ b/ports/linux/guts/canonicalize_file_name.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static char * * wrap_canonicalize_file_name(const char *filename) { * char * rc = NULL; diff --git a/ports/linux/guts/capset.c b/ports/linux/guts/capset.c index 51e0cdf..1a4219b 100644 --- a/ports/linux/guts/capset.c +++ b/ports/linux/guts/capset.c @@ -2,6 +2,8 @@ * Copyright (c) 2016 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int capset(cap_user_header_t hdrp, const cap_user_data_t datap) * int rc = -1; */ diff --git a/ports/linux/guts/close_range.c b/ports/linux/guts/close_range.c new file mode 100644 index 0000000..4bd2fe1 --- /dev/null +++ b/ports/linux/guts/close_range.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021 Richard Purdie + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * int close_range(unsigned int lowfd, unsigned int maxfd, int flags) + * int rc = -1; + */ + + (void) lowfd; + (void) maxfd; + (void) flags; + /* for now pretend the kernel doesn't support it regardless + which users are supposed to be able to handle */ + errno = ENOSYS; + rc = -1; + +/* return rc; + * } + */ diff --git a/ports/linux/guts/closefrom.c b/ports/linux/guts/closefrom.c new file mode 100644 index 0000000..1350506 --- /dev/null +++ b/ports/linux/guts/closefrom.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2021 Richard Purdie + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * void closefrom(int fd) + */ + pseudo_msg_t *msg; + /* this cleans up internal tables, and shouldn't make it to the server. Avoids pseudo's internal fds */ + msg = pseudo_client_op(OP_CLOSEFROM, 0, fd, -1, 0, 0); + /* fds between fd and msg->fd are closed within the above function avoiding pseudo's own fds */ + real_closefrom(msg->fd); + +/* return; + * } + */ diff --git a/ports/linux/guts/creat64.c b/ports/linux/guts/creat64.c index 2d2fc27..9ce7e3d 100644 --- a/ports/linux/guts/creat64.c +++ b/ports/linux/guts/creat64.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_creat64(const char *path, ...mode_t mode) { * int rc = -1; diff --git a/ports/linux/guts/eaccess.c b/ports/linux/guts/eaccess.c index e2119cc..66b5b56 100644 --- a/ports/linux/guts/eaccess.c +++ b/ports/linux/guts/eaccess.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_eaccess(const char *path, int mode) { * int rc = -1; diff --git a/ports/linux/guts/euidaccess.c b/ports/linux/guts/euidaccess.c index 85433a8..cf9a8cc 100644 --- a/ports/linux/guts/euidaccess.c +++ b/ports/linux/guts/euidaccess.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_euidaccess(const char *path, int mode) { * int rc = -1; diff --git a/ports/linux/guts/fcntl.c b/ports/linux/guts/fcntl.c index 639fd24..ffb50be 100644 --- a/ports/linux/guts/fcntl.c +++ b/ports/linux/guts/fcntl.c @@ -2,10 +2,28 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_fcntl(int fd, int cmd, ...struct flock *lock) { * int rc = -1; */ +#if !defined(F_GETPIPE_SZ) +#define F_GETPIPE_SZ (1032) +#endif + +#if F_GETPIPE_SZ != 1032 +#error System F_GETPIPE_SZ has unexpected value +#endif + +#if !defined(F_SETPIPE_SZ) +#define F_SETPIPE_SZ (1031) +#endif + +#if F_SETPIPE_SZ != 1031 +#error System F_SETPIPE_SZ has unexpected value +#endif + long arg; int save_errno; @@ -29,12 +47,17 @@ } errno = save_errno; break; + case F_SETPIPE_SZ: + /* actually do something */ + rc = real_fcntl(fd, cmd, arg); + break; /* no argument: */ case F_GETFD: case F_GETFL: case F_GETOWN: case F_GETSIG: case F_GETLEASE: + case F_GETPIPE_SZ: rc = real_fcntl(fd, cmd); break; /* long argument */ @@ -50,6 +73,11 @@ case F_GETLK: case F_SETLK: case F_SETLKW: +#ifdef F_OFD_GETLK + case F_OFD_GETLK: + case F_OFD_SETLK: + case F_OFD_SETLKW: +#endif rc = real_fcntl(fd, cmd, lock); break; #if defined(F_GETLK64) && (F_GETLK64 != F_GETLK) diff --git a/ports/linux/guts/fcntl64.c b/ports/linux/guts/fcntl64.c new file mode 100644 index 0000000..99de43d --- /dev/null +++ b/ports/linux/guts/fcntl64.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2008-2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * static int + * wrap_fcntl64(int fd, int cmd, ...struct flock *lock) { + * int rc = -1; + */ +#if !defined(F_GETPIPE_SZ) +#define F_GETPIPE_SZ (1032) +#endif + +#if F_GETPIPE_SZ != 1032 +#error System F_GETPIPE_SZ has unexpected value +#endif + +#if !defined(F_SETPIPE_SZ) +#define F_SETPIPE_SZ (1031) +#endif + +#if F_SETPIPE_SZ != 1031 +#error System F_SETPIPE_SZ has unexpected value +#endif + + long arg; + int save_errno; + + /* we don't know whether we need lock or arg; grab both, which + * should be safe enough on Linuxy systems. */ + va_start(ap, cmd); + arg = va_arg(ap, long); + va_end(ap); + + switch (cmd) { + case F_DUPFD: +#ifdef F_DUPFD_CLOEXEC + case F_DUPFD_CLOEXEC: +#endif + /* actually do something */ + rc = real_fcntl64(fd, cmd, arg); + save_errno = errno; + if (rc != -1) { + pseudo_debug(PDBGF_OP, "fcntl64_dup: %d->%d\n", fd, rc); + pseudo_client_op(OP_DUP, 0, fd, rc, 0, 0); + } + errno = save_errno; + break; + case F_SETPIPE_SZ: + /* actually do something */ + rc = real_fcntl64(fd, cmd, arg); + break; + /* no argument: */ + case F_GETFD: + case F_GETFL: + case F_GETOWN: + case F_GETSIG: + case F_GETLEASE: + case F_GETPIPE_SZ: + rc = real_fcntl64(fd, cmd); + break; + /* long argument */ + case F_SETFD: + case F_SETFL: + case F_SETOWN: + case F_SETSIG: + case F_SETLEASE: + case F_NOTIFY: + rc = real_fcntl64(fd, cmd, arg); + break; + /* struct flock * argument */ + case F_GETLK: + case F_SETLK: + case F_SETLKW: +#ifdef F_OFD_GETLK + case F_OFD_GETLK: + case F_OFD_SETLK: + case F_OFD_SETLKW: +#endif + rc = real_fcntl64(fd, cmd, lock); + break; +#if defined(F_GETLK64) && (F_GETLK64 != F_GETLK) + /* the cast is safe, all struct pointers must smell the same */ + case F_GETLK64: + case F_SETLK64: + case F_SETLKW64: + rc = real_fcntl64(fd, cmd, (struct flock64 *) lock); + break; +#endif + default: + pseudo_diag("unknown fcntl64 argument %d, assuming long argument.\n", + cmd); + rc = real_fcntl64(fd, cmd, arg); + break; + } +/* return rc; + * } + */ diff --git a/ports/linux/guts/fopen64.c b/ports/linux/guts/fopen64.c index b243345..e76da69 100644 --- a/ports/linux/guts/fopen64.c +++ b/ports/linux/guts/fopen64.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static FILE * * wrap_fopen64(const char *path, const char *mode) { * FILE * rc = 0; diff --git a/ports/linux/guts/freopen64.c b/ports/linux/guts/freopen64.c index 4bad533..5fc9073 100644 --- a/ports/linux/guts/freopen64.c +++ b/ports/linux/guts/freopen64.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static FILE * * wrap_freopen64(const char *path, const char *mode, FILE *stream) { * FILE * rc = NULL; diff --git a/ports/linux/guts/fstat.c b/ports/linux/guts/fstat.c index 2cf2787..b089b15 100644 --- a/ports/linux/guts/fstat.c +++ b/ports/linux/guts/fstat.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fstat(int fd, struct stat *buf) * int rc = -1; */ diff --git a/ports/linux/guts/fstat64.c b/ports/linux/guts/fstat64.c index 4a759f7..6dd97da 100644 --- a/ports/linux/guts/fstat64.c +++ b/ports/linux/guts/fstat64.c @@ -2,6 +2,8 @@ * Copyright (c) 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fstat64(int fd, struct stat *buf) * int rc = -1; */ diff --git a/ports/linux/guts/fstatat.c b/ports/linux/guts/fstatat.c new file mode 100644 index 0000000..3267641 --- /dev/null +++ b/ports/linux/guts/fstatat.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021 Linux Foundation; see + * guts/COPYRIGHT for information. + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * int fstatat(int dirfd, const char *path, struct stat *buf, int flags) + * int rc = -1; + */ + + rc = wrap___fxstatat(_STAT_VER, dirfd, path, buf, flags); + +/* return rc; + * } + */ diff --git a/ports/linux/guts/fstatat64.c b/ports/linux/guts/fstatat64.c new file mode 100644 index 0000000..c981e14 --- /dev/null +++ b/ports/linux/guts/fstatat64.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021 Linux Foundation; see + * guts/COPYRIGHT for information. + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * int fstatat64(int dirfd, const char *path, struct stat64 *buf, int flags) + * int rc = -1; + */ + + rc = wrap___fxstatat64(_STAT_VER, dirfd, path, buf, flags); + +/* return rc; + * } + */ diff --git a/ports/linux/guts/ftw64.c b/ports/linux/guts/ftw64.c index a375fbf..48adb80 100644 --- a/ports/linux/guts/ftw64.c +++ b/ports/linux/guts/ftw64.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_ftw64(const char *path, int (*fn)(const char *, const struct stat64 *, int), int nopenfd) { * int rc = -1; diff --git a/ports/linux/guts/get_current_dir_name.c b/ports/linux/guts/get_current_dir_name.c index 79f82f9..cd62326 100644 --- a/ports/linux/guts/get_current_dir_name.c +++ b/ports/linux/guts/get_current_dir_name.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static char * * wrap_get_current_dir_name(void) { * char * rc = NULL; diff --git a/ports/linux/guts/getgrent_r.c b/ports/linux/guts/getgrent_r.c index b04373d..c94f319 100644 --- a/ports/linux/guts/getgrent_r.c +++ b/ports/linux/guts/getgrent_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2010-2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getgrent_r(struct group *gbuf, char *buf, size_t buflen, struct group **gbufp) { * int rc = -1; diff --git a/ports/linux/guts/getgrouplist.c b/ports/linux/guts/getgrouplist.c index 8b16e47..5481a38 100644 --- a/ports/linux/guts/getgrouplist.c +++ b/ports/linux/guts/getgrouplist.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups) { * int rc = -1; diff --git a/ports/linux/guts/getgroups.c b/ports/linux/guts/getgroups.c index afb9662..814caaf 100644 --- a/ports/linux/guts/getgroups.c +++ b/ports/linux/guts/getgroups.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getgroups(int size, gid_t *list) { * int rc = -1; diff --git a/ports/linux/guts/getpw.c b/ports/linux/guts/getpw.c index 62b44da..5aa0bca 100644 --- a/ports/linux/guts/getpw.c +++ b/ports/linux/guts/getpw.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getpw(uid_t uid, char *buf) { * int rc = -1; diff --git a/ports/linux/guts/getpwent_r.c b/ports/linux/guts/getpwent_r.c index 4fd9cc0..4796edf 100644 --- a/ports/linux/guts/getpwent_r.c +++ b/ports/linux/guts/getpwent_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2010-2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) { * int rc = -1; diff --git a/ports/linux/guts/getresgid.c b/ports/linux/guts/getresgid.c index 13551a4..f79b9f3 100644 --- a/ports/linux/guts/getresgid.c +++ b/ports/linux/guts/getresgid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid) { * int rc = -1; diff --git a/ports/linux/guts/getresuid.c b/ports/linux/guts/getresuid.c index 2e47520..59816d4 100644 --- a/ports/linux/guts/getresuid.c +++ b/ports/linux/guts/getresuid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getresuid(uid_t *ruid, uid_t *euid, uid_t *suid) { * int rc = -1; diff --git a/ports/linux/guts/glob64.c b/ports/linux/guts/glob64.c index ccac6e4..7e45368 100644 --- a/ports/linux/guts/glob64.c +++ b/ports/linux/guts/glob64.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_glob64(const char *pattern, int flags, int (*errfunc)(const char *, int), glob64_t *pglob) { * int rc = -1; diff --git a/ports/linux/guts/lchmod.c b/ports/linux/guts/lchmod.c new file mode 100644 index 0000000..da330a7 --- /dev/null +++ b/ports/linux/guts/lchmod.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2021 Linux Foundation + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * static int + * wrap_lchmod(const char *path, mode_t mode) { + */ + + rc = wrap_fchmodat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW); + +/* return rc; + * } + */ diff --git a/ports/linux/guts/lchown.c b/ports/linux/guts/lchown.c index 4eb1202..b41ccaa 100644 --- a/ports/linux/guts/lchown.c +++ b/ports/linux/guts/lchown.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_lchown(const char *path, uid_t owner, gid_t group) { */ diff --git a/ports/linux/guts/lckpwdf.c b/ports/linux/guts/lckpwdf.c index b452ec0..f96ab53 100644 --- a/ports/linux/guts/lckpwdf.c +++ b/ports/linux/guts/lckpwdf.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_lckpwdf(void) { * int rc = -1; diff --git a/ports/linux/guts/lstat.c b/ports/linux/guts/lstat.c index 19c202f..d2c4d50 100644 --- a/ports/linux/guts/lstat.c +++ b/ports/linux/guts/lstat.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int lstat(const char *path, struct stat *buf) * int rc = -1; */ diff --git a/ports/linux/guts/lstat64.c b/ports/linux/guts/lstat64.c index 94eb60f..43d0ce1 100644 --- a/ports/linux/guts/lstat64.c +++ b/ports/linux/guts/lstat64.c @@ -2,6 +2,8 @@ * Copyright (c) 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int lstat64(const char *path, struct stat *buf) * int rc = -1; */ diff --git a/ports/linux/guts/mknod.c b/ports/linux/guts/mknod.c index eb90e66..61fd320 100644 --- a/ports/linux/guts/mknod.c +++ b/ports/linux/guts/mknod.c @@ -2,6 +2,8 @@ * Copyright (c) 2016 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int mknod(const char *path, mode_t mode, dev_t dev) * int rc = -1; */ diff --git a/ports/linux/guts/mknodat.c b/ports/linux/guts/mknodat.c index 4956a6a..a7e4293 100644 --- a/ports/linux/guts/mknodat.c +++ b/ports/linux/guts/mknodat.c @@ -2,6 +2,8 @@ * Copyright (c) 2016 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev) * int rc = -1; */ diff --git a/ports/linux/guts/mkostemp64.c b/ports/linux/guts/mkostemp64.c new file mode 100644 index 0000000..502211b --- /dev/null +++ b/ports/linux/guts/mkostemp64.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2010 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * static int + * wrap_mkstemp64(char *template, int oflags) { + * int rc = -1; + */ + struct stat64 buf; + int save_errno; + size_t len; + char *tmp_template; + + if (!template) { + errno = EFAULT; + return 0; + } + + len = strlen(template); + tmp_template = PSEUDO_ROOT_PATH(AT_FDCWD, template, AT_SYMLINK_NOFOLLOW); + + if (!tmp_template) { + errno = ENOENT; + return -1; + } + + /* mkstemp64 wrapper uses this code and mkostemp64 not present in some glibc versions */ + if (oflags == 0) + rc = real_mkstemp64(tmp_template); + else + rc = real_mkostemp64(tmp_template, oflags); + + if (rc != -1) { + save_errno = errno; + + if (real___fxstat64(_STAT_VER, rc, &buf) != -1) { + real_fchmod(rc, PSEUDO_FS_MODE(0600, 0)); + pseudo_client_op(OP_CREAT, 0, -1, -1, tmp_template, &buf); + pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, &buf); + } else { + pseudo_debug(PDBGF_CONSISTENCY, "mkstemp (fd %d) succeeded, but fstat failed (%s).\n", + rc, strerror(errno)); + pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, 0); + } + errno = save_errno; + } + /* mkstemp only changes the XXXXXX at the end. */ + memcpy(template + len - 6, tmp_template + strlen(tmp_template) - 6, 6); +/* return rc; + * } + */ diff --git a/ports/linux/guts/mkstemp64.c b/ports/linux/guts/mkstemp64.c index 48be612..487f256 100644 --- a/ports/linux/guts/mkstemp64.c +++ b/ports/linux/guts/mkstemp64.c @@ -2,46 +2,15 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_mkstemp64(char *template) { * int rc = -1; */ - struct stat64 buf; - int save_errno; - size_t len; - char *tmp_template; - - if (!template) { - errno = EFAULT; - return 0; - } - - len = strlen(template); - tmp_template = PSEUDO_ROOT_PATH(AT_FDCWD, template, AT_SYMLINK_NOFOLLOW); - - if (!tmp_template) { - errno = ENOENT; - return -1; - } - - rc = real_mkstemp64(tmp_template); - - if (rc != -1) { - save_errno = errno; + /* mkstemp64() is just like mkostemp64() with no flags */ + rc = wrap_mkostemp64(template, 0); - if (real___fxstat64(_STAT_VER, rc, &buf) != -1) { - real_fchmod(rc, PSEUDO_FS_MODE(0600, 0)); - pseudo_client_op(OP_CREAT, 0, -1, -1, tmp_template, &buf); - pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, &buf); - } else { - pseudo_debug(PDBGF_CONSISTENCY, "mkstemp (fd %d) succeeded, but fstat failed (%s).\n", - rc, strerror(errno)); - pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, 0); - } - errno = save_errno; - } - /* mkstemp only changes the XXXXXX at the end. */ - memcpy(template + len - 6, tmp_template + strlen(tmp_template) - 6, 6); /* return rc; * } */ diff --git a/ports/linux/guts/nftw64.c b/ports/linux/guts/nftw64.c index 82571cd..816faba 100644 --- a/ports/linux/guts/nftw64.c +++ b/ports/linux/guts/nftw64.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_nftw64(const char *path, int (*fn)(const char *, const struct stat64 *, int, struct FTW *), int nopenfd, int flag) { * int rc = -1; diff --git a/ports/linux/guts/open.c b/ports/linux/guts/open.c index 0a0596c..ad7fd65 100644 --- a/ports/linux/guts/open.c +++ b/ports/linux/guts/open.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_open(const char *path, int flags, ...mode_t mode) { * int rc = -1; diff --git a/ports/linux/guts/open64.c b/ports/linux/guts/open64.c index 8028ede..b7d9ca3 100644 --- a/ports/linux/guts/open64.c +++ b/ports/linux/guts/open64.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010,2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_open64(const char *path, int flags, ...mode_t mode) { * int rc = -1; diff --git a/ports/linux/guts/openat.c b/ports/linux/guts/openat.c index cc6b118..656ac2b 100644 --- a/ports/linux/guts/openat.c +++ b/ports/linux/guts/openat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_openat(int dirfd, const char *path, int flags, ...mode_t mode) { * int rc = -1; @@ -53,9 +55,13 @@ if (flags & O_CREAT) { save_errno = errno; #ifdef PSEUDO_NO_REAL_AT_FUNCTIONS - rc = real___xstat64(_STAT_VER, path, &buf); + if (flags & O_NOFOLLOW) { + rc = real___lxstat64(_STAT_VER, path, &buf); + } else { + rc = real___xstat64(_STAT_VER, path, &buf); + } #else - rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, 0); + rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0); #endif existed = (rc != -1); if (!existed) @@ -70,9 +76,13 @@ if (!(flags & O_NONBLOCK) && ((flags & (O_WRONLY | O_RDONLY | O_RDWR)) != O_RDWR)) { save_errno = errno; #ifdef PSEUDO_NO_REAL_AT_FUNCTIONS - rc = real___xstat64(_STAT_VER, path, &buf); + if (flags & O_NOFOLLOW) { + rc = real___lxstat64(_STAT_VER, path, &buf); + } else { + rc = real___xstat64(_STAT_VER, path, &buf); + } #else - rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, 0); + rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0); #endif if (rc != -1 && S_ISFIFO(buf.st_mode)) { overly_magic_nonblocking = 1; @@ -124,11 +134,17 @@ } #endif #ifdef PSEUDO_NO_REAL_AT_FUNCTIONS - stat_rc = real___xstat64(_STAT_VER, path, &buf); + if (flags & O_NOFOLLOW) { + stat_rc = real___lxstat64(_STAT_VER, path, &buf); + } else { + stat_rc = real___xstat64(_STAT_VER, path, &buf); + } #else - stat_rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, 0); + stat_rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0); #endif + pseudo_debug(PDBGF_FILE, "openat(path %s), flags %o, stat rc %d, stat mode %o\n", + path, flags, stat_rc, buf.st_mode); if (stat_rc != -1) { buf.st_mode = PSEUDO_DB_MODE(buf.st_mode, mode); if (!existed) { diff --git a/ports/linux/guts/openat64.c b/ports/linux/guts/openat64.c index 8dedcbf..7f9d226 100644 --- a/ports/linux/guts/openat64.c +++ b/ports/linux/guts/openat64.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010,2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_openat64(int dirfd, const char *path, int flags, ...mode_t mode) { * int rc = -1; diff --git a/ports/linux/guts/renameat2.c b/ports/linux/guts/renameat2.c index 135933b..e2c8cf1 100644 --- a/ports/linux/guts/renameat2.c +++ b/ports/linux/guts/renameat2.c @@ -5,6 +5,8 @@ * [Note: copyright added by code generator, may be * incorrect. Remove this if you fix it.] * + * SPDX-License-Identifier: LGPL-2.1-only + * * int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags) * int rc = -1; */ diff --git a/ports/linux/guts/scandir.c b/ports/linux/guts/scandir.c index afcebaf..60a275a 100644 --- a/ports/linux/guts/scandir.c +++ b/ports/linux/guts/scandir.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_scandir(const char *path, struct dirent ***namelist, int (*filter)(const struct dirent *), int (*compar)(const void *, const void *)) { * int rc = -1; diff --git a/ports/linux/guts/scandir64.c b/ports/linux/guts/scandir64.c index 1317b73..233602e 100644 --- a/ports/linux/guts/scandir64.c +++ b/ports/linux/guts/scandir64.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_scandir64(const char *path, struct dirent64 ***namelist, int (*filter)(const struct dirent64 *), int (*compar)(const void *, const void *)) { * int rc = -1; diff --git a/ports/linux/guts/setfsgid.c b/ports/linux/guts/setfsgid.c index 0e5a10b..81e916e 100644 --- a/ports/linux/guts/setfsgid.c +++ b/ports/linux/guts/setfsgid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setfsgid(gid_t fsgid) { * int rc = -1; diff --git a/ports/linux/guts/setfsuid.c b/ports/linux/guts/setfsuid.c index e52b65e..423ca03 100644 --- a/ports/linux/guts/setfsuid.c +++ b/ports/linux/guts/setfsuid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setfsuid(uid_t fsuid) { * int rc = -1; diff --git a/ports/linux/guts/setgroups.c b/ports/linux/guts/setgroups.c index 31b2b57..d26db31 100644 --- a/ports/linux/guts/setgroups.c +++ b/ports/linux/guts/setgroups.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setgroups(size_t size, const gid_t *list) { * int rc = -1; diff --git a/ports/linux/guts/setresgid.c b/ports/linux/guts/setresgid.c index 2a26405..37739b9 100644 --- a/ports/linux/guts/setresgid.c +++ b/ports/linux/guts/setresgid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setresgid(gid_t rgid, gid_t egid, gid_t sgid) { * int rc = -1; diff --git a/ports/linux/guts/setresuid.c b/ports/linux/guts/setresuid.c index a0a367f..3219fc5 100644 --- a/ports/linux/guts/setresuid.c +++ b/ports/linux/guts/setresuid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setresuid(uid_t ruid, uid_t euid, uid_t suid) { * int rc = -1; diff --git a/ports/linux/guts/stat.c b/ports/linux/guts/stat.c index 1fe800e..f8c73f7 100644 --- a/ports/linux/guts/stat.c +++ b/ports/linux/guts/stat.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int stat(const char *path, struct stat *buf) * int rc = -1; */ diff --git a/ports/linux/guts/stat64.c b/ports/linux/guts/stat64.c index 53dd156..d8b3f36 100644 --- a/ports/linux/guts/stat64.c +++ b/ports/linux/guts/stat64.c @@ -2,6 +2,8 @@ * Copyright (c) 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int stat64(const char *path, struct stat *buf) * int rc = -1; */ diff --git a/ports/linux/guts/syscall.c b/ports/linux/guts/syscall.c index d1226c5..0fefddc 100644 --- a/ports/linux/guts/syscall.c +++ b/ports/linux/guts/syscall.c @@ -2,6 +2,8 @@ * Copyright (c) 2018 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * long syscall(long nr) * long rc = -1; */ diff --git a/ports/linux/guts/truncate64.c b/ports/linux/guts/truncate64.c index a798984..aaf1797 100644 --- a/ports/linux/guts/truncate64.c +++ b/ports/linux/guts/truncate64.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_truncate64(const char *path, off64_t length) { * int rc = -1; diff --git a/ports/linux/guts/ulckpwdf.c b/ports/linux/guts/ulckpwdf.c index ed6a671..b4a26da 100644 --- a/ports/linux/guts/ulckpwdf.c +++ b/ports/linux/guts/ulckpwdf.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_ulckpwdf(void) { * int rc = -1; diff --git a/ports/linux/newclone/guts/clone.c b/ports/linux/newclone/guts/clone.c index ee6fc09..bc64c5a 100644 --- a/ports/linux/newclone/guts/clone.c +++ b/ports/linux/newclone/guts/clone.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * clone(...) { * .... diff --git a/ports/linux/newclone/pseudo_wrappers.c b/ports/linux/newclone/pseudo_wrappers.c index 1fc6c59..5b137ee 100644 --- a/ports/linux/newclone/pseudo_wrappers.c +++ b/ports/linux/newclone/pseudo_wrappers.c @@ -1,3 +1,8 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + static int wrap_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, va_list ap) { diff --git a/ports/linux/nostatx/portdefs.h b/ports/linux/nostatx/portdefs.h new file mode 100644 index 0000000..ded8ff9 --- /dev/null +++ b/ports/linux/nostatx/portdefs.h @@ -0,0 +1,38 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copy of the statx struct to allow a pseudo built on a system without + * statx to work on one with statx and hence work with OE's uninative + */ + +struct statx_timestamp +{ + __int64_t tv_sec; + __uint32_t tv_nsec; + __int32_t __statx_timestamp_pad1[1]; +}; + +struct statx +{ + __uint32_t stx_mask; + __uint32_t stx_blksize; + __uint64_t stx_attributes; + __uint32_t stx_nlink; + __uint32_t stx_uid; + __uint32_t stx_gid; + __uint16_t stx_mode; + __uint16_t __statx_pad1[1]; + __uint64_t stx_ino; + __uint64_t stx_size; + __uint64_t stx_blocks; + __uint64_t stx_attributes_mask; + struct statx_timestamp stx_atime; + struct statx_timestamp stx_btime; + struct statx_timestamp stx_ctime; + struct statx_timestamp stx_mtime; + __uint32_t stx_rdev_major; + __uint32_t stx_rdev_minor; + __uint32_t stx_dev_major; + __uint32_t stx_dev_minor; + __uint64_t __statx_pad2[14]; +}; diff --git a/ports/linux/noxattr/guts/fgetxattr.c b/ports/linux/noxattr/guts/fgetxattr.c index 9d33643..9ab1be2 100644 --- a/ports/linux/noxattr/guts/fgetxattr.c +++ b/ports/linux/noxattr/guts/fgetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/noxattr/guts/flistxattr.c b/ports/linux/noxattr/guts/flistxattr.c index 77db021..e9ad277 100644 --- a/ports/linux/noxattr/guts/flistxattr.c +++ b/ports/linux/noxattr/guts/flistxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t flistxattr(int filedes, char *list, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/noxattr/guts/fremovexattr.c b/ports/linux/noxattr/guts/fremovexattr.c index 529a9de..99c0906 100644 --- a/ports/linux/noxattr/guts/fremovexattr.c +++ b/ports/linux/noxattr/guts/fremovexattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fremovexattr(int filedes, const char *name) * int rc = -1; */ diff --git a/ports/linux/noxattr/guts/fsetxattr.c b/ports/linux/noxattr/guts/fsetxattr.c index 3c56ddd..780fa9a 100644 --- a/ports/linux/noxattr/guts/fsetxattr.c +++ b/ports/linux/noxattr/guts/fsetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags) * int rc = -1; */ diff --git a/ports/linux/noxattr/guts/getxattr.c b/ports/linux/noxattr/guts/getxattr.c index fe8912d..939060b 100644 --- a/ports/linux/noxattr/guts/getxattr.c +++ b/ports/linux/noxattr/guts/getxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t getxattr(const char *pathname, const char *name, void *value, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/noxattr/guts/lgetxattr.c b/ports/linux/noxattr/guts/lgetxattr.c index 404211f..48a0b95 100644 --- a/ports/linux/noxattr/guts/lgetxattr.c +++ b/ports/linux/noxattr/guts/lgetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t lgetxattr(const char *pathname, const char *name, void *value, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/noxattr/guts/listxattr.c b/ports/linux/noxattr/guts/listxattr.c index 1b0b5e7..9c351a5 100644 --- a/ports/linux/noxattr/guts/listxattr.c +++ b/ports/linux/noxattr/guts/listxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t listxattr(const char *pathname, char *list, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/noxattr/guts/llistxattr.c b/ports/linux/noxattr/guts/llistxattr.c index a33f970..6fc6bcc 100644 --- a/ports/linux/noxattr/guts/llistxattr.c +++ b/ports/linux/noxattr/guts/llistxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t llistxattr(const char *pathname, char *list, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/noxattr/guts/lremovexattr.c b/ports/linux/noxattr/guts/lremovexattr.c index 38429da..e31c46c 100644 --- a/ports/linux/noxattr/guts/lremovexattr.c +++ b/ports/linux/noxattr/guts/lremovexattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int lremovexattr(const char *pathname, const char *name) * int rc = -1; */ diff --git a/ports/linux/noxattr/guts/lsetxattr.c b/ports/linux/noxattr/guts/lsetxattr.c index 140ae8d..096cbf2 100644 --- a/ports/linux/noxattr/guts/lsetxattr.c +++ b/ports/linux/noxattr/guts/lsetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int lsetxattr(const char *pathname, const char *name, const void *value, size_t size, int flags) * int rc = -1; */ diff --git a/ports/linux/noxattr/guts/removexattr.c b/ports/linux/noxattr/guts/removexattr.c index cd7f486..4adee0e 100644 --- a/ports/linux/noxattr/guts/removexattr.c +++ b/ports/linux/noxattr/guts/removexattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int removexattr(const char *pathname, const char *name) * int rc = -1; */ diff --git a/ports/linux/noxattr/guts/setxattr.c b/ports/linux/noxattr/guts/setxattr.c index de2de98..3172e6f 100644 --- a/ports/linux/noxattr/guts/setxattr.c +++ b/ports/linux/noxattr/guts/setxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int setxattr(const char *pathname, const char *name, const void *value, size_t size, int flags) * int rc = -1; */ diff --git a/ports/linux/oldclone/guts/clone.c b/ports/linux/oldclone/guts/clone.c index c6771e5..e0ff768 100644 --- a/ports/linux/oldclone/guts/clone.c +++ b/ports/linux/oldclone/guts/clone.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * clone(...) { * .... diff --git a/ports/linux/oldclone/pseudo_wrappers.c b/ports/linux/oldclone/pseudo_wrappers.c index 1720dfb..ba9cf42 100644 --- a/ports/linux/oldclone/pseudo_wrappers.c +++ b/ports/linux/oldclone/pseudo_wrappers.c @@ -1,3 +1,7 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ static int wrap_clone(int (*fn)(void *), void *child_stack, int flags, void *arg) { /* unused */ diff --git a/ports/linux/portdefs.h b/ports/linux/portdefs.h index 86aa4f9..9545550 100644 --- a/ports/linux/portdefs.h +++ b/ports/linux/portdefs.h @@ -1,3 +1,7 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ #define PRELINK_LIBRARIES "LD_PRELOAD" #define PRELINK_PATH "LD_LIBRARY_PATH" #define PSEUDO_STATBUF_64 1 @@ -28,3 +32,24 @@ GLIBC_COMPAT_SYMBOL(memcpy,2.0); #include <linux/capability.h> #include <sys/syscall.h> +#include <sys/prctl.h> +#include <linux/seccomp.h> + +#ifndef _STAT_VER +#if defined (__aarch64__) +#define _STAT_VER 0 +#elif defined (__x86_64__) +#define _STAT_VER 1 +#else +#define _STAT_VER 3 +#endif +#endif +#ifndef _MKNOD_VER +#if defined (__aarch64__) +#define _MKNOD_VER 0 +#elif defined (__x86_64__) +#define _MKNOD_VER 0 +#else +#define _MKNOD_VER 1 +#endif +#endif diff --git a/ports/linux/pseudo_wrappers.c b/ports/linux/pseudo_wrappers.c index 6a76632..7659897 100644 --- a/ports/linux/pseudo_wrappers.c +++ b/ports/linux/pseudo_wrappers.c @@ -1,3 +1,7 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ /* the unix port wants to know that real_stat() and * friends exist. So they do. And because the Linux * port really uses stat64 for those... @@ -53,6 +57,7 @@ int pseudo_capset(cap_user_header_t hdrp, const cap_user_data_t datap) { long syscall(long number, ...) { long rc = -1; + va_list ap; if (!pseudo_check_wrappers() || !real_syscall) { /* rc was initialized to the "failure" value */ @@ -73,11 +78,25 @@ syscall(long number, ...) { (void) number; #endif +#ifdef SYS_seccomp + /* pseudo and seccomp are incompatible as pseudo uses different syscalls + * so pretend to enable seccomp but really do nothing */ + if (number == SYS_seccomp) { + unsigned long cmd; + va_start(ap, number); + cmd = va_arg(ap, unsigned long); + va_end(ap); + if (cmd == SECCOMP_SET_MODE_FILTER) { + return 0; + } + } +#endif + /* gcc magic to attempt to just pass these args to syscall. we have to * guess about the number of args; the docs discuss calling conventions * up to 7, so let's try that? */ - void *res = __builtin_apply((void (*)()) real_syscall, __builtin_apply_args(), sizeof(long) * 7); + void *res = __builtin_apply((void (*)(void)) real_syscall, __builtin_apply_args(), sizeof(long) * 7); __builtin_return(res); } @@ -88,3 +107,44 @@ static long wrap_syscall(long nr, va_list ap) { (void) ap; return -1; } + +int +prctl(int option, ...) { + int rc = -1; + va_list ap; + + if (!pseudo_check_wrappers() || !real_prctl) { + /* rc was initialized to the "failure" value */ + pseudo_enosys("prctl"); + return rc; + } + +#ifdef SECCOMP_SET_MODE_FILTER + /* pseudo and seccomp are incompatible as pseudo uses different syscalls + * so pretend to enable seccomp but really do nothing */ + if (option == PR_SET_SECCOMP) { + unsigned long cmd; + va_start(ap, option); + cmd = va_arg(ap, unsigned long); + va_end(ap); + if (cmd == SECCOMP_SET_MODE_FILTER) { + return 0; + } + } +#endif + + /* gcc magic to attempt to just pass these args to prctl. we have to + * guess about the number of args; the docs discuss calling conventions + * up to 5, so let's try that? + */ + void *res = __builtin_apply((void (*)(void)) real_prctl, __builtin_apply_args(), sizeof(long) * 5); + __builtin_return(res); +} + +/* unused. + */ +static int wrap_prctl(int option, va_list ap) { + (void) option; + (void) ap; + return -1; +} diff --git a/ports/linux/statvfs/guts/statvfs.c b/ports/linux/statvfs/guts/statvfs.c index c516649..e69ee41 100644 --- a/ports/linux/statvfs/guts/statvfs.c +++ b/ports/linux/statvfs/guts/statvfs.c @@ -2,6 +2,8 @@ * Copyright (c) 2018 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int statvfs(const char *path, struct statvfs *buf) * int rc = -1; */ diff --git a/ports/linux/statvfs/guts/statvfs64.c b/ports/linux/statvfs/guts/statvfs64.c new file mode 100644 index 0000000..856d3db --- /dev/null +++ b/ports/linux/statvfs/guts/statvfs64.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018 Wind River Systems; see + * guts/COPYRIGHT for information. + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * int statvfs64(const char *path, struct statvfs64 *buf) + * int rc = -1; + */ + + rc = real_statvfs64(path, buf); + +/* return rc; + * } + */ diff --git a/ports/linux/statvfs/wrapfuncs.in b/ports/linux/statvfs/wrapfuncs.in index 1afb64d..6a59660 100644 --- a/ports/linux/statvfs/wrapfuncs.in +++ b/ports/linux/statvfs/wrapfuncs.in @@ -1 +1,2 @@ int statvfs(const char *path, struct statvfs *buf); +int statvfs64(const char *path, struct statvfs64 *buf); diff --git a/ports/linux/statx/guts/statx.c b/ports/linux/statx/guts/statx.c new file mode 100644 index 0000000..42aebe5 --- /dev/null +++ b/ports/linux/statx/guts/statx.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 Linux Foundation + * Author: Richard Purdie + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * int + * statx(int dirfd, const char *path, int flags, unsigned int mask, struct statx *statxbuf) { + * int rc = -1; + */ + pseudo_msg_t *msg; + PSEUDO_STATBUF buf; + int save_errno; + + rc = real_statx(dirfd, path, flags, mask, statxbuf); + save_errno = errno; + if (rc == -1) { + return rc; + } + + buf.st_uid = statxbuf->stx_uid; + buf.st_gid = statxbuf->stx_gid; + buf.st_dev = makedev(statxbuf->stx_dev_major, statxbuf->stx_dev_minor); + buf.st_ino = statxbuf->stx_ino; + buf.st_mode = statxbuf->stx_mode; + buf.st_rdev = makedev(statxbuf->stx_rdev_major, statxbuf->stx_rdev_minor); + buf.st_nlink = statxbuf->stx_nlink; + msg = pseudo_client_op(OP_STAT, 0, -1, dirfd, path, &buf); + if (msg && msg->result == RESULT_SUCCEED) { + pseudo_debug(PDBGF_FILE, "statx(path %s), flags %o, stat rc %d, stat uid %o\n", path, flags, rc, statxbuf->stx_uid); + statxbuf->stx_uid = msg->uid; + statxbuf->stx_gid = msg->gid; + statxbuf->stx_mode = msg->mode; + statxbuf->stx_rdev_major = major(msg->rdev); + statxbuf->stx_rdev_minor = minor(msg->rdev); + } else { + pseudo_debug(PDBGF_FILE, "statx(path %s) failed, flags %o, stat rc %d, stat uid %o\n", path, flags, rc, statxbuf->stx_uid); + } + errno = save_errno; +/* return rc; + * } + */ diff --git a/ports/linux/statx/portdefs.h b/ports/linux/statx/portdefs.h new file mode 100644 index 0000000..bf934dc --- /dev/null +++ b/ports/linux/statx/portdefs.h @@ -0,0 +1,6 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ +#include <sys/stat.h> +#include <sys/sysmacros.h> diff --git a/ports/linux/statx/wrapfuncs.in b/ports/linux/statx/wrapfuncs.in new file mode 100644 index 0000000..168234f --- /dev/null +++ b/ports/linux/statx/wrapfuncs.in @@ -0,0 +1 @@ +int statx(int dirfd, const char *path, int flags, unsigned int mask, struct statx *statxbuf); diff --git a/ports/linux/subports b/ports/linux/subports index a29044a..099ea59 100755 --- a/ports/linux/subports +++ b/ports/linux/subports @@ -29,11 +29,12 @@ fi if $port_xattr; then cat > dummy.c <<EOF #include <sys/types.h> -#include <attr/xattr.h> +#include <sys/xattr.h> +#include <attr/attributes.h> int i; EOF if ! ${CC} -c -o dummy.o dummy.c >/dev/null 2>&1; then - echo >&2 "Warning: Can't compile trivial program using <attr/xattr.h>". + echo >&2 "Warning: Can't compile trivial program using <attr/attributes.h>". echo >&2 " xattr support will require that header." fi echo "linux/xattr" @@ -54,3 +55,18 @@ else fi rm -f dummy.c dummy.o +# For statx, we want a pseudo which can work with OE's uninative, i.e. build on a system without +# statx but work on one with it. We have a header in nostatx to allow this. +cat > dummy.c <<EOF +#define _GNU_SOURCE +#include <sys/stat.h> +struct statx x; +EOF +if ${CC} -c -o dummy.o dummy.c >/dev/null 2>&1; then + echo "linux/statx" +else + echo "linux/nostatx" + echo "linux/statx" +fi +rm -f dummy.c dummy.o + diff --git a/ports/linux/wrapfuncs.in b/ports/linux/wrapfuncs.in index a129eba..97b16c2 100644 --- a/ports/linux/wrapfuncs.in +++ b/ports/linux/wrapfuncs.in @@ -1,41 +1,46 @@ -int open(const char *path, int flags, ...{mode_t mode}); /* flags=0 */ +int open(const char *path, int flags, ...{mode_t mode}); /* flags=flags&O_NOFOLLOW, noignore_path=1 */ char *get_current_dir_name(void); int __xstat(int ver, const char *path, struct stat *buf); int __lxstat(int ver, const char *path, struct stat *buf); /* flags=AT_SYMLINK_NOFOLLOW */ int __fxstat(int ver, int fd, struct stat *buf); +int lchmod(const char *path, mode_t mode); /* flags=AT_SYMLINK_NOFOLLOW */ int lchown(const char *path, uid_t owner, gid_t group); /* flags=AT_SYMLINK_NOFOLLOW */ int __fxstatat(int ver, int dirfd, const char *path, struct stat *buf, int flags); -int openat(int dirfd, const char *path, int flags, ...{mode_t mode}); /* flags=0 */ -int __openat_2(int dirfd, const char *path, int flags); /* flags=0 */ +int openat(int dirfd, const char *path, int flags, ...{mode_t mode}); /* flags=flags&O_NOFOLLOW, noignore_path=1 */ +int __openat_2(int dirfd, const char *path, int flags); /* flags=flags&O_NOFOLLOW, noignore_path=1 */ int mknod(const char *path, mode_t mode, dev_t dev); /* real_func=pseudo_mknod */ int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev); /* real_func=pseudo_mknodat */ int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW */ int __xmknodat(int ver, int dirfd, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW */ -int fcntl(int fd, int cmd, ...{struct flock *lock}); +int fcntl(int fd, int cmd, ...{struct flock *lock}); /* noignore_path=1 */ +int fcntl64(int fd, int cmd, ...{struct flock *lock}); /* noignore_path=1 */ # just so we know the inums of symlinks char *canonicalize_file_name(const char *filename); int eaccess(const char *path, int mode); -int open64(const char *path, int flags, ...{mode_t mode}); /* flags=0 */ -int openat64(int dirfd, const char *path, int flags, ...{mode_t mode}); /* flags=0 */ -int __openat64_2(int dirfd, const char *path, int flags); /* flags=0 */ +int open64(const char *path, int flags, ...{mode_t mode}); /* flags=flags&O_NOFOLLOW, noignore_path=1 */ +int openat64(int dirfd, const char *path, int flags, ...{mode_t mode}); /* flags=flags&O_NOFOLLOW, noignore_path=1 */ +int __openat64_2(int dirfd, const char *path, int flags); /* flags=flags&O_NOFOLLOW, noignore_path=1 */ int creat64(const char *path, mode_t mode); int stat(const char *path, struct stat *buf); /* real_func=pseudo_stat */ int lstat(const char *path, struct stat *buf); /* real_func=pseudo_lstat, flags=AT_SYMLINK_NOFOLLOW */ int fstat(int fd, struct stat *buf); /* real_func=pseudo_fstat */ +int fstatat(int dirfd, const char *path, struct stat *buf, int flags); int stat64(const char *path, struct stat64 *buf); /* real_func=pseudo_stat64 */ int lstat64(const char *path, struct stat64 *buf); /* real_func=pseudo_lstat64, flags=AT_SYMLINK_NOFOLLOW */ int fstat64(int fd, struct stat64 *buf); /* real_func=pseudo_fstat64 */ +int fstatat64(int dirfd, const char *path, struct stat64 *buf, int flags); int __xstat64(int ver, const char *path, struct stat64 *buf); int __lxstat64(int ver, const char *path, struct stat64 *buf); /* flags=AT_SYMLINK_NOFOLLOW */ int __fxstat64(int ver, int fd, struct stat64 *buf); int __fxstatat64(int ver, int dirfd, const char *path, struct stat64 *buf, int flags); -FILE *fopen64(const char *path, const char *mode); -int nftw64(const char *path, int (*fn)(const char *, const struct stat64 *, int, struct FTW *), int nopenfd, int flag); -FILE *freopen64(const char *path, const char *mode, FILE *stream); +FILE *fopen64(const char *path, const char *mode); /* noignore_path=1 */ +int nftw64(const char *path, int (*fn)(const char *, const struct stat64 *, int, struct FTW *), int nopenfd, int flag); /* noignore_path=1 */ +FILE *freopen64(const char *path, const char *mode, FILE *stream); /* noignore_path=1 */ int ftw64(const char *path, int (*fn)(const char *, const struct stat64 *, int), int nopenfd); int glob64(const char *pattern, int flags, int (*errfunc)(const char *, int), glob64_t *pglob); int scandir64(const char *path, struct dirent64 ***namelist, int (*filter)(const struct dirent64 *), int (*compar)()); int truncate64(const char *path, off64_t length); +int mkostemp64(char *template, int oflags); /* flags=AT_SYMLINK_NOFOLLOW */ int mkstemp64(char *template); /* flags=AT_SYMLINK_NOFOLLOW */ int getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups); int setgroups(size_t size, const gid_t *list); @@ -56,3 +61,6 @@ int getgrent_r(struct group *gbuf, char *buf, size_t buflen, struct group **gbuf int capset(cap_user_header_t hdrp, const cap_user_data_t datap); /* real_func=pseudo_capset */ long syscall(long nr, ...); /* hand_wrapped=1 */ int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags); /* flags=AT_SYMLINK_NOFOLLOW */ +int prctl(int option, ...); /* hand_wrapped=1 */ +int close_range(unsigned int lowfd, unsigned int maxfd, int flags); +void closefrom(int fd); diff --git a/ports/linux/xattr/guts/fgetxattr.c b/ports/linux/xattr/guts/fgetxattr.c index ae8c3a3..91a4bd6 100644 --- a/ports/linux/xattr/guts/fgetxattr.c +++ b/ports/linux/xattr/guts/fgetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/xattr/guts/flistxattr.c b/ports/linux/xattr/guts/flistxattr.c index cdd9454..aeb7e4e 100644 --- a/ports/linux/xattr/guts/flistxattr.c +++ b/ports/linux/xattr/guts/flistxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t flistxattr(int filedes, char *list, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/xattr/guts/fremovexattr.c b/ports/linux/xattr/guts/fremovexattr.c index a029d2c..e6c5b0d 100644 --- a/ports/linux/xattr/guts/fremovexattr.c +++ b/ports/linux/xattr/guts/fremovexattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fremovexattr(int filedes, const char *name) * int rc = -1; */ diff --git a/ports/linux/xattr/guts/fsetxattr.c b/ports/linux/xattr/guts/fsetxattr.c index 376cf08..679c1f6 100644 --- a/ports/linux/xattr/guts/fsetxattr.c +++ b/ports/linux/xattr/guts/fsetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fsetxattr(int filedes, const char *name, const void *value, size_t size, int xflags) * int rc = -1; */ diff --git a/ports/linux/xattr/guts/getxattr.c b/ports/linux/xattr/guts/getxattr.c index 7bd2bf5..20e7c72 100644 --- a/ports/linux/xattr/guts/getxattr.c +++ b/ports/linux/xattr/guts/getxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t getxattr(const char *path, const char *name, void *value, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/xattr/guts/lgetxattr.c b/ports/linux/xattr/guts/lgetxattr.c index 675d3da..f24771e 100644 --- a/ports/linux/xattr/guts/lgetxattr.c +++ b/ports/linux/xattr/guts/lgetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/xattr/guts/listxattr.c b/ports/linux/xattr/guts/listxattr.c index 0decf71..ac733b2 100644 --- a/ports/linux/xattr/guts/listxattr.c +++ b/ports/linux/xattr/guts/listxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t listxattr(const char *path, char *list, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/xattr/guts/llistxattr.c b/ports/linux/xattr/guts/llistxattr.c index 9934256..42bbf10 100644 --- a/ports/linux/xattr/guts/llistxattr.c +++ b/ports/linux/xattr/guts/llistxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * ssize_t llistxattr(const char *path, char *list, size_t size) * ssize_t rc = -1; */ diff --git a/ports/linux/xattr/guts/lremovexattr.c b/ports/linux/xattr/guts/lremovexattr.c index 1f39788..38c83dc 100644 --- a/ports/linux/xattr/guts/lremovexattr.c +++ b/ports/linux/xattr/guts/lremovexattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int lremovexattr(const char *path, const char *name) * int rc = -1; */ diff --git a/ports/linux/xattr/guts/lsetxattr.c b/ports/linux/xattr/guts/lsetxattr.c index 9fe35bc..8eeec75 100644 --- a/ports/linux/xattr/guts/lsetxattr.c +++ b/ports/linux/xattr/guts/lsetxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int lsetxattr(const char *path, const char *name, const void *value, size_t size, int xflags) * int rc = -1; */ diff --git a/ports/linux/xattr/guts/removexattr.c b/ports/linux/xattr/guts/removexattr.c index 0d4d8e3..2b5719f 100644 --- a/ports/linux/xattr/guts/removexattr.c +++ b/ports/linux/xattr/guts/removexattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int removexattr(const char *path, const char *name) * int rc = -1; */ diff --git a/ports/linux/xattr/guts/setxattr.c b/ports/linux/xattr/guts/setxattr.c index bace0d8..ba318ee 100644 --- a/ports/linux/xattr/guts/setxattr.c +++ b/ports/linux/xattr/guts/setxattr.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int setxattr(const char *path, const char *name, const void *value, size_t size, int xflags) * int rc = -1; */ diff --git a/ports/linux/xattr/portdefs.h b/ports/linux/xattr/portdefs.h index 367ca60..beab7d0 100644 --- a/ports/linux/xattr/portdefs.h +++ b/ports/linux/xattr/portdefs.h @@ -1,2 +1,10 @@ -#include <attr/xattr.h> +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ +#include <sys/xattr.h> #include <stdint.h> + +#ifndef ENOATTR +#define ENOATTR ENODATA +#endif diff --git a/ports/linux/xattr/pseudo_wrappers.c b/ports/linux/xattr/pseudo_wrappers.c index 1c228a2..0b65920 100644 --- a/ports/linux/xattr/pseudo_wrappers.c +++ b/ports/linux/xattr/pseudo_wrappers.c @@ -1,3 +1,7 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ /* shared functionality for the xattr code */ /* Each of these functions is expecting to get an optional name, and * a populated statbuf to use for sending messages to the server. @@ -130,7 +134,7 @@ static ssize_t shared_getxattr(const char *path, int fd, const char *name, void pseudo_debug(PDBGF_XATTR, "getxattr(%s [fd %d], %s)\n", path ? path : "<no path>", fd, name); pseudo_msg_t *result = pseudo_client_op(OP_GET_XATTR, 0, fd, -1, path, &buf, name); - if (result->result != RESULT_SUCCEED) { + if (!result || result->result != RESULT_SUCCEED) { errno = ENOATTR; return -1; } @@ -193,7 +197,7 @@ static int shared_setxattr(const char *path, int fd, const char *name, const voi mode |= get_special_bits(path, fd); pseudo_debug(PDBGF_XATTR, "posix_acl_access translated to mode %04o. Remaining attribute(s): %d.\n", mode, extra); - buf.st_mode = mode; + /* we want to actually issue a corresponding chmod, * as well, or else the file ends up 0600 on the * host. Using the slightly-less-efficient wrap_chmod @@ -250,7 +254,7 @@ static int shared_setxattr(const char *path, int fd, const char *name, const voi static ssize_t shared_listxattr(const char *path, int fd, char *list, size_t size) { RC_AND_BUF pseudo_msg_t *result = pseudo_client_op(OP_LIST_XATTR, 0, fd, -1, path, &buf); - if (result->result != RESULT_SUCCEED) { + if (!result || result->result != RESULT_SUCCEED) { pseudo_debug(PDBGF_XATTR, "listxattr: no success.\n"); errno = ENOATTR; return -1; @@ -272,7 +276,7 @@ static int shared_removexattr(const char *path, int fd, const char *name) { RC_AND_BUF pseudo_msg_t *result = pseudo_client_op(OP_REMOVE_XATTR, 0, fd, -1, path, &buf, name); - if (result->result != RESULT_SUCCEED) { + if (!result || result->result != RESULT_SUCCEED) { /* docs say ENOATTR, but I don't have one */ errno = ENOENT; return -1; diff --git a/ports/linux/xattr/wrapfuncs.in b/ports/linux/xattr/wrapfuncs.in index c37f78a..09eba23 100644 --- a/ports/linux/xattr/wrapfuncs.in +++ b/ports/linux/xattr/wrapfuncs.in @@ -1,12 +1,12 @@ -ssize_t getxattr(const char *path, const char *name, void *value, size_t size); /* flags=0 */ -ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size); /* flags=AT_SYMLINK_NOFOLLOW */ -ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size); -int setxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=0 */ -int lsetxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=AT_SYMLINK_NOFOLLOW */ -int fsetxattr(int filedes, const char *name, const void *value, size_t size, int xflags); -ssize_t listxattr(const char *path, char *list, size_t size); /* flags=0 */ -ssize_t llistxattr(const char *path, char *list, size_t size); /* flags=AT_SYMLINK_NOFOLLOW */ -ssize_t flistxattr(int filedes, char *list, size_t size); -int removexattr(const char *path, const char *name); /* flags=0 */ -int lremovexattr(const char *path, const char *name); /* flags=AT_SYMLINK_NOFOLLOW */ -int fremovexattr(int filedes, const char *name); +ssize_t getxattr(const char *path, const char *name, void *value, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int setxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int lsetxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int fsetxattr(int filedes, const char *name, const void *value, size_t size, int xflags); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +ssize_t listxattr(const char *path, char *list, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +ssize_t llistxattr(const char *path, char *list, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +ssize_t flistxattr(int filedes, char *list, size_t size); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int removexattr(const char *path, const char *name); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int lremovexattr(const char *path, const char *name); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int fremovexattr(int filedes, const char *name); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ diff --git a/ports/uids_generic/guts/COPYRIGHT b/ports/uids_generic/guts/COPYRIGHT index c96e1b1..b860a36 100644 --- a/ports/uids_generic/guts/COPYRIGHT +++ b/ports/uids_generic/guts/COPYRIGHT @@ -1,17 +1,6 @@ /* * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ diff --git a/ports/uids_generic/guts/endgrent.c b/ports/uids_generic/guts/endgrent.c index 843cad0..8ddbb99 100644 --- a/ports/uids_generic/guts/endgrent.c +++ b/ports/uids_generic/guts/endgrent.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static void * wrap_endgrent(void) { * diff --git a/ports/uids_generic/guts/endpwent.c b/ports/uids_generic/guts/endpwent.c index f76cf10..92947ea 100644 --- a/ports/uids_generic/guts/endpwent.c +++ b/ports/uids_generic/guts/endpwent.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static void * wrap_endpwent(void) { * diff --git a/ports/uids_generic/guts/getegid.c b/ports/uids_generic/guts/getegid.c index 7c14f48..56e9d44 100644 --- a/ports/uids_generic/guts/getegid.c +++ b/ports/uids_generic/guts/getegid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static gid_t * wrap_getegid(void) { * gid_t rc = 0; diff --git a/ports/uids_generic/guts/geteuid.c b/ports/uids_generic/guts/geteuid.c index 1745e13..276a51d 100644 --- a/ports/uids_generic/guts/geteuid.c +++ b/ports/uids_generic/guts/geteuid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static uid_t * wrap_geteuid(void) { * uid_t rc = 0; diff --git a/ports/uids_generic/guts/getgid.c b/ports/uids_generic/guts/getgid.c index ca8bad3..43e18d0 100644 --- a/ports/uids_generic/guts/getgid.c +++ b/ports/uids_generic/guts/getgid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static gid_t * wrap_getgid(void) { * gid_t rc = 0; diff --git a/ports/uids_generic/guts/getgrent.c b/ports/uids_generic/guts/getgrent.c index d6592e6..ff0051b 100644 --- a/ports/uids_generic/guts/getgrent.c +++ b/ports/uids_generic/guts/getgrent.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static struct group * * wrap_getgrent(void) { * struct group * rc = NULL; diff --git a/ports/uids_generic/guts/getgrgid.c b/ports/uids_generic/guts/getgrgid.c index 0d3dafb..29af413 100644 --- a/ports/uids_generic/guts/getgrgid.c +++ b/ports/uids_generic/guts/getgrgid.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static struct group * * wrap_getgrgid(gid_t gid) { * struct group * rc = NULL; diff --git a/ports/uids_generic/guts/getgrgid_r.c b/ports/uids_generic/guts/getgrgid_r.c index b043995..0c5ae44 100644 --- a/ports/uids_generic/guts/getgrgid_r.c +++ b/ports/uids_generic/guts/getgrgid_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getgrgid_r(gid_t gid, struct group *gbuf, char *buf, size_t buflen, struct group **gbufp) { * int rc = -1; diff --git a/ports/uids_generic/guts/getgrnam.c b/ports/uids_generic/guts/getgrnam.c index 19006ad..7644e3a 100644 --- a/ports/uids_generic/guts/getgrnam.c +++ b/ports/uids_generic/guts/getgrnam.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static struct group * * wrap_getgrnam(const char *name) { * struct group * rc = NULL; diff --git a/ports/uids_generic/guts/getgrnam_r.c b/ports/uids_generic/guts/getgrnam_r.c index 39de641..e2196ef 100644 --- a/ports/uids_generic/guts/getgrnam_r.c +++ b/ports/uids_generic/guts/getgrnam_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getgrnam_r(const char *name, struct group *gbuf, char *buf, size_t buflen, struct group **gbufp) { * int rc = -1; diff --git a/ports/uids_generic/guts/getpwent.c b/ports/uids_generic/guts/getpwent.c index 3b1f837..a860e7e 100644 --- a/ports/uids_generic/guts/getpwent.c +++ b/ports/uids_generic/guts/getpwent.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static struct passwd * * wrap_getpwent(void) { * struct passwd * rc = NULL; diff --git a/ports/uids_generic/guts/getpwnam.c b/ports/uids_generic/guts/getpwnam.c index 024b3d8..0f99038 100644 --- a/ports/uids_generic/guts/getpwnam.c +++ b/ports/uids_generic/guts/getpwnam.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static struct passwd * * wrap_getpwnam(const char *name) { * struct passwd * rc = NULL; diff --git a/ports/uids_generic/guts/getpwnam_r.c b/ports/uids_generic/guts/getpwnam_r.c index 5d7a4ea..cb9f2c6 100644 --- a/ports/uids_generic/guts/getpwnam_r.c +++ b/ports/uids_generic/guts/getpwnam_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getpwnam_r(const char *name, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) { * int rc = -1; diff --git a/ports/uids_generic/guts/getpwuid.c b/ports/uids_generic/guts/getpwuid.c index 11142de..315647c 100644 --- a/ports/uids_generic/guts/getpwuid.c +++ b/ports/uids_generic/guts/getpwuid.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static struct passwd * * wrap_getpwuid(uid_t uid) { * struct passwd * rc = NULL; diff --git a/ports/uids_generic/guts/getpwuid_r.c b/ports/uids_generic/guts/getpwuid_r.c index 06b920e..bfeb649 100644 --- a/ports/uids_generic/guts/getpwuid_r.c +++ b/ports/uids_generic/guts/getpwuid_r.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_getpwuid_r(uid_t uid, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) { * int rc = -1; diff --git a/ports/uids_generic/guts/getuid.c b/ports/uids_generic/guts/getuid.c index e783cc8..3945836 100644 --- a/ports/uids_generic/guts/getuid.c +++ b/ports/uids_generic/guts/getuid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static uid_t * wrap_getuid(void) { * uid_t rc = 0; diff --git a/ports/uids_generic/guts/setegid.c b/ports/uids_generic/guts/setegid.c index ff777a0..d6ddca7 100644 --- a/ports/uids_generic/guts/setegid.c +++ b/ports/uids_generic/guts/setegid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setegid(gid_t egid) { * int rc = -1; diff --git a/ports/uids_generic/guts/seteuid.c b/ports/uids_generic/guts/seteuid.c index 430768f..032e5f1 100644 --- a/ports/uids_generic/guts/seteuid.c +++ b/ports/uids_generic/guts/seteuid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_seteuid(uid_t euid) { * int rc = -1; diff --git a/ports/uids_generic/guts/setgid.c b/ports/uids_generic/guts/setgid.c index b94db1a..c5746f9 100644 --- a/ports/uids_generic/guts/setgid.c +++ b/ports/uids_generic/guts/setgid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setgid(gid_t gid) { * int rc = -1; diff --git a/ports/uids_generic/guts/setgrent.c b/ports/uids_generic/guts/setgrent.c index 75aab61..97faec0 100644 --- a/ports/uids_generic/guts/setgrent.c +++ b/ports/uids_generic/guts/setgrent.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static void * wrap_setgrent(void) { * diff --git a/ports/uids_generic/guts/setpwent.c b/ports/uids_generic/guts/setpwent.c index fb35e07..53661fd 100644 --- a/ports/uids_generic/guts/setpwent.c +++ b/ports/uids_generic/guts/setpwent.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static void * wrap_setpwent(void) { * diff --git a/ports/uids_generic/guts/setregid.c b/ports/uids_generic/guts/setregid.c index 78b2037..865553f 100644 --- a/ports/uids_generic/guts/setregid.c +++ b/ports/uids_generic/guts/setregid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setregid(gid_t rgid, gid_t egid) { * int rc = -1; diff --git a/ports/uids_generic/guts/setreuid.c b/ports/uids_generic/guts/setreuid.c index 3ff82ab..d189d65 100644 --- a/ports/uids_generic/guts/setreuid.c +++ b/ports/uids_generic/guts/setreuid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setreuid(uid_t ruid, uid_t euid) { * int rc = -1; diff --git a/ports/uids_generic/guts/setuid.c b/ports/uids_generic/guts/setuid.c index 6bfdf6c..831f8ff 100644 --- a/ports/uids_generic/guts/setuid.c +++ b/ports/uids_generic/guts/setuid.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_setuid(uid_t uid) { * int rc = -1; diff --git a/ports/unix/guts/COPYRIGHT b/ports/unix/guts/COPYRIGHT index c96e1b1..b860a36 100644 --- a/ports/unix/guts/COPYRIGHT +++ b/ports/unix/guts/COPYRIGHT @@ -1,17 +1,6 @@ /* * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ diff --git a/ports/unix/guts/access.c b/ports/unix/guts/access.c index 0093a3b..4725f49 100644 --- a/ports/unix/guts/access.c +++ b/ports/unix/guts/access.c @@ -2,6 +2,8 @@ * Copyright (c) 2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_access(const char *path, int mode) { * int rc = -1; @@ -19,7 +21,7 @@ if (buf.st_mode & 0111) { return 0; } else { - errno = EPERM; + errno = EACCES; return -1; } } else { diff --git a/ports/unix/guts/acct.c b/ports/unix/guts/acct.c index b8dca5d..4acd3fb 100644 --- a/ports/unix/guts/acct.c +++ b/ports/unix/guts/acct.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_acct(const char *path) { * int rc = -1; diff --git a/ports/unix/guts/bind.c b/ports/unix/guts/bind.c index 46164be..6f8a1d2 100644 --- a/ports/unix/guts/bind.c +++ b/ports/unix/guts/bind.c @@ -2,6 +2,8 @@ * Copyright (c) 2016 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) * int rc = -1; */ diff --git a/ports/unix/guts/chdir.c b/ports/unix/guts/chdir.c index 9e30348..d796c2e 100644 --- a/ports/unix/guts/chdir.c +++ b/ports/unix/guts/chdir.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_chdir(const char *path) { * int rc = -1; diff --git a/ports/unix/guts/chmod.c b/ports/unix/guts/chmod.c index a157335..77a5c9a 100644 --- a/ports/unix/guts/chmod.c +++ b/ports/unix/guts/chmod.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_chmod(const char *path, mode_t mode) { * int rc = -1; diff --git a/ports/unix/guts/chown.c b/ports/unix/guts/chown.c index 4fcbdda..69bef79 100644 --- a/ports/unix/guts/chown.c +++ b/ports/unix/guts/chown.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_chown(const char *path, uid_t owner, gid_t group) { * int rc = -1; diff --git a/ports/unix/guts/chroot.c b/ports/unix/guts/chroot.c index ac24955..62d5e88 100644 --- a/ports/unix/guts/chroot.c +++ b/ports/unix/guts/chroot.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_chroot(const char *path) { * int rc = -1; diff --git a/ports/unix/guts/close.c b/ports/unix/guts/close.c index 09c73e6..2f1c385 100644 --- a/ports/unix/guts/close.c +++ b/ports/unix/guts/close.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_close(int fd) { * int rc = -1; diff --git a/ports/unix/guts/closedir.c b/ports/unix/guts/closedir.c index 1085361..32c008f 100644 --- a/ports/unix/guts/closedir.c +++ b/ports/unix/guts/closedir.c @@ -2,6 +2,8 @@ * Copyright (c) 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_closedir(DIR *dirp) { * int rc = -1; diff --git a/ports/unix/guts/creat.c b/ports/unix/guts/creat.c index 8593cd4..7aaf735 100644 --- a/ports/unix/guts/creat.c +++ b/ports/unix/guts/creat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_creat(const char *path, mode_t mode) { * int rc = -1; diff --git a/ports/unix/guts/dup.c b/ports/unix/guts/dup.c index 927b264..be8626a 100644 --- a/ports/unix/guts/dup.c +++ b/ports/unix/guts/dup.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_dup(int fd) { * int rc = -1; diff --git a/ports/unix/guts/dup2.c b/ports/unix/guts/dup2.c index 8180039..0b20f01 100644 --- a/ports/unix/guts/dup2.c +++ b/ports/unix/guts/dup2.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_dup2(int oldfd, int newfd) { * int rc = -1; diff --git a/ports/unix/guts/faccessat.c b/ports/unix/guts/faccessat.c new file mode 100644 index 0000000..02515ee --- /dev/null +++ b/ports/unix/guts/faccessat.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021, Linux Foundation; see + * guts/COPYRIGHT for information. + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * static int + * wrap_fsaccessat(int dirfd, const char *path, int mode, int flags) { + * int rc = -1; + */ + rc = wrap_faccessat2(dirfd, path, mode, flags); + +/* return rc; + * } + */ diff --git a/ports/unix/guts/faccessat2.c b/ports/unix/guts/faccessat2.c new file mode 100644 index 0000000..1283cc6 --- /dev/null +++ b/ports/unix/guts/faccessat2.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021, Linux Foundation; see + * guts/COPYRIGHT for information. + * + * SPDX-License-Identifier: LGPL-2.1-only + * + * static int + * wrap_fsaccessat2(int dirfd, const char *path, int mode, int flags) { + * int rc = -1; + */ + PSEUDO_STATBUF buf; + +#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS + if (dirfd != AT_FDCWD) { + errno = ENOSYS; + return -1; + } + if (flags & AT_SYMLINK_NOFOLLOW) { + rc = base_lstat(path, &buf); + } else { + rc = base_stat(path, &buf); + } +#else + rc = base_fstatat(dirfd, path, &buf, flags & AT_SYMLINK_NOFOLLOW); +#endif + if (rc == -1) + return rc; + + /* note: no attempt to handle the case where user isn't + * root. + */ + + if (mode & X_OK) { + if (buf.st_mode & 0111) { + return 0; + } else { + errno = EACCES; + return -1; + } + } else { + return 0; + } + +/* return rc; + * } + */ diff --git a/ports/unix/guts/fchdir.c b/ports/unix/guts/fchdir.c index ba77ebf..cace897 100644 --- a/ports/unix/guts/fchdir.c +++ b/ports/unix/guts/fchdir.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_fchdir(int dirfd) { * int rc = -1; diff --git a/ports/unix/guts/fchmod.c b/ports/unix/guts/fchmod.c index e2301e3..4d2d127 100644 --- a/ports/unix/guts/fchmod.c +++ b/ports/unix/guts/fchmod.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012, 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_fchmod(int fd, mode_t mode) { * int rc = -1; diff --git a/ports/unix/guts/fchmodat.c b/ports/unix/guts/fchmodat.c index 0506794..5a31151 100644 --- a/ports/unix/guts/fchmodat.c +++ b/ports/unix/guts/fchmodat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012, 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_fchmodat(int dirfd, const char *path, mode_t mode, int flags) { * int rc = -1; @@ -9,16 +11,16 @@ PSEUDO_STATBUF buf; int save_errno = errno; - if (flags & AT_SYMLINK_NOFOLLOW) { - errno = ENOTSUP; - return -1; - } #ifdef PSEUDO_NO_REAL_AT_FUNCTIONS if (dirfd != AT_FDCWD) { errno = ENOSYS; return -1; } - rc = base_stat(path, &buf); + if (flags & AT_SYMLINK_NOFOLLOW) { + rc = base_lstat(path, &buf); + } else { + rc = base_stat(path, &buf); + } #else rc = base_fstatat(dirfd, path, &buf, flags); #endif @@ -26,9 +28,8 @@ return rc; } if (S_ISLNK(buf.st_mode)) { - /* we don't really support chmod of a symlink */ - errno = ENOSYS; - return -1; + /* according to docs, "chmod on a symbolic link always succeeds and has no effect" */ + return 0; } save_errno = errno; diff --git a/ports/unix/guts/fchown.c b/ports/unix/guts/fchown.c index 89cabe2..fb3343d 100644 --- a/ports/unix/guts/fchown.c +++ b/ports/unix/guts/fchown.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012, 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_fchown(int fd, uid_t owner, gid_t group) { * int rc = -1; diff --git a/ports/unix/guts/fchownat.c b/ports/unix/guts/fchownat.c index 2888087..76d276a 100644 --- a/ports/unix/guts/fchownat.c +++ b/ports/unix/guts/fchownat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012, 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_fchownat(int dirfd, const char *path, uid_t owner, gid_t group, int flags) { * int rc = -1; diff --git a/ports/unix/guts/fclose.c b/ports/unix/guts/fclose.c index 4469f5b..15d0f85 100644 --- a/ports/unix/guts/fclose.c +++ b/ports/unix/guts/fclose.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_fclose(FILE *fp) { * int rc = -1; diff --git a/ports/unix/guts/fdatasync.c b/ports/unix/guts/fdatasync.c index 4aa77a8..594ad8f 100644 --- a/ports/unix/guts/fdatasync.c +++ b/ports/unix/guts/fdatasync.c @@ -2,6 +2,8 @@ * Copyright (c) 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fdatasync(int fd) * int rc = -1; */ diff --git a/ports/unix/guts/fopen.c b/ports/unix/guts/fopen.c index 87c7d78..26a6abc 100644 --- a/ports/unix/guts/fopen.c +++ b/ports/unix/guts/fopen.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static FILE * * wrap_fopen(const char *path, const char *mode) { * FILE * rc = 0; diff --git a/ports/unix/guts/freopen.c b/ports/unix/guts/freopen.c index e706d9f..703b6aa 100644 --- a/ports/unix/guts/freopen.c +++ b/ports/unix/guts/freopen.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static FILE * * wrap_freopen(const char *path, const char *mode, FILE *stream) { * FILE * rc = NULL; diff --git a/ports/unix/guts/fsync.c b/ports/unix/guts/fsync.c index 6c87a56..c78f43c 100644 --- a/ports/unix/guts/fsync.c +++ b/ports/unix/guts/fsync.c @@ -2,6 +2,8 @@ * Copyright (c) 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int fsync(int fd) * int rc = -1; */ diff --git a/ports/unix/guts/fts_open.c b/ports/unix/guts/fts_open.c index 964314e..e5b27ba 100644 --- a/ports/unix/guts/fts_open.c +++ b/ports/unix/guts/fts_open.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static FTS * * wrap_fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **)) { * FTS * rc = NULL; diff --git a/ports/unix/guts/ftw.c b/ports/unix/guts/ftw.c index 0861194..58945a1 100644 --- a/ports/unix/guts/ftw.c +++ b/ports/unix/guts/ftw.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int nopenfd) { * int rc = -1; diff --git a/ports/unix/guts/getcwd.c b/ports/unix/guts/getcwd.c index 2915a18..a5bf2ef 100644 --- a/ports/unix/guts/getcwd.c +++ b/ports/unix/guts/getcwd.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static char * * wrap_getcwd(char *buf, size_t size) { * char * rc = NULL; diff --git a/ports/unix/guts/getwd.c b/ports/unix/guts/getwd.c index b1bcf90..bc99f93 100644 --- a/ports/unix/guts/getwd.c +++ b/ports/unix/guts/getwd.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static char * * wrap_getwd(char *buf) { * char * rc = NULL; diff --git a/ports/unix/guts/glob.c b/ports/unix/guts/glob.c index 0012179..8c17123 100644 --- a/ports/unix/guts/glob.c +++ b/ports/unix/guts/glob.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) { * int rc = -1; diff --git a/ports/unix/guts/lchown.c b/ports/unix/guts/lchown.c index 60727d0..3a14e2f 100644 --- a/ports/unix/guts/lchown.c +++ b/ports/unix/guts/lchown.c @@ -2,6 +2,8 @@ * Copyright (c) 2008,2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int lchown(const char *path, uid_t owner, gid_t group) * int rc = -1; */ diff --git a/ports/unix/guts/link.c b/ports/unix/guts/link.c index 3b340ee..1e03902 100644 --- a/ports/unix/guts/link.c +++ b/ports/unix/guts/link.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012, 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_link(const char *oldname, const char *newname) { * int rc = -1; diff --git a/ports/unix/guts/linkat.c b/ports/unix/guts/linkat.c index 279a15b..7d8dff4 100644 --- a/ports/unix/guts/linkat.c +++ b/ports/unix/guts/linkat.c @@ -2,6 +2,8 @@ * Copyright (c) 2012, 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int linkat(int olddirfd, const char *oldname, int newdirfd, const char *newname, int flags) * int rc = -1; */ @@ -114,6 +116,7 @@ * if the thing linked is a symlink. */ pseudo_client_op(OP_LINK, 0, -1, -1, newpath, &buf); + pseudo_client_linked_paths(oldpath, newpath); errno = save_errno; diff --git a/ports/unix/guts/lutimes.c b/ports/unix/guts/lutimes.c index cdadbbd..07cab66 100644 --- a/ports/unix/guts/lutimes.c +++ b/ports/unix/guts/lutimes.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_lutimes(const char *path, const struct timeval *tv) { * int rc = -1; diff --git a/ports/unix/guts/mkdir.c b/ports/unix/guts/mkdir.c index 9f116e2..2eaf81b 100644 --- a/ports/unix/guts/mkdir.c +++ b/ports/unix/guts/mkdir.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_mkdir(const char *path, mode_t mode) { * int rc = -1; diff --git a/ports/unix/guts/mkdirat.c b/ports/unix/guts/mkdirat.c index ef2e3a1..f66e99a 100644 --- a/ports/unix/guts/mkdirat.c +++ b/ports/unix/guts/mkdirat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_mkdirat(int dirfd, const char *path, mode_t mode) { * int rc = -1; diff --git a/ports/unix/guts/mkdtemp.c b/ports/unix/guts/mkdtemp.c index 5337661..61cd11c 100644 --- a/ports/unix/guts/mkdtemp.c +++ b/ports/unix/guts/mkdtemp.c @@ -2,6 +2,8 @@ * Copyright (c) 2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static char * * wrap_mkdtemp(char *template) { * char * rc = NULL; diff --git a/ports/unix/guts/mkfifo.c b/ports/unix/guts/mkfifo.c index 32f79fb..81d9c0c 100644 --- a/ports/unix/guts/mkfifo.c +++ b/ports/unix/guts/mkfifo.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_mkfifo(const char *path, mode_t mode) { * int rc = -1; diff --git a/ports/unix/guts/mkfifoat.c b/ports/unix/guts/mkfifoat.c index 6947e70..bc547eb 100644 --- a/ports/unix/guts/mkfifoat.c +++ b/ports/unix/guts/mkfifoat.c @@ -2,6 +2,8 @@ * Copyright (c) 2015 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_mkfifoat(int dirfd, const char *path, mode_t mode) { * int rc = -1; diff --git a/ports/unix/guts/mknod.c b/ports/unix/guts/mknod.c index eeca65d..aff3a0b 100644 --- a/ports/unix/guts/mknod.c +++ b/ports/unix/guts/mknod.c @@ -2,6 +2,8 @@ * Copyright (c) 2011,2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int mknod(const char *path, mode_t mode, dev_t dev) * int rc = -1; */ diff --git a/ports/unix/guts/mknodat.c b/ports/unix/guts/mknodat.c index afeab46..9e86c93 100644 --- a/ports/unix/guts/mknodat.c +++ b/ports/unix/guts/mknodat.c @@ -2,6 +2,8 @@ * Copyright (c) 2011 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev) * int rc = -1; */ diff --git a/ports/unix/guts/mkostemp.c b/ports/unix/guts/mkostemp.c index bce0939..199ff20 100644 --- a/ports/unix/guts/mkostemp.c +++ b/ports/unix/guts/mkostemp.c @@ -2,6 +2,8 @@ * Copyright (c) 2018 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int mkostemp(char *template, int oflags) * int rc = -1; */ diff --git a/ports/unix/guts/mkostemps.c b/ports/unix/guts/mkostemps.c index 27ada46..013757d 100644 --- a/ports/unix/guts/mkostemps.c +++ b/ports/unix/guts/mkostemps.c @@ -5,6 +5,8 @@ * Copyright (c) 2018 Peter Seebach; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int mkostemps(char *template, int suffixlen, int oflags) * int rc = -1; */ diff --git a/ports/unix/guts/mkstemp.c b/ports/unix/guts/mkstemp.c index 8fab58b..0aab6ed 100644 --- a/ports/unix/guts/mkstemp.c +++ b/ports/unix/guts/mkstemp.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_mkstemp(char *template) { * int rc = -1; diff --git a/ports/unix/guts/mkstemps.c b/ports/unix/guts/mkstemps.c index 95b3b83..5b16457 100644 --- a/ports/unix/guts/mkstemps.c +++ b/ports/unix/guts/mkstemps.c @@ -2,6 +2,8 @@ * Copyright (c) 2018 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int mkstemps(char *template, int suffixlen) * int rc = -1; */ diff --git a/ports/unix/guts/mktemp.c b/ports/unix/guts/mktemp.c index a39d1b7..9aee829 100644 --- a/ports/unix/guts/mktemp.c +++ b/ports/unix/guts/mktemp.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static char * * wrap_mktemp(char *template) { * char * rc = NULL; diff --git a/ports/unix/guts/msync.c b/ports/unix/guts/msync.c index fbc5e26..926ab50 100644 --- a/ports/unix/guts/msync.c +++ b/ports/unix/guts/msync.c @@ -2,6 +2,8 @@ * Copyright (c) 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int msync(void *addr, size_t length, int flags) * int rc = -1; */ diff --git a/ports/unix/guts/nftw.c b/ports/unix/guts/nftw.c index 73daec8..dac3106 100644 --- a/ports/unix/guts/nftw.c +++ b/ports/unix/guts/nftw.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_nftw(const char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int nopenfd, int flag) { * int rc = -1; diff --git a/ports/unix/guts/opendir.c b/ports/unix/guts/opendir.c index c8a78f8..5d6f1f2 100644 --- a/ports/unix/guts/opendir.c +++ b/ports/unix/guts/opendir.c @@ -2,6 +2,8 @@ * Copyright (c) 2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static DIR * * wrap_opendir(const char *path) { * DIR * rc = NULL; diff --git a/ports/unix/guts/pathconf.c b/ports/unix/guts/pathconf.c index c6caa34..9300595 100644 --- a/ports/unix/guts/pathconf.c +++ b/ports/unix/guts/pathconf.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static long * wrap_pathconf(const char *path, int name) { * long rc = -1; diff --git a/ports/unix/guts/popen.c b/ports/unix/guts/popen.c index 5d44c0e..d19ec7e 100644 --- a/ports/unix/guts/popen.c +++ b/ports/unix/guts/popen.c @@ -2,6 +2,8 @@ * Copyright (c) 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * FILE *popen(const char *command, const char *mode) * FILE *rc = NULL; */ diff --git a/ports/unix/guts/readlink.c b/ports/unix/guts/readlink.c index 18d9dc7..4b3d492 100644 --- a/ports/unix/guts/readlink.c +++ b/ports/unix/guts/readlink.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static ssize_t * wrap_readlink(const char *path, char *buf, size_t bufsiz) { * ssize_t rc = -1; diff --git a/ports/unix/guts/readlinkat.c b/ports/unix/guts/readlinkat.c index 5282e2b..86832da 100644 --- a/ports/unix/guts/readlinkat.c +++ b/ports/unix/guts/readlinkat.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static ssize_t * wrap_readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz) { * ssize_t rc = -1; diff --git a/ports/unix/guts/realpath.c b/ports/unix/guts/realpath.c index a59808d..8d8118b 100644 --- a/ports/unix/guts/realpath.c +++ b/ports/unix/guts/realpath.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static char * * wrap_realpath(const char *name, char *resolved_name) { * char * rc = NULL; @@ -12,7 +14,14 @@ errno = ENAMETOOLONG; return NULL; } - if ((len = strlen(rname)) >= pseudo_sys_path_max()) { + len = strlen(rname); + char *ep = rname + len - 1; + while (ep > rname && *ep == '/') { + --len; + *(ep--) = '\0'; + } + + if (len >= pseudo_sys_path_max()) { errno = ENAMETOOLONG; return NULL; } diff --git a/ports/unix/guts/remove.c b/ports/unix/guts/remove.c index 4e2cecb..375e648 100644 --- a/ports/unix/guts/remove.c +++ b/ports/unix/guts/remove.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_remove(const char *path) { * int rc = -1; diff --git a/ports/unix/guts/rename.c b/ports/unix/guts/rename.c index b8ee8b0..80bbf41 100644 --- a/ports/unix/guts/rename.c +++ b/ports/unix/guts/rename.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_rename(const char *oldpath, const char *newpath) { * int rc = -1; @@ -11,7 +13,8 @@ int oldrc, newrc; int save_errno; int old_db_entry = 0; - int may_unlinked = 0; + int may_unlink_new = 0; + int may_unlink_old = 0; pseudo_debug(PDBGF_OP, "rename: %s->%s\n", oldpath ? oldpath : "<nil>", @@ -27,41 +30,51 @@ newrc = base_lstat(newpath, &newbuf); oldrc = base_lstat(oldpath, &oldbuf); + /* nothing to do for a "rename" of a link to itself */ + if (newrc != -1 && oldrc != -1 && + newbuf.st_dev == oldbuf.st_dev && + newbuf.st_ino == oldbuf.st_ino) { + pseudo_debug(PDBGF_OP, "rename: paths are the same\n"); + return real_rename(oldpath, newpath); + } + errno = save_errno; /* newpath must be removed. */ /* as with unlink, we have to mark that the file may get deleted */ msg = pseudo_client_op(OP_MAY_UNLINK, 0, -1, -1, newpath, newrc ? NULL : &newbuf); if (msg && msg->result == RESULT_SUCCEED) - may_unlinked = 1; + may_unlink_new = 1; + /* oldpath is also likely to disappear. Something could call stat() after + real_rename so we need to mark as MAY_UNLINK too */ + msg = pseudo_client_op(OP_MAY_UNLINK, 0, -1, -1, oldpath, oldrc ? NULL : &oldbuf); + if (msg && msg->result == RESULT_SUCCEED) + may_unlink_old = 1; + msg = pseudo_client_op(OP_STAT, 0, -1, -1, oldpath, oldrc ? NULL : &oldbuf); if (msg && msg->result == RESULT_SUCCEED) old_db_entry = 1; rc = real_rename(oldpath, newpath); save_errno = errno; - if (may_unlinked) { - if (rc == -1) { - /* since we failed, that wasn't really unlinked -- put - * it back. - */ - pseudo_client_op(OP_CANCEL_UNLINK, 0, -1, -1, newpath, &newbuf); - } else { - /* confirm that the file was removed */ - pseudo_client_op(OP_DID_UNLINK, 0, -1, -1, newpath, &newbuf); - } - } + if (rc == -1) { + /* since we failed, that wasn't really unlinked -- put + * it back. + */ + if (may_unlink_new) + pseudo_client_op(OP_CANCEL_UNLINK, 0, -1, -1, newpath, &newbuf); + if (may_unlink_old) + pseudo_client_op(OP_CANCEL_UNLINK, 0, -1, -1, oldpath, &oldbuf); /* and we're done. */ errno = save_errno; return rc; } + + /* confirm that the file was removed */ + if (may_unlink_new) + pseudo_client_op(OP_DID_UNLINK, 0, -1, -1, newpath, &newbuf); + /* OP_DID_UNLINK for oldpath is handled by the server */ save_errno = errno; - /* nothing to do for a "rename" of a link to itself */ - if (newrc != -1 && oldrc != -1 && - newbuf.st_dev == oldbuf.st_dev && - newbuf.st_ino == oldbuf.st_ino) { - return rc; - } /* rename(3) is not mv(1). rename(file, dir) fails; you must provide * the corrected path yourself. You can rename over a directory only diff --git a/ports/unix/guts/renameat.c b/ports/unix/guts/renameat.c index d5e36fa..5ac63f9 100644 --- a/ports/unix/guts/renameat.c +++ b/ports/unix/guts/renameat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) { * int rc = -1; @@ -11,7 +13,8 @@ int oldrc, newrc; int save_errno; int old_db_entry = 0; - int may_unlinked = 0; + int may_unlink_new = 0; + int may_unlink_old = 0; pseudo_debug(PDBGF_FILE, "renameat: %d,%s->%d,%s\n", olddirfd, oldpath ? oldpath : "<nil>", @@ -39,42 +42,51 @@ newrc = base_fstatat(newdirfd, newpath, &newbuf, AT_SYMLINK_NOFOLLOW); #endif + /* nothing to do for a "rename" of a link to itself */ + if (newrc != -1 && oldrc != -1 && + newbuf.st_dev == oldbuf.st_dev && + newbuf.st_ino == oldbuf.st_ino) { + pseudo_debug(PDBGF_OP, "renameat: paths are the same\n"); + return real_renameat(olddirfd, oldpath, newdirfd, newpath); + } + errno = save_errno; /* newpath must be removed. */ /* as with unlink, we have to mark that the file may get deleted */ msg = pseudo_client_op(OP_MAY_UNLINK, 0, -1, newdirfd, newpath, newrc ? NULL : &newbuf); if (msg && msg->result == RESULT_SUCCEED) - may_unlinked = 1; + may_unlink_new = 1; + /* oldpath is also likely to disappear. Something could call stat() after + real_rename so we need to mark as MAY_UNLINK too */ + msg = pseudo_client_op(OP_MAY_UNLINK, 0, -1, olddirfd, oldpath, oldrc ? NULL : &oldbuf); + if (msg && msg->result == RESULT_SUCCEED) + may_unlink_old = 1; + msg = pseudo_client_op(OP_STAT, 0, -1, olddirfd, oldpath, oldrc ? NULL : &oldbuf); if (msg && msg->result == RESULT_SUCCEED) old_db_entry = 1; rc = real_renameat(olddirfd, oldpath, newdirfd, newpath); save_errno = errno; - if (may_unlinked) { - if (rc == -1) { - /* since we failed, that wasn't really unlinked -- put - * it back. - */ - pseudo_client_op(OP_CANCEL_UNLINK, 0, -1, newdirfd, newpath, &newbuf); - } else { - /* confirm that the file was removed */ - pseudo_client_op(OP_DID_UNLINK, 0, -1, newdirfd, newpath, &newbuf); - } - } if (rc == -1) { + /* since we failed, that wasn't really unlinked -- put + * it back. + */ + if (may_unlink_new) + pseudo_client_op(OP_CANCEL_UNLINK, 0, -1, newdirfd, newpath, &newbuf); + if (may_unlink_old) + pseudo_client_op(OP_CANCEL_UNLINK, 0, -1, olddirfd, oldpath, &oldbuf); /* and we're done. */ errno = save_errno; return rc; } + + /* confirm that the file was removed */ + if (may_unlink_new) + pseudo_client_op(OP_DID_UNLINK, 0, -1, newdirfd, newpath, &newbuf); + /* OP_DID_UNLINK for oldpath is handled by the server */ save_errno = errno; - /* nothing to do for a "rename" of a link to itself */ - if (newrc != -1 && oldrc != -1 && - newbuf.st_dev == oldbuf.st_dev && - newbuf.st_ino == oldbuf.st_ino) { - return rc; - } /* rename(3) is not mv(1). rename(file, dir) fails; you must provide * the corrected path yourself. You can rename over a directory only diff --git a/ports/unix/guts/rmdir.c b/ports/unix/guts/rmdir.c index ebc522a..43fcecb 100644 --- a/ports/unix/guts/rmdir.c +++ b/ports/unix/guts/rmdir.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_rmdir(const char *path) { * int rc = -1; diff --git a/ports/unix/guts/symlink.c b/ports/unix/guts/symlink.c index 487c135..ce9fa1b 100644 --- a/ports/unix/guts/symlink.c +++ b/ports/unix/guts/symlink.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_symlink(const char *oldname, const char *newpath) { * int rc = -1; diff --git a/ports/unix/guts/symlinkat.c b/ports/unix/guts/symlinkat.c index 1346db1..c96ff3e 100644 --- a/ports/unix/guts/symlinkat.c +++ b/ports/unix/guts/symlinkat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_symlinkat(const char *oldname, int dirfd, const char *newpath) { * int rc = -1; diff --git a/ports/unix/guts/sync.c b/ports/unix/guts/sync.c index c5d9554..a6eca98 100644 --- a/ports/unix/guts/sync.c +++ b/ports/unix/guts/sync.c @@ -2,6 +2,8 @@ * Copyright (c) 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * void sync(void) * */ diff --git a/ports/unix/guts/sync_file_range.c b/ports/unix/guts/sync_file_range.c index 03cfc6c..7e03b7a 100644 --- a/ports/unix/guts/sync_file_range.c +++ b/ports/unix/guts/sync_file_range.c @@ -2,6 +2,8 @@ * Copyright (c) 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags) * int rc = -1; */ diff --git a/ports/unix/guts/system.c b/ports/unix/guts/system.c index 6351592..1214314 100644 --- a/ports/unix/guts/system.c +++ b/ports/unix/guts/system.c @@ -2,6 +2,8 @@ * Copyright (c) 2011, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int system(const char *command) * int rc = -1; */ diff --git a/ports/unix/guts/tempnam.c b/ports/unix/guts/tempnam.c index 9b0257f..26ae3e1 100644 --- a/ports/unix/guts/tempnam.c +++ b/ports/unix/guts/tempnam.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static char * * wrap_tempnam(const char *template, const char *pfx) { * char * rc = NULL; diff --git a/ports/unix/guts/tmpnam.c b/ports/unix/guts/tmpnam.c index 3fece57..190d260 100644 --- a/ports/unix/guts/tmpnam.c +++ b/ports/unix/guts/tmpnam.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static char * * wrap_tmpnam(char *s) { * char * rc = NULL; diff --git a/ports/unix/guts/truncate.c b/ports/unix/guts/truncate.c index 6a19a50..6a51105 100644 --- a/ports/unix/guts/truncate.c +++ b/ports/unix/guts/truncate.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_truncate(const char *path, off_t length) { * int rc = -1; diff --git a/ports/unix/guts/umask.c b/ports/unix/guts/umask.c index 6b060d3..df1fbb3 100644 --- a/ports/unix/guts/umask.c +++ b/ports/unix/guts/umask.c @@ -2,6 +2,8 @@ * Copyright (c) 2014 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * mode_t umask(mode_t mask) * mode_t rc = 0; */ diff --git a/ports/unix/guts/unlink.c b/ports/unix/guts/unlink.c index d8a5d01..fe96cad 100644 --- a/ports/unix/guts/unlink.c +++ b/ports/unix/guts/unlink.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_unlink(const char *path) { * int rc = -1; diff --git a/ports/unix/guts/unlinkat.c b/ports/unix/guts/unlinkat.c index e723a01..7e4f87c 100644 --- a/ports/unix/guts/unlinkat.c +++ b/ports/unix/guts/unlinkat.c @@ -2,6 +2,8 @@ * Copyright (c) 2008-2010, 2012 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_unlinkat(int dirfd, const char *path, int rflags) { * int rc = -1; diff --git a/ports/unix/guts/utime.c b/ports/unix/guts/utime.c index ff65237..c726ff8 100644 --- a/ports/unix/guts/utime.c +++ b/ports/unix/guts/utime.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_utime(const char *path, const struct utimbuf *buf) { * int rc = -1; diff --git a/ports/unix/guts/utimes.c b/ports/unix/guts/utimes.c index 69ad949..ec49f02 100644 --- a/ports/unix/guts/utimes.c +++ b/ports/unix/guts/utimes.c @@ -2,6 +2,8 @@ * Copyright (c) 2010 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * static int * wrap_utimes(const char *path, const struct timeval *times) { * int rc = -1; diff --git a/ports/unix/pseudo_wrappers.c b/ports/unix/pseudo_wrappers.c index b825d56..bf69aa9 100644 --- a/ports/unix/pseudo_wrappers.c +++ b/ports/unix/pseudo_wrappers.c @@ -1,3 +1,7 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ FILE * popen(const char *command, const char *mode) { sigset_t saved; diff --git a/ports/unix/subports b/ports/unix/subports index e41b036..bd5a2f6 100755 --- a/ports/unix/subports +++ b/ports/unix/subports @@ -1,11 +1,13 @@ #!/bin/sh cat > dummy.c <<EOF +#define _GNU_SOURCE #include <unistd.h> int main(void) { syncfs(0); return 0; } EOF + if ${CC} -o dummy dummy.c > /dev/null 2>&1; then echo "unix/syncfs" fi diff --git a/ports/unix/syncfs/guts/syncfs.c b/ports/unix/syncfs/guts/syncfs.c index 2c9a685..76b509e 100644 --- a/ports/unix/syncfs/guts/syncfs.c +++ b/ports/unix/syncfs/guts/syncfs.c @@ -2,6 +2,8 @@ * Copyright (c) 2013 Wind River Systems; see * guts/COPYRIGHT for information. * + * SPDX-License-Identifier: LGPL-2.1-only + * * int syncfs(int fd) * int rc = -1; */ diff --git a/ports/unix/wrapfuncs.in b/ports/unix/wrapfuncs.in index 3910fae..7724fc7 100644 --- a/ports/unix/wrapfuncs.in +++ b/ports/unix/wrapfuncs.in @@ -1,15 +1,17 @@ int creat(const char *path, mode_t mode); char *getcwd(char *buf, size_t size); char *getwd(char *buf); -int close(int fd); +int close(int fd); /* noignore_path=1 */ int fchmod(int fd, mode_t mode); int fchown(int fd, uid_t owner, gid_t group); int lchown(const char *path, uid_t owner, gid_t group); /* flags=AT_SYMLINK_NOFOLLOW */ -int dup2(int oldfd, int newfd); -int dup(int fd); -int chdir(const char *path); -int fchdir(int dirfd); +int dup2(int oldfd, int newfd); /* noignore_path=1 */ +int dup(int fd); /* noignore_path=1 */ +int chdir(const char *path); /* noignore_path=1 */ +int fchdir(int dirfd); /* noignore_path=1 */ int access(const char *path, int mode); +int faccessat(int dirfd, const char *path, int mode, int flags); +int faccessat2(int dirfd, const char *path, int mode, int flags); FTS *fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **)); /* inode64=1 */ int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int nopenfd); int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int nopenfd, int flag); @@ -20,18 +22,18 @@ char *mktemp(char *template); long pathconf(const char *path, int name); char *realpath(const char *name, char *resolved_name); /* version="GLIBC_2.3" */ int remove(const char *path); /* flags=AT_SYMLINK_NOFOLLOW */ -DIR *opendir(const char *path); -int closedir(DIR *dirp); +DIR *opendir(const char *path); /* noignore_path=1 */ +int closedir(DIR *dirp); /* noignore_path=1 */ char *tempnam(const char *template, const char *pfx); char *tmpnam(char *s); int truncate(const char *path, off_t length); int utime(const char *path, const struct utimbuf *buf); int utimes(const char *path, const struct timeval *times); # needed because libc stdio does horrible things with inline asm syscalls -FILE *fopen(const char *path, const char *mode); -int fclose(FILE *fp); -FILE *freopen(const char *path, const char *mode, FILE *stream); -int chroot(const char *path); +FILE *fopen(const char *path, const char *mode); /* noignore_path=1 */ +int fclose(FILE *fp); /* noignore_path=1 */ +FILE *freopen(const char *path, const char *mode, FILE *stream); /* noignore_path=1 */ +int chroot(const char *path); /* noignore_path=1 */ int acct(const char *path); int chmod(const char *path, mode_t mode); int chown(const char *path, uid_t owner, gid_t group); @@ -295,7 +295,7 @@ options increase the debugging level. .TP 8 .BI \-x\ (debug) -Set specific deugging flags (the +Set specific debugging flags (the .I pseudo utility's help message lists them). This is equivalent to the string form of the @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2013 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ #include <stdlib.h> @@ -256,10 +245,12 @@ main(int argc, char *argv[]) { /* Options are processed, preserve them... */ pseudo_set_value("PSEUDO_OPTS", opts); - if (!pseudo_get_prefix(argv[0])) { + s = pseudo_get_prefix(argv[0]); + if (!s) { pseudo_diag("Can't figure out prefix. Set PSEUDO_PREFIX or invoke with full path.\n"); exit(PSEUDO_EXIT_PSEUDO_PREFIX); } + free(s); /* move database */ if (opt_m || opt_M) { @@ -691,31 +682,30 @@ pseudo_op(pseudo_msg_t *msg, const char *program, const char *tag, char **respon } break; default: - if (strcmp(msg->path, path_by_ino)) { + /* Ignore NAMELESS FILE entries since those could be created by other threads on new files */ + if (strcmp(msg->path, path_by_ino) && strcmp(path_by_ino, "NAMELESS FILE")) { mismatch = 1; } break; } if (mismatch) { - /* a mismatch, but we were planning to delete - * the file, so it must have gotten deleted - * already. - */ if (by_ino.deleting != 0) { - pseudo_debug(PDBGF_FILE, "inode mismatch for '%s' -- old one was marked for deletion, deleting.\n", + /* a mismatch, likely a race but we were planning to + * delete the file, or are in the middle of a rename + * so continue, need the old entry for a rename. + */ + pseudo_debug(PDBGF_FILE, "inode mismatch for '%s' -- old one was marked for deletion.\n", msg->path); - pdb_did_unlink_file(path_by_ino, &by_ino, by_ino.deleting); } else { - int flags = 0; - if (msg->nlink > 1) { - flags = PDBGF_FILE | PDBGF_VERBOSE; - } - pseudo_debug(flags, "path mismatch [%d link%s]: ino %llu db '%s' req '%s'.\n", + pseudo_diag("path mismatch [%d link%s]: ino %llu db '%s' req '%s'.\n", msg->nlink, msg->nlink == 1 ? "" : "s", (unsigned long long) msg_header.ino, path_by_ino ? path_by_ino : "no path", msg->path); + found_ino = 0; + msg->result = RESULT_ABORT; + goto op_exit; } } } else { @@ -1035,6 +1025,24 @@ pseudo_op(pseudo_msg_t *msg, const char *program, const char *tag, char **respon break; } + switch (msg->op) { + case OP_FCHOWN: /* FALLTHROUGH */ + case OP_FCHMOD: /* FALLTHROUGH */ + case OP_FSTAT: + if (!found_path && !found_ino && (msg->nlink == 0)) { + /* If nlink is 0 for an fchown/fchmod/fstat, we probably have an fd which is + * unlinked and we don't want to do inode/path matching against it. Marking it + * as may unlink gives the right hints in the database to ensure we + * handle correctly whilst maintaining the permissions whilst the + * file exists for the fd. */ + pdb_may_unlink_file(msg, msg->client); + } + break; + default: + break; + } + +op_exit: /* in the case of an exact match, we just used the pointer * rather than allocating space. */ @@ -1098,9 +1106,15 @@ pseudo_db_check(int fix) { int fixup_needed = 0; pseudo_debug(PDBGF_DB, "Checking <%s>\n", m->path); if (lstat(m->path, &buf)) { - errors = EXIT_FAILURE; - pseudo_diag("can't stat <%s>\n", m->path); - continue; + if (!fix) { + pseudo_diag("can't stat <%s>\n", m->path); + errors = EXIT_FAILURE; + continue; + } else { + pseudo_debug(PDBGF_DB, "can't stat <%s>\n", m->path); + fixup_needed = 2; + goto do_fixup; + } } /* can't check for device type mismatches, uid/gid, or * permissions, because those are the very things we @@ -1136,6 +1150,7 @@ pseudo_db_check(int fix) { S_ISDIR(m->mode)); fixup_needed = 2; } + do_fixup: if (fixup_needed) { /* in fixup mode, either delete (mismatches) or * correct (dev/ino). @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2010, 2013 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ #include <stdlib.h> diff --git a/pseudo_client.c b/pseudo_client.c index 5604cbf..a03d6b1 100644 --- a/pseudo_client.c +++ b/pseudo_client.c @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2013 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ #define _GNU_SOURCE @@ -81,6 +70,8 @@ int pseudo_umask = 022; static char **fd_paths = NULL; static int nfds = 0; +static char **linked_fd_paths = NULL; +static int linked_nfds = 0; static const char **passwd_paths = NULL; static int npasswd_paths = 0; #ifdef PSEUDO_PROFILING @@ -440,6 +431,7 @@ pseudo_profile_report(void) { void pseudo_init_client(void) { char *env; + int need_free = 0; pseudo_antimagic(); pseudo_new_pid(); @@ -459,9 +451,11 @@ pseudo_init_client(void) { * or it may have gone away, in which case we'd enable * pseudo (and cause it to reinit the defaults). */ + need_free = 0; env = getenv("PSEUDO_DISABLED"); if (!env) { env = pseudo_get_value("PSEUDO_DISABLED"); + need_free = 1; } if (env) { int actually_disabled = 1; @@ -496,15 +490,19 @@ pseudo_init_client(void) { } else { pseudo_set_value("PSEUDO_DISABLED", "0"); } + if (need_free) + free(env); /* ALLOW_FSYNC is here because some crazy hosts will otherwise * report incorrect values for st_size/st_blocks. I can sort of * understand st_blocks, but bogus values for st_size? Not cool, * dudes, not cool. */ + need_free = 0; env = getenv("PSEUDO_ALLOW_FSYNC"); if (!env) { env = pseudo_get_value("PSEUDO_ALLOW_FSYNC"); + need_free = 1; } else { pseudo_set_value("PSEUDO_ALLOW_FSYNC", env); } @@ -513,6 +511,8 @@ pseudo_init_client(void) { } else { pseudo_allow_fsync = 0; } + if (need_free) + free(env); /* in child processes, PSEUDO_UNLOAD may become set to * some truthy value, in which case we're being asked to @@ -833,6 +833,8 @@ pseudo_client_chroot(const char *path) { } memcpy(pseudo_chroot, path, pseudo_chroot_len + 1); pseudo_set_value("PSEUDO_CHROOT", pseudo_chroot); + /* Rebuild passwd paths since we've done a chroot */ + build_passwd_paths(); return 0; } @@ -844,7 +846,7 @@ pseudo_root_path(const char *func, int line, int dirfd, const char *path, int le pseudo_magic(); if (!rc) { pseudo_diag("couldn't allocate absolute path for '%s'.\n", - path); + path ? path : "null"); } pseudo_debug(PDBGF_CHROOT, "root_path [%s, %d]: '%s' from '%s'\n", func, line, @@ -900,39 +902,102 @@ fd_path(int fd) { } static void -pseudo_client_path(int fd, const char *path) { +pseudo_client_path_set(int fd, const char *path, char ***patharray, int *len) { if (fd < 0) return; - if (fd >= nfds) { + if (fd >= *len) { int i; pseudo_debug(PDBGF_CLIENT, "expanding fds from %d to %d\n", - nfds, fd + 1); - fd_paths = realloc(fd_paths, (fd + 1) * sizeof(char *)); - for (i = nfds; i < fd + 1; ++i) - fd_paths[i] = 0; - nfds = fd + 1; + *len, fd + 1); + (*patharray) = realloc((*patharray), (fd + 1) * sizeof(char *)); + for (i = *len; i < fd + 1; ++i) + (*patharray)[i] = 0; + *len = fd + 1; } else { - if (fd_paths[fd]) { + if ((*patharray)[fd]) { pseudo_debug(PDBGF_CLIENT, "reopening fd %d [%s] -- didn't see close\n", - fd, fd_paths[fd]); + fd, (*patharray)[fd]); } /* yes, it is safe to free null pointers. yay for C89 */ - free(fd_paths[fd]); - fd_paths[fd] = 0; + free((*patharray)[fd]); + (*patharray)[fd] = 0; } if (path) { - fd_paths[fd] = strdup(path); + (*patharray)[fd] = strdup(path); + } +} + +static void +pseudo_client_path(int fd, const char *path) { + pseudo_client_path_set(fd, path, &fd_paths, &nfds); +} + +void +pseudo_client_linked_paths(const char *oldpath, const char *newpath) { + int fd; + for (fd = 3; fd < nfds; ++fd) { + if (fd_paths[fd] && !strcmp(oldpath, fd_paths[fd])) { + pseudo_client_path_set(fd, newpath, &linked_fd_paths, &linked_nfds); + } + } +} + +static void +pseudo_client_rename_path(const char *oldpath, const char *newpath) { + int fd; + for (fd = 3; fd < nfds; ++fd) { + if (fd_paths[fd] && !strcmp(oldpath, fd_paths[fd])) { + pseudo_client_path(fd, newpath); + } + } + for (fd = 0; fd < linked_nfds; ++fd) { + if (linked_fd_paths[fd] && fd_paths[fd] && !strcmp(oldpath, linked_fd_paths[fd])) { + pseudo_client_path_set(fd, newpath, &linked_fd_paths, &linked_nfds); + } } } static void +pseudo_client_unlinked_path(const char *path) { + int fd; + for (fd = 0; fd < linked_nfds; ++fd) { + if (linked_fd_paths[fd] && fd_paths[fd] && !strcmp(path, fd_paths[fd])) { + pseudo_client_path(fd, linked_fd_paths[fd]); + } + } +} + + +static void pseudo_client_close(int fd) { if (fd < 0 || fd >= nfds) return; free(fd_paths[fd]); fd_paths[fd] = 0; + + if (fd < linked_nfds) { + free(linked_fd_paths[fd]); + linked_fd_paths[fd] = 0; + } +} + +static void +pseudo_client_closefrom(int fd) { + int i; + if (fd < 0 || fd >= nfds) + return; + + for (i = fd; i < nfds; ++i) { + free(fd_paths[i]); + fd_paths[i] = 0; + + if (i < linked_nfds) { + free(linked_fd_paths[i]); + linked_fd_paths[i] = 0; + } + } } /* spawn server */ @@ -1282,7 +1347,7 @@ pseudo_client_setup(void) { } } -#define PSEUDO_RETRIES 20 +#define PSEUDO_RETRIES 250 static pseudo_msg_t * pseudo_client_request(pseudo_msg_t *msg, size_t len, const char *path) { pseudo_msg_t *response = 0; @@ -1447,8 +1512,12 @@ base_path(int dirfd, const char *path, int leave_last) { if (!path) return NULL; - if (!*path) + + if (!*path) { + if (dirfd != -1 && dirfd != AT_FDCWD) + return fd_path(dirfd); return ""; + } if (path[0] != '/') { if (dirfd != -1 && dirfd != AT_FDCWD) { @@ -1493,10 +1562,52 @@ base_path(int dirfd, const char *path, int leave_last) { return newpath; } +int pseudo_client_ignore_fd(int fd) { + if (fd >= 0 && fd <= nfds) + return pseudo_client_ignore_path(fd_path(fd)); + return 0; +} + +int pseudo_client_ignore_path_chroot(const char *path, int ignore_chroot) { + char *env; + + if (!path) + return 0; + + if (ignore_chroot && pseudo_chroot && strncmp(path, pseudo_chroot, pseudo_chroot_len) == 0) + return 0; + + env = pseudo_get_value("PSEUDO_IGNORE_PATHS"); + if (!env) + return 0; + + int ret = 0; + char *p = env; + while (p) { + char *next = strchr(p, ','); + if (next) + *next++ = '\0'; + if (*p && !strncmp(path, p, strlen(p))) { + pseudo_debug(PDBGF_PATH | PDBGF_VERBOSE, "ignoring path: '%s'\n", path); + ret = 1; + break; + } + p = next; + } + free(env); + + return ret; +} + +int pseudo_client_ignore_path(const char *path) { + return pseudo_client_ignore_path_chroot(path, 1); +} + pseudo_msg_t * pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path, const PSEUDO_STATBUF *buf, ...) { pseudo_msg_t *result = 0; - pseudo_msg_t msg = { .type = PSEUDO_MSG_OP }; + static pseudo_msg_t msg; + msg = (pseudo_msg_t) { .type = PSEUDO_MSG_OP }; size_t pathlen = -1; int do_request = 0; char *path_extra_1 = 0; @@ -1506,6 +1617,7 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path static char *alloced_path = 0; static size_t alloced_len = 0; int strip_slash; + int startfd, i; #ifdef PSEUDO_PROFILING struct timeval tv1_op, tv2_op; @@ -1533,6 +1645,25 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path } } + if (op != OP_CHROOT && op != OP_CHDIR && op != OP_CLOSE && op != OP_CLOSEFROM && op != OP_DUP + && pseudo_client_ignore_path_chroot(path, 0)) { + if (op == OP_OPEN) { + /* Sanitise the path to have no trailing slash as this is convention in the database */ + char *stripped_path; + pathlen = strlen(path); + if (pathlen > 2 && (path[pathlen - 1]) == '/') { + stripped_path = strndup(path, pathlen-1); + pseudo_client_path(fd, stripped_path); + free(stripped_path); + } else { + pseudo_client_path(fd, path); + } + } + /* reenable wrappers */ + pseudo_magic(); + return result; + } + #ifdef PSEUDO_XATTRDB if (buf) { struct stat64 bufcopy = *buf; @@ -1783,9 +1914,36 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path break; case OP_OPEN: pseudo_client_path(fd, path); - case OP_EXEC: /* fallthrough */ + /* fallthrough */ + case OP_EXEC: do_request = pseudo_client_logging; break; + case OP_CLOSEFROM: + /* no request needed */ + startfd = fd; + if (pseudo_util_debug_fd > startfd) + startfd = pseudo_util_debug_fd + 1; + if (pseudo_localstate_dir_fd > startfd) + startfd = pseudo_localstate_dir_fd + 1; + if (pseudo_pwd_fd > startfd) + startfd = pseudo_pwd_fd + 1; + if (pseudo_grp_fd > startfd) + startfd = pseudo_grp_fd + 1; + if (connect_fd > startfd) + startfd = connect_fd + 1; + for (i = fd; i < startfd; ++i) { + if (i == pseudo_util_debug_fd || i == pseudo_localstate_dir_fd || i == pseudo_pwd_fd || + i == pseudo_grp_fd || i == connect_fd) + continue; + pseudo_client_close(i); + close(i); + } + pseudo_client_closefrom(startfd); + /* tell the caller to close from startfd instead of fd */ + result = &msg; + msg.fd = startfd; + do_request = 0; + break; case OP_CLOSE: /* no request needed */ if (fd >= 0) { @@ -1824,6 +1982,12 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path dirfd); pseudo_client_path(dirfd, fd_path(fd)); break; + case OP_UNLINK: + case OP_DID_UNLINK: + if (path) + pseudo_client_unlinked_path(path); + do_request = 1; + break; /* operations for which we should use the magic uid/gid */ case OP_CHMOD: case OP_CREAT: @@ -1844,10 +2008,7 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path case OP_FCHOWN: case OP_FSTAT: case OP_LINK: - case OP_RENAME: case OP_STAT: - case OP_UNLINK: - case OP_DID_UNLINK: case OP_CANCEL_UNLINK: case OP_MAY_UNLINK: case OP_GET_XATTR: @@ -1856,12 +2017,16 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path case OP_REMOVE_XATTR: do_request = 1; break; + case OP_RENAME: + pseudo_client_rename_path(path_extra_1, path); + do_request = 1; + break; default: pseudo_diag("error: unknown or unimplemented operator %d (%s)", op, pseudo_op_name(op)); break; } /* result can only be set when PSEUDO_XATTRDB resulted in a - * successful store to or read from the local database. + * successful store to or read from the local database or for OP_CLOSEFROM. */ if (do_request && !result) { #ifdef PSEUDO_PROFILING @@ -1887,6 +2052,12 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path #endif if (result) { pseudo_debug(PDBGF_OP, "(%d) %s", getpid(), pseudo_res_name(result->result)); + if (result->result == RESULT_ABORT) { + char *local_state_dir = pseudo_get_value("PSEUDO_LOCALSTATEDIR"); + pseudo_diag("abort()ing pseudo client by server request. See https://wiki.yoctoproject.org/wiki/Pseudo_Abort for more details on this.\n" + "Check logfile: %s/%s\n", local_state_dir, PSEUDO_LOGFILE); + abort(); + } if (op == OP_STAT || op == OP_FSTAT) { pseudo_debug(PDBGF_OP, " mode 0%o uid %d:%d", (int) result->mode, diff --git a/pseudo_client.h b/pseudo_client.h index 28b23dc..d7944ce 100644 --- a/pseudo_client.h +++ b/pseudo_client.h @@ -3,21 +3,13 @@ * * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ extern pseudo_msg_t *pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *path, const PSEUDO_STATBUF *buf, ...); +extern int pseudo_client_ignore_path(const char *path); +extern int pseudo_client_ignore_fd(int fd); +extern void pseudo_client_linked_paths(const char *oldpath, const char *newpath); #if PSEUDO_STATBUF_64 #define base_lstat real_lstat64 #define base_fstat real_fstat64 diff --git a/pseudo_db.c b/pseudo_db.c index d7b28f1..14bafcb 100644 --- a/pseudo_db.c +++ b/pseudo_db.c @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2010,2013 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ #include <stdio.h> @@ -169,11 +158,24 @@ static struct sql_index { static char *file_pragmas[] = { "PRAGMA legacy_file_format = OFF;", - "PRAGMA journal_mode = OFF;", +#ifdef USE_MEMORY_DB /* the default page size produces painfully bad behavior * for memory databases with some versions of sqlite. */ "PRAGMA page_size = 8192;", + "PRAGMA journal_mode = OFF;", +#else + /* Use WAL mode when using the on-disk database. If user care about + * performance, they can use the in-memory database, but if they care + * more about resilience, they can disable it and WAL mode will prevent + * corruption of the on-disk database (for a slight performance + * penalty). Note that the database still keeps synchronous to OFF, + * meaning its resilient to the pseudo process crashing or being killed + * unexpectedly, but not to the OS crashing and losing buffered disk + * state + */ + "PRAGMA journal_mode = WAL;", +#endif "PRAGMA locking_mode = EXCLUSIVE;", /* Setting this to NORMAL makes pseudo noticably slower * than fakeroot, but is perhaps more secure. However, @@ -397,7 +399,7 @@ signed_ino(ino_t ino) { #ifdef USE_MEMORY_DB -static void +void pdb_backup() { sqlite3_backup *pBackup; /* no point in doing this if we don't have a database to back up, @@ -2018,8 +2020,8 @@ int pdb_rename_file(const char *oldpath, pseudo_msg_t *msg) { static sqlite3_stmt *update_exact, *update_sub; int rc; - char *sql_update_exact = "UPDATE files SET path = ? WHERE path = ?;"; - char *sql_update_sub = "UPDATE files SET path = replace(path, ?, ?) " + char *sql_update_exact = "UPDATE files SET path = ?, deleting = 0 WHERE path = ?;"; + char *sql_update_sub = "UPDATE files SET path = replace(path, ?, ?), deleting = 0 " "WHERE (path > (? || '/') AND path < (? || '0'));"; if (!file_db && get_dbs()) { diff --git a/pseudo_db.h b/pseudo_db.h index 1b2599c..9d01232 100644 --- a/pseudo_db.h +++ b/pseudo_db.h @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ typedef struct { @@ -37,6 +26,7 @@ typedef struct { char *program; } log_entry; +extern void pdb_backup(void); extern int pdb_maybe_backup(void); extern int pdb_cancel_unlink_file(pseudo_msg_t *msg); extern int pdb_did_unlink_file(char *path, pseudo_msg_t *msg, int deleting); diff --git a/pseudo_ipc.c b/pseudo_ipc.c index 3571dad..838eba2 100644 --- a/pseudo_ipc.c +++ b/pseudo_ipc.c @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ #include <stddef.h> diff --git a/pseudo_ipc.h b/pseudo_ipc.h index 46277bc..d945257 100644 --- a/pseudo_ipc.h +++ b/pseudo_ipc.h @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ @@ -40,7 +29,7 @@ typedef struct { char path[]; } pseudo_msg_t; -enum { +typedef enum { PSA_EXEC = 1, PSA_WRITE = (PSA_EXEC << 1), PSA_READ = (PSA_WRITE << 1), diff --git a/pseudo_profile.c b/pseudo_profile.c index c4af803..c4b16e6 100644 --- a/pseudo_profile.c +++ b/pseudo_profile.c @@ -1,3 +1,7 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + */ #define _GNU_SOURCE #include <errno.h> diff --git a/pseudo_server.c b/pseudo_server.c index d4428cf..815c76b 100644 --- a/pseudo_server.c +++ b/pseudo_server.c @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2010, 2013 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ #include <stdio.h> @@ -579,6 +568,7 @@ serve_client(int i) { } in->pathlen = (s - response_path) + 1; /* exit quickly once clients go away, though */ + pdb_backup(); pseudo_server_timeout = 3; } else { in->type = PSEUDO_MSG_ACK; @@ -803,6 +793,7 @@ pseudo_server_loop(void) { struct sigaction eat_usr2 = { .sa_handler = set_do_list_clients }; + int hitmaxfiles; clients = malloc(16 * sizeof(*clients)); @@ -821,6 +812,7 @@ pseudo_server_loop(void) { active_clients = 1; max_clients = 16; highest_client = 0; + hitmaxfiles = 0; pseudo_debug(PDBGF_SERVER, "server loop started.\n"); if (listen_fd < 0) { @@ -879,10 +871,15 @@ pseudo_server_loop(void) { } else { serve_client(i); } + } else if (hitmaxfiles) { + /* Only close one per loop iteration in the interests of caution */ + close_client(i); + hitmaxfiles = 0; } if (die_forcefully) break; } + hitmaxfiles = 0; if (!die_forcefully && (FD_ISSET(clients[0].fd, &events) || FD_ISSET(clients[0].fd, &reads))) { @@ -904,6 +901,9 @@ pseudo_server_loop(void) { */ pseudo_server_timeout = DEFAULT_PSEUDO_SERVER_TIMEOUT; die_peacefully = 0; + } else if (errno == EMFILE) { + hitmaxfiles = 1; + pseudo_debug(PDBGF_SERVER, "Hit max open files, dropping a client.\n"); } } pseudo_debug(PDBGF_SERVER, "server loop complete [%d clients left]\n", active_clients); diff --git a/pseudo_server.h b/pseudo_server.h index 06598e7..35f5b78 100644 --- a/pseudo_server.h +++ b/pseudo_server.h @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2009 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ extern int pseudo_server_start(int); diff --git a/pseudo_util.c b/pseudo_util.c index b46417d..b58036f 100644 --- a/pseudo_util.c +++ b/pseudo_util.c @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2013 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ /* we need access to RTLD_NEXT for a horrible workaround */ @@ -54,6 +43,7 @@ static struct pseudo_variables pseudo_env[] = { { "PSEUDO_BINDIR", 13, NULL }, { "PSEUDO_LIBDIR", 13, NULL }, { "PSEUDO_LOCALSTATEDIR", 20, NULL }, + { "PSEUDO_IGNORE_PATHS", 19, NULL }, { "PSEUDO_PASSWD", 13, NULL }, { "PSEUDO_CHROOT", 13, NULL }, { "PSEUDO_UIDS", 11, NULL }, @@ -169,7 +159,7 @@ pseudo_get_value(const char *key) { if (pseudo_util_initted == -1) pseudo_init_util(); - for (i = 0; pseudo_env[i].key && memcmp(pseudo_env[i].key, key, pseudo_env[i].key_len + 1); i++) + for (i = 0; pseudo_env[i].key && strcmp(pseudo_env[i].key, key); i++) ; /* Check if the environment has it and we don't ... @@ -198,7 +188,7 @@ pseudo_set_value(const char *key, const char *value) { if (pseudo_util_initted == -1) pseudo_init_util(); - for (i = 0; pseudo_env[i].key && memcmp(pseudo_env[i].key, key, pseudo_env[i].key_len + 1); i++) + for (i = 0; pseudo_env[i].key && strcmp(pseudo_env[i].key, key); i++) ; if (pseudo_env[i].key) { @@ -689,7 +679,7 @@ pseudo_append_element(char *newpath, char *root, size_t allocated, char **pcurre if (!leave_this && is_dir) { int is_link = S_ISLNK(buf->st_mode); if (link_recursion >= PSEUDO_MAX_LINK_RECURSION && is_link) { - pseudo_diag("link recursion too deep, not expanding path '%s'.\n", newpath); + pseudo_debug(PDBGF_PATH, "link recursion too deep, not expanding path '%s'.\n", newpath); is_link = 0; } if (is_link) { @@ -699,14 +689,15 @@ pseudo_append_element(char *newpath, char *root, size_t allocated, char **pcurre linklen = readlink(newpath, linkbuf, pseudo_path_max()); if (linklen == -1) { - pseudo_diag("uh-oh! '%s' seems to be a symlink, but I can't read it. Ignoring.", newpath); + pseudo_debug(PDBGF_PATH, "uh-oh! '%s' seems to be a symlink, but I can't read it. Ignoring.\n", newpath); + *pcurrent = current; return 0; } /* null-terminate buffer */ linkbuf[linklen] = '\0'; - /* absolute symlink means start over! */ + /* absolute symlink means go back to root */ if (*linkbuf == '/') { - current = newpath; + current = root; } else { /* point back at the end of the previous path... */ current -= (elen + 1); @@ -801,11 +792,9 @@ static char *pathbufs[PATHBUFS] = { 0 }; static int pathbuf = 0; /* Canonicalize path. "base", if present, is an already-canonicalized - * path of baselen characters, presumed not to end in a /. path is - * the new path to be canonicalized. The tricky part is that path may - * contain symlinks, which must be resolved. - * if "path" starts with a /, then it is an absolute path, and - * we ignore base. + * path of baselen characters, presumed not to end in a / unless it is + * just "/". path is the new path to be canonicalized. The tricky part + * is that path may contain symlinks, which must be resolved. */ char * pseudo_fix_path(const char *base, const char *path, size_t rootlen, size_t baselen, size_t *lenp, int leave_last) { @@ -819,13 +808,28 @@ pseudo_fix_path(const char *base, const char *path, size_t rootlen, size_t basel pseudo_diag("can't fix empty path.\n"); return 0; } + if (baselen == 1) { + baselen = 0; + } + if (rootlen == 1) { + rootlen = 0; + } newpathlen = pseudo_path_max(); + pathlen = strlen(path); + /* Crazy shell code (e.g. libtool) can pass in a command pipeline as a path which exceeds the max path + * length the system can support (6000+ chars). This will fail in libc or the syscall but if we don't + * do something here, we'd segfault before it can do that. Leave path unchanged and let libc deal + * with it. + */ + if ((pathlen + baselen) >= newpathlen) { + return path; + } if (!pathbufs[pathbuf]) { pathbufs[pathbuf] = malloc(newpathlen); } newpath = pathbufs[pathbuf]; pathbuf = (pathbuf + 1) % PATHBUFS; - pathlen = strlen(path); + /* a trailing slash has special meaning, but processing * trailing slashes is expensive. */ @@ -977,6 +981,7 @@ pseudo_setupenv() { } snprintf(newenv, len, "%s:%s64", libdir_path, libdir_path); SETENV(PRELINK_PATH, newenv, 1); + free(newenv); } else if (!strstr(ld_library_path, libdir_path)) { size_t len = strlen(ld_library_path) + 1 + strlen(libdir_path) + 1 + (strlen(libdir_path) + 2) + 1; char *newenv = malloc(len); @@ -985,6 +990,7 @@ pseudo_setupenv() { } snprintf(newenv, len, "%s:%s:%s64", ld_library_path, libdir_path, libdir_path); SETENV(PRELINK_PATH, newenv, 1); + free(newenv); } else { /* nothing to do, ld_library_path exists and contains * our preferred path */ @@ -1605,7 +1611,7 @@ pseudo_logfile(char *filename, char *defname, int prefer_fd) { } free(filename); } - fd = open(pseudo_path, O_WRONLY | O_APPEND | O_CREAT, 0644); + fd = open(pseudo_path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0644); if (fd == -1) { pseudo_diag("help: can't open log file %s: %s\n", pseudo_path, strerror(errno)); } else { diff --git a/pseudo_wrappers.c b/pseudo_wrappers.c index e05f73a..9ae1200 100644 --- a/pseudo_wrappers.c +++ b/pseudo_wrappers.c @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2012 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ #include <assert.h> @@ -151,7 +140,7 @@ pseudo_init_one_wrapper(pseudo_function *func) { #endif f = dlsym(RTLD_NEXT, func->name); if (f) { - *func->real = f; + *func->real = (void (*)(void)) f; } /* it turns out that in some cases, we get apparently-harmless * errors if a function is missing, and that printing output @@ -3,18 +3,7 @@ * * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ #include <stdio.h> diff --git a/pseudolog.c b/pseudolog.c index ced421d..ad04753 100644 --- a/pseudolog.c +++ b/pseudolog.c @@ -3,23 +3,13 @@ * * Copyright (c) 2008-2010 Wind River Systems, Inc. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the Lesser GNU General Public License version 2.1 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Lesser GNU General Public License for more details. - * - * You should have received a copy of the Lesser GNU General Public License - * version 2.1 along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * SPDX-License-Identifier: LGPL-2.1-only * */ /* We need _XOPEN_SOURCE for strptime(), but if we define that, * we then don't get S_IFSOCK... _GNU_SOURCE turns on everything. */ -#define _GNU_SOURCE +#define _DEFAULT_SOURCE +#define _XOPEN_SOURCE #include <ctype.h> #include <limits.h> @@ -385,7 +375,7 @@ plog_trait(int opt, char *string) { pseudo_diag("invalid empty string for -%c\n", opt); return 0; } - new_trait = calloc(sizeof(*new_trait), 1); + new_trait = calloc(1, sizeof(*new_trait)); if (!new_trait) { pseudo_diag("Couldn't allocate requested trait (for -%c %s)\n", opt, string ? string : "<nil>"); diff --git a/run_tests.sh b/run_tests.sh index 0eced9f..c637c27 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,4 +1,8 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# + opt_verbose= usage() diff --git a/templatefile.py b/templatefile.py index abf9a2c..be82de3 100644 --- a/templatefile.py +++ b/templatefile.py @@ -1,3 +1,7 @@ +# +# SPDX-License-Identifier: LGPL-2.1-only +# + from string import Template import os diff --git a/templates/guts b/templates/guts index 70607e6..05605ea 100644 --- a/templates/guts +++ b/templates/guts @@ -8,6 +8,8 @@ * [Note: copyright added by code generator, may be * incorrect. Remove this if you fix it.] * + * SPDX-License-Identifier: LGPL-2.1-only + * * ${comment} * ${rc_decl} */ diff --git a/templates/wrapfuncs.c b/templates/wrapfuncs.c index 3859183..93bb671 100644 --- a/templates/wrapfuncs.c +++ b/templates/wrapfuncs.c @@ -60,9 +60,15 @@ ${maybe_async_skip} ${rc_assign} (*real_${name})(${call_args}); } else { ${fix_paths} - /* exec*() use this to restore the sig mask */ - pseudo_saved_sigmask = saved; - ${rc_assign} wrap_$name(${call_args}); + if (${ignore_paths}) { + /* call the real syscall */ + pseudo_debug(PDBGF_SYSCALL, "${name} ignored path, calling real syscall.\n"); + ${rc_assign} (*real_${name})(${call_args}); + } else { + /* exec*() use this to restore the sig mask */ + pseudo_saved_sigmask = saved; + ${rc_assign} wrap_$name(${call_args}); + } } ${variadic_end} save_errno = errno; diff --git a/templates/wrapper_table b/templates/wrapper_table index bb30530..498ca81 100644 --- a/templates/wrapper_table +++ b/templates/wrapper_table @@ -6,8 +6,8 @@ * script if you want to modify this. */ typedef struct { char *name; /* the name */ - int (**real)(void); /* the underlying syscall */ - int (*wrapper)(void); /* the wrapper from guts/name.c */ + void (**real)(void); /* the underlying syscall */ + void (*wrapper)(void); /* the wrapper from guts/name.c */ char *version; /* the version, if we know and care */ } pseudo_function; @@ -15,8 +15,8 @@ static pseudo_function pseudo_functions[] = { @body { /* ${comment}; */ "${name}${maybe_inode64}", - (int (**)(void)) &real_${name}, - (int (*)(void)) wrap_${name}, + (void (**)(void)) &real_${name}, + (void (*)(void)) wrap_${name}, ${version} }, @footer diff --git a/test/test-acl.sh b/test/test-acl.sh new file mode 100755 index 0000000..fb7d5ec --- /dev/null +++ b/test/test-acl.sh @@ -0,0 +1,188 @@ +#!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# + +# Return vals: 2 - Unable to run ACL commands, assertion failure +# 1 - Invalid return value +# 0 - Pass + +# NOTE: these test exclusively test setfacl -m + +set -u + +check_owner () { + local file="$1" + local expected="$2" + local msg="$3" + local actual=$(stat -c "%U" "$file") + if [ "$actual" != "$expected" ] + then + echo "$msg" "Fail, '$file' unexpected owner '$actual'" + exit 2 + fi +} + +check_group () { + local file="$1" + local expected="$2" + local msg="$3" + local actual=$(stat -c "%G" "$file") + if [ "$actual" != "$expected" ] + then + echo "$msg" "Fail, '$file' unexpected group '$actual'" + exit 2 + fi +} + +check_acl_contains () { + local file="$1" + local acl="$2" + local msg="$3" + IFS=',' read -ra acls <<< "$acl" + for pattern in "${acls[@]}"; do + result=$(getfacl -c "$file" | grep -o "^$pattern") + if [ "$result" != "$pattern" ] + then + echo "$msg" "Fail, did not find desired acl '$pattern' in '$file'" + exit 2 + fi + done +} + +check_acl_minimal () { + local file="$1" + local msg="${2:-''}" + local acls + acls=$(getfacl -c "${file}" | grep -v "::") + if [ -n "$acls" ] + then + echo "$msg" "Fail, '$file' unexpected getfacl result '$acls'" + exit 1 + fi +} + +test_modify_once () { + local file="$1" + local acl="$2" + local msg="${3:-''}" + # ensure that file is pristine + check_acl_minimal "$file" "$msg precondition:" + check_owner "$file" root "$msg precondition:" + check_group "$file" root "$msg precondition:" + if ! setfacl -m "$acl" "$file" + then + echo "$msg" "Fail, unable to call setfacl" + exit 2 + fi + check_acl_contains "$file" "$acl" "$msg: acl not set:" + check_owner "$file" root "$msg owner corrupted:" + check_group "$file" root "$msg group corrupted:" +} + + +trap "rm -rf testdir" EXIT +mkdir testdir || exit 1 + + +# user +touch testdir/f1 || exit 1 +mkdir testdir/d1 || exit 1 +# regular file +test_modify_once testdir/f1 "user:root:r" "$LINENO:" +# directory +test_modify_once testdir/d1 "user:root:r" "$LINENO:" +rm -rf testdir/f1 testdir/d1 + +#group +rm -rf testdir/f1 testdir/d1 +touch testdir/f1 || exit 1 +mkdir testdir/d1 || exit 1 +# regular file +test_modify_once testdir/f1 "group:root:r" "$LINENO:" +# directory +test_modify_once testdir/d1 "group:root:r" "$LINENO:" +rm -rf testdir/f1 testdir/d1 + +# multiple users +touch testdir/f1 || exit 1 +mkdir testdir/d1 || exit 1 +# regular file +test_modify_once testdir/f1 "user:root:r,group:root:r,user:bin:rw" "$LINENO:" +# directory +test_modify_once testdir/d1 "user:root:r,group:root:r,user:bin:rw" "$LINENO:" +rm -rf testdir/f1 testdir/d1 + + +# setfacl default acls +mkdir testdir/d1 || exit 1 +test_modify_once testdir/d1 "default:user:root:r,user:root:r" "$LINENO:" +rm -rf testdir/d1 + + +# multiple calls to setfacl -m on same file +touch testdir/f1 || exit 1 +mkdir testdir/d1 || exit 1 +check_owner testdir/f1 root "$LINENO: precondition:" +check_group testdir/f1 root "$LINENO: precondition:" +check_acl_minimal testdir/f1 "$LINENO: precondition:" + +acl1="user:root:r" +acl2="user:bin:rw" + +if ! setfacl -m "$acl1" testdir/f1 # first setfacl +then + echo "$LINENO:" "Fail, unable to call setfacl" + exit 2 +fi +check_acl_contains testdir/f1 "$acl1" "$LINENO: acl1 not set:" +check_owner testdir/f1 root "$LINENO: owner corrupted:" +check_group testdir/f1 root "$LINENO: group corrupted:" + +if ! setfacl -m "$acl2" testdir/f1 # second setfacl +then + echo "$LINENO:" "Fail, unable to call setfacl" + exit 2 +fi + +check_acl_contains testdir/f1 "$acl1" "$LINENO: acl1 not set:" +check_acl_contains testdir/f1 "$acl2" "$LINENO: acl2 not set:" +check_owner testdir/f1 root "$LINENO: owner corrupted:" +check_group testdir/f1 root "$LINENO: group corrupted:" +rm -rf testdir/f1 testdir/d1 + +# setfacl recursive +test_modify_recursive () { + local root_dir="$1" + local acl="$2" + local msg="${3:-''}" + + find "$root_dir" | while read -r file; do + check_owner "$file" root "$msg precondition:" + check_group "$file" root "$msg precondition:" + check_acl_minimal "$file" "$msg precondition:" + done + if ! setfacl -R -m "$acl" "$root_dir" + then + echo "$msg" "Fail, unable to call setfacl" + exit 2 + fi + find "$root_dir" | while read -r file; do + check_owner "$file" root "$msg owner corrupted:" + check_group "$file" root "$msg group corrupted:" + check_acl_contains "$file" "$acl" "$msg acl not set:" + done +} + +mkdir -p testdir/d1/d2 || exit 1 +touch testdir/d1/d2/f1 || exit 1 +test_modify_recursive testdir/d1 "user:root:r,group:root:r,user:bin:rw" "$LINENO:" +rm -rf testdir/d1 + +mkdir -p testdir/d1/d2 || exit 1 +mkdir -p testdir/d1/d3 || exit 1 +test_modify_recursive testdir/d1 "default:user:root:rwx,user:root:r,group:root:r,user:bin:rw" "$LINENO:" +rm -rf testdir/d1 + +#echo "Passed." +exit 0 diff --git a/test/test-chroot-symlink.c b/test/test-chroot-symlink.c new file mode 100644 index 0000000..469cb49 --- /dev/null +++ b/test/test-chroot-symlink.c @@ -0,0 +1,28 @@ +/* + * Test that stat'ing absolute/relative symlinks in a chroot environment works + * SPDX-License-Identifier: LGPL-2.1-only + * + */ +#define _GNU_SOURCE + +#include <unistd.h> +#include <sys/stat.h> +#include <stdio.h> + +int main(int argc, char *argv[]) { + struct stat buf; + + if (argc != 2) { + perror("args"); + return 2; + } + if (chroot(argv[1]) == -1) { + perror("chroot"); + return 1; + } + if (stat("symlink", &buf) == -1) { + perror("stat symlink"); + return 1; + } + return 0; +} diff --git a/test/test-chroot-symlink.sh b/test/test-chroot-symlink.sh new file mode 100755 index 0000000..91092c1 --- /dev/null +++ b/test/test-chroot-symlink.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Test that stat'ing absolute/relative symlinks in a chroot environment works +# SPDX-License-Identifier: LGPL-2.1-only +# + +set -e + +touch symlink_target +trap "rm -f symlink_target symlink" 0 + +# Absolute symlink +ln -s /symlink_target symlink +./test/test-chroot-symlink `pwd` +rm symlink + +# Relative symlink +ln -s symlink_target symlink +./test/test-chroot-symlink `pwd` diff --git a/test/test-chroot.sh b/test/test-chroot.sh index 02c9ff6..faa4ffe 100755 --- a/test/test-chroot.sh +++ b/test/test-chroot.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# # Return vals: 2 - invalid arg list # 1 - chroot failed diff --git a/test/test-cp-setuid.sh b/test/test-cp-setuid.sh index cdb2cd3..0759608 100755 --- a/test/test-cp-setuid.sh +++ b/test/test-cp-setuid.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# set -e # Verify that special bits (setuid/setgid/sticky) are preserved. diff --git a/test/test-dir-move.sh b/test/test-dir-move.sh index 37182f3..7bb0256 100755 --- a/test/test-dir-move.sh +++ b/test/test-dir-move.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# mkdir d1 touch d1/f1 mv d1 d2 diff --git a/test/test-env_i.sh b/test/test-env_i.sh index c38cf1d..454a7b4 100755 --- a/test/test-env_i.sh +++ b/test/test-env_i.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# env -i A=A B=B C=C env | grep -q "PSEUDO_" diff --git a/test/test-execl.sh b/test/test-execl.sh index 1a1c580..134055b 100755 --- a/test/test-execl.sh +++ b/test/test-execl.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# cat > execl_test.c << EOF #include <unistd.h> int main() { diff --git a/test/test-fcntl.c b/test/test-fcntl.c new file mode 100644 index 0000000..b593d50 --- /dev/null +++ b/test/test-fcntl.c @@ -0,0 +1,58 @@ +/* fcntl-linux.h doesn't define F_GETPIPE_SZ and F_SETPIPE_SZ without + * this */ +#define _GNU_SOURCE + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <unistd.h> +#include <string.h> + +int test_pipe_sz() +{ +#if defined(F_GETPIPE_SZ) && defined(F_SETPIPE_SZ) + int pipefd[2]; + + if (pipe(pipefd) < 0) { + perror("pipe"); + return 1; + } + + const int orig_size = fcntl(pipefd[0], F_GETPIPE_SZ); + if (orig_size < 0) { + perror("F_GETPIPE_SZ"); + return 1; + } + + const int new_size = orig_size * 2; + + if (fcntl(pipefd[0], F_SETPIPE_SZ, new_size) < 0) { + perror("F_SETPIPE_SZ"); + return 1; + } + + const int final_size = fcntl(pipefd[0], F_GETPIPE_SZ); + if (final_size < 0) { + perror("Second F_GETPIPE_SZ"); + return 1; + } + + if (final_size < new_size) { + fprintf(stderr, "Unexpected final pipe size: %d\n", final_size); + return 1; + } +#else + printf("Host too old for F_GETPIPE_SZ and F_SETPIPE_SZ tests\n"); +#endif + return 0; +} + +int main() +{ + int result = 0; + result += test_pipe_sz(); + return result; +} diff --git a/test/test-fcntl.sh b/test/test-fcntl.sh new file mode 100755 index 0000000..7112620 --- /dev/null +++ b/test/test-fcntl.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# +./test/test-fcntl diff --git a/test/test-fstat.c b/test/test-fstat.c new file mode 100644 index 0000000..78f7013 --- /dev/null +++ b/test/test-fstat.c @@ -0,0 +1,29 @@ +/* + * Test that stat'ing a file descriptor of a symlink does not dereference the symlink + * SPDX-License-Identifier: LGPL-2.1-only + * + */ +#define _GNU_SOURCE + +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <stdio.h> + +int main(void) { + struct stat buf; + int fd = open("symlink", O_NOFOLLOW | O_PATH); + if (fd == -1) { + perror("open symlink"); + return 1; + } + if (fstatat(fd, "", &buf, AT_EMPTY_PATH) == -1) { + perror("stat symlink"); + return 1; + } + if (S_ISLNK(buf.st_mode) != 1) { + fprintf(stderr, "path is not a symlink\n"); + return 1; + } + return 0; +} diff --git a/test/test-fstat.sh b/test/test-fstat.sh new file mode 100755 index 0000000..88eab8b --- /dev/null +++ b/test/test-fstat.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# + +ln -s . symlink +trap "rm symlink" 0 +./test/test-fstat diff --git a/test/test-openat.c b/test/test-openat.c new file mode 100644 index 0000000..df6655a --- /dev/null +++ b/test/test-openat.c @@ -0,0 +1,58 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <unistd.h> +#include <string.h> + +char *path_of(int fd) { + ssize_t len; + char proc[PATH_MAX], real[PATH_MAX]; + snprintf(proc, sizeof(proc), "/proc/self/fd/%d", fd); + len = readlink(proc, real, sizeof(real)); + real[len] = '\0'; + return strdup(real); +} + +/* +* Test that recusing up the tree with openat(fd, "../") handles slashes +* correctly and doesn't end up opening the same directory instead of going up a +* level. +*/ +int main () { + int fd, dir_fd; + struct stat st; + ino_t ino; + dev_t dev; + char *path; + + fd = openat(AT_FDCWD, ".", O_DIRECTORY, 0); + fstat(fd, &st); + ino = st.st_ino; + dev = st.st_dev; + + while (1) { + path = path_of(fd); + //puts(path); + + dir_fd = openat(fd, "../", O_DIRECTORY, 0); + fstat(dir_fd, &st); + if (st.st_ino == ino && st.st_dev == dev) { + if (strcmp(path, "/") == 0) { + //puts("Reached top of tree"); + return 0; + } else { + //puts("Recursion failed!"); + return 1; + } + } + + free (path); + ino = st.st_ino; + dev = st.st_dev; + fd = dir_fd; + } + return 0; +} diff --git a/test/test-openat.sh b/test/test-openat.sh new file mode 100755 index 0000000..0455586 --- /dev/null +++ b/test/test-openat.sh @@ -0,0 +1,7 @@ +#! /bin/sh + +# Test with and without paths being ignored. The bug was with paths being ignored. + +./test/test-openat + +PSEUDO_IGNORE_PATHS=/ ./test/test-openat diff --git a/test/test-pseudo_disable-fork-env_i.sh b/test/test-pseudo_disable-fork-env_i.sh index 1e679aa..0bcf797 100755 --- a/test/test-pseudo_disable-fork-env_i.sh +++ b/test/test-pseudo_disable-fork-env_i.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# # Verify normal operation... uid=`env -i id -u` diff --git a/test/test-pseudo_disable-fork.sh b/test/test-pseudo_disable-fork.sh index 13a42a4..e0f5fd3 100755 --- a/test/test-pseudo_disable-fork.sh +++ b/test/test-pseudo_disable-fork.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# # Verify normal operation... uid=`id -u` diff --git a/test/test-pseudo_unload-fork-env_i.sh b/test/test-pseudo_unload-fork-env_i.sh index d6658e0..0e89ba0 100755 --- a/test/test-pseudo_unload-fork-env_i.sh +++ b/test/test-pseudo_unload-fork-env_i.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# # Verify normal operation... uid=`env -i id -u` diff --git a/test/test-pseudo_unload-fork.sh b/test/test-pseudo_unload-fork.sh index 9f79198..822f478 100755 --- a/test/test-pseudo_unload-fork.sh +++ b/test/test-pseudo_unload-fork.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# # Verify normal operation... uid=`id -u` diff --git a/test/test-reexec-chroot.sh b/test/test-reexec-chroot.sh index bde93f1..f6412bc 100755 --- a/test/test-reexec-chroot.sh +++ b/test/test-reexec-chroot.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# # Test if we re-invoke pseudo that chroot still works diff --git a/test/test-relative-from-root.sh b/test/test-relative-from-root.sh new file mode 100755 index 0000000..e2c230e --- /dev/null +++ b/test/test-relative-from-root.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# pseudo had a bug that made it abort() when looking up a relative path from +# base "/", such as by openat(dirfd_of_root, "foo/bar") or when cwd is /. It +# tried to look up base+"/"+path = "//foo/bar", which is wrong. + +set -e + +touch f1 +relative_pwd=${PWD#/} + +cd / +cat "$relative_pwd/f1" + +rm "$relative_pwd/f1" diff --git a/test/test-rename-fstat.c b/test/test-rename-fstat.c new file mode 100644 index 0000000..fb47c05 --- /dev/null +++ b/test/test-rename-fstat.c @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Test we can rename a file whilst holding an open fd which we fstat after renaming + */ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +int main() +{ + struct stat buf; + int err; + int fd = open("test-rename-fstat1", O_RDONLY); + err = rename("test-rename-fstat1", "test-rename-fstat1"); + if (err) + return err; + return fstat(fd, &buf); +} diff --git a/test/test-rename-fstat.sh b/test/test-rename-fstat.sh new file mode 100755 index 0000000..4ac89b8 --- /dev/null +++ b/test/test-rename-fstat.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# + +rm -f test-rename-fstat1 test-rename-fstat2 +touch test-rename-fstat1 +# Will abort if it fails +./test/test-rename-fstat +ecode=$? +rm -f test-rename-fstat1 test-rename-fstat2 +exit $ecode diff --git a/test/test-statx.c b/test/test-statx.c new file mode 100644 index 0000000..06d86af --- /dev/null +++ b/test/test-statx.c @@ -0,0 +1,20 @@ +/* + * Test that passing NULL to a parameter marked as nonnull works correctly + * SPDX-License-Identifier: LGPL-2.1-only + * + */ +#define _GNU_SOURCE + +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> + +// Passing a null pointer is the test scenario +#pragma GCC diagnostic ignored "-Wnonnull" + +int main(void) { + if (statx(0, NULL, 0, 0, NULL) != -1) { + return 1; + } + return 0; +} diff --git a/test/test-statx.sh b/test/test-statx.sh new file mode 100755 index 0000000..77d0302 --- /dev/null +++ b/test/test-statx.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# + +exec ./test/test-statx diff --git a/test/test-tclsh-fork.sh b/test/test-tclsh-fork.sh index e9dec66..e06f36b 100755 --- a/test/test-tclsh-fork.sh +++ b/test/test-tclsh-fork.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# # Check that tclsh doesn't hang. Note that the timeout is not needed to # reproduce the hang in tclsh, it's only there to ensure that this test script diff --git a/test/test-umask.sh b/test/test-umask.sh index 8ca4963..e09fdbf 100755 --- a/test/test-umask.sh +++ b/test/test-umask.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# mode() { ls -l "$1" | awk '{ print $1 }' @@ -32,3 +35,4 @@ case $(mode b) in *) exit 1;; esac +rm a b diff --git a/test/test-xattr.sh b/test/test-xattr.sh index 7d818d2..09cd6b0 100755 --- a/test/test-xattr.sh +++ b/test/test-xattr.sh @@ -1,4 +1,7 @@ #!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# # Return vals: 2 - Unable to run xattr commands # 1 - Invalid return value |