nfsrahead: Stop being killed by SIGSEGV (bz 2078147)

Signed-off-by: Steve Dickson <steved@redhat.com>
This commit is contained in:
Steve Dickson 2022-04-29 16:41:24 -04:00
parent 1ab5a14fa0
commit aaeff91253
2 changed files with 140 additions and 2 deletions

View File

@ -0,0 +1,134 @@
diff --git a/tools/nfsrahead/main.c b/tools/nfsrahead/main.c
index b3af3aa..5fae941 100644
--- a/tools/nfsrahead/main.c
+++ b/tools/nfsrahead/main.c
@@ -26,27 +26,31 @@ struct device_info {
};
/* Convert a string in the format n:m to a device number */
-static dev_t dev_from_arg(const char *device_number)
+static int fill_device_number(struct device_info *info)
{
- char *s = strdup(device_number), *p;
+ char *s = strdup(info->device_number), *p;
char *maj_s, *min_s;
unsigned int maj, min;
- dev_t dev;
+ int err = -EINVAL;
maj_s = p = s;
- for ( ; *p != ':'; p++)
+ for ( ; *p != ':' && *p != '\0'; p++)
;
+ if (*p == '\0')
+ goto out_free;
+
+ err = 0;
*p = '\0';
min_s = p + 1;
maj = strtol(maj_s, NULL, 10);
min = strtol(min_s, NULL, 10);
- dev = makedev(maj, min);
-
+ info->dev = makedev(maj, min);
+out_free:
free(s);
- return dev;
+ return err;
}
#define sfree(ptr) if (ptr) free(ptr)
@@ -55,7 +59,7 @@ static dev_t dev_from_arg(const char *device_number)
static void init_device_info(struct device_info *di, const char *device_number)
{
di->device_number = strdup(device_number);
- di->dev = dev_from_arg(device_number);
+ di->dev = 0;
di->mountpoint = NULL;
di->fstype = NULL;
}
@@ -76,11 +80,15 @@ static int get_mountinfo(const char *device_number, struct device_info *device_i
char *target;
init_device_info(device_info, device_number);
+ if ((ret = fill_device_number(device_info)) < 0)
+ goto out_free_device_info;
mnttbl = mnt_new_table();
- if ((ret = mnt_table_parse_file(mnttbl, mountinfo_path)) < 0)
+ if ((ret = mnt_table_parse_file(mnttbl, mountinfo_path)) < 0) {
+ xlog(D_GENERAL, "Failed to parse %s\n", mountinfo_path);
goto out_free_tbl;
+ }
if ((fs = mnt_table_find_devno(mnttbl, device_info->dev, MNT_ITER_FORWARD)) == NULL) {
ret = ENOENT;
@@ -101,6 +109,7 @@ out_free_fs:
mnt_free_fs(fs);
out_free_tbl:
mnt_free_table(mnttbl);
+out_free_device_info:
free(device_info->device_number);
device_info->device_number = NULL;
return ret;
@@ -123,19 +132,20 @@ static int conf_get_readahead(const char *kind) {
return readahead;
}
-#define L_DEFAULT (L_WARNING | L_ERROR | L_FATAL)
int main(int argc, char **argv)
{
int ret = 0, retry;
struct device_info device;
- unsigned int readahead = 128, verbose = 0, log_stderr = 0;
+ unsigned int readahead = 128, log_level, log_stderr = 0;
char opt;
+
+ log_level = D_ALL & ~D_GENERAL;
while((opt = getopt(argc, argv, "dF")) != -1) {
switch (opt) {
case 'd':
- verbose = 1;
+ log_level = D_ALL;
break;
case 'F':
log_stderr = 1;
@@ -147,7 +157,7 @@ int main(int argc, char **argv)
xlog_stderr(log_stderr);
xlog_syslog(~log_stderr);
- xlog_config(L_DEFAULT | (L_NOTICE & verbose), 1);
+ xlog_config(log_level, 1);
xlog_open(CONF_NAME);
// xlog_err causes the system to exit
@@ -159,12 +169,12 @@ int main(int argc, char **argv)
break;
if (ret != 0) {
- xlog(L_ERROR, "unable to find device %s\n", argv[optind]);
+ xlog(D_GENERAL, "unable to find device %s\n", argv[optind]);
goto out;
}
if (strncmp("nfs", device.fstype, 3) != 0) {
- xlog(L_NOTICE,
+ xlog(D_GENERAL,
"not setting readahead for non supported fstype %s on device %s\n",
device.fstype, argv[optind]);
ret = -EINVAL;
@@ -173,7 +183,7 @@ int main(int argc, char **argv)
readahead = conf_get_readahead(device.fstype);
- xlog(L_WARNING, "setting %s readahead to %d\n", device.mountpoint, readahead);
+ xlog(D_FAC7, "setting %s readahead to %d\n", device.mountpoint, readahead);
printf("%d\n", readahead);

View File

@ -2,7 +2,7 @@ Summary: NFS utilities and supporting clients and daemons for the kernel NFS ser
Name: nfs-utils
URL: http://linux-nfs.org/
Version: 2.6.1
Release: 1.rc4%{?dist}
Release: 2.rc4%{?dist}
Epoch: 1
# group all 32bit related archs
@ -18,6 +18,7 @@ Source6: nfs-convert.service
Source7: 10-nfsv4.conf
Patch001: nfs-utils-2.6.2-rc4.patch
Patch002: nfs-utils-2.6.2-nfsrahead.patch
Patch100: nfs-utils-1.2.1-statdpath-man.patch
Patch101: nfs-utils-1.2.1-exp-subtree-warn-off.patch
@ -462,7 +463,10 @@ fi
%{_mandir}/*/nfsiostat.8.gz
%changelog
* Wed Apr 20 2022 Steve Dickson <steved@redhat.com> 2.6.1-0.rc4
* Thu Apr 28 2022 Steve Dickson <steved@redhat.com> 2.6.1-2.rc4
- nfsrahead: Stop being killed by SIGSEGV (bz 2078147)
* Wed Apr 20 2022 Steve Dickson <steved@redhat.com> 2.6.1-1.rc4
- Updated to the latest RC release: nfs-utils-2-6-2-rc4 (bz 2022136)
* Wed Mar 2 2022 Steve Dickson <steved@redhat.com> 2.6.1-0.rc3