[clang-tidy] do not use else after return

Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2020-04-18 22:16:22 -07:00
parent bd89499e07
commit 042f62dfc5
No known key found for this signature in database
GPG key ID: 36D31CFA845F0E3B
63 changed files with 372 additions and 300 deletions

View file

@ -986,7 +986,9 @@ static size_t menuitem_get_line(struct cfdisk *cf, size_t idx)
if (!m->page_sz) /* small menu */ if (!m->page_sz) /* small menu */
return (ui_lines - (cf->menu->nitems + 1)) / 2 + idx; return (ui_lines - (cf->menu->nitems + 1)) / 2 + idx;
return (idx % m->page_sz) + 1; return (idx % m->page_sz) + 1;
} else { }
{
size_t len = MENU_H_ITEMWIDTH(m) + MENU_H_BETWEEN; /** item width */ size_t len = MENU_H_ITEMWIDTH(m) + MENU_H_BETWEEN; /** item width */
size_t items = ui_cols / len; /* items per line */ 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) if ((size_t) ui_cols <= nc)
return 0; return 0;
return (ui_cols - nc) / 2; return (ui_cols - nc) / 2;
} else { }
{
size_t len = MENU_H_ITEMWIDTH(cf->menu) + MENU_H_BETWEEN; /* item width */ size_t len = MENU_H_ITEMWIDTH(cf->menu) + MENU_H_BETWEEN; /* item width */
size_t items = ui_cols / len; /* items per line */ size_t items = ui_cols / len; /* items per line */
size_t extra = items < cf->menu->nitems ? /* extra space on 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) { if (rc == 0) {
ui_warnx(_("Please, specify size.")); ui_warnx(_("Please, specify size."));
continue; /* nothing specified */ continue; /* nothing specified */
} else if (rc == -CFDISK_ERR_ESC) } if (rc == -CFDISK_ERR_ESC)
break; /* cancel dialog */ break; /* cancel dialog */
if (strcmp(buf, dflt) == 0) if (strcmp(buf, dflt) == 0)

View file

@ -172,8 +172,8 @@ static int string_to_int(const char *s)
l = strtol(s, &p, 0); l = strtol(s, &p, 0);
if (*p || l == LONG_MIN || l == LONG_MAX || l < 0 || l > INT_MAX) if (*p || l == LONG_MIN || l == LONG_MAX || l < 0 || l > INT_MAX)
return -1; return -1;
else
return (int) l; return (int) l;
} }
/* Do we really really want to check this fs? */ /* Do we really really want to check this fs? */

View file

@ -131,12 +131,15 @@ static int get_superblock_endianness(uint32_t magic)
if (magic == CRAMFS_MAGIC) { if (magic == CRAMFS_MAGIC) {
cramfs_is_big_endian = HOST_IS_BIG_ENDIAN; cramfs_is_big_endian = HOST_IS_BIG_ENDIAN;
return 0; return 0;
} else if (magic == }
if (magic ==
u32_toggle_endianness(!HOST_IS_BIG_ENDIAN, CRAMFS_MAGIC)) { u32_toggle_endianness(!HOST_IS_BIG_ENDIAN, CRAMFS_MAGIC)) {
cramfs_is_big_endian = !HOST_IS_BIG_ENDIAN; cramfs_is_big_endian = !HOST_IS_BIG_ENDIAN;
return 0; return 0;
} else }
return -1;
return -1;
} }
static void test_super(int *start, size_t * length) static void test_super(int *start, size_t * length)

View file

@ -300,7 +300,7 @@ static int is_valid_zone_nr(unsigned short nr)
{ {
if (nr < get_first_zone()) if (nr < get_first_zone())
return 0; return 0;
else if (nr >= get_nzones()) if (nr >= get_nzones())
return 0; return 0;
return 1; return 1;
} }
@ -1355,7 +1355,9 @@ main(int argc, char **argv) {
if (repair) if (repair)
printf(_("%s is clean, no check.\n"), device_name); printf(_("%s is clean, no check.\n"), device_name);
return retcode; return retcode;
} else if (force) }
if (force)
printf(_("Forcing filesystem check on %s.\n"), device_name); printf(_("Forcing filesystem check on %s.\n"), device_name);
else if (repair) else if (repair)
printf(_("Filesystem on %s is dirty, needs checking.\n"), printf(_("Filesystem on %s is dirty, needs checking.\n"),

View file

@ -547,9 +547,9 @@ static int is_zero(unsigned char const *begin, unsigned len)
(len-- == 0 || (len-- == 0 ||
(begin[3] == '\0' && (begin[3] == '\0' &&
memcmp(begin, begin + 4, len) == 0)))))))); memcmp(begin, begin + 4, len) == 0))))))));
else
/* Never create holes. */ /* Never create holes. */
return 0; return 0;
} }
/* /*

View file

@ -332,7 +332,9 @@ static int del_parts(int fd, const char *device, dev_t devno,
if (verbose) if (verbose)
printf(_("%s: partition #%d removed\n"), device, i); printf(_("%s: partition #%d removed\n"), device, i);
continue; continue;
} else if (errno == ENXIO) { }
if (errno == ENXIO) {
if (verbose) if (verbose)
printf(_("%s: partition #%d doesn't exist\n"), device, i); printf(_("%s: partition #%d doesn't exist\n"), device, i);
continue; continue;

View file

@ -1869,14 +1869,18 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
fdisk_warnx(sf->cxt, _("Unknown script header '%s' -- ignore."), buf); fdisk_warnx(sf->cxt, _("Unknown script header '%s' -- ignore."), buf);
continue; continue;
} else if (rc < 0) { }
if (rc < 0) {
DBG(PARSE, ul_debug("script parsing failed, trying sfdisk specific commands")); DBG(PARSE, ul_debug("script parsing failed, trying sfdisk specific commands"));
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
rc = loop_control_commands(sf, dp, buf); rc = loop_control_commands(sf, dp, buf);
if (rc) if (rc)
break; break;
continue; continue;
} else if (rc == 1) { }
if (rc == 1) {
rc = SFDISK_DONE_EOF; rc = SFDISK_DONE_EOF;
if (!sf->quiet) if (!sf->quiet)
fputs(_("Done.\n"), stdout); 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 = fdisk_set_partition(sf->cxt, partno, pa);
rc = rc == 0 ? SFDISK_DONE_ASK : SFDISK_DONE_ABORT; rc = rc == 0 ? SFDISK_DONE_ASK : SFDISK_DONE_ABORT;
break; break;
} else if (!rc) { /* add partition */ }
if (!rc) { /* add partition */
if (!sf->interactive && !sf->quiet && if (!sf->interactive && !sf->quiet &&
(!sf->prompt || startswith(sf->prompt, SFDISK_PROMPT))) { (!sf->prompt || startswith(sf->prompt, SFDISK_PROMPT))) {
refresh_prompt_buffer(sf, devname, next_partno, created); refresh_prompt_buffer(sf, devname, next_partno, created);

View file

@ -281,8 +281,8 @@ int blkdev_is_cdrom(int fd)
if ((ret = ioctl(fd, CDROM_GET_CAPABILITY, NULL)) < 0) if ((ret = ioctl(fd, CDROM_GET_CAPABILITY, NULL)) < 0)
return 0; return 0;
else
return ret; return ret;
} }
#else #else
int blkdev_is_cdrom(int fd __attribute__((__unused__))) int blkdev_is_cdrom(int fd __attribute__((__unused__)))

View file

@ -48,7 +48,9 @@ size_t ul_encode_to_utf8(int enc, unsigned char *dest, size_t len,
if (c == 0) { if (c == 0) {
dest[j] = '\0'; dest[j] = '\0';
break; break;
} else if (c < 0x80) { }
if (c < 0x80) {
if (j+1 >= len) if (j+1 >= len)
break; break;
dest[j++] = (uint8_t) c; dest[j++] = (uint8_t) c;

View file

@ -1074,8 +1074,8 @@ found:
uint64_t sz = 0; uint64_t sz = 0;
return loopcxt_get_sizelimit(lc, &sz) == 0 && sz == sizelimit; return loopcxt_get_sizelimit(lc, &sz) == 0 && sz == sizelimit;
} else }
return rc; return rc;
} }
return 1; return 1;
} }

View file

@ -255,7 +255,9 @@ int parse_switch(const char *arg, const char *errmesg, ...)
if (strcmp(arg, a) == 0) { if (strcmp(arg, a) == 0) {
va_end(ap); va_end(ap);
return 1; return 1;
} else if (strcmp(arg, b) == 0) { }
if (strcmp(arg, b) == 0) {
va_end(ap); va_end(ap);
return 0; return 0;
} }
@ -1110,19 +1112,16 @@ int main(int argc, char *argv[])
if (argc == 3 && strcmp(argv[1], "--size") == 0) if (argc == 3 && strcmp(argv[1], "--size") == 0)
return test_strutils_sizes(argc - 1, argv + 1); 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); 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); return test_strdup_to_member(argc - 1, argv + 1);
else { fprintf(stderr, "usage: %1$s --size <number>[suffix]\n"
fprintf(stderr, "usage: %1$s --size <number>[suffix]\n" " %1$s --cmp-paths <path> <path>\n"
" %1$s --cmp-paths <path> <path>\n" " %1$s --strdup-member <str> <str>\n",
" %1$s --strdup-member <str> <str>\n", argv[0]);
argv[0]);
exit(EXIT_FAILURE);
}
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View file

@ -73,9 +73,9 @@ int get_terminal_stdfd(void)
{ {
if (isatty(STDIN_FILENO)) if (isatty(STDIN_FILENO))
return STDIN_FILENO; return STDIN_FILENO;
else if (isatty(STDOUT_FILENO)) if (isatty(STDOUT_FILENO))
return STDOUT_FILENO; return STDOUT_FILENO;
else if (isatty(STDERR_FILENO)) if (isatty(STDERR_FILENO))
return STDERR_FILENO; return STDERR_FILENO;
return -EINVAL; return -EINVAL;

View file

@ -321,7 +321,7 @@ static int probe_gpt_pt(blkid_probe pr,
ret = is_pmbr_valid(pr, NULL); ret = is_pmbr_valid(pr, NULL);
if (ret < 0) if (ret < 0)
return ret; return ret;
else if (ret == 0) if (ret == 0)
goto nothing; goto nothing;
errno = 0; errno = 0;

View file

@ -1245,7 +1245,9 @@ int blkid_do_wipe(blkid_probe pr, int dryrun)
return blkid_probe_step_back(pr); return blkid_probe_step_back(pr);
} else if (dryrun) { }
if (dryrun) {
/* wipe in memory only */ /* wipe in memory only */
blkid_probe_hide_range(pr, magoff, len); blkid_probe_hide_range(pr, magoff, len);
return blkid_probe_step_back(pr); return blkid_probe_step_back(pr);

View 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, return get_custom_block_run(pr, bs,
&ds->direct[i], &ds->direct[i],
start, length, fs_le); 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)) { } else if (start < (int64_t) FS64_TO_CPU(ds->max_indirect_range, fs_le)) {
struct block_run *br; 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) if (start < br_len)
return get_custom_block_run(pr, bs, &br[i], return get_custom_block_run(pr, bs, &br[i],
start, length, fs_le); 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)) { } else if (start < (int64_t) FS64_TO_CPU(ds->max_double_indirect_range, fs_le)) {
struct block_run *br; 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) if ((int64_t) FS64_TO_CPU(bn->overflow_link, fs_le)
== BPLUSTREE_NULL) == BPLUSTREE_NULL)
return FS64_TO_CPU(values[last], fs_le); 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) } else if (cmp < 0)
node_pointer = FS64_TO_CPU(bn->overflow_link, fs_le); node_pointer = FS64_TO_CPU(bn->overflow_link, fs_le);
else { else {
@ -352,9 +350,10 @@ static int64_t get_key_value(blkid_probe pr, const struct befs_super_block *bs,
fs_le) == BPLUSTREE_NULL) fs_le) == BPLUSTREE_NULL)
return FS64_TO_CPU(values[mid], return FS64_TO_CPU(values[mid],
fs_le); fs_le);
else break;
break; }
} else if (cmp < 0)
if (cmp < 0)
first = mid + 1; first = mid + 1;
else else
last = mid - 1; last = mid - 1;
@ -411,7 +410,9 @@ static int get_uuid(blkid_probe pr, const struct befs_super_block *bs,
sizeof(uint64_t)); sizeof(uint64_t));
break; 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->name_size, fs_le) == 0
&& FS16_TO_CPU(sd->data_size, fs_le) == 0) && FS16_TO_CPU(sd->data_size, fs_le) == 0)
break; break;
@ -437,7 +438,7 @@ static int get_uuid(blkid_probe pr, const struct befs_super_block *bs,
if (value < 0) if (value < 0)
return value == -ENOENT ? BLKID_PROBE_NONE : value; return value == -ENOENT ? BLKID_PROBE_NONE : value;
else if (value > 0) { if (value > 0) {
bi = (struct befs_inode *) blkid_probe_get_buffer(pr, bi = (struct befs_inode *) blkid_probe_get_buffer(pr,
value << FS32_TO_CPU(bs->block_shift, fs_le), value << FS32_TO_CPU(bs->block_shift, fs_le),
FS32_TO_CPU(bs->block_size, fs_le)); FS32_TO_CPU(bs->block_size, fs_le));

View 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)) { if (!memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L)) {
/* LUKS primary header was found. */ /* LUKS primary header was found. */
return luks_attributes(pr, header, 0); 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) /* No primary header, scan for known offsets of LUKS2 secondary header. */
return errno ? -errno : BLKID_PROBE_NONE; 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 (!memcmp(header->magic, LUKS_MAGIC_2, LUKS_MAGIC_L)) if (!header)
return luks_attributes(pr, header, secondary_offsets[i]); 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; return BLKID_PROBE_NONE;

View file

@ -143,7 +143,8 @@ static int probe_minix(blkid_probe pr,
ext = blkid_probe_get_buffer(pr, 0x400 + 0x38, 2); ext = blkid_probe_get_buffer(pr, 0x400 + 0x38, 2);
if (!ext) if (!ext)
return errno ? -errno : 1; return errno ? -errno : 1;
else if (memcmp(ext, "\123\357", 2) == 0)
if (memcmp(ext, "\123\357", 2) == 0)
return 1; return 1;
blkid_probe_sprintf_version(pr, "%d", version); blkid_probe_sprintf_version(pr, "%d", version);

View file

@ -91,7 +91,9 @@ static int probe_swap(blkid_probe pr, const struct blkid_idmag *mag)
blkid_probe_set_version(pr, "0"); blkid_probe_set_version(pr, "0");
return 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 swap_set_info(pr, "1");
return 1; return 1;

View file

@ -217,7 +217,7 @@ static int probe_udf(blkid_probe pr,
if (vsd_len == 2048) { if (vsd_len == 2048) {
if (vsd_2048_valid == 0) if (vsd_2048_valid == 0)
continue; continue;
else if (vsd_2048_valid == 1) if (vsd_2048_valid == 1)
goto anchor; goto anchor;
} }

View file

@ -226,7 +226,8 @@ struct fdisk_label *fdisk_get_label(struct fdisk_context *cxt, const char *name)
if (!name) if (!name)
return cxt->label; return cxt->label;
else if (strcasecmp(name, "mbr") == 0)
if (strcasecmp(name, "mbr") == 0)
name = "dos"; name = "dos";
for (i = 0; i < cxt->nlabels; i++) 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)) if (!S_ISBLK(cxt->dev_st.st_mode))
return 0; return 0;
else {
DBG(CXT, ul_debugobj(cxt, "calling re-read ioctl")); DBG(CXT, ul_debugobj(cxt, "calling re-read ioctl"));
sync(); sync();
#ifdef BLKRRPART #ifdef BLKRRPART
fdisk_info(cxt, _("Calling ioctl() to re-read partition table.")); fdisk_info(cxt, _("Calling ioctl() to re-read partition table."));
i = ioctl(cxt->dev_fd, BLKRRPART); i = ioctl(cxt->dev_fd, BLKRRPART);
#else #else
errno = ENOSYS; errno = ENOSYS;
i = 1; i = 1;
#endif #endif
}
if (i) { if (i) {
fdisk_warn(cxt, _("Re-reading the partition table failed.")); fdisk_warn(cxt, _("Re-reading the partition table failed."));

View file

@ -1715,7 +1715,9 @@ static int dos_add_partition(struct fdisk_context *cxt,
if (!ext_pe) { if (!ext_pe) {
fdisk_warnx(cxt, _("Extended partition does not exists. Failed to add logical partition.")); fdisk_warnx(cxt, _("Extended partition does not exists. Failed to add logical partition."));
return -EINVAL; return -EINVAL;
} else if (fdisk_partition_has_start(pa) }
if (fdisk_partition_has_start(pa)
&& pa->start < l->ext_offset && pa->start < l->ext_offset
&& pa->start > get_abs_partition_end(ext_pe)) { && pa->start > get_abs_partition_end(ext_pe)) {
DBG(LABEL, ul_debug("DOS: pa template specifies partno>=4, but start out of extended")); 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)) { if (pa && fdisk_partition_has_start(pa)) {
fdisk_warnx(cxt, msg); fdisk_warnx(cxt, msg);
return -EINVAL; return -EINVAL;
} else }
fdisk_info(cxt, msg); fdisk_info(cxt, msg);
} }
rc = add_logical(cxt, pa, &res); rc = add_logical(cxt, pa, &res);
} else { } else {

View file

@ -753,7 +753,9 @@ int fdisk_partition_next_partno(
} }
return -ERANGE; 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)); DBG(PART, ul_debugobj(pa, "next partno (specified=%zu)", pa->partno));
@ -763,7 +765,9 @@ int fdisk_partition_next_partno(
*n = pa->partno; *n = pa->partno;
return 0; return 0;
} else if (fdisk_has_dialogs(cxt)) }
if (fdisk_has_dialogs(cxt))
return fdisk_ask_partnum(cxt, n, 1); return fdisk_ask_partnum(cxt, n, 1);
return -EINVAL; return -EINVAL;

View file

@ -396,14 +396,18 @@ static int sgi_check_bootfile(struct fdisk_context *cxt, const char *name)
"e.g. \"/unix\" or \"/unix.save\".")); "e.g. \"/unix\" or \"/unix.save\"."));
return -EINVAL; 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.", fdisk_warnx(cxt, P_("Name of bootfile is too long: %zu byte maximum.",
"Name of bootfile is too long: %zu bytes maximum.", "Name of bootfile is too long: %zu bytes maximum.",
sizeof(sgilabel->boot_file)), sizeof(sgilabel->boot_file)),
sizeof(sgilabel->boot_file)); sizeof(sgilabel->boot_file));
return -EINVAL; return -EINVAL;
} else if (*name != '/') { }
if (*name != '/') {
fdisk_warnx(cxt, _("Bootfile must have a fully qualified pathname.")); fdisk_warnx(cxt, _("Bootfile must have a fully qualified pathname."));
return -EINVAL; return -EINVAL;
} }

View file

@ -34,12 +34,12 @@ static PyObject *Context_set_tables_errcb(ContextObjext *self, PyObject *func,
if (!PyCallable_Check(func)) if (!PyCallable_Check(func))
return NULL; return NULL;
else {
PyObject *tmp = self->table_errcb; PyObject *tmp = self->table_errcb;
Py_INCREF(func); Py_INCREF(func);
self->table_errcb = func; self->table_errcb = func;
Py_XDECREF(tmp); Py_XDECREF(tmp);
}
return UL_IncRef(self); 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); PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
return -1; return -1;
} }
else if (!PyLong_Check(value)) { if (!PyLong_Check(value)) {
PyErr_SetString(PyExc_TypeError, ARG_ERR); PyErr_SetString(PyExc_TypeError, ARG_ERR);
return -1; return -1;
} }
@ -586,7 +586,7 @@ static int Context_set_syscall_status(ContextObjext *self, PyObject *value, void
PyErr_SetString(PyExc_TypeError, NODEL_ATTR); PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
return -1; return -1;
} }
else if (!PyLong_Check(value)) { if (!PyLong_Check(value)) {
PyErr_SetString(PyExc_TypeError, ARG_ERR); PyErr_SetString(PyExc_TypeError, ARG_ERR);
return -1; return -1;
} }
@ -602,7 +602,7 @@ static int Context_set_user_mflags(ContextObjext *self, PyObject *value, void *c
PyErr_SetString(PyExc_TypeError, NODEL_ATTR); PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
return -1; return -1;
} }
else if (!PyLong_Check(value)) { if (!PyLong_Check(value)) {
PyErr_SetString(PyExc_TypeError, ARG_ERR); PyErr_SetString(PyExc_TypeError, ARG_ERR);
return -1; return -1;
} }
@ -619,7 +619,7 @@ static int Context_set_mflags(ContextObjext *self, PyObject *value, void *closur
PyErr_SetString(PyExc_TypeError, NODEL_ATTR); PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
return -1; return -1;
} }
else if (!PyLong_Check(value)) { if (!PyLong_Check(value)) {
PyErr_SetString(PyExc_TypeError, ARG_ERR); PyErr_SetString(PyExc_TypeError, ARG_ERR);
return -1; return -1;
} }

View file

@ -370,7 +370,9 @@ static int Fs_set_freq(FsObject *self, PyObject *value,
PyErr_SetString(PyExc_TypeError, NODEL_ATTR); PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
return -1; return -1;
} else if (!PyLong_Check(value)) { }
if (!PyLong_Check(value)) {
PyErr_SetString(PyExc_TypeError, ARG_ERR); PyErr_SetString(PyExc_TypeError, ARG_ERR);
return -1; return -1;
} }
@ -395,7 +397,9 @@ static int Fs_set_passno(FsObject *self, PyObject *value, void *closure __attrib
if (!value) { if (!value) {
PyErr_SetString(PyExc_TypeError, NODEL_ATTR); PyErr_SetString(PyExc_TypeError, NODEL_ATTR);
return -1; return -1;
} else if (!PyLong_Check(value)) { }
if (!PyLong_Check(value)) {
PyErr_SetString(PyExc_TypeError, ARG_ERR); PyErr_SetString(PyExc_TypeError, ARG_ERR);
return -1; 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")); DBG(FS, pymnt_debug_h(dest, "copy data"));
return (PyObject *)dest; return (PyObject *)dest;
} else if (dest == Py_None) { /* create new object */ }
if (dest == Py_None) { /* create new object */
FsObject *result = PyObject_New(FsObject, &FsType); FsObject *result = PyObject_New(FsObject, &FsType);
DBG(FS, pymnt_debug_h(result, "new copy")); DBG(FS, pymnt_debug_h(result, "new copy"));

View file

@ -492,7 +492,9 @@ static PyObject *Table_next_fs(TableObject *self)
if (rc == 1) { if (rc == 1) {
mnt_reset_iter(self->iter, MNT_ITER_FORWARD); mnt_reset_iter(self->iter, MNT_ITER_FORWARD);
Py_RETURN_NONE; Py_RETURN_NONE;
} else if (rc) }
if (rc)
return UL_RaiseExc(-rc); return UL_RaiseExc(-rc);
return PyObjectResultFs(fs); return PyObjectResultFs(fs);

View file

@ -578,7 +578,8 @@ char *mnt_resolve_target(const char *path, struct libmnt_cache *cache)
p = (char *) cache_find_path(cache, path); p = (char *) cache_find_path(cache, path);
if (p) if (p)
return p; return p;
else {
{
struct libmnt_iter itr; struct libmnt_iter itr;
struct libmnt_fs *fs = NULL; 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) { while (mnt_table_next_fs(cache->mtab, &itr, &fs) == 0) {
if (!mnt_fs_is_kernel(fs) if (!mnt_fs_is_kernel(fs)
|| mnt_fs_is_swaparea(fs) || mnt_fs_is_swaparea(fs)
|| !mnt_fs_streq_target(fs, path)) || !mnt_fs_streq_target(fs, path))
continue; continue;
p = strdup(path); p = strdup(path);

View file

@ -2864,7 +2864,9 @@ int mnt_context_is_fs_mounted(struct libmnt_context *cxt,
} }
*mounted = 0; *mounted = 0;
return 0; /* /proc not mounted */ return 0; /* /proc not mounted */
} else if (rc) }
if (rc)
return rc; return rc;
*mounted = __mnt_table_is_fs_mounted(mtab, fs, *mounted = __mnt_table_is_fs_mounted(mtab, fs,

View file

@ -1733,12 +1733,16 @@ int mnt_context_get_mount_excode(
if (buf) if (buf)
snprintf(buf, bufsz, _("filesystem was mounted, but failed to update userspace mount table")); snprintf(buf, bufsz, _("filesystem was mounted, but failed to update userspace mount table"));
return MNT_EX_FILEIO; return MNT_EX_FILEIO;
} else if (rc == -MNT_ERR_NAMESPACE) { }
if (rc == -MNT_ERR_NAMESPACE) {
if (buf) if (buf)
snprintf(buf, bufsz, _("filesystem was mounted, but failed to switch namespace back")); snprintf(buf, bufsz, _("filesystem was mounted, but failed to switch namespace back"));
return MNT_EX_SYSERR; return MNT_EX_SYSERR;
} else if (rc < 0) }
if (rc < 0)
return mnt_context_get_generic_excode(rc, buf, bufsz, return mnt_context_get_generic_excode(rc, buf, bufsz,
_("filesystem was mounted, but any subsequent operation failed: %m")); _("filesystem was mounted, but any subsequent operation failed: %m"));

View file

@ -1253,11 +1253,15 @@ int mnt_context_get_umount_excode(
if (buf) if (buf)
snprintf(buf, bufsz, _("not mounted")); snprintf(buf, bufsz, _("not mounted"));
return MNT_EX_USAGE; return MNT_EX_USAGE;
} else if (rc == -MNT_ERR_LOCK) { }
if (rc == -MNT_ERR_LOCK) {
if (buf) if (buf)
snprintf(buf, bufsz, _("locking failed")); snprintf(buf, bufsz, _("locking failed"));
return MNT_EX_FILEIO; return MNT_EX_FILEIO;
} else if (rc == -MNT_ERR_NAMESPACE) { }
if (rc == -MNT_ERR_NAMESPACE) {
if (buf) if (buf)
snprintf(buf, bufsz, _("failed to switch namespace")); snprintf(buf, bufsz, _("failed to switch namespace"));
return MNT_EX_SYSERR; return MNT_EX_SYSERR;
@ -1265,7 +1269,7 @@ int mnt_context_get_umount_excode(
return mnt_context_get_generic_excode(rc, buf, bufsz, return mnt_context_get_generic_excode(rc, buf, bufsz,
_("umount failed: %m")); _("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 * umount(2) syscall success, but something else failed
* (probably error in mtab processing). * (probably error in mtab processing).
@ -1274,12 +1278,16 @@ int mnt_context_get_umount_excode(
if (buf) if (buf)
snprintf(buf, bufsz, _("filesystem was unmounted, but failed to update userspace mount table")); snprintf(buf, bufsz, _("filesystem was unmounted, but failed to update userspace mount table"));
return MNT_EX_FILEIO; return MNT_EX_FILEIO;
} else if (rc == -MNT_ERR_NAMESPACE) { }
if (rc == -MNT_ERR_NAMESPACE) {
if (buf) if (buf)
snprintf(buf, bufsz, _("filesystem was unmounted, but failed to switch namespace back")); snprintf(buf, bufsz, _("filesystem was unmounted, but failed to switch namespace back"));
return MNT_EX_SYSERR; return MNT_EX_SYSERR;
} else if (rc < 0) }
if (rc < 0)
return mnt_context_get_generic_excode(rc, buf, bufsz, return mnt_context_get_generic_excode(rc, buf, bufsz,
_("filesystem was unmounted, but any subsequent operation failed: %m")); _("filesystem was unmounted, but any subsequent operation failed: %m"));

View file

@ -474,25 +474,25 @@ static int lock_mtab(struct libmnt_lock *ml)
/* proceed, since it was us who created the lockfile anyway */ /* proceed, since it was us who created the lockfile anyway */
} }
break; 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", DBG(LOCKS, ul_debugobj(ml, "%s: (%d) successfully locked",
lockfile, getpid())); lockfile, getpid()));

View file

@ -263,7 +263,9 @@ static int userspace_add_watch(struct monitor_entry *me, int *final, int *fd)
if (fd) if (fd)
*fd = wd; *fd = wd;
break; break;
} else if (errno != ENOENT) { }
if (errno != ENOENT) {
rc = -errno; rc = -errno;
break; break;
} }

View file

@ -209,7 +209,7 @@ const struct libmnt_optmap *mnt_get_builtin_optmap(int id)
if (id == MNT_LINUX_MAP) if (id == MNT_LINUX_MAP)
return linux_flags_map; return linux_flags_map;
else if (id == MNT_USERSPACE_MAP) if (id == MNT_USERSPACE_MAP)
return userspace_opts_map; return userspace_opts_map;
return NULL; return NULL;
} }

View file

@ -983,7 +983,7 @@ int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next)
(*(value + 7) == ',' || !*(value + 7))) (*(value + 7) == ',' || !*(value + 7)))
return set_uint_value(optstr, getuid(), value, end, next); return set_uint_value(optstr, getuid(), value, end, next);
else if (!isdigit(*value)) { if (!isdigit(*value)) {
uid_t id; uid_t id;
int rc; int rc;
char *p = strndup(value, valsz); 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))) (*(value + 7) == ',' || !*(value + 7)))
return set_uint_value(optstr, getgid(), value, end, next); return set_uint_value(optstr, getgid(), value, end, next);
else if (!isdigit(*value)) { if (!isdigit(*value)) {
int rc; int rc;
gid_t id; gid_t id;
char *p = strndup(value, valsz); char *p = strndup(value, valsz);

View file

@ -701,28 +701,32 @@ static int try_write(const char *filename, const char *directory)
if (eaccess(filename, R_OK|W_OK) == 0) { if (eaccess(filename, R_OK|W_OK) == 0) {
DBG(UTILS, ul_debug(" access OK")); DBG(UTILS, ul_debug(" access OK"));
return 0; return 0;
} else if (errno != ENOENT) { }
if (errno != ENOENT) {
DBG(UTILS, ul_debug(" access FAILED")); DBG(UTILS, ul_debug(" access FAILED"));
return -errno; return -errno;
} else if (directory) { }
if (directory) {
/* file does not exist; try if directory is writable */ /* file does not exist; try if directory is writable */
if (eaccess(directory, R_OK|W_OK) != 0) if (eaccess(directory, R_OK|W_OK) != 0)
rc = -errno; rc = -errno;
DBG(UTILS, ul_debug(" access %s [%s]", rc ? "FAILED" : "OK", directory)); DBG(UTILS, ul_debug(" access %s [%s]", rc ? "FAILED" : "OK", directory));
return rc; 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);
} }
#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);
return rc; return rc;
} }
@ -1210,7 +1214,7 @@ static int read_procfs_file(int fd, char **buf, size_t *bufsiz)
} }
break; break;
} else if (ret > 0) { } if (ret > 0) {
/* success -- verify no event during read */ /* success -- verify no event during read */
struct pollfd fds[] = { struct pollfd fds[] = {
{ .fd = fd, .events = POLLPRI } { .fd = fd, .events = POLLPRI }

View 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) if (cl->is_extreme && cl->width_avg && len > cl->width_avg * 2)
return 0; return 0;
else if (scols_column_is_noextremes(cl)) { if (scols_column_is_noextremes(cl)) {
cl->extreme_sum += len; cl->extreme_sum += len;
cl->extreme_count++; cl->extreme_count++;
} }

View file

@ -226,7 +226,7 @@ int scols_cell_get_alignment(const struct libscols_cell *ce)
{ {
if (ce->flags & SCOLS_CELL_FL_RIGHT) if (ce->flags & SCOLS_CELL_FL_RIGHT)
return 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_CENTER;
return SCOLS_CELL_FL_LEFT; /* default */ return SCOLS_CELL_FL_LEFT; /* default */

View file

@ -62,8 +62,7 @@ int uuid_parse_range(const char *in_start, const char *in_end, uuid_t uu)
(i == 23)) { (i == 23)) {
if (*cp == '-') if (*cp == '-')
continue; continue;
else return -1;
return -1;
} }
if (i== 36) if (i== 36)
if (*cp == 0) if (*cp == 0)

View file

@ -68,13 +68,16 @@ const uuid_t *uuid_get_template(const char *alias)
if (!strcmp(alias, "dns")) if (!strcmp(alias, "dns"))
return &NameSpace_DNS; return &NameSpace_DNS;
else if (!strcmp(alias, "url"))
if (!strcmp(alias, "url"))
return &NameSpace_URL; return &NameSpace_URL;
else if (!strcmp(alias, "oid"))
if (!strcmp(alias, "oid"))
return &NameSpace_OID; return &NameSpace_OID;
else if (!strcmp(alias, "x500") || !strcmp(alias, "x.500"))
if (!strcmp(alias, "x500") || !strcmp(alias, "x.500"))
return &NameSpace_X500; return &NameSpace_X500;
else
return NULL; return NULL;
} }

View file

@ -56,12 +56,11 @@ static int is_local_in_file(const char *user, const char *filename)
* but it is just an optimisation * but it is just an optimisation
* anyway. */ * anyway. */
break; 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) { } else if ('\n' == chin) {
/* This line contains no colon; it's /* This line contains no colon; it's
* malformed. No skip since we are already * malformed. No skip since we are already
@ -96,17 +95,17 @@ int main(int argc, char *argv[])
fprintf(stderr, _("Usage: %s <passwordfile> <username>...\n"), fprintf(stderr, _("Usage: %s <passwordfile> <username>...\n"),
argv[0]); argv[0]);
return 1; 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]);
}
return 0;
} }
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]);
}
return 0;
} }
#endif #endif

View file

@ -391,8 +391,9 @@ int get_hushlogin_status(struct passwd *pwd, int force_check)
rc = effective_access(buf, O_RDONLY); rc = effective_access(buf, O_RDONLY);
if (rc == 0) if (rc == 0)
return 1; return 1;
else if (rc == -1 && errno == EACCES)
return -1; if (rc == -1 && errno == EACCES)
return -1;
} }
} }

View file

@ -222,15 +222,14 @@ static FILE *dump(FILE *in, const char *filename, int follow, FILE *out)
#ifdef HAVE_INOTIFY_INIT #ifdef HAVE_INOTIFY_INIT
if (follow_by_inotify(in, filename, out) == 0) if (follow_by_inotify(in, filename, out) == 0)
return NULL; /* file already closed */ return NULL; /* file already closed */
else
#endif #endif
/* fallback for systems without inotify or with non-free /* fallback for systems without inotify or with non-free
* inotify instances */ * inotify instances */
for (;;) { for (;;) {
while (fread(&ut, sizeof(ut), 1, in) == 1) while (fread(&ut, sizeof(ut), 1, in) == 1)
print_utline(&ut, out); print_utline(&ut, out);
sleep(1); sleep(1);
} }
return in; return in;
} }

View file

@ -618,8 +618,8 @@ static int leap_year(const struct cal_control *ctl, int32_t year)
{ {
if (year <= ctl->reform_year) if (year <= ctl->reform_year)
return !(year % 4); 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) static void init_monthnames(struct cal_control *ctl)

View file

@ -407,7 +407,7 @@ static int verify_fstype(struct verify_context *vfy)
&& mnt_fs_get_option(vfy->fs, "move", NULL, NULL) == 1) && 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")); 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; isauto = 1;
else if (strcmp(type, "swap") == 0) else if (strcmp(type, "swap") == 0)
isswap = 1; isswap = 1;

View file

@ -392,8 +392,8 @@ int main(int argc, char *argv[])
*/ */
printf(" --\n"); printf(" --\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} else }
parse_error(_("missing optstring argument")); parse_error(_("missing optstring argument"));
} }
add_longopt(&ctl, NULL, 0); /* init */ add_longopt(&ctl, NULL, 0); /* init */

View file

@ -505,7 +505,7 @@ int main(int argc, char **argv)
#endif #endif
if (ct && nerrs == 0) if (ct && nerrs == 0)
return EXIT_SUCCESS; /* full success */ return EXIT_SUCCESS; /* full success */
else if (ct == nerrs) if (ct == nerrs)
return EXIT_FAILURE; /* all failed */ return EXIT_FAILURE; /* all failed */
return KILL_EXIT_SOMEOK; /* partial success */ return KILL_EXIT_SOMEOK; /* partial success */

View file

@ -96,8 +96,8 @@ static int ask(char *name)
buf[1] = '\0'; buf[1] = '\0';
if (rpmatch(buf) == RPMATCH_YES) if (rpmatch(buf) == RPMATCH_YES)
return 0; return 0;
else
return 1; return 1;
} }
static int do_symlink(char *from, char *to, char *s, int verbose, int noact, static int do_symlink(char *from, char *to, char *s, int verbose, int noact,

View file

@ -428,8 +428,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
if (ns < 0) { if (ns < 0) {
if ((errno == EAGAIN) || (errno == EINTR)) if ((errno == EAGAIN) || (errno == EINTR))
continue; continue;
else err(EXIT_FAILURE, "accept");
err(EXIT_FAILURE, "accept");
} }
len = read(ns, &op, 1); len = read(ns, &op, 1);
if (len != 1) { if (len != 1) {

View file

@ -298,13 +298,12 @@ static char *find_device(const char *name)
if ((*name == '.' || *name == '/') && access(name, F_OK) == 0) if ((*name == '.' || *name == '/') && access(name, F_OK) == 0)
return xstrdup(name); return xstrdup(name);
else {
char buf[PATH_MAX];
snprintf(buf, sizeof(buf), "/dev/%s", name); char buf[PATH_MAX];
if (access(buf, F_OK) == 0)
return xstrdup(buf); snprintf(buf, sizeof(buf), "/dev/%s", name);
} if (access(buf, F_OK) == 0)
return xstrdup(buf);
return NULL; return NULL;
} }

View file

@ -258,48 +258,48 @@ static int synchronize_to_clock_tick_rtc(const struct hwclock_control *ctl)
if (rtc_fd == -1) { if (rtc_fd == -1) {
warn(_("cannot open rtc device")); warn(_("cannot open rtc device"));
return ret; return ret;
} else { }
/* Turn on update interrupts (one per second) */
int rc = ioctl(rtc_fd, RTC_UIE_ON, 0);
if (rc != -1) { /* Turn on update interrupts (one per second) */
/* int rc = ioctl(rtc_fd, RTC_UIE_ON, 0);
* 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;
/* if (rc != -1) {
* Wait up to ten seconds for the next update /*
* interrupt * Just reading rtc_fd fails on broken hardware: no
*/ * update interrupt comes and a bootscript with a
FD_ZERO(&rfds); * hwclock call hangs
FD_SET(rtc_fd, &rfds); */
tv.tv_sec = 10; fd_set rfds;
tv.tv_usec = 0; struct timeval tv;
rc = select(rtc_fd + 1, &rfds, NULL, NULL, &tv);
if (0 < rc) /*
ret = 0; * Wait up to ten seconds for the next update
else if (rc == 0) { * interrupt
warnx(_("select() to %s to wait for clock tick timed out"), */
rtc_dev_name); FD_ZERO(&rfds);
} else FD_SET(rtc_fd, &rfds);
warn(_("select() to %s to wait for clock tick failed"), tv.tv_sec = 10;
rtc_dev_name); tv.tv_usec = 0;
/* Turn off update interrupts */ rc = select(rtc_fd + 1, &rfds, NULL, NULL, &tv);
rc = ioctl(rtc_fd, RTC_UIE_OFF, 0); if (0 < rc)
if (rc == -1) ret = 0;
warn(_("ioctl() to %s to turn off update interrupts failed"), else if (rc == 0) {
rtc_dev_name); 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) { } else if (errno == ENOTTY || errno == EINVAL) {
/* rtc ioctl interrupts are unimplemented */ /* rtc ioctl interrupts are unimplemented */
ret = busywait_for_rtc_clock_tick(ctl, rtc_fd); ret = busywait_for_rtc_clock_tick(ctl, rtc_fd);
} else } else
warn(_("ioctl(%d, RTC_UIE_ON, 0) to %s failed"), warn(_("ioctl(%d, RTC_UIE_ON, 0) to %s failed"),
rtc_fd, rtc_dev_name); rtc_fd, rtc_dev_name);
}
return ret; return ret;
} }

View file

@ -876,7 +876,9 @@ static int save_adjtime(const struct hwclock_control *ctl,
if (fp == NULL) { if (fp == NULL) {
warn(_("cannot open %s"), ctl->adj_file_name); warn(_("cannot open %s"), ctl->adj_file_name);
return EXIT_FAILURE; 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); warn(_("cannot update %s"), ctl->adj_file_name);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -1053,7 +1055,9 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time,
} }
if (ctl->show || ctl->get) { if (ctl->show || ctl->get) {
return display_time(startup_hclocktime); return display_time(startup_hclocktime);
} else if (ctl->set) { }
if (ctl->set) {
set_hardware_clock_exact(ctl, set_time, startup_time); set_hardware_clock_exact(ctl, set_time, startup_time);
if (!ctl->noadjfile) if (!ctl->noadjfile)
adjust_drift_factor(ctl, adjtime, t2tv(set_time), adjust_drift_factor(ctl, adjtime, t2tv(set_time),

View file

@ -145,8 +145,8 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
if (id == p->shm_perm.id) { if (id == p->shm_perm.id) {
i = 1; i = 1;
break; break;
} else }
continue; continue;
} }
p->next = xcalloc(1, sizeof(struct shm_data)); 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); get_sem_elements(p);
i = 1; i = 1;
break; break;
} else }
continue; continue;
} }
p->next = xcalloc(1, sizeof(struct sem_data)); 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; p->q_qbytes = msgseg.msg_qbytes;
i = 1; i = 1;
break; break;
} else }
continue; continue;
} }
p->next = xcalloc(1, sizeof(struct msg_data)); p->next = xcalloc(1, sizeof(struct msg_data));

View file

@ -221,12 +221,12 @@ static int column_name_to_id(const char *name, size_t namesz)
if (i > COL_CTIME) { if (i > COL_CTIME) {
if (i >= LOWER && i <= UPPER) if (i >= LOWER && i <= UPPER)
return i; return i;
else {
warnx(_("column %s does not apply to the specified IPC"), name); warnx(_("column %s does not apply to the specified IPC"), name);
return -1; return -1;
} }
} else
return i; return i;
} }
} }
warnx(_("unknown column: %s"), name); warnx(_("unknown column: %s"), name);

View file

@ -596,11 +596,10 @@ static int netnsid_xasputs(char **str, int netnsid)
if (netnsid >= 0) if (netnsid >= 0)
return xasprintf(str, "%d", netnsid); return xasprintf(str, "%d", netnsid);
#ifdef NETNSA_NSID_NOT_ASSIGNED #ifdef NETNSA_NSID_NOT_ASSIGNED
else if (netnsid == NETNSA_NSID_NOT_ASSIGNED) if (netnsid == NETNSA_NSID_NOT_ASSIGNED)
return xasprintf(str, "%s", "unassigned"); return xasprintf(str, "%s", "unassigned");
#endif #endif
else return 0;
return 0;
} }
static int read_namespaces(struct lsns *ls) static int read_namespaces(struct lsns *ls)

View file

@ -397,7 +397,9 @@ static int get_range(char *str, rlim_t *soft, rlim_t *hard, int *found)
*found |= PRLIMIT_SOFT | PRLIMIT_HARD; *found |= PRLIMIT_SOFT | PRLIMIT_HARD;
return 0; return 0;
} else if (*str == ':') { /* <:hard> */ }
if (*str == ':') { /* <:hard> */
str++; str++;
if (strcmp(str, INFINITY_STR) != 0) { if (strcmp(str, INFINITY_STR) != 0) {

View file

@ -593,7 +593,7 @@ int main(int argc, char *argv[])
err(EXIT_FAILURE, _("waitpid failed")); err(EXIT_FAILURE, _("waitpid failed"));
if (WIFEXITED(status)) if (WIFEXITED(status))
return WEXITSTATUS(status); return WEXITSTATUS(status);
else if (WIFSIGNALED(status)) if (WIFSIGNALED(status))
kill(getpid(), WTERMSIG(status)); kill(getpid(), WTERMSIG(status));
err(EXIT_FAILURE, _("child exit failed")); err(EXIT_FAILURE, _("child exit failed"));
} }

View 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); ul_path_read_string(sysfs, &str, name);
return str; 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 size_to_human_string(SIZE_SUFFIX_1LETTER, num);
return NULL; return NULL;

View file

@ -1701,7 +1701,9 @@ static int wait_for_term_input(int fd)
if (FD_ISSET(fd, &rfds)) { if (FD_ISSET(fd, &rfds)) {
return 1; return 1;
} else if (netlink_fd >= 0 && FD_ISSET(netlink_fd, &rfds)) { }
if (netlink_fd >= 0 && FD_ISSET(netlink_fd, &rfds)) {
if (!process_netlink()) if (!process_netlink())
continue; continue;

View file

@ -126,11 +126,11 @@ static int process_next_step(struct scriptlive *ss)
ul_pty_set_mainloop_time(ss->pty, &target); ul_pty_set_mainloop_time(ss->pty, &target);
break; 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); } while (rc == 0);
return rc; return rc;

View file

@ -247,11 +247,11 @@ static char *find_optional_arg(char **av, char *oa, int *oi)
char *arg; char *arg;
if (oa) if (oa)
return oa; return oa;
else {
arg = av[*oi]; arg = av[*oi];
if (!arg || arg[0] == '-') if (!arg || arg[0] == '-')
return NULL; return NULL;
}
(*oi)++; (*oi)++;
return arg; return arg;
} }
@ -265,29 +265,28 @@ static int parse_blank(char **av, char *oa, int *oi)
return BLANKEDSCREEN; return BLANKEDSCREEN;
if (!strcmp(arg, "force")) if (!strcmp(arg, "force"))
return BLANKSCREEN; return BLANKSCREEN;
else if (!strcmp(arg, "poke")) if (!strcmp(arg, "poke"))
return UNBLANKSCREEN; return UNBLANKSCREEN;
else {
int ret;
ret = strtos32_or_err(arg, _("argument error")); int ret;
if (ret < 0 || BLANK_MAX < ret)
errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg); ret = strtos32_or_err(arg, _("argument error"));
return ret; if (ret < 0 || BLANK_MAX < ret)
} errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg);
return ret;
} }
static int parse_powersave(const char *arg) static int parse_powersave(const char *arg)
{ {
if (strcmp(arg, "on") == 0) if (strcmp(arg, "on") == 0)
return VESA_BLANK_MODE_SUSPENDV; return VESA_BLANK_MODE_SUSPENDV;
else if (strcmp(arg, "vsync") == 0) if (strcmp(arg, "vsync") == 0)
return VESA_BLANK_MODE_SUSPENDV; return VESA_BLANK_MODE_SUSPENDV;
else if (strcmp(arg, "hsync") == 0) if (strcmp(arg, "hsync") == 0)
return VESA_BLANK_MODE_SUSPENDH; return VESA_BLANK_MODE_SUSPENDH;
else if (strcmp(arg, "powerdown") == 0) if (strcmp(arg, "powerdown") == 0)
return VESA_BLANK_MODE_POWERDOWN; return VESA_BLANK_MODE_POWERDOWN;
else if (strcmp(arg, "off") == 0) if (strcmp(arg, "off") == 0)
return VESA_BLANK_MODE_OFF; return VESA_BLANK_MODE_OFF;
errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg); errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg);
} }

View file

@ -895,10 +895,9 @@ static void ttyin(struct more_control *ctl, char buf[], int nmax, char pchar)
erase_one_column(ctl); erase_one_column(ctl);
} }
continue; 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) { } else if (c == ctl->output_tty.c_cc[VKILL] && !slash) {
if (ctl->hard_tty) { if (ctl->hard_tty) {
show(ctl, c); show(ctl, c);
@ -1340,8 +1339,8 @@ static void search(struct more_control *ctl, char buf[], int n)
puts(ctl->line_buf); puts(ctl->line_buf);
} }
break; break;
} else }
more_poll(ctl, 1); more_poll(ctl, 1);
} }
/* Move ctrl+c signal handling back to more_key_command(). */ /* Move ctrl+c signal handling back to more_key_command(). */
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);

View file

@ -987,42 +987,43 @@ static void pgfile(FILE *f, const char *name)
*b = '\0'; *b = '\0';
dline = pagelen; dline = pagelen;
break; 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 (p == NULL || *b == '\0') {
if (ferror(f)) if (ferror(f))
warn("%s", name); warn("%s", name);
eofline = fline; eofline = fline;
eof = 1; eof = 1;
break; 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++;
}
}
fline++;
} }
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++;
} while (line > bline++); } while (line > bline++);
} else { } else {
/* eofline != 0 */ /* eofline != 0 */
@ -1057,7 +1058,9 @@ static void pgfile(FILE *f, const char *name)
skip(1); skip(1);
} }
continue; continue;
} else if (eof) { }
if (eof) {
/* We are not searching. */ /* We are not searching. */
line = bline; line = bline;
} else if (*b != '\0') { } else if (*b != '\0') {

View file

@ -69,8 +69,8 @@ static int put1wc(int c)
{ {
if (putwchar(c) == WEOF) if (putwchar(c) == WEOF)
return EOF; return EOF;
else
return c; return c;
} }
#define putwp(s) tputs(s, STDOUT_FILENO, put1wc) #define putwp(s) tputs(s, STDOUT_FILENO, put1wc)
#else #else