]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Merge branch 'non-canonical-completion' of https://github.com/kevinoid/util-linux
authorKarel Zak <kzak@redhat.com>
Mon, 30 Sep 2019 09:06:09 +0000 (11:06 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 30 Sep 2019 09:06:09 +0000 (11:06 +0200)
* 'non-canonical-completion' of https://github.com/kevinoid/util-linux:
  bash-completion: Add non-canonical device fallback
  bash-completion: Add fallback for symlinks/images
  bash-completion: Standardize fsck/mkfs file/device

23 files changed:
Documentation/howto-tests.txt
disk-utils/fdformat.c
disk-utils/mkswap.c
disk-utils/sfdisk.8
include/all-io.h
include/pt-sgi.h
include/pwdutils.h
lib/pwdutils.c
libblkid/src/probe.c
libfdisk/src/bsd.c
libfdisk/src/gpt.c
libfdisk/src/iter.c
libmount/src/utils.c
libuuid/src/uuidP.h
login-utils/auth.h
login-utils/chsh.c
login-utils/islocal.h
login-utils/libuser.h
sys-utils/fsfreeze.c
term-utils/ttymsg.h
tests/expected/lscpu/lscpu-s390-nested-virt [new file with mode: 0644]
tests/ts/lscpu/dumps/s390-nested-virt.tar.gz [new file with mode: 0644]
text-utils/hexdump.h

index 71c7f85c1612719c82954fc136387c71e45ddfbd..4d302beea5e3879432b123325258c551d4cf480b 100644 (file)
@@ -5,21 +5,25 @@
  It's expected that for each invasive change or important bugfix you will
  include a test to your patch.
 
- Compile tests & run basic tests:
+ Compile binaries, libs, extra test programs and run the basic tests:
 
        $ make check
 
+ Compile extra test programs only:
+
+       $ make check-programs
+
  Note that the configure option --disable-static disables many of libmount and
  libblkid unit tests.
 
  Run all tests including tests that require root permissions:
 
        # cd tests
-       # ./run.sh [--verbose] [--memcheck]
+       # ./run.sh [options, see --help]
 
        Alternatively using sudo and make:
 
-       $ make check TS_COMMAND="true"
+       $ make check-programs
        $ sudo -E make check TS_OPTS="--parallel=1"
 
  note that as root you have to manually remove output and diff directories
@@ -31,6 +35,7 @@
 
  Run subset of tests:
 
+       $ cd tests
        $ ./run.sh <test_directory-name>
 
         for example:
               $ ./run.sh blkid
               $ ./run.sh libmount
 
+        or individual test script, for example:
+
+             $ ./ts/cal/year
+
  The tests is possible to exclude by ./run.sh --exclude=<list>  where the
  <list> is blank separated test names in format "testdir/testname", for example:
 
index c10776f76eac785cf43bd0e2025a1a01a7ceb90b..38849eb7e040c795b8498ae16392ef214736f25a 100644 (file)
@@ -43,7 +43,8 @@ static void format_track_head(int ctrl, struct format_descr *descr)
 
 static void seek_track_head(int ctrl, struct format_descr *descr)
 {
-       lseek(ctrl, (descr->track * param.head + descr->head) * param.sect * SECTOR_SIZE, SEEK_SET);
+       lseek(ctrl, ((off_t) descr->track * param.head + descr->head)
+                       * param.sect * SECTOR_SIZE, SEEK_SET);
 }
 
 static void format_disk(int ctrl, unsigned int track_from, unsigned int track_to)
index 659ebf0d712d1f07883a5992ab37a571a87b959a..c6aaaf5f1b6348a6f0815f838746e3ca0453a0d2 100644 (file)
@@ -191,9 +191,9 @@ static void check_blocks(struct mkswap_control *ctl)
        buffer = xmalloc(ctl->pagesize);
        while (current_page < ctl->npages) {
                ssize_t rc;
+               off_t offset = (off_t) current_page * ctl->pagesize;
 
-               if (do_seek && lseek(ctl->fd, current_page * ctl->pagesize, SEEK_SET) !=
-                   current_page * ctl->pagesize)
+               if (do_seek && lseek(ctl->fd, offset, SEEK_SET) != offset)
                        errx(EXIT_FAILURE, _("seek failed in check_blocks"));
 
                rc = read(ctl->fd, buffer, ctl->pagesize);
index d1e429381f74c6921294e646e6e90e1bd7ea9569..ff0739a328c7fda37b210217446b616db83ead58 100644 (file)
@@ -25,7 +25,8 @@ sfdisk \- display or manipulate a disk partition table
 .I command
 .SH DESCRIPTION
 .B sfdisk
-is a script-oriented tool for partitioning any block device.
+is a script-oriented tool for partitioning any block device.  It
+runs in interactive mode if executed on terminal (stdin refers to a terminal).
 
 Since version 2.26
 .B sfdisk
index dd4556fcb60662b3a08e5d524f9e4cd119e03cbe..8ffa9cfb110722d48493404b9035df3732c360e4 100644 (file)
@@ -70,8 +70,7 @@ static inline ssize_t read_all(int fd, char *buf, size_t count)
                        }
                        return c ? c : -1;
                }
-               if (ret > 0)
-                       tries = 0;
+               tries = 0;
                count -= ret;
                buf += ret;
                c += ret;
index 5d6b68f1343dc9a7787a7e88f09aae014ad56874..6d512ee0093921e870ffe6e5b3682a48858106a5 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef UTIL_LINUX_PT_SUN_H
-#define UTIL_LINUX_PT_SUN_H
+#ifndef UTIL_LINUX_PT_SGI_H
+#define UTIL_LINUX_PT_SGI_H
 
 #include <stdint.h>
 
@@ -112,4 +112,4 @@ static inline uint32_t sgi_pt_checksum(struct sgi_disklabel *label)
        return sum;
 }
 
-#endif /* UTIL_LINUX_PT_SUN_H */
+#endif /* UTIL_LINUX_PT_SGI_H */
index a69dd6b454273e1f0685afd44a83b2671e35ab02..bea46e57e3b04d4267b3e4fa25b23939b0c41f48 100644 (file)
@@ -5,6 +5,7 @@
 #include <pwd.h>
 
 extern struct passwd *xgetpwnam(const char *username, char **pwdbuf);
+extern struct passwd *xgetpwuid(uid_t uid, char **pwdbuf);
 extern char *xgetlogin(void);
 
 #endif /* UTIL_LINUX_PWDUTILS_H */
index 25b4daed0e859ba695fd112fb47b9758e3f5ccdf..d54458d65da6fd539e81df23a3c7b099883267c1 100644 (file)
@@ -36,6 +36,34 @@ failed:
        return NULL;
 }
 
+struct passwd *xgetpwuid(uid_t uid, char **pwdbuf)
+{
+       struct passwd *pwd = NULL, *res = NULL;
+       int rc;
+
+       if (!pwdbuf)
+               return NULL;
+
+       *pwdbuf = xmalloc(UL_GETPW_BUFSIZ);
+       pwd = xcalloc(1, sizeof(struct passwd));
+
+       errno = 0;
+       rc = getpwuid_r(uid, pwd, *pwdbuf, UL_GETPW_BUFSIZ, &res);
+       if (rc != 0) {
+               errno = rc;
+               goto failed;
+       }
+       if (!res) {
+               errno = EINVAL;
+               goto failed;
+       }
+       return pwd;
+failed:
+       free(pwd);
+       free(*pwdbuf);
+       return NULL;
+}
+
 char *xgetlogin(void)
 {
        struct passwd *pw = NULL;
index ae1fc06d6ac8935b690c30eee8c6161a083fdd7c..790168c16cbe248154150e89627296a5899f14fe 100644 (file)
@@ -217,8 +217,7 @@ blkid_probe blkid_new_probe_from_filename(const char *filename)
        pr->flags |= BLKID_FL_PRIVATE_FD;
        return pr;
 err:
-       if (fd >= 0)
-               close(fd);
+       close(fd);
        blkid_free_probe(pr);
        return NULL;
 }
index 4e05bb3288c7bffe7f9ddba7994999578131cbc6..a7e2791a7ca0985f5e59cadb9cd409c5941a421c 100644 (file)
@@ -615,8 +615,9 @@ int fdisk_bsd_edit_disklabel(struct fdisk_context *cxt)
        d->d_ntracks = ask_uint32(cxt, d->d_ntracks, _("tracks/cylinder"));
        d->d_ncylinders = ask_uint32(cxt, d->d_ncylinders  ,_("cylinders"));
 #endif
-       if (fdisk_ask_number(cxt, 1, d->d_nsectors * d->d_ntracks,
-                            d->d_nsectors * d->d_ntracks,
+       if (fdisk_ask_number(cxt, 1,
+                       (uintmax_t) d->d_nsectors * d->d_ntracks,
+                       (uintmax_t) d->d_nsectors * d->d_ntracks,
                             _("sectors/cylinder"), &res) == 0)
                d->d_secpercyl = res;
 
index 279f229789fc6dc15b15f0cd3552e8998df9075a..f7057916907186ce146227386b5903c07baec8ce 100644 (file)
@@ -508,7 +508,7 @@ static inline int gpt_calculate_sizeof_ents(struct gpt_header *hdr, uint32_t nen
                return -ERANGE;
        }
 
-       *sz = nents * esz;
+       *sz = (size_t) nents * esz;
        return 0;
 }
 
index 9a0b0801cce1a3c8862efcff32f67ac941f6b5b2..abc3d35a44c039db745e1cb60435cb58382bf135 100644 (file)
@@ -57,7 +57,7 @@ void fdisk_free_iter(struct fdisk_iter *itr)
 /**
  * fdisk_reset_iter:
  * @itr: iterator pointer
- * @direction: FDISK_INTER_{FOR,BACK}WARD or -1 to keep the direction unchanged
+ * @direction: FDISK_ITER_{FOR,BACK}WARD or -1 to keep the direction unchanged
  *
  * Resets the iterator.
  */
index 6b731b8af5948e36de02849123439ffb40731d09..1cd8329fccd4b6f6f8502e72bfc3d8491758b1ae 100644 (file)
@@ -1242,20 +1242,26 @@ success:
  */
 FILE *mnt_get_procfs_memstream(int fd, char **membuf)
 {
-       FILE *memf;
        size_t sz = 0;
        off_t cur;
 
+       *membuf = NULL;
+
        /* in case of error, rewind to the original position */
        cur = lseek(fd, 0, SEEK_CUR);
 
-       if (read_procfs_file(fd, membuf, &sz) == 0
-           && sz > 0
-           && (memf = fmemopen(*membuf, sz, "r")))
-               return memf;
+       if (read_procfs_file(fd, membuf, &sz) == 0 && sz > 0) {
+               FILE *memf = fmemopen(*membuf, sz, "r");
+               if (memf)
+                       return memf;    /* success */
+
+               free(*membuf);
+               *membuf = NULL;
+       }
 
        /* error */
-       lseek(fd, cur, SEEK_SET);
+       if (cur != (off_t) -1)
+               lseek(fd, cur, SEEK_SET);
        return NULL;
 }
 #else
index 78183ded75d5f07690aa2550cf7f162efb7c1445..200702c1e5281254a8f4e2bf10960ebc57ba6e5b 100644 (file)
@@ -31,6 +31,8 @@
  * DAMAGE.
  * %End-Header%
  */
+#ifndef _UUID_UUID_PRIVATE_H
+#define _UUID_UUID_PRIVATE_H
 
 #include <inttypes.h>
 #include <sys/types.h>
@@ -88,3 +90,5 @@ struct uuid {
  */
 void uuid_pack(const struct uuid *uu, uuid_t ptr);
 void uuid_unpack(const uuid_t in, struct uuid *uu);
+
+#endif /* _UUID_UUID_PRIVATE_H */
index bf7c36924db22ee6f6f8bd65650e4bfe319788a5..ee58d1257047b287e7b898a81871f1df53ff8c18 100644 (file)
@@ -7,7 +7,11 @@
  *   there is no warranty.
  *
  */
+#ifndef UTIL_LINUX_LOGIN_AUTH_H
+#define UTIL_LINUX_LOGIN_AUTH_H
 
 #include <sys/types.h>
 
 extern int auth_pam(const char *service_name, uid_t uid, const char *username);
+
+#endif /* UTIL_LINUX_LOGIN_AUTH_H */
index 9b2761157342aaffaaf67a61d4a3eb69d9a7bd1b..a9ebec86ff66b8b67cfbb3a871b714f63582c9da 100644 (file)
@@ -38,6 +38,7 @@
 #include "islocal.h"
 #include "nls.h"
 #include "pathnames.h"
+#include "pwdutils.h"
 #include "setpwnam.h"
 #include "strutils.h"
 #include "xalloc.h"
@@ -253,7 +254,7 @@ static void check_shell(const char *shell)
 
 int main(int argc, char **argv)
 {
-       char *oldshell;
+       char *oldshell, *pwbuf;
        int nullshell = 0;
        const uid_t uid = getuid();
        struct sinfo info = { NULL };
@@ -267,12 +268,12 @@ int main(int argc, char **argv)
 
        parse_argv(argc, argv, &info);
        if (!info.username) {
-               pw = getpwuid(uid);
+               pw = xgetpwuid(uid, &pwbuf);
                if (!pw)
                        errx(EXIT_FAILURE, _("you (user %d) don't exist."),
                             uid);
        } else {
-               pw = getpwnam(info.username);
+               pw = xgetpwnam(info.username, &pwbuf);
                if (!pw)
                        errx(EXIT_FAILURE, _("user \"%s\" does not exist."),
                             info.username);
index 2c5879906c01a2662f1685662276fe5ed352eccd..11a1beda6e5c9599acf79293329dc3b257acee02 100644 (file)
@@ -1 +1,6 @@
+#ifndef UTIL_LINUX_LOGIN_ISLOCAL_H
+#define UTIL_LINUX_LOGIN_ISLOCAL_H
+
 extern int is_local(const char *user);
+
+#endif /* UTIL_LINUX_LOGIN_ISLOCAL_H */
index 7454b997e48ea15867d2e73030baed0bbb5f8311..d4fae64ce7200e97dd4ecb0dcbb718688578e9bf 100644 (file)
@@ -7,8 +7,12 @@
  *   there is no warranty.
  *
  */
+#ifndef UTIL_LINUX_LOGIN_LIBUSER_H
+#define UTIL_LINUX_LOGIN_LIBUSER_H
 
 #include <sys/types.h>
 
 extern int set_value_libuser(const char *service_name, const char *username,
                        uid_t uid, const char *attr, const char *val);
+
+#endif /* UTIL_LINUX_LOGIN_LIBUSER_H */
index 6035a1010db60257e0d288c8f15a8d1cc255226b..cd2bb4790f34d0cb53046f836309695ff6716dc8 100644 (file)
@@ -144,8 +144,7 @@ int main(int argc, char **argv)
 
        rc = EXIT_SUCCESS;
 done:
-       if (fd >= 0)
-               close(fd);
+       close(fd);
        return rc;
 }
 
index 2cfa73027b6dcefd435cbf7a9d08e6188e1fb5a4..8424ac40f6b04f3f15db44431176bc8bdbc89c7b 100644 (file)
@@ -1,2 +1,6 @@
+#ifndef UTIL_LINUX_TERM_TTYMSG_H
+#define UTIL_LINUX_TERM_TTYMSG_H
+
 char *ttymsg(struct iovec *iov, size_t iovcnt, char *line, int tmout);
 
+#endif /* UTIL_LINUX_TERM_TTYMSG_H */
diff --git a/tests/expected/lscpu/lscpu-s390-nested-virt b/tests/expected/lscpu/lscpu-s390-nested-virt
new file mode 100644 (file)
index 0000000..2665fd8
--- /dev/null
@@ -0,0 +1,45 @@
+CPU op-mode(s):                  32-bit, 64-bit
+CPU(s):                          2
+On-line CPU(s) list:             0,1
+Thread(s) per core:              1
+Core(s) per socket:              1
+Socket(s) per book:              1
+Book(s) per drawer:              1
+Drawer(s):                       2
+NUMA node(s):                    1
+Vendor ID:                       IBM/S390
+Machine type:                    2964
+CPU dynamic MHz:                 5000
+CPU static MHz:                  5000
+BogoMIPS:                        3033.00
+Hypervisor:                      KVM/Linux
+Hypervisor vendor:               KVM
+Virtualization type:             full
+Dispatching mode:                horizontal
+L1d cache:                       256 KiB
+L1i cache:                       192 KiB
+L2d cache:                       4 MiB
+L2i cache:                       4 MiB
+L3 cache:                        64 MiB
+L4 cache:                        480 MiB
+NUMA node0 CPU(s):               0,1
+Vulnerability L1tf:              Not affected
+Vulnerability Meltdown:          Not affected
+Vulnerability Spec store bypass: Not affected
+Vulnerability Spectre v1:        Mitigation; __user pointer sanitization
+Vulnerability Spectre v2:        Mitigation; execute trampolines
+Flags:                           esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs te vx
+
+# The following is the parsable format, which can be fed to other
+# programs. Each different item in every column has an unique ID
+# starting from zero.
+# CPU,Core,Socket,Node,,L1d,L1i,L2d,L2i
+0,0,0,0,,0,0,0,0
+1,1,1,0,,1,1,1,1
+
+# The following is the parsable format, which can be fed to other
+# programs. Each different item in every column has an unique ID
+# starting from zero.
+# CPU,Core,Socket,Node,,L1d,L1i,L2d,L2i
+0,0,0,0,,0,0,0,0
+1,1,1,0,,1,1,1,1
diff --git a/tests/ts/lscpu/dumps/s390-nested-virt.tar.gz b/tests/ts/lscpu/dumps/s390-nested-virt.tar.gz
new file mode 100644 (file)
index 0000000..7992699
Binary files /dev/null and b/tests/ts/lscpu/dumps/s390-nested-virt.tar.gz differ
index 4a8d10916ba3496f9b6515f5dfc04d7ba8456135..3233985d739c1b3e82a1f1a0b66f0b715bbc3e2d 100644 (file)
@@ -32,6 +32,9 @@
  *
  *     @(#)hexdump.h   5.4 (Berkeley) 6/1/90
  */
+#ifndef UTIL_LINUX_HEXDUMP_H
+#define UTIL_LINUX_HEXDUMP_H
+
 #include "c.h"
 #include "list.h"
 
@@ -106,3 +109,5 @@ void conv_c(struct hexdump_pr *, u_char *);
 void conv_u(struct hexdump_pr *, u_char *);
 int  next(char **, struct hexdump *);
 int parse_args(int, char **, struct hexdump *);
+
+#endif /* UTIL_LINUX_HEXDUMP_H */