]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
[clang-tidy] do not use else after return
authorRosen Penev <rosenp@gmail.com>
Sun, 19 Apr 2020 05:16:22 +0000 (22:16 -0700)
committerRosen Penev <rosenp@gmail.com>
Mon, 20 Apr 2020 20:20:59 +0000 (13:20 -0700)
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
63 files changed:
disk-utils/cfdisk.c
disk-utils/fsck.c
disk-utils/fsck.cramfs.c
disk-utils/fsck.minix.c
disk-utils/mkfs.cramfs.c
disk-utils/partx.c
disk-utils/sfdisk.c
lib/blkdev.c
lib/encode.c
lib/loopdev.c
lib/strutils.c
lib/ttyutils.c
libblkid/src/partitions/gpt.c
libblkid/src/probe.c
libblkid/src/superblocks/befs.c
libblkid/src/superblocks/luks.c
libblkid/src/superblocks/minix.c
libblkid/src/superblocks/swap.c
libblkid/src/superblocks/udf.c
libfdisk/src/context.c
libfdisk/src/dos.c
libfdisk/src/partition.c
libfdisk/src/sgi.c
libmount/python/context.c
libmount/python/fs.c
libmount/python/tab.c
libmount/src/cache.c
libmount/src/context.c
libmount/src/context_mount.c
libmount/src/context_umount.c
libmount/src/lock.c
libmount/src/monitor.c
libmount/src/optmap.c
libmount/src/optstr.c
libmount/src/utils.c
libsmartcols/src/calculate.c
libsmartcols/src/cell.c
libuuid/src/parse.c
libuuid/src/predefined.c
login-utils/islocal.c
login-utils/logindefs.c
login-utils/utmpdump.c
misc-utils/cal.c
misc-utils/findmnt-verify.c
misc-utils/getopt.c
misc-utils/kill.c
misc-utils/rename.c
misc-utils/uuidd.c
sys-utils/eject.c
sys-utils/hwclock-rtc.c
sys-utils/hwclock.c
sys-utils/ipcutils.c
sys-utils/lsipc.c
sys-utils/lsns.c
sys-utils/prlimit.c
sys-utils/unshare.c
sys-utils/zramctl.c
term-utils/agetty.c
term-utils/scriptlive.c
term-utils/setterm.c
text-utils/more.c
text-utils/pg.c
text-utils/ul.c

index 89e54d6f430f28cccc69e2381c054239bd29e50b..2fb442dc33a5987f54797a53ccb9992d20fcace6 100644 (file)
@@ -986,7 +986,9 @@ static size_t menuitem_get_line(struct cfdisk *cf, size_t idx)
                if (!m->page_sz)                                /* small menu */
                        return (ui_lines - (cf->menu->nitems + 1)) / 2 + idx;
                return (idx % m->page_sz) + 1;
-       } else {
+       }
+
+       {
                size_t len = MENU_H_ITEMWIDTH(m) + MENU_H_BETWEEN; /** item width */
                size_t items = ui_cols / len;                   /* items per line */
 
@@ -1003,7 +1005,9 @@ static int menuitem_get_column(struct cfdisk *cf, size_t idx)
                if ((size_t) ui_cols <= nc)
                        return 0;
                return (ui_cols - nc) / 2;
-       } else {
+       }
+
+       {
                size_t len = MENU_H_ITEMWIDTH(cf->menu) + MENU_H_BETWEEN; /* item width */
                size_t items = ui_cols / len;                           /* items per line */
                size_t extra = items < cf->menu->nitems ?               /* extra space on line */
@@ -1877,7 +1881,7 @@ static int ui_get_size(struct cfdisk *cf, /* context */
                if (rc == 0) {
                        ui_warnx(_("Please, specify size."));
                        continue;                       /* nothing specified */
-               } else if (rc == -CFDISK_ERR_ESC)
+               } if (rc == -CFDISK_ERR_ESC)
                        break;                          /* cancel dialog */
 
                if (strcmp(buf, dflt) == 0)
index a071c0eb498690fc9cb7747ea41eb56ad1ca13fb..8391e5d940592df9a6c871ff8b0d81dae8dfbe97 100644 (file)
@@ -172,8 +172,8 @@ static int string_to_int(const char *s)
        l = strtol(s, &p, 0);
        if (*p || l == LONG_MIN || l == LONG_MAX || l < 0 || l > INT_MAX)
                return -1;
-       else
-               return (int) l;
+
+       return (int) l;
 }
 
 /* Do we really really want to check this fs? */
index 3a43dd7b913ce2f93ffb590def523fa47b65aa66..5145bcfd7aa80d8dc5f8a78e393aa96903a07bd5 100644 (file)
@@ -131,12 +131,15 @@ static int get_superblock_endianness(uint32_t magic)
        if (magic == CRAMFS_MAGIC) {
                cramfs_is_big_endian = HOST_IS_BIG_ENDIAN;
                return 0;
-       } else if (magic ==
+       }
+
+       if (magic ==
                   u32_toggle_endianness(!HOST_IS_BIG_ENDIAN, CRAMFS_MAGIC)) {
                cramfs_is_big_endian = !HOST_IS_BIG_ENDIAN;
                return 0;
-       } else
-               return -1;
+       }
+
+       return -1;
 }
 
 static void test_super(int *start, size_t * length)
index 53879895da06199e4475108c8a1051cc7e6c5e77..d3725ee0d1822463cf891af5872adb9b79a0d398 100644 (file)
@@ -300,7 +300,7 @@ static int is_valid_zone_nr(unsigned short nr)
 {
        if (nr < get_first_zone())
                return 0;
-       else if (nr >= get_nzones())
+       if (nr >= get_nzones())
                return 0;
        return 1;
 }
@@ -1355,7 +1355,9 @@ main(int argc, char **argv) {
                if (repair)
                        printf(_("%s is clean, no check.\n"), device_name);
                return retcode;
-       } else if (force)
+       }
+
+       if (force)
                printf(_("Forcing filesystem check on %s.\n"), device_name);
        else if (repair)
                printf(_("Filesystem on %s is dirty, needs checking.\n"),
index e6afd2df0f73678d4e89dc76627477ae1f4a9b18..1d0d17bf1deef050b091a9ae839eff4962493e99 100644 (file)
@@ -547,9 +547,9 @@ static int is_zero(unsigned char const *begin, unsigned len)
                             (len-- == 0 ||
                              (begin[3] == '\0' &&
                               memcmp(begin, begin + 4, len) == 0))))))));
-       else
-               /* Never create holes. */
-               return 0;
+
+       /* Never create holes. */
+       return 0;
 }
 
 /*
index e1f6b8f9e40f7f3ffc3acede03dcc4055e545328..4f73c5f23805a62f732c173a87a08bb07a8e091b 100644 (file)
@@ -332,7 +332,9 @@ static int del_parts(int fd, const char *device, dev_t devno,
                        if (verbose)
                                printf(_("%s: partition #%d removed\n"), device, i);
                        continue;
-               } else if (errno == ENXIO) {
+               }
+
+               if (errno == ENXIO) {
                        if (verbose)
                                printf(_("%s: partition #%d doesn't exist\n"), device, i);
                        continue;
index 0c14627799e7922caecc2c6599b1dab8a5e29e1f..24d1f729c40eda4c59a95cded8f39316feae7e95 100644 (file)
@@ -1869,14 +1869,18 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
                        buf[sizeof(buf) - 1] = '\0';
                        fdisk_warnx(sf->cxt, _("Unknown script header '%s' -- ignore."), buf);
                        continue;
-               } else if (rc < 0) {
+               }
+
+               if (rc < 0) {
                        DBG(PARSE, ul_debug("script parsing failed, trying sfdisk specific commands"));
                        buf[sizeof(buf) - 1] = '\0';
                        rc = loop_control_commands(sf, dp, buf);
                        if (rc)
                                break;
                        continue;
-               } else if (rc == 1) {
+               }
+
+               if (rc == 1) {
                        rc = SFDISK_DONE_EOF;
                        if (!sf->quiet)
                                fputs(_("Done.\n"), stdout);
@@ -1910,7 +1914,9 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
                                rc = fdisk_set_partition(sf->cxt, partno, pa);
                                rc = rc == 0 ? SFDISK_DONE_ASK : SFDISK_DONE_ABORT;
                                break;
-                       } else if (!rc) {               /* add partition */
+                       }
+
+                       if (!rc) {              /* add partition */
                                if (!sf->interactive && !sf->quiet &&
                                    (!sf->prompt || startswith(sf->prompt, SFDISK_PROMPT))) {
                                        refresh_prompt_buffer(sf, devname, next_partno, created);
index 0616142b882635b12b99ad0cab60502af32b41dd..c71550e63ef8a02b9ccee0d18986c8f665cfeb8b 100644 (file)
@@ -281,8 +281,8 @@ int blkdev_is_cdrom(int fd)
 
        if ((ret = ioctl(fd, CDROM_GET_CAPABILITY, NULL)) < 0)
                return 0;
-       else
-               return ret;
+
+       return ret;
 }
 #else
 int blkdev_is_cdrom(int fd __attribute__((__unused__)))
index bee5bd53d5b774d5eb69ccceae49a0439122b86d..10b5971c578b4b9f749ee2a37c15f3b4b8a510b5 100644 (file)
@@ -48,7 +48,9 @@ size_t ul_encode_to_utf8(int enc, unsigned char *dest, size_t len,
                if (c == 0) {
                        dest[j] = '\0';
                        break;
-               } else if (c < 0x80) {
+               }
+
+               if (c < 0x80) {
                        if (j+1 >= len)
                                break;
                        dest[j++] = (uint8_t) c;
index 99a0939260c12511536887625ab8c32b4b4be40f..76eac7b8dcac8fedcdf8e996f75e8481887d91eb 100644 (file)
@@ -1074,8 +1074,8 @@ found:
                        uint64_t sz = 0;
 
                        return loopcxt_get_sizelimit(lc, &sz) == 0 && sz == sizelimit;
-               } else
-                       return rc;
+               }
+               return rc;
        }
        return 1;
 }
index b76ab995205acdff60ebe33a06f243f7b5aff037..e1629fb56dc6e819c4ef71896fff9c5c0c8256ef 100644 (file)
@@ -255,7 +255,9 @@ int parse_switch(const char *arg, const char *errmesg, ...)
                if (strcmp(arg, a) == 0) {
                        va_end(ap);
                        return 1;
-               } else if (strcmp(arg, b) == 0) {
+               }
+
+               if (strcmp(arg, b) == 0) {
                        va_end(ap);
                        return 0;
                }
@@ -1110,19 +1112,16 @@ int main(int argc, char *argv[])
        if (argc == 3 && strcmp(argv[1], "--size") == 0)
                return test_strutils_sizes(argc - 1, argv + 1);
 
-       else if (argc == 4 && strcmp(argv[1], "--cmp-paths") == 0)
+       if (argc == 4 && strcmp(argv[1], "--cmp-paths") == 0)
                return test_strutils_cmp_paths(argc - 1, argv + 1);
 
-       else if (argc == 4 && strcmp(argv[1], "--strdup-member") == 0)
+       if (argc == 4 && strcmp(argv[1], "--strdup-member") == 0)
                return test_strdup_to_member(argc - 1, argv + 1);
 
-       else {
-               fprintf(stderr, "usage: %1$s --size <number>[suffix]\n"
-                               "       %1$s --cmp-paths <path> <path>\n"
-                               "       %1$s --strdup-member <str> <str>\n",
-                               argv[0]);
-               exit(EXIT_FAILURE);
-       }
+       fprintf(stderr, "usage: %1$s --size <number>[suffix]\n"
+                       "       %1$s --cmp-paths <path> <path>\n"
+                       "       %1$s --strdup-member <str> <str>\n",
+                       argv[0]);
 
        return EXIT_FAILURE;
 }
index 8649f435aedac0c78ab45f9ead4548539fda1fe4..70645650391b1864d5b24444a7330bfcf7703b08 100644 (file)
@@ -73,9 +73,9 @@ int get_terminal_stdfd(void)
 {
        if (isatty(STDIN_FILENO))
                return STDIN_FILENO;
-       else if (isatty(STDOUT_FILENO))
+       if (isatty(STDOUT_FILENO))
                return STDOUT_FILENO;
-       else if (isatty(STDERR_FILENO))
+       if (isatty(STDERR_FILENO))
                return STDERR_FILENO;
 
        return -EINVAL;
index 3ca64183c9a1968c6d4cc0fd534aa33861e0fbc9..889ff772ca1e622b503152e773726317ed0ca2cd 100644 (file)
@@ -321,7 +321,7 @@ static int probe_gpt_pt(blkid_probe pr,
        ret = is_pmbr_valid(pr, NULL);
        if (ret < 0)
                return ret;
-       else if (ret == 0)
+       if (ret == 0)
                goto nothing;
 
        errno = 0;
index faf3596e6d86dbcb59ff3ded86163c0d5f401f16..e148fddc01898193c0af4cf199bb32456baa4075 100644 (file)
@@ -1245,7 +1245,9 @@ int blkid_do_wipe(blkid_probe pr, int dryrun)
 
                return blkid_probe_step_back(pr);
 
-       } else if (dryrun) {
+       }
+
+       if (dryrun) {
                /* wipe in memory only */
                blkid_probe_hide_range(pr, magoff, len);
                return blkid_probe_step_back(pr);
index 516d800939016f114003377df4ce8e58a8b3d905..211feae9fed2105bf68e3882c9cb37cc162a5f6a 100644 (file)
@@ -169,8 +169,7 @@ static unsigned char *get_tree_node(blkid_probe pr, const struct befs_super_bloc
                                return get_custom_block_run(pr, bs,
                                                        &ds->direct[i],
                                                        start, length, fs_le);
-                       else
-                               start -= br_len;
+                       start -= br_len;
                }
        } else if (start < (int64_t) FS64_TO_CPU(ds->max_indirect_range, fs_le)) {
                struct block_run *br;
@@ -192,8 +191,7 @@ static unsigned char *get_tree_node(blkid_probe pr, const struct befs_super_bloc
                        if (start < br_len)
                                return get_custom_block_run(pr, bs, &br[i],
                                                        start, length, fs_le);
-                       else
-                               start -= br_len;
+                       start -= br_len;
                }
        } else if (start < (int64_t) FS64_TO_CPU(ds->max_double_indirect_range, fs_le)) {
                struct block_run *br;
@@ -333,8 +331,8 @@ static int64_t get_key_value(blkid_probe pr, const struct befs_super_block *bs,
                        if ((int64_t) FS64_TO_CPU(bn->overflow_link, fs_le)
                                                        == BPLUSTREE_NULL)
                                return FS64_TO_CPU(values[last], fs_le);
-                       else
-                               node_pointer = FS64_TO_CPU(values[last], fs_le);
+
+                       node_pointer = FS64_TO_CPU(values[last], fs_le);
                } else if (cmp < 0)
                        node_pointer = FS64_TO_CPU(bn->overflow_link, fs_le);
                else {
@@ -352,9 +350,10 @@ static int64_t get_key_value(blkid_probe pr, const struct befs_super_block *bs,
                                                fs_le) == BPLUSTREE_NULL)
                                                return FS64_TO_CPU(values[mid],
                                                                        fs_le);
-                                       else
-                                               break;
-                               } else if (cmp < 0)
+                                       break;
+                               }
+
+                               if (cmp < 0)
                                        first = mid + 1;
                                else
                                        last = mid - 1;
@@ -411,7 +410,9 @@ static int get_uuid(blkid_probe pr, const struct befs_super_block *bs,
                               sizeof(uint64_t));
 
                        break;
-               } else if (FS32_TO_CPU(sd->type, fs_le) == 0
+               }
+
+               if (FS32_TO_CPU(sd->type, fs_le) == 0
                                && FS16_TO_CPU(sd->name_size, fs_le) == 0
                                && FS16_TO_CPU(sd->data_size, fs_le) == 0)
                        break;
@@ -437,7 +438,7 @@ static int get_uuid(blkid_probe pr, const struct befs_super_block *bs,
                if (value < 0)
                        return value == -ENOENT ? BLKID_PROBE_NONE : value;
 
-               else if (value > 0) {
+               if (value > 0) {
                        bi = (struct befs_inode *) blkid_probe_get_buffer(pr,
                                value << FS32_TO_CPU(bs->block_shift, fs_le),
                                FS32_TO_CPU(bs->block_size, fs_le));
index 67d7cfcc5224f98b61744a08a18bbf6f2fd87652..0230b349267081966641122a0dbbecc57df47e6d 100644 (file)
@@ -108,18 +108,18 @@ static int probe_luks(blkid_probe pr, const struct blkid_idmag *mag __attribute_
        if (!memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L)) {
                /* LUKS primary header was found. */
                return luks_attributes(pr, header, 0);
-       } else {
-               /* No primary header, scan for known offsets of LUKS2 secondary header. */
-               for (i = 0; i < ARRAY_SIZE(secondary_offsets); i++) {
-                       header = (struct luks2_phdr *) blkid_probe_get_buffer(pr,
-                                 secondary_offsets[i], sizeof(struct luks2_phdr));
-
-                       if (!header)
-                               return errno ? -errno : BLKID_PROBE_NONE;
-
-                       if (!memcmp(header->magic, LUKS_MAGIC_2, LUKS_MAGIC_L))
-                               return luks_attributes(pr, header, secondary_offsets[i]);
-               }
+       }
+
+       /* No primary header, scan for known offsets of LUKS2 secondary header. */
+       for (i = 0; i < ARRAY_SIZE(secondary_offsets); i++) {
+               header = (struct luks2_phdr *) blkid_probe_get_buffer(pr,
+                         secondary_offsets[i], sizeof(struct luks2_phdr));
+
+               if (!header)
+                       return errno ? -errno : BLKID_PROBE_NONE;
+
+               if (!memcmp(header->magic, LUKS_MAGIC_2, LUKS_MAGIC_L))
+                       return luks_attributes(pr, header, secondary_offsets[i]);
        }
 
        return BLKID_PROBE_NONE;
index a3354f6e7cec89e6e6233e4f03b5a87b2e66dfdf..b521efb2bc89348c8125b385209f3eb8c2adcd7d 100644 (file)
@@ -143,7 +143,8 @@ static int probe_minix(blkid_probe pr,
        ext = blkid_probe_get_buffer(pr, 0x400 + 0x38, 2);
        if (!ext)
                return errno ? -errno : 1;
-       else if (memcmp(ext, "\123\357", 2) == 0)
+
+       if (memcmp(ext, "\123\357", 2) == 0)
                return 1;
 
        blkid_probe_sprintf_version(pr, "%d", version);
index 3f21391c8c336c72ec4319d1bccf0a917c191ace..94f51aa11dfafcb69813e84ae941159ffec4ab24 100644 (file)
@@ -91,7 +91,9 @@ static int probe_swap(blkid_probe pr, const struct blkid_idmag *mag)
                blkid_probe_set_version(pr, "0");
                return 0;
 
-       } else if (!memcmp(mag->magic, "SWAPSPACE2", mag->len))
+       }
+
+       if (!memcmp(mag->magic, "SWAPSPACE2", mag->len))
                return swap_set_info(pr, "1");
 
        return 1;
index a8f0099642e5709d492dd4760810c33c1b87a970..f2865b2d0213df37b1edbf1ce2f01e500b37fc8f 100644 (file)
@@ -217,7 +217,7 @@ static int probe_udf(blkid_probe pr,
                if (vsd_len == 2048) {
                        if (vsd_2048_valid == 0)
                                continue;
-                       else if (vsd_2048_valid == 1)
+                       if (vsd_2048_valid == 1)
                                goto anchor;
                }
 
index efbd80c1a204911ee690f97a1886ee6958e5c890..153f1a8629ce4df74f9218ed7bd7718badecc12f 100644 (file)
@@ -226,7 +226,8 @@ struct fdisk_label *fdisk_get_label(struct fdisk_context *cxt, const char *name)
 
        if (!name)
                return cxt->label;
-       else if (strcasecmp(name, "mbr") == 0)
+
+       if (strcasecmp(name, "mbr") == 0)
                name = "dos";
 
        for (i = 0; i < cxt->nlabels; i++)
@@ -818,17 +819,16 @@ int fdisk_reread_partition_table(struct fdisk_context *cxt)
 
        if (!S_ISBLK(cxt->dev_st.st_mode))
                return 0;
-       else {
-               DBG(CXT, ul_debugobj(cxt, "calling re-read ioctl"));
-               sync();
+
+       DBG(CXT, ul_debugobj(cxt, "calling re-read ioctl"));
+       sync();
 #ifdef BLKRRPART
-               fdisk_info(cxt, _("Calling ioctl() to re-read partition table."));
-               i = ioctl(cxt->dev_fd, BLKRRPART);
+       fdisk_info(cxt, _("Calling ioctl() to re-read partition table."));
+       i = ioctl(cxt->dev_fd, BLKRRPART);
 #else
-               errno = ENOSYS;
-               i = 1;
+       errno = ENOSYS;
+       i = 1;
 #endif
-       }
 
        if (i) {
                fdisk_warn(cxt, _("Re-reading the partition table failed."));
index a79912e8b56a67fdd6612c3e66ec35b37efb6546..5e8ad178ebc24bf1ee80efbcbf24ed037bf856f8 100644 (file)
@@ -1715,7 +1715,9 @@ static int dos_add_partition(struct fdisk_context *cxt,
                if (!ext_pe) {
                        fdisk_warnx(cxt, _("Extended partition does not exists. Failed to add logical partition."));
                        return -EINVAL;
-               } else if (fdisk_partition_has_start(pa)
+               }
+
+               if (fdisk_partition_has_start(pa)
                           && pa->start < l->ext_offset
                           && pa->start > get_abs_partition_end(ext_pe)) {
                        DBG(LABEL, ul_debug("DOS: pa template specifies partno>=4, but start out of extended"));
@@ -1775,8 +1777,8 @@ static int dos_add_partition(struct fdisk_context *cxt,
                                if (pa && fdisk_partition_has_start(pa)) {
                                        fdisk_warnx(cxt, msg);
                                        return -EINVAL;
-                               } else
-                                       fdisk_info(cxt, msg);
+                               }
+                               fdisk_info(cxt, msg);
                        }
                        rc = add_logical(cxt, pa, &res);
                } else {
index 3aa1ea67c09eab300fae9d92123f8c625c9e1456..f737ff9be61fa60b4eb07ff05a3ff30feffbcc14 100644 (file)
@@ -753,7 +753,9 @@ int fdisk_partition_next_partno(
                }
                return -ERANGE;
 
-       } else if (pa && fdisk_partition_has_partno(pa)) {
+       }
+
+       if (pa && fdisk_partition_has_partno(pa)) {
 
                DBG(PART, ul_debugobj(pa, "next partno (specified=%zu)", pa->partno));
 
@@ -763,7 +765,9 @@ int fdisk_partition_next_partno(
                *n = pa->partno;
                return 0;
 
-       } else if (fdisk_has_dialogs(cxt))
+       }
+
+       if (fdisk_has_dialogs(cxt))
                return fdisk_ask_partnum(cxt, n, 1);
 
        return -EINVAL;
index 884e385ac4ac158677d412be5cad735ae5483266..d5391b51a6e303a18f9c177e6feea43dd1898faa 100644 (file)
@@ -396,14 +396,18 @@ static int sgi_check_bootfile(struct fdisk_context *cxt, const char *name)
                                   "e.g. \"/unix\" or \"/unix.save\"."));
                return -EINVAL;
 
-       } else if (sz > sizeof(sgilabel->boot_file)) {
+       }
+
+       if (sz > sizeof(sgilabel->boot_file)) {
                fdisk_warnx(cxt, P_("Name of bootfile is too long: %zu byte maximum.",
                                    "Name of bootfile is too long: %zu bytes maximum.",
                                    sizeof(sgilabel->boot_file)),
                            sizeof(sgilabel->boot_file));
                return -EINVAL;
 
-       } else if (*name != '/') {
+       }
+
+       if (*name != '/') {
                fdisk_warnx(cxt, _("Bootfile must have a fully qualified pathname."));
                return -EINVAL;
        }
index 982414d01d882b706fb40b59ef4faaebe9216d12..6e3ffcb397c216e3a70aa8a3bc56f048675fbbd0 100644 (file)
@@ -34,12 +34,12 @@ static PyObject *Context_set_tables_errcb(ContextObjext *self, PyObject *func,
 
        if (!PyCallable_Check(func))
                return NULL;
-       else {
-               PyObject *tmp = self->table_errcb;
-               Py_INCREF(func);
-               self->table_errcb = func;
-               Py_XDECREF(tmp);
-       }
+
+       PyObject *tmp = self->table_errcb;
+       Py_INCREF(func);
+       self->table_errcb = func;
+       Py_XDECREF(tmp);
+
        return UL_IncRef(self);
 }
 
@@ -570,7 +570,7 @@ static int Context_set_optsmode(ContextObjext *self, PyObject *value, void *clos
                PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
                return -1;
        }
-       else if (!PyLong_Check(value)) {
+       if (!PyLong_Check(value)) {
                PyErr_SetString(PyExc_TypeError, ARG_ERR);
                return -1;
        }
@@ -586,7 +586,7 @@ static int Context_set_syscall_status(ContextObjext *self, PyObject *value, void
                PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
                return -1;
        }
-       else if (!PyLong_Check(value)) {
+       if (!PyLong_Check(value)) {
                PyErr_SetString(PyExc_TypeError, ARG_ERR);
                return -1;
        }
@@ -602,7 +602,7 @@ static int Context_set_user_mflags(ContextObjext *self, PyObject *value, void *c
                PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
                return -1;
        }
-       else if (!PyLong_Check(value)) {
+       if (!PyLong_Check(value)) {
                PyErr_SetString(PyExc_TypeError, ARG_ERR);
                return -1;
        }
@@ -619,7 +619,7 @@ static int Context_set_mflags(ContextObjext *self, PyObject *value, void *closur
                PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
                return -1;
        }
-       else if (!PyLong_Check(value)) {
+       if (!PyLong_Check(value)) {
                PyErr_SetString(PyExc_TypeError, ARG_ERR);
                return -1;
        }
index b35cfe33de11bb0f7311dfff547de9dfec276876..0ba78bed0856a14fefded0b9e6d38b0285efc6ee 100644 (file)
@@ -370,7 +370,9 @@ static int Fs_set_freq(FsObject *self, PyObject *value,
                PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
                return -1;
 
-       } else if (!PyLong_Check(value)) {
+       }
+
+       if (!PyLong_Check(value)) {
                PyErr_SetString(PyExc_TypeError, ARG_ERR);
                return -1;
        }
@@ -395,7 +397,9 @@ static int Fs_set_passno(FsObject *self, PyObject *value, void *closure __attrib
        if (!value) {
                PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
                return -1;
-       } else if (!PyLong_Check(value)) {
+       }
+
+       if (!PyLong_Check(value)) {
                PyErr_SetString(PyExc_TypeError, ARG_ERR);
                return -1;
        }
@@ -810,7 +814,9 @@ static PyObject *Fs_copy_fs(FsObject *self, PyObject *args, PyObject *kwds)
                DBG(FS, pymnt_debug_h(dest, "copy data"));
                return (PyObject *)dest;
 
-       } else if (dest == Py_None) {                   /* create new object */
+       }
+
+       if (dest == Py_None) {                  /* create new object */
                FsObject *result = PyObject_New(FsObject, &FsType);
 
                DBG(FS, pymnt_debug_h(result, "new copy"));
index ce604dd611e5d43d573a01d756ac970012fcaf67..e3185065ea7de941fe20aa3823bef1de9db3dbcc 100644 (file)
@@ -492,7 +492,9 @@ static PyObject *Table_next_fs(TableObject *self)
        if (rc == 1) {
                mnt_reset_iter(self->iter, MNT_ITER_FORWARD);
                Py_RETURN_NONE;
-       } else if (rc)
+       }
+
+       if (rc)
                return UL_RaiseExc(-rc);
 
        return PyObjectResultFs(fs);
index 7adadb849cfa1991a9219332168e900190cd12e7..0e76891b85d05d0d8875f83420f942acc90ce1e2 100644 (file)
@@ -578,7 +578,8 @@ char *mnt_resolve_target(const char *path, struct libmnt_cache *cache)
        p = (char *) cache_find_path(cache, path);
        if (p)
                return p;
-       else {
+
+       {
                struct libmnt_iter itr;
                struct libmnt_fs *fs = NULL;
 
@@ -586,8 +587,8 @@ char *mnt_resolve_target(const char *path, struct libmnt_cache *cache)
                while (mnt_table_next_fs(cache->mtab, &itr, &fs) == 0) {
 
                        if (!mnt_fs_is_kernel(fs)
-                            || mnt_fs_is_swaparea(fs)
-                            || !mnt_fs_streq_target(fs, path))
+                            || mnt_fs_is_swaparea(fs)
+                            || !mnt_fs_streq_target(fs, path))
                                continue;
 
                        p = strdup(path);
index 91fe8e4bfc1afe185fdb119fd0e8889f4cbf4a82..2b598dbb9dd3d78d82bdf4e97aa399181b52b917 100644 (file)
@@ -2864,7 +2864,9 @@ int mnt_context_is_fs_mounted(struct libmnt_context *cxt,
                }
                *mounted = 0;
                return 0;       /* /proc not mounted */
-       } else if (rc)
+       }
+
+       if (rc)
                return rc;
 
        *mounted = __mnt_table_is_fs_mounted(mtab, fs,
index ff7ee695e4b14a06be776cfdd2c3a65a60ed29c1..c00e7326134e3bf8264d6630123c51ecfff5c02c 100644 (file)
@@ -1733,12 +1733,16 @@ int mnt_context_get_mount_excode(
                        if (buf)
                                snprintf(buf, bufsz, _("filesystem was mounted, but failed to update userspace mount table"));
                        return MNT_EX_FILEIO;
-               } else if (rc == -MNT_ERR_NAMESPACE) {
+               }
+
+               if (rc == -MNT_ERR_NAMESPACE) {
                        if (buf)
                                snprintf(buf, bufsz, _("filesystem was mounted, but failed to switch namespace back"));
                        return MNT_EX_SYSERR;
 
-               } else if (rc < 0)
+               }
+
+               if (rc < 0)
                        return mnt_context_get_generic_excode(rc, buf, bufsz,
                                _("filesystem was mounted, but any subsequent operation failed: %m"));
 
index e3547d3564530c1f79847727e8aab22a9d76d78e..f3e079981e17df3c57de7f82841efadc389facb2 100644 (file)
@@ -1253,11 +1253,15 @@ int mnt_context_get_umount_excode(
                        if (buf)
                                snprintf(buf, bufsz, _("not mounted"));
                        return MNT_EX_USAGE;
-               } else if (rc == -MNT_ERR_LOCK) {
+               }
+
+               if (rc == -MNT_ERR_LOCK) {
                        if (buf)
                                snprintf(buf, bufsz, _("locking failed"));
                        return MNT_EX_FILEIO;
-               } else if (rc == -MNT_ERR_NAMESPACE) {
+               }
+
+               if (rc == -MNT_ERR_NAMESPACE) {
                        if (buf)
                                snprintf(buf, bufsz, _("failed to switch namespace"));
                        return MNT_EX_SYSERR;
@@ -1265,7 +1269,7 @@ int mnt_context_get_umount_excode(
                return mnt_context_get_generic_excode(rc, buf, bufsz,
                                        _("umount failed: %m"));
 
-       } else if (mnt_context_get_syscall_errno(cxt) == 0) {
+       } if (mnt_context_get_syscall_errno(cxt) == 0) {
                /*
                 * umount(2) syscall success, but something else failed
                 * (probably error in mtab processing).
@@ -1274,12 +1278,16 @@ int mnt_context_get_umount_excode(
                        if (buf)
                                snprintf(buf, bufsz, _("filesystem was unmounted, but failed to update userspace mount table"));
                        return MNT_EX_FILEIO;
-               } else if (rc == -MNT_ERR_NAMESPACE) {
+               }
+
+               if (rc == -MNT_ERR_NAMESPACE) {
                        if (buf)
                                snprintf(buf, bufsz, _("filesystem was unmounted, but failed to switch namespace back"));
                        return MNT_EX_SYSERR;
 
-               } else if (rc < 0)
+               }
+
+               if (rc < 0)
                        return mnt_context_get_generic_excode(rc, buf, bufsz,
                                _("filesystem was unmounted, but any subsequent operation failed: %m"));
 
index e6eefa13ae89c5d1968bd382743d2deea084cff5..484841fbcf415e386cca2b09bcc092746a435190 100644 (file)
@@ -474,25 +474,25 @@ static int lock_mtab(struct libmnt_lock *ml)
                                /* proceed, since it was us who created the lockfile anyway */
                        }
                        break;
-               } else {
-                       /* Someone else made the link. Wait. */
-                       int err = mnt_wait_mtab_lock(ml, &flock, maxtime.tv_sec);
+               }
 
-                       if (err == 1) {
-                               DBG(LOCKS, ul_debugobj(ml,
-                                       "%s: can't create link: time out (perhaps "
-                                       "there is a stale lock file?)", lockfile));
-                               rc = -ETIMEDOUT;
-                               goto failed;
-
-                       } else if (err < 0) {
-                               rc = err;
-                               goto failed;
-                       }
-                       nanosleep(&waittime, NULL);
-                       close(ml->lockfile_fd);
-                       ml->lockfile_fd = -1;
+               /* Someone else made the link. Wait. */
+               int err = mnt_wait_mtab_lock(ml, &flock, maxtime.tv_sec);
+
+               if (err == 1) {
+                       DBG(LOCKS, ul_debugobj(ml,
+                               "%s: can't create link: time out (perhaps "
+                               "there is a stale lock file?)", lockfile));
+                       rc = -ETIMEDOUT;
+                       goto failed;
+
+               } else if (err < 0) {
+                       rc = err;
+                       goto failed;
                }
+               nanosleep(&waittime, NULL);
+               close(ml->lockfile_fd);
+               ml->lockfile_fd = -1;
        }
        DBG(LOCKS, ul_debugobj(ml, "%s: (%d) successfully locked",
                                        lockfile, getpid()));
index 1f6eb1a572e4cffc4a978e869de4ee042ec9956b..dada02ed3910ea2be7ebe6eadadb92159f07bd48 100644 (file)
@@ -263,7 +263,9 @@ static int userspace_add_watch(struct monitor_entry *me, int *final, int *fd)
                        if (fd)
                                *fd = wd;
                        break;
-               } else if (errno != ENOENT) {
+               }
+
+               if (errno != ENOENT) {
                        rc = -errno;
                        break;
                }
index abd81bc8eec8714749cc040d9ad538bdbc801c0f..1f3ace3d8ed8d26fcb5db1eb8e16d663eac3ec40 100644 (file)
@@ -209,7 +209,7 @@ const struct libmnt_optmap *mnt_get_builtin_optmap(int id)
 
        if (id == MNT_LINUX_MAP)
                return linux_flags_map;
-       else if (id == MNT_USERSPACE_MAP)
+       if (id == MNT_USERSPACE_MAP)
                return userspace_opts_map;
        return NULL;
 }
index 49fc9cc40e6d9fddf72f7f99511760bd22893bd9..f975cef24b51d98f975fd65ecd1705fae440d5a7 100644 (file)
@@ -983,7 +983,7 @@ int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next)
            (*(value + 7) == ',' || !*(value + 7)))
                return set_uint_value(optstr, getuid(), value, end, next);
 
-       else if (!isdigit(*value)) {
+       if (!isdigit(*value)) {
                uid_t id;
                int rc;
                char *p = strndup(value, valsz);
@@ -1031,7 +1031,7 @@ int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next)
            (*(value + 7) == ',' || !*(value + 7)))
                return set_uint_value(optstr, getgid(), value, end, next);
 
-       else if (!isdigit(*value)) {
+       if (!isdigit(*value)) {
                int rc;
                gid_t id;
                char *p = strndup(value, valsz);
index 77207e7e7ba84ae8cbc75f1a94f4fe8dbbb0b7ac..606830797b5bb59d6842cc9da453790ab033e46b 100644 (file)
@@ -701,28 +701,32 @@ static int try_write(const char *filename, const char *directory)
        if (eaccess(filename, R_OK|W_OK) == 0) {
                DBG(UTILS, ul_debug(" access OK"));
                return 0;
-       } else if (errno != ENOENT) {
+       }
+
+       if (errno != ENOENT) {
                DBG(UTILS, ul_debug(" access FAILED"));
                return -errno;
-       } else if (directory) {
+       }
+
+       if (directory) {
                /* file does not exist; try if directory is writable */
                if (eaccess(directory, R_OK|W_OK) != 0)
                        rc = -errno;
 
                DBG(UTILS, ul_debug(" access %s [%s]", rc ? "FAILED" : "OK", directory));
                return rc;
-       } else
+       }
 #endif
-       {
-               DBG(UTILS, ul_debug(" doing open-write test"));
 
-               int fd = open(filename, O_RDWR|O_CREAT|O_CLOEXEC,
-                           S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH);
-               if (fd < 0)
-                       rc = -errno;
-               else
-                       close(fd);
-       }
+       DBG(UTILS, ul_debug(" doing open-write test"));
+
+       int fd = open(filename, O_RDWR|O_CREAT|O_CLOEXEC,
+                   S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH);
+       if (fd < 0)
+               rc = -errno;
+       else
+               close(fd);
+
        return rc;
 }
 
@@ -1210,7 +1214,7 @@ static int read_procfs_file(int fd, char **buf, size_t *bufsiz)
                        }
                        break;
 
-               } else if (ret > 0) {
+               } if (ret > 0) {
                        /* success -- verify no event during read */
                        struct pollfd fds[] = {
                                { .fd = fd, .events = POLLPRI }
index 625fe71ea9c6a7bde3926331a60ab7fa3c6946c8..360c7e0c19f6362624149b10a95ece7270f616fa 100644 (file)
@@ -60,7 +60,7 @@ static int count_cell_width(struct libscols_table *tb,
        if (cl->is_extreme && cl->width_avg && len > cl->width_avg * 2)
                return 0;
 
-       else if (scols_column_is_noextremes(cl)) {
+       if (scols_column_is_noextremes(cl)) {
                cl->extreme_sum += len;
                cl->extreme_count++;
        }
index 0717a2d09e22d991da496545ddbfb975d62b44f5..4cd6e59811be9f108d15df1f868b20b5051feed3 100644 (file)
@@ -226,7 +226,7 @@ int scols_cell_get_alignment(const struct libscols_cell *ce)
 {
        if (ce->flags & SCOLS_CELL_FL_RIGHT)
                return SCOLS_CELL_FL_RIGHT;
-       else if (ce->flags & SCOLS_CELL_FL_CENTER)
+       if (ce->flags & SCOLS_CELL_FL_CENTER)
                return SCOLS_CELL_FL_CENTER;
 
        return SCOLS_CELL_FL_LEFT;      /* default */
index 536b1ed23c1764e088039782c71789487180d57e..ce9cc09e9a045ca2497bf50257a91ab3cf6a1be1 100644 (file)
@@ -62,8 +62,7 @@ int uuid_parse_range(const char *in_start, const char *in_end, uuid_t uu)
                    (i == 23)) {
                        if (*cp == '-')
                                continue;
-                       else
-                               return -1;
+                       return -1;
                }
                if (i== 36)
                        if (*cp == 0)
index 0be90ca04d78b61f56496044783b3dadf8bd2c12..fec17739b8b997b5452bb62f73d42607f91a0c0a 100644 (file)
@@ -68,13 +68,16 @@ const uuid_t *uuid_get_template(const char *alias)
 
        if (!strcmp(alias, "dns"))
                return &NameSpace_DNS;
-       else if (!strcmp(alias, "url"))
+
+       if (!strcmp(alias, "url"))
                return &NameSpace_URL;
-       else if (!strcmp(alias, "oid"))
+
+       if (!strcmp(alias, "oid"))
                return &NameSpace_OID;
-       else if (!strcmp(alias, "x500") || !strcmp(alias, "x.500"))
+
+       if (!strcmp(alias, "x500") || !strcmp(alias, "x.500"))
                return &NameSpace_X500;
-       else
-               return NULL;
+
+       return NULL;
 }
 
index 469bc5629de222caf1d047ecc3402a4c77009823..ab5c52ed585300085696e9887c667a0aee49786e 100644 (file)
@@ -56,12 +56,11 @@ static int is_local_in_file(const char *user, const char *filename)
                                         * but it is just an optimisation
                                         * anyway.  */
                                        break;
-                               } else {
-                                       /* we read a whole username, but it
-                                        * is the wrong user.  Skip to the
-                                        * next line.  */
-                                       skip = 1;
                                }
+                               /* we read a whole username, but it
+                                * is the wrong user.  Skip to the
+                                * next line.  */
+                               skip = 1;
                        } else if ('\n' == chin) {
                                /* This line contains no colon; it's
                                 * malformed.  No skip since we are already
@@ -96,17 +95,17 @@ int main(int argc, char *argv[])
                fprintf(stderr, _("Usage: %s <passwordfile> <username>...\n"),
                        argv[0]);
                return 1;
-       } else {
-               int i;
-               for (i = 2; i < argc; i++) {
-                       const int rv = is_local_in_file(argv[i], argv[1]);
-                       if (rv < 0) {
-                               perror(argv[1]);
-                               return 2;
-                       }
-                       printf("%d:%s\n", rv, argv[i]);
+       }
+
+       int i;
+       for (i = 2; i < argc; i++) {
+               const int rv = is_local_in_file(argv[i], argv[1]);
+               if (rv < 0) {
+                       perror(argv[1]);
+                       return 2;
                }
-               return 0;
+               printf("%d:%s\n", rv, argv[i]);
        }
+       return 0;
 }
 #endif
index 2b505d255d564be365bbb812677e1f918a5778e9..9782e6804e88c3b94a501116749504b7818ea44f 100644 (file)
@@ -391,8 +391,9 @@ int get_hushlogin_status(struct passwd *pwd, int force_check)
                        rc = effective_access(buf, O_RDONLY);
                        if (rc == 0)
                                return 1;
-                       else if (rc == -1 && errno == EACCES)
-                                       return -1;
+
+                       if (rc == -1 && errno == EACCES)
+                               return -1;
                }
 
        }
index defa230b9a937299ceca7f41eb8bb9494896ac09..5ccae8655c5b57befb29744d1c17953455046dcb 100644 (file)
@@ -222,15 +222,14 @@ static FILE *dump(FILE *in, const char *filename, int follow, FILE *out)
 #ifdef HAVE_INOTIFY_INIT
        if (follow_by_inotify(in, filename, out) == 0)
                return NULL;                            /* file already closed */
-       else
 #endif
-               /* fallback for systems without inotify or with non-free
-                * inotify instances */
-               for (;;) {
-                       while (fread(&ut, sizeof(ut), 1, in) == 1)
-                               print_utline(&ut, out);
-                       sleep(1);
-               }
+       /* fallback for systems without inotify or with non-free
+        * inotify instances */
+       for (;;) {
+               while (fread(&ut, sizeof(ut), 1, in) == 1)
+                       print_utline(&ut, out);
+               sleep(1);
+       }
 
        return in;
 }
index feff1e805eb30a0fc90a1b9ff966cfbb6f08166b..ec37a88d2c52b41e359b676d37040414e15ba623 100644 (file)
@@ -618,8 +618,8 @@ static int leap_year(const struct cal_control *ctl, int32_t year)
 {
        if (year <= ctl->reform_year)
                return !(year % 4);
-       else
-               return ( !(year % 4) && (year % 100) ) || !(year % 400);
+
+       return ( !(year % 4) && (year % 100) ) || !(year % 400);
 }
 
 static void init_monthnames(struct cal_control *ctl)
index 2b6f5e7fa90c1adfa5a1910d9b715ad0ce86aa97..1d255426d600098656cc9680ed84e41b249e2794 100644 (file)
@@ -407,7 +407,7 @@ static int verify_fstype(struct verify_context *vfy)
                    && mnt_fs_get_option(vfy->fs, "move", NULL, NULL) == 1)
                        return verify_warn(vfy, _("\"none\" FS type is recommended for bind or move oprations only"));
 
-               else if (strcmp(type, "auto") == 0)
+               if (strcmp(type, "auto") == 0)
                        isauto = 1;
                else if (strcmp(type, "swap") == 0)
                        isswap = 1;
index 3fa158eb3bed57d78a7a4e1ae487e9ef1b2563a5..01a2df6dd05e4acc0a36340484d615b3d92b3e8d 100644 (file)
@@ -392,8 +392,8 @@ int main(int argc, char *argv[])
                         */
                        printf(" --\n");
                        return EXIT_SUCCESS;
-               } else
-                       parse_error(_("missing optstring argument"));
+               }
+               parse_error(_("missing optstring argument"));
        }
 
        add_longopt(&ctl, NULL, 0);     /* init */
index 19182b4a319354ebfc177528ace6f1e47ea5fafe..9cfb03cb91a9e3d550c493ea0363a3922eba17df 100644 (file)
@@ -505,7 +505,7 @@ int main(int argc, char **argv)
 #endif
        if (ct && nerrs == 0)
                return EXIT_SUCCESS;    /* full success */
-       else if (ct == nerrs)
+       if (ct == nerrs)
                return EXIT_FAILURE;    /* all failed */
 
        return KILL_EXIT_SOMEOK;        /* partial success */
index a9378af59be687a144efb8ba7d08430d645ee9c5..d17b25abe56b22bf2ec2d6e4c636626e4460dfa1 100644 (file)
@@ -96,8 +96,8 @@ static int ask(char *name)
        buf[1] = '\0';
        if (rpmatch(buf) == RPMATCH_YES)
                return 0;
-       else
-               return 1;
+
+       return 1;
 }
 
 static int do_symlink(char *from, char *to, char *s, int verbose, int noact,
index af24efc14f9d8882ff8b2300d1dfa8f685c7722b..ef95946e23be229c108f6034a63bab913af914c7 100644 (file)
@@ -428,8 +428,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
                if (ns < 0) {
                        if ((errno == EAGAIN) || (errno == EINTR))
                                continue;
-                       else
-                               err(EXIT_FAILURE, "accept");
+                       err(EXIT_FAILURE, "accept");
                }
                len = read(ns, &op, 1);
                if (len != 1) {
index 2f3b200bf8dee07695dc57306e31093e14ecc640..f1087f3e808cdf956cdfd38f18c156a6b65c5dc6 100644 (file)
@@ -298,13 +298,12 @@ static char *find_device(const char *name)
 
        if ((*name == '.' || *name == '/') && access(name, F_OK) == 0)
                return xstrdup(name);
-       else {
-               char buf[PATH_MAX];
 
-               snprintf(buf, sizeof(buf), "/dev/%s", name);
-               if (access(buf, F_OK) == 0)
-                       return xstrdup(buf);
-       }
+       char buf[PATH_MAX];
+
+       snprintf(buf, sizeof(buf), "/dev/%s", name);
+       if (access(buf, F_OK) == 0)
+               return xstrdup(buf);
 
        return NULL;
 }
index 0caf6be1045a6323e7ff24f659edeed883e9299b..fb94868481ebca1920712b02993f32fc59270efd 100644 (file)
@@ -258,48 +258,48 @@ static int synchronize_to_clock_tick_rtc(const struct hwclock_control *ctl)
        if (rtc_fd == -1) {
                warn(_("cannot open rtc device"));
                return ret;
-       } else {
-               /* Turn on update interrupts (one per second) */
-               int rc = ioctl(rtc_fd, RTC_UIE_ON, 0);
-
-               if (rc != -1) {
-                       /*
-                        * Just reading rtc_fd fails on broken hardware: no
-                        * update interrupt comes and a bootscript with a
-                        * hwclock call hangs
-                        */
-                       fd_set rfds;
-                       struct timeval tv;
-
-                       /*
-                        * Wait up to ten seconds for the next update
-                        * interrupt
-                        */
-                       FD_ZERO(&rfds);
-                       FD_SET(rtc_fd, &rfds);
-                       tv.tv_sec = 10;
-                       tv.tv_usec = 0;
-                       rc = select(rtc_fd + 1, &rfds, NULL, NULL, &tv);
-                       if (0 < rc)
-                               ret = 0;
-                       else if (rc == 0) {
-                               warnx(_("select() to %s to wait for clock tick timed out"),
-                                     rtc_dev_name);
-                       } else
-                               warn(_("select() to %s to wait for clock tick failed"),
-                                    rtc_dev_name);
-                       /* Turn off update interrupts */
-                       rc = ioctl(rtc_fd, RTC_UIE_OFF, 0);
-                       if (rc == -1)
-                               warn(_("ioctl() to %s to turn off update interrupts failed"),
-                                    rtc_dev_name);
+       }
+
+       /* Turn on update interrupts (one per second) */
+       int rc = ioctl(rtc_fd, RTC_UIE_ON, 0);
+
+       if (rc != -1) {
+               /*
+                * Just reading rtc_fd fails on broken hardware: no
+                * update interrupt comes and a bootscript with a
+                * hwclock call hangs
+                */
+               fd_set rfds;
+               struct timeval tv;
+
+               /*
+                * Wait up to ten seconds for the next update
+                * interrupt
+                */
+               FD_ZERO(&rfds);
+               FD_SET(rtc_fd, &rfds);
+               tv.tv_sec = 10;
+               tv.tv_usec = 0;
+               rc = select(rtc_fd + 1, &rfds, NULL, NULL, &tv);
+               if (0 < rc)
+                       ret = 0;
+               else if (rc == 0) {
+                       warnx(_("select() to %s to wait for clock tick timed out"),
+                             rtc_dev_name);
+               } else
+                       warn(_("select() to %s to wait for clock tick failed"),
+                            rtc_dev_name);
+               /* Turn off update interrupts */
+               rc = ioctl(rtc_fd, RTC_UIE_OFF, 0);
+               if (rc == -1)
+                       warn(_("ioctl() to %s to turn off update interrupts failed"),
+                            rtc_dev_name);
                } else if (errno == ENOTTY || errno == EINVAL) {
                        /* rtc ioctl interrupts are unimplemented */
                        ret = busywait_for_rtc_clock_tick(ctl, rtc_fd);
                } else
                        warn(_("ioctl(%d, RTC_UIE_ON, 0) to %s failed"),
                             rtc_fd, rtc_dev_name);
-       }
        return ret;
 }
 
index 89d8a1fd93716f587bb83f809afd632a8721a675..1026adc23fa8bafb289cd62ac371fe8858fce863 100644 (file)
@@ -876,7 +876,9 @@ static int save_adjtime(const struct hwclock_control *ctl,
                if (fp == NULL) {
                        warn(_("cannot open %s"), ctl->adj_file_name);
                        return EXIT_FAILURE;
-               } else if (fputs(content, fp) < 0 || close_stream(fp) != 0) {
+               }
+
+               if (fputs(content, fp) < 0 || close_stream(fp) != 0) {
                        warn(_("cannot update %s"), ctl->adj_file_name);
                        return EXIT_FAILURE;
                }
@@ -1053,7 +1055,9 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time,
        }
        if (ctl->show || ctl->get) {
                return display_time(startup_hclocktime);
-       } else if (ctl->set) {
+       }
+
+       if (ctl->set) {
                set_hardware_clock_exact(ctl, set_time, startup_time);
                if (!ctl->noadjfile)
                        adjust_drift_factor(ctl, adjtime, t2tv(set_time),
index e5ead7ba6bac7ed61d325b9f6a2005805d86e8d4..674b6124d20a81469fc934f8971da537958797b6 100644 (file)
@@ -145,8 +145,8 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
                        if (id == p->shm_perm.id) {
                                i = 1;
                                break;
-                       } else
-                               continue;
+                       }
+                       continue;
                }
 
                p->next = xcalloc(1, sizeof(struct shm_data));
@@ -284,8 +284,8 @@ int ipc_sem_get_info(int id, struct sem_data **semds)
                                get_sem_elements(p);
                                i = 1;
                                break;
-                       } else
-                               continue;
+                       }
+                       continue;
                }
 
                p->next = xcalloc(1, sizeof(struct sem_data));
@@ -397,8 +397,8 @@ int ipc_msg_get_info(int id, struct msg_data **msgds)
                                        p->q_qbytes = msgseg.msg_qbytes;
                                i = 1;
                                break;
-                       } else
-                               continue;
+                       }
+                       continue;
                }
 
                p->next = xcalloc(1, sizeof(struct msg_data));
index 5a1a3d7ac92cdeb14581a70598b373d15d38e2bd..debd9a9b1402f385e5e8dc207e36fd1e94ca81fe 100644 (file)
@@ -221,12 +221,12 @@ static int column_name_to_id(const char *name, size_t namesz)
                        if (i > COL_CTIME) {
                                if (i >= LOWER && i <= UPPER)
                                        return i;
-                               else {
-                                       warnx(_("column %s does not apply to the specified IPC"), name);
-                                       return -1;
-                               }
-                       } else
-                               return i;
+
+                               warnx(_("column %s does not apply to the specified IPC"), name);
+                               return -1;
+                       }
+
+                       return i;
                }
        }
        warnx(_("unknown column: %s"), name);
index cab9343175071d1b830540b07011624a7408c805..eec8e273b379c4ca200b28c5a5475b5e76b33fc8 100644 (file)
@@ -596,11 +596,10 @@ static int netnsid_xasputs(char **str, int netnsid)
        if (netnsid >= 0)
                return xasprintf(str, "%d", netnsid);
 #ifdef NETNSA_NSID_NOT_ASSIGNED
-       else if (netnsid == NETNSA_NSID_NOT_ASSIGNED)
+       if (netnsid == NETNSA_NSID_NOT_ASSIGNED)
                return xasprintf(str, "%s", "unassigned");
 #endif
-       else
-               return 0;
+       return 0;
 }
 
 static int read_namespaces(struct lsns *ls)
index 607849066fc293380b994e3ddd7b6fa374751fc3..c8c7d5c42c164b3bbe60824c4ebc1673fd4b4d35 100644 (file)
@@ -397,7 +397,9 @@ static int get_range(char *str, rlim_t *soft, rlim_t *hard, int *found)
                *found |= PRLIMIT_SOFT | PRLIMIT_HARD;
                return 0;
 
-       } else if (*str == ':') {                       /* <:hard> */
+       }
+
+       if (*str == ':') {                      /* <:hard> */
                str++;
 
                if (strcmp(str, INFINITY_STR) != 0) {
index 0d352e453707f7bc94c822090fdcfc6f7b0b3277..6211aacb5c21ee15629a07cc0d79498f2e6e36d8 100644 (file)
@@ -593,7 +593,7 @@ int main(int argc, char *argv[])
                                err(EXIT_FAILURE, _("waitpid failed"));
                        if (WIFEXITED(status))
                                return WEXITSTATUS(status);
-                       else if (WIFSIGNALED(status))
+                       if (WIFSIGNALED(status))
                                kill(getpid(), WTERMSIG(status));
                        err(EXIT_FAILURE, _("child exit failed"));
                }
index bc0d0d069eadd5ba72371909eddd20856cea01ef..003349fadf2602b42c7544e2caa10019a5628a90 100644 (file)
@@ -385,7 +385,9 @@ static char *get_mm_stat(struct zram *z, size_t idx, int bytes)
                ul_path_read_string(sysfs, &str, name);
                return str;
 
-       } else if (ul_path_read_u64(sysfs, &num, name) == 0)
+       }
+
+       if (ul_path_read_u64(sysfs, &num, name) == 0)
                return size_to_human_string(SIZE_SUFFIX_1LETTER, num);
 
        return NULL;
index 49151e085465a66834961c9ecb72cea179ed91b5..f88a8da5152473d7c75c23bce7887a29983bf2e5 100644 (file)
@@ -1701,7 +1701,9 @@ static int wait_for_term_input(int fd)
                if (FD_ISSET(fd, &rfds)) {
                        return 1;
 
-               } else if (netlink_fd >= 0 && FD_ISSET(netlink_fd, &rfds)) {
+               }
+
+               if (netlink_fd >= 0 && FD_ISSET(netlink_fd, &rfds)) {
                        if (!process_netlink())
                                continue;
 
index b17dc9ef304e0f8f7dc72a752fede00dd64feb29..ee2573a72b5fb0d2735ddec54cc76daaf407c3b6 100644 (file)
@@ -126,11 +126,11 @@ static int process_next_step(struct scriptlive *ss)
 
                        ul_pty_set_mainloop_time(ss->pty, &target);
                        break;
-               } else {
-                       /* no delay -- immediately write */
-                       rc = replay_emit_step_data(ss->setup, ss->step, fd);
-                       fdatasync(fd);
                }
+
+               /* no delay -- immediately write */
+               rc = replay_emit_step_data(ss->setup, ss->step, fd);
+               fdatasync(fd);
        } while (rc == 0);
 
        return rc;
index 456abc59e95ddc91ac938a7139bd9c8931a64c48..22afc761632ed063f0a63bf545b140da517e9d7f 100644 (file)
@@ -247,11 +247,11 @@ static char *find_optional_arg(char **av, char *oa, int *oi)
        char *arg;
        if (oa)
                return oa;
-       else {
-               arg = av[*oi];
-               if (!arg || arg[0] == '-')
-                       return NULL;
-       }
+
+       arg = av[*oi];
+       if (!arg || arg[0] == '-')
+               return NULL;
+
        (*oi)++;
        return arg;
 }
@@ -265,29 +265,28 @@ static int parse_blank(char **av, char *oa, int *oi)
                return BLANKEDSCREEN;
        if (!strcmp(arg, "force"))
                return BLANKSCREEN;
-       else if (!strcmp(arg, "poke"))
+       if (!strcmp(arg, "poke"))
                return UNBLANKSCREEN;
-       else {
-               int ret;
 
-               ret = strtos32_or_err(arg, _("argument error"));
-               if (ret < 0 || BLANK_MAX < ret)
-                       errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg);
-               return ret;
-       }
+       int ret;
+
+       ret = strtos32_or_err(arg, _("argument error"));
+       if (ret < 0 || BLANK_MAX < ret)
+               errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg);
+       return ret;
 }
 
 static int parse_powersave(const char *arg)
 {
        if (strcmp(arg, "on") == 0)
                return VESA_BLANK_MODE_SUSPENDV;
-       else if (strcmp(arg, "vsync") == 0)
+       if (strcmp(arg, "vsync") == 0)
                return VESA_BLANK_MODE_SUSPENDV;
-       else if (strcmp(arg, "hsync") == 0)
+       if (strcmp(arg, "hsync") == 0)
                return VESA_BLANK_MODE_SUSPENDH;
-       else if (strcmp(arg, "powerdown") == 0)
+       if (strcmp(arg, "powerdown") == 0)
                return VESA_BLANK_MODE_POWERDOWN;
-       else if (strcmp(arg, "off") == 0)
+       if (strcmp(arg, "off") == 0)
                return VESA_BLANK_MODE_OFF;
        errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg);
 }
index bbced5c38aea2d4d8ecc7655b48212c13f8f028a..69a0b89f6aec6540371eee0262a6a3709f2ff3b8 100644 (file)
@@ -895,10 +895,9 @@ static void ttyin(struct more_control *ctl, char buf[], int nmax, char pchar)
                                        erase_one_column(ctl);
                                }
                                continue;
-                       } else {
-                               if (!ctl->erase_line)
-                                       ctl->prompt_len = maxlen;
                        }
+                       if (!ctl->erase_line)
+                               ctl->prompt_len = maxlen;
                } else if (c == ctl->output_tty.c_cc[VKILL] && !slash) {
                        if (ctl->hard_tty) {
                                show(ctl, c);
@@ -1340,8 +1339,8 @@ static void search(struct more_control *ctl, char buf[], int n)
                                puts(ctl->line_buf);
                        }
                        break;
-               } else
-                       more_poll(ctl, 1);
+               }
+               more_poll(ctl, 1);
        }
        /* Move ctrl+c signal handling back to more_key_command(). */
        signal(SIGINT, SIG_DFL);
index 7eef9b88be0dcf1d102da4ff5f13235b2d369fb1..5d01ebff34f1389ff0716e69b6034842fd02bfa1 100644 (file)
@@ -987,42 +987,43 @@ static void pgfile(FILE *f, const char *name)
                                        *b = '\0';
                                        dline = pagelen;
                                        break;
-                               } else {
-                                       if (nobuf)
-                                               fseeko(f, fpos, SEEK_SET);
-                                       canjump = 1;
-                                       p = fgets(b, READBUF, f);
-                                       if (nobuf)
-                                               if ((fpos = ftello(f)) == -1)
-                                                       warn("%s", name);
-                                       canjump = 0;
                                }
+
+                               if (nobuf)
+                                       fseeko(f, fpos, SEEK_SET);
+                               canjump = 1;
+                               p = fgets(b, READBUF, f);
+                               if (nobuf)
+                                       if ((fpos = ftello(f)) == -1)
+                                               warn("%s", name);
+                               canjump = 0;
+
                                if (p == NULL || *b == '\0') {
                                        if (ferror(f))
                                                warn("%s", name);
                                        eofline = fline;
                                        eof = 1;
                                        break;
-                               } else {
-                                       if (!nobuf)
-                                               fputs(b, fbuf);
-                                       fwrite_all(&pos, sizeof pos, 1, find);
-                                       if (!fflag) {
-                                               oldpos = pos;
-                                               p = b;
-                                               while (*(p = endline(ttycols,
-                                                                    p))
-                                                      != '\0') {
-                                                       pos = oldpos + (p - b);
-                                                       fwrite_all(&pos,
-                                                                  sizeof pos,
-                                                                  1, find);
-                                                       fline++;
-                                                       bline++;
-                                               }
+                               }
+
+                               if (!nobuf)
+                                       fputs(b, fbuf);
+                               fwrite_all(&pos, sizeof pos, 1, find);
+                               if (!fflag) {
+                                       oldpos = pos;
+                                       p = b;
+                                       while (*(p = endline(ttycols,
+                                                            p))
+                                              != '\0') {
+                                               pos = oldpos + (p - b);
+                                               fwrite_all(&pos,
+                                                          sizeof pos,
+                                                          1, find);
+                                               fline++;
+                                               bline++;
                                        }
-                                       fline++;
                                }
+                               fline++;
                        } while (line > bline++);
                } else {
                        /* eofline != 0 */
@@ -1057,7 +1058,9 @@ static void pgfile(FILE *f, const char *name)
                                skip(1);
                        }
                        continue;
-               } else if (eof) {
+               }
+
+               if (eof) {
                        /* We are not searching. */
                        line = bline;
                } else if (*b != '\0') {
index e8137edbd88278b04b4c5ac480a2636c719abe68..39b69a5972350a26b07d1bc53e801e5bd5aff729 100644 (file)
@@ -69,8 +69,8 @@ static int put1wc(int c)
 {
        if (putwchar(c) == WEOF)
                return EOF;
-       else
-               return c;
+
+       return c;
 }
 #define putwp(s) tputs(s, STDOUT_FILENO, put1wc)
 #else