mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
tree-wide: code improvements suggested by Coccinelle
This commit is contained in:
parent
4a4eaade60
commit
ed0cb34682
@ -59,7 +59,7 @@ int main(int argc, char **argv) {
|
||||
vtable,
|
||||
&object));
|
||||
|
||||
while (true) {
|
||||
for (;;) {
|
||||
check(sd_bus_wait(bus, UINT64_MAX));
|
||||
check(sd_bus_process(bus, NULL));
|
||||
}
|
||||
|
@ -303,8 +303,12 @@ static int bus_socket_set_transient_property(
|
||||
if (streq(name, "SocketProtocol"))
|
||||
return bus_set_transient_socket_protocol(u, name, &s->socket_protocol, message, flags, error);
|
||||
|
||||
if ((ci = socket_exec_command_from_string(name)) >= 0)
|
||||
return bus_set_transient_exec_command(u, name, &s->exec_command[ci], message, flags, error);
|
||||
ci = socket_exec_command_from_string(name);
|
||||
if (ci >= 0)
|
||||
return bus_set_transient_exec_command(u, name,
|
||||
&s->exec_command[ci],
|
||||
message, flags, error);
|
||||
|
||||
|
||||
if (streq(name, "Symlinks")) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
|
@ -1036,10 +1036,7 @@ static int send_iovec(const struct iovec iovec[], size_t n_iovec, int input_fd)
|
||||
* (truncated) copy of what we want to send, and the second one
|
||||
* contains the trailing dots. */
|
||||
copy[0] = iovec[i];
|
||||
copy[1] = (struct iovec) {
|
||||
.iov_base = (char[]) { '.', '.', '.' },
|
||||
.iov_len = 3,
|
||||
};
|
||||
copy[1] = IOVEC_MAKE(((char[]){'.', '.', '.'}), 3);
|
||||
|
||||
mh.msg_iov = copy;
|
||||
mh.msg_iovlen = 2;
|
||||
|
@ -250,7 +250,7 @@ static void transfer_send_logs(Transfer *t, bool flush) {
|
||||
n = strndup(t->log_message, e - t->log_message);
|
||||
|
||||
/* Skip over NUL and newlines */
|
||||
while (e < t->log_message + t->log_message_size && (*e == 0 || *e == '\n'))
|
||||
while (e < t->log_message + t->log_message_size && IN_SET(*e, 0, '\n'))
|
||||
e++;
|
||||
|
||||
memmove(t->log_message, e, t->log_message + sizeof(t->log_message) - e);
|
||||
|
@ -693,8 +693,7 @@ bool manager_all_buttons_ignored(Manager *m) {
|
||||
return false;
|
||||
if (m->handle_lid_switch != HANDLE_IGNORE)
|
||||
return false;
|
||||
if (m->handle_lid_switch_ep != _HANDLE_ACTION_INVALID &&
|
||||
m->handle_lid_switch_ep != HANDLE_IGNORE)
|
||||
if (!IN_SET(m->handle_lid_switch_ep, _HANDLE_ACTION_INVALID, HANDLE_IGNORE))
|
||||
return false;
|
||||
if (m->handle_lid_switch_docked != HANDLE_IGNORE)
|
||||
return false;
|
||||
|
@ -754,7 +754,7 @@ void user_update_last_session_timer(User *u) {
|
||||
|
||||
assert(!u->timer_event_source);
|
||||
|
||||
if (u->manager->user_stop_delay == 0 || u->manager->user_stop_delay == USEC_INFINITY)
|
||||
if (IN_SET(u->manager->user_stop_delay, 0, USEC_INFINITY))
|
||||
return;
|
||||
|
||||
if (sd_event_get_state(u->manager->event) == SD_EVENT_FINISHED) {
|
||||
|
@ -37,7 +37,7 @@ int dns_label_unescape(const char **name, char *dest, size_t sz, DNSLabelFlags f
|
||||
d = dest;
|
||||
|
||||
for (;;) {
|
||||
if (*n == 0 || *n == '.') {
|
||||
if (IN_SET(*n, 0, '.')) {
|
||||
if (FLAGS_SET(flags, DNS_LABEL_LDH) && last_char == '-')
|
||||
/* Trailing dash */
|
||||
return -EINVAL;
|
||||
|
@ -395,7 +395,7 @@ static int image_make(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (size != 0 && size != UINT64_MAX)
|
||||
if (!IN_SET(size, 0, UINT64_MAX))
|
||||
(*ret)->usage = (*ret)->usage_exclusive = (*ret)->limit = (*ret)->limit_exclusive = size;
|
||||
|
||||
return 0;
|
||||
|
@ -203,8 +203,7 @@ static int cd_capability_compat(int fd) {
|
||||
|
||||
capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
|
||||
if (capability < 0) {
|
||||
log_debug("CDROM_GET_CAPABILITY failed");
|
||||
return -1;
|
||||
return log_debug_errno(errno, "CDROM_GET_CAPABILITY failed");
|
||||
}
|
||||
|
||||
if (capability & CDC_CD_R)
|
||||
@ -226,8 +225,7 @@ static int cd_capability_compat(int fd) {
|
||||
|
||||
static int cd_media_compat(int fd) {
|
||||
if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) {
|
||||
log_debug("CDROM_DRIVE_STATUS != CDS_DISC_OK");
|
||||
return -1;
|
||||
return log_debug_errno(errno, "CDROM_DRIVE_STATUS != CDS_DISC_OK");
|
||||
}
|
||||
cd_media = 1;
|
||||
return 0;
|
||||
@ -249,8 +247,7 @@ static int cd_inquiry(int fd) {
|
||||
}
|
||||
|
||||
if ((inq[0] & 0x1F) != 5) {
|
||||
log_debug("not an MMC unit");
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "not an MMC unit");
|
||||
}
|
||||
|
||||
log_debug("INQUIRY: [%.8s][%.16s][%.4s]", inq + 8, inq + 16, inq + 32);
|
||||
@ -474,8 +471,8 @@ static int cd_profiles_old_mmc(int fd) {
|
||||
cd_media_track_count_data = 1;
|
||||
return 0;
|
||||
} else {
|
||||
log_debug("no current profile, assuming no media");
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
|
||||
"no current profile, assuming no media");
|
||||
}
|
||||
};
|
||||
|
||||
@ -660,8 +657,8 @@ static int cd_media_info(int fd) {
|
||||
|
||||
len = format[3];
|
||||
if (len & 7 || len < 16) {
|
||||
log_debug("invalid format capacities length");
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"invalid format capacities length");
|
||||
}
|
||||
|
||||
switch(format[8] & 3) {
|
||||
@ -680,8 +677,8 @@ static int cd_media_info(int fd) {
|
||||
|
||||
case 3:
|
||||
cd_media = 0; //return no media
|
||||
log_debug("format capacities returned no media");
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
|
||||
"format capacities returned no media");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -347,16 +347,18 @@ static int set_options(int argc, char **argv,
|
||||
else if (streq(optarg, "pre-spc3-83"))
|
||||
default_page_code = PAGE_83_PRE_SPC3;
|
||||
else {
|
||||
log_error("Unknown page code '%s'", optarg);
|
||||
return -1;
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Unknown page code '%s'",
|
||||
optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
sg_version = atoi(optarg);
|
||||
if (sg_version < 3 || sg_version > 4) {
|
||||
log_error("Unknown SG version '%s'", optarg);
|
||||
return -1;
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Unknown SG version '%s'",
|
||||
optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -169,8 +169,9 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
|
||||
*/
|
||||
|
||||
if (sb_len < 1) {
|
||||
log_debug("%s: sense buffer empty", dev_scsi->kernel);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: sense buffer empty",
|
||||
dev_scsi->kernel);
|
||||
}
|
||||
|
||||
sense_class = (sense_buffer[0] >> 4) & 0x07;
|
||||
@ -182,9 +183,10 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
|
||||
*/
|
||||
s = sense_buffer[7] + 8;
|
||||
if (sb_len < s) {
|
||||
log_debug("%s: sense buffer too small %d bytes, %d bytes too short",
|
||||
dev_scsi->kernel, sb_len, s - sb_len);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: sense buffer too small %d bytes, %d bytes too short",
|
||||
dev_scsi->kernel, sb_len,
|
||||
s - sb_len);
|
||||
}
|
||||
if (IN_SET(code, 0x0, 0x1)) {
|
||||
sense_key = sense_buffer[2] & 0xf;
|
||||
@ -192,9 +194,9 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
|
||||
/*
|
||||
* Possible?
|
||||
*/
|
||||
log_debug("%s: sense result too" " small %d bytes",
|
||||
dev_scsi->kernel, s);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: sense result too small %d bytes",
|
||||
dev_scsi->kernel, s);
|
||||
}
|
||||
asc = sense_buffer[12];
|
||||
ascq = sense_buffer[13];
|
||||
@ -203,17 +205,18 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
|
||||
asc = sense_buffer[2];
|
||||
ascq = sense_buffer[3];
|
||||
} else {
|
||||
log_debug("%s: invalid sense code 0x%x",
|
||||
dev_scsi->kernel, code);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: invalid sense code 0x%x",
|
||||
dev_scsi->kernel, code);
|
||||
}
|
||||
log_debug("%s: sense key 0x%x ASC 0x%x ASCQ 0x%x",
|
||||
dev_scsi->kernel, sense_key, asc, ascq);
|
||||
} else {
|
||||
if (sb_len < 4) {
|
||||
log_debug("%s: sense buffer too small %d bytes, %d bytes too short",
|
||||
dev_scsi->kernel, sb_len, 4 - sb_len);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: sense buffer too small %d bytes, %d bytes too short",
|
||||
dev_scsi->kernel, sb_len,
|
||||
4 - sb_len);
|
||||
}
|
||||
|
||||
if (sense_buffer[0] < 15)
|
||||
@ -235,8 +238,9 @@ static int scsi_dump(struct scsi_id_device *dev_scsi, struct sg_io_hdr *io) {
|
||||
/*
|
||||
* Impossible, should not be called.
|
||||
*/
|
||||
log_debug("%s: called with no error", __FUNCTION__);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: called with no error",
|
||||
__FUNCTION__);
|
||||
}
|
||||
|
||||
log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x",
|
||||
@ -253,8 +257,9 @@ static int scsi_dump_v4(struct scsi_id_device *dev_scsi, struct sg_io_v4 *io) {
|
||||
/*
|
||||
* Impossible, should not be called.
|
||||
*/
|
||||
log_debug("%s: called with no error", __FUNCTION__);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: called with no error",
|
||||
__FUNCTION__);
|
||||
}
|
||||
|
||||
log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x",
|
||||
@ -279,8 +284,8 @@ static int scsi_inquiry(struct scsi_id_device *dev_scsi, int fd,
|
||||
int retval;
|
||||
|
||||
if (buflen > SCSI_INQ_BUFF_LEN) {
|
||||
log_debug("buflen %d too long", buflen);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"buflen %d too long", buflen);
|
||||
}
|
||||
|
||||
resend:
|
||||
@ -412,9 +417,10 @@ static int prepend_vendor_model(struct scsi_id_device *dev_scsi, char *serial) {
|
||||
* above, ind will never be too large.
|
||||
*/
|
||||
if (ind != (VENDOR_LENGTH + MODEL_LENGTH)) {
|
||||
log_debug("%s: expected length %d, got length %d",
|
||||
dev_scsi->kernel, (VENDOR_LENGTH + MODEL_LENGTH), ind);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: expected length %d, got length %d",
|
||||
dev_scsi->kernel,
|
||||
(VENDOR_LENGTH + MODEL_LENGTH), ind);
|
||||
}
|
||||
return ind;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user