Always initialize head of simple linked list

OBS-URL: https://build.opensuse.org/package/show/Base:System/psmisc?expand=0&rev=116
This commit is contained in:
Dr. Werner Fink 2018-11-30 14:26:22 +00:00 committed by Git OBS Bridge
parent f13b879ded
commit e872579636
3 changed files with 84 additions and 23 deletions

View File

@ -1,4 +1,4 @@
From 2588a03273329961e5eefe6fed695b8f80a352e3 Mon Sep 17 00:00:00 2001 From 8d0edbbb8d09bc7998bf926b318270b6f7989195 Mon Sep 17 00:00:00 2001
From: Werner Fink <werner@suse.de> From: Werner Fink <werner@suse.de>
Date: Mon, 22 Oct 2018 12:02:50 +0200 Date: Mon, 22 Oct 2018 12:02:50 +0200
Subject: [PATCH] Use mountinfo to be able to use the mount identity Subject: [PATCH] Use mountinfo to be able to use the mount identity
@ -12,15 +12,16 @@ Add support for name_to_handle_at() system call to
get the real mount ID for each file get the real mount ID for each file
Support also BtrFS with its various subvolumes Support also BtrFS with its various subvolumes
On BtrFS stat(2) on binary does not see subvol dev
Signed-off-by: Werner Fink <werner@suse.de> Signed-off-by: Werner Fink <werner@suse.de>
--- ---
configure.ac | 18 +- configure.ac | 18 +-
src/fuser.c | 644 ++++++++++++++++++++++++++++--------- src/fuser.c | 647 ++++++++++++++++++++++++++++---------
src/fuser.h | 27 +- src/fuser.h | 27 +-
testsuite/Makefile.am | 3 +- testsuite/Makefile.am | 3 +-
testsuite/killall.test/killall.exp | 4 + testsuite/killall.test/killall.exp | 4 +
5 files changed, 543 insertions(+), 153 deletions(-) 5 files changed, 546 insertions(+), 153 deletions(-)
diff --git configure.ac configure.ac diff --git configure.ac configure.ac
index 176a2fc..d8d3366 100644 index 176a2fc..d8d3366 100644
@ -66,7 +67,7 @@ index 176a2fc..d8d3366 100644
dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST AC_C_CONST
diff --git src/fuser.c src/fuser.c diff --git src/fuser.c src/fuser.c
index c44cee8..7ee9b49 100644 index c44cee8..48d52d0 100644
--- src/fuser.c --- src/fuser.c
+++ src/fuser.c +++ src/fuser.c
@@ -32,6 +32,10 @@ @@ -32,6 +32,10 @@
@ -248,9 +249,9 @@ index c44cee8..7ee9b49 100644
dev_tmp->name = this_name; dev_tmp->name = this_name;
dev_tmp->device = device; dev_tmp->device = device;
+ dev_tmp->mnt_id = this_name->mnt_id; + dev_tmp->mnt_id = this_name->mnt_id;
+ dev_tmp->vol = NULL;
+ if (dev_tmp->device != subvol) + if (dev_tmp->device != subvol)
+ add_subvol(&dev_tmp->vol, subvol, this_name->mnt_id); + add_subvol(&dev_tmp->vol, subvol, this_name->mnt_id);
+ else dev_tmp->vol = NULL;
dev_tmp->next = dev_head; dev_tmp->next = dev_head;
*dev_list = dev_tmp; *dev_list = dev_tmp;
} }
@ -713,7 +714,7 @@ index c44cee8..7ee9b49 100644
{ {
list_t *ptr, *tmp; list_t *ptr, *tmp;
@@ -2018,72 +2202,244 @@ static void clear_mntinfo(void) @@ -2018,72 +2202,247 @@ static void clear_mntinfo(void)
} }
} }
@ -757,8 +758,11 @@ index c44cee8..7ee9b49 100644
+ struct stat st; + struct stat st;
+ mntinf = add_mntinfo(mpoint, type, mid, parid, makedev(maj, min)); + mntinf = add_mntinfo(mpoint, type, mid, parid, makedev(maj, min));
+ if (mntinf && strncmp(devname, "/dev/", 5) == 0 && stat(devname, &st) == 0) { + if (mntinf && strncmp(devname, "/dev/", 5) == 0 && stat(devname, &st) == 0) {
+ if (st.st_rdev != 0 && mntinf->dev != st.st_rdev) + if (st.st_rdev != 0 && mntinf->dev != st.st_rdev) {
+ mntinf->vol = st.st_rdev; + mntinf->vol = st.st_rdev;
+ stat(mpoint, &st);
+ mntinf->dev = st.st_dev; /* stat(2) on binary does not see subvol dev */
+ }
} }
- append(mnt, mntinfo); - append(mnt, mntinfo);
- mnt->mpoint = ((char *)mnt) + alignof(mntinfo_t); - mnt->mpoint = ((char *)mnt) + alignof(mntinfo_t);
@ -1002,7 +1006,7 @@ index c44cee8..7ee9b49 100644
/* /*
* Determine device of links below /proc/ * Determine device of links below /proc/
*/ */
@@ -2091,8 +2447,7 @@ static int mntstat(const char *path, struct stat *buf) @@ -2091,8 +2450,7 @@ static int mntstat(const char *path, struct stat *buf)
{ {
char name[PATH_MAX + 1]; char name[PATH_MAX + 1];
const char *use; const char *use;
@ -1012,7 +1016,7 @@ index c44cee8..7ee9b49 100644
if ((use = realpath(path, name)) == NULL || *use != '/') if ((use = realpath(path, name)) == NULL || *use != '/')
{ {
@@ -2104,27 +2459,26 @@ static int mntstat(const char *path, struct stat *buf) @@ -2104,27 +2462,26 @@ static int mntstat(const char *path, struct stat *buf)
errno = 0; errno = 0;
return stat(path, buf); return stat(path, buf);
} }

View File

@ -90,7 +90,7 @@ index d8d3366..81d3674 100644
# Enable hardened compile and link flags # Enable hardened compile and link flags
AC_ARG_ENABLE([harden_flags], AC_ARG_ENABLE([harden_flags],
diff --git src/fuser.c src/fuser.c diff --git src/fuser.c src/fuser.c
index 7ee9b49..3f512de 100644 index 48d52d0..f824581 100644
--- src/fuser.c --- src/fuser.c
+++ src/fuser.c +++ src/fuser.c
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
@ -235,7 +235,38 @@ index 7ee9b49..3f512de 100644
continue; continue;
} }
/* Scan the devices */ /* Scan the devices */
@@ -2296,7 +2291,7 @@ out: @@ -2225,10 +2220,10 @@ init_mntinfo(void)
&mid, &parid, &maj, &min, &mpoint[0], &type[0], &devname[0]) == 7) {
struct stat st;
mntinf = add_mntinfo(mpoint, type, mid, parid, makedev(maj, min));
- if (mntinf && strncmp(devname, "/dev/", 5) == 0 && stat(devname, &st) == 0) {
+ if (mntinf && strncmp(devname, "/dev/", 5) == 0 && statn(devname, 0, &st) == 0) {
if (st.st_rdev != 0 && mntinf->dev != st.st_rdev) {
mntinf->vol = st.st_rdev;
- stat(mpoint, &st);
+ statn(mpoint, 0, &st);
mntinf->dev = st.st_dev; /* stat(2) on binary does not see subvol dev */
}
}
@@ -2240,7 +2235,7 @@ init_mntinfo(void)
parid = -1;
while (fscanf (mnt, "%s %s %s %*[^\n]", &devname[0], &mpoint[0], &type[0]) == 3) {
struct stat st;
- if (stat(mpoint, &st) != 0) {
+ if (statn(mpoint, 0, &st) != 0) {
if (errno != EACCES) {
fprintf(stderr, _("Cannot stat %s: %s\n"),
mnt->mpoint, strerror(errno));
@@ -2249,7 +2244,7 @@ init_mntinfo(void)
st.st_dev = (dev_t)-1;
}
mntinf = add_mntinfo(mpoint, type, mid++, parid, st.st_dev);
- if (mntinf && strncmp(devname, "/dev/", 5) == 0 && stat(devname, &st) == 0) {
+ if (mntinf && strncmp(devname, "/dev/", 5) == 0 && statn(devname, 0, &st) == 0) {
if (st.st_rdev != 0 && mntinf->dev != st.st_rdev)
mntinf->vol = st.st_rdev;
}
@@ -2299,7 +2294,7 @@ out:
struct stat lst; struct stat lst;
snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd); snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd);
@ -244,7 +275,25 @@ index 7ee9b49..3f512de 100644
if (lst.st_mode & S_IWUSR) if (lst.st_mode & S_IWUSR)
info->flags |= O_WRONLY; info->flags |= O_WRONLY;
ret++; ret++;
@@ -2439,49 +2434,6 @@ out: @@ -2372,7 +2367,7 @@ find_mountpoint(const char *path, mntinfo_t **mountinfo)
/* could be a chroot or a container */
- if (stat(path, &st) != 0) {
+ if (statn(path, 0, &st) != 0) {
if (errno != EACCES) {
fprintf(stderr, _("Cannot stat %s: %s\n"),
path, strerror(errno));
@@ -2404,7 +2399,7 @@ find_mountpoint(const char *path, mntinfo_t **mountinfo)
/* could be a chroot or a container */
- if (stat(use, &st) != 0) {
+ if (statn(use, 0, &st) != 0) {
if (errno != EACCES) {
fprintf(stderr, _("Cannot stat %s: %s\n"),
use, strerror(errno));
@@ -2442,49 +2437,6 @@ out:
return ret; return ret;
} }
@ -296,10 +345,10 @@ index 7ee9b49..3f512de 100644
* it avoids lstat(2) system calls. * it avoids lstat(2) system calls.
diff --git src/statx.c src/statx.c diff --git src/statx.c src/statx.c
new file mode 100644 new file mode 100644
index 0000000..2554da7 index 0000000..a598c89
--- /dev/null --- /dev/null
+++ src/statx.c +++ src/statx.c
@@ -0,0 +1,147 @@ @@ -0,0 +1,149 @@
+/* +/*
+ * statx.c - Map modern statx(2) system call to older stat(2), lstat(2), + * statx.c - Map modern statx(2) system call to older stat(2), lstat(2),
+ * and fstat(2) replacements named {,l,f}statn() + * and fstat(2) replacements named {,l,f}statn()
@ -333,10 +382,12 @@ index 0000000..2554da7
+# include <linux/fcntl.h> /* Definition of AT_* and AT_STATX_* constants ! */ +# include <linux/fcntl.h> /* Definition of AT_* and AT_STATX_* constants ! */
+#endif +#endif
+#include <fcntl.h> /* Definition of AT_* constants */ +#include <fcntl.h> /* Definition of AT_* constants */
+#ifndef HAVE_STATX
+# include <linux/stat.h> /* Provides 'struct statx' and STATX_* ! */
+#endif
+#include <sys/stat.h> +#include <sys/stat.h>
+#ifndef HAVE_STATX
+# ifndef STATX_TYPE
+# include <linux/stat.h> /* Provides 'struct statx' and STATX_* ! */
+# endif
+#endif
+#include <sys/sysmacros.h> +#include <sys/sysmacros.h>
+#include <sys/syscall.h> +#include <sys/syscall.h>
+#include <sys/types.h> +#include <sys/types.h>
@ -449,10 +500,10 @@ index 0000000..2554da7
+} +}
diff --git src/statx.h src/statx.h diff --git src/statx.h src/statx.h
new file mode 100644 new file mode 100644
index 0000000..bc9eda7 index 0000000..fdd0137
--- /dev/null --- /dev/null
+++ src/statx.h +++ src/statx.h
@@ -0,0 +1,66 @@ @@ -0,0 +1,68 @@
+/* +/*
+ * statx.h - Map modern statx(2) system call to older stat(2), lstat(2), + * statx.h - Map modern statx(2) system call to older stat(2), lstat(2),
+ * and fstat(2) replacements named {,l,f}statn() + * and fstat(2) replacements named {,l,f}statn()
@ -482,8 +533,10 @@ index 0000000..bc9eda7
+# ifndef HAVE_STATX +# ifndef HAVE_STATX
+# define _ASM_GENERIC_FCNTL_H /* Avoid collisions between asm/fcntl.h and bits/fcntl.h ! */ +# define _ASM_GENERIC_FCNTL_H /* Avoid collisions between asm/fcntl.h and bits/fcntl.h ! */
+# include <linux/fcntl.h> /* Definition of AT_* and AT_STATX_* constants ! */ +# include <linux/fcntl.h> /* Definition of AT_* and AT_STATX_* constants ! */
+# ifndef STATX_TYPE
+# include <linux/stat.h> /* Provides 'struct statx' and STATX_* ! */ +# include <linux/stat.h> /* Provides 'struct statx' and STATX_* ! */
+# endif +# endif
+# endif
+extern int statn(const char*, unsigned int, struct stat*); +extern int statn(const char*, unsigned int, struct stat*);
+extern int fstatn(int, unsigned int, struct stat*); +extern int fstatn(int, unsigned int, struct stat*);
+extern int lstatn(const char*, unsigned int, struct stat*); +extern int lstatn(const char*, unsigned int, struct stat*);
@ -948,6 +1001,3 @@ index f372297..0000000
-#endif -#endif
- -
-#endif -#endif
--
2.16.4

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Nov 30 13:21:44 UTC 2018 - Dr. Werner Fink <werner@suse.de>
- Modify patch 0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch
* Always initialize head of simple linked list (bsc#1098697)
* stat(2) on binary does not see subvol dev
------------------------------------------------------------------- -------------------------------------------------------------------
Wed Nov 14 07:44:55 UTC 2018 - Dr. Werner Fink <werner@suse.de> Wed Nov 14 07:44:55 UTC 2018 - Dr. Werner Fink <werner@suse.de>