Merge pull request #17130 from keszybz/static-analyzer-cleanups

Trivial cleanups based on static analysis
This commit is contained in:
Lennart Poettering 2020-09-23 13:23:56 +02:00 committed by GitHub
commit 6b6737119a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 62 deletions

View File

@ -122,7 +122,6 @@ static int open_sockets(int *epoll_fd, bool accept) {
}
static int exec_process(const char *name, char **argv, char **env, int start_fd, size_t n_fds) {
_cleanup_strv_free_ char **envp = NULL;
_cleanup_free_ char *joined = NULL;
size_t n_env = 0, length;
@ -200,7 +199,6 @@ static int exec_process(const char *name, char **argv, char **env, int start_fd,
return log_error_errno(errno, "Failed to dup connection: %m");
safe_close(start_fd);
start_fd = SD_LISTEN_FDS_START;
}
if (asprintf((char **) (envp + n_env++), "LISTEN_FDS=%zu", n_fds) < 0)
@ -215,15 +213,13 @@ static int exec_process(const char *name, char **argv, char **env, int start_fd,
char *e;
len = strv_length(arg_fdnames);
if (len == 1) {
size_t i;
for (i = 1; i < n_fds; i++) {
if (len == 1)
for (size_t i = 1; i < n_fds; i++) {
r = strv_extend(&arg_fdnames, arg_fdnames[0]);
if (r < 0)
return log_error_errno(r, "Failed to extend strv: %m");
return log_oom();
}
} else if (len != n_fds)
else if (len != n_fds)
log_warning("The number of fd names is different than number of fds: %zu vs %zu", len, n_fds);
names = strv_join(arg_fdnames, ":");

View File

@ -79,7 +79,7 @@ static int find_pci_or_platform_parent(sd_device *device, sd_device **ret) {
} else if (streq(subsystem, "pci") &&
sd_device_get_sysattr_value(parent, "class", &value) >= 0) {
unsigned long class = 0;
unsigned long class;
r = safe_atolu(value, &class);
if (r < 0)

View File

@ -64,15 +64,15 @@ typedef enum ProcSubset {
} ProcSubset;
struct NamespaceInfo {
bool ignore_protect_paths:1;
bool private_dev:1;
bool private_mounts:1;
bool protect_control_groups:1;
bool protect_kernel_tunables:1;
bool protect_kernel_modules:1;
bool protect_kernel_logs:1;
bool mount_apivfs:1;
bool protect_hostname:1;
bool ignore_protect_paths;
bool private_dev;
bool private_mounts;
bool protect_control_groups;
bool protect_kernel_tunables;
bool protect_kernel_modules;
bool protect_kernel_logs;
bool mount_apivfs;
bool protect_hostname;
ProtectHome protect_home;
ProtectSystem protect_system;
ProtectProc protect_proc;
@ -82,10 +82,10 @@ struct NamespaceInfo {
struct BindMount {
char *source;
char *destination;
bool read_only:1;
bool nosuid:1;
bool recursive:1;
bool ignore_enoent:1;
bool read_only;
bool nosuid;
bool recursive;
bool ignore_enoent;
};
struct TemporaryFileSystem {

View File

@ -689,7 +689,6 @@ _public_ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p, int
LIST_APPEND(prefix, ra->route_prefixes, p);
ra->n_route_prefixes++;
cur = p;
if (!dynamic) {
log_radv("Added prefix %s/%u", strempty(pretty), p->opt.prefixlen);
return 0;

View File

@ -70,7 +70,7 @@ static int server_init(sd_bus **_bus) {
goto fail;
}
r = sd_bus_get_description(bus, &desc);
assert_se(sd_bus_get_description(bus, &desc) >= 0);
assert_se(streq(desc, "my bus!"));
log_info("Peer ID is " SD_ID128_FORMAT_STR ".", SD_ID128_FORMAT_VAL(id));

View File

@ -997,20 +997,13 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
if (!good)
return -EINVAL;
*m = FD_TO_MONITOR(fd);
fd = -1;
*m = FD_TO_MONITOR(TAKE_FD(fd));
return 0;
}
_public_ sd_login_monitor* sd_login_monitor_unref(sd_login_monitor *m) {
int fd;
if (!m)
return NULL;
fd = MONITOR_TO_FD(m);
close_nointr(fd);
if (m)
close_nointr(MONITOR_TO_FD(m));
return NULL;
}

View File

@ -135,8 +135,7 @@ int netlink_open_family(sd_netlink **ret, int family) {
r = sd_netlink_open_fd(ret, fd);
if (r < 0)
return r;
fd = -1;
TAKE_FD(fd);
return 0;
}

View File

@ -373,19 +373,13 @@ _public_ int sd_network_monitor_new(sd_network_monitor **m, const char *category
if (!good)
return -EINVAL;
*m = FD_TO_MONITOR(fd);
fd = -1;
*m = FD_TO_MONITOR(TAKE_FD(fd));
return 0;
}
_public_ sd_network_monitor* sd_network_monitor_unref(sd_network_monitor *m) {
int fd;
if (m) {
fd = MONITOR_TO_FD(m);
close_nointr(fd);
}
if (m)
close_nointr(MONITOR_TO_FD(m));
return NULL;
}

View File

@ -3195,7 +3195,6 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
_cleanup_free_ char *id = NULL;
_cleanup_close_ int fifo_fd = -1;
Manager *m = userdata;
Inhibitor *i = NULL;
InhibitMode mm;
InhibitWhat w;
pid_t pid;
@ -3278,6 +3277,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
} while (hashmap_get(m->inhibitors, id));
_cleanup_(inhibitor_freep) Inhibitor *i = NULL;
r = manager_add_inhibitor(m, id, &i);
if (r < 0)
return r;
@ -3289,28 +3289,18 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
i->why = strdup(why);
i->who = strdup(who);
if (!i->why || !i->who) {
r = -ENOMEM;
goto fail;
}
if (!i->why || !i->who)
return -ENOMEM;
fifo_fd = inhibitor_create_fifo(i);
if (fifo_fd < 0) {
r = fifo_fd;
goto fail;
}
if (fifo_fd < 0)
return fifo_fd;
r = inhibitor_start(i);
if (r < 0)
goto fail;
return r;
return sd_bus_reply_method_return(message, "h", fifo_fd);
fail:
if (i)
inhibitor_free(i);
return r;
}
static const sd_bus_vtable manager_vtable[] = {

View File

@ -703,7 +703,7 @@ int config_parse_tristate(
return 0;
}
*t = !!k;
*t = k;
return 0;
}