1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 09:56:51 +03:00

Merge pull request #8284 from keszybz/gcc-warning-fixes

Gcc warning fixes
This commit is contained in:
Lennart Poettering 2018-02-26 21:20:13 +01:00 committed by GitHub
commit 84df74c6f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 35 deletions

View File

@ -1062,13 +1062,11 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
continue; continue;
*e = 0; *e = 0;
FOREACH_WORD_SEPARATOR(word, k, l, ",", state) { FOREACH_WORD_SEPARATOR(word, k, l, ",", state)
if (k == cs && memcmp(word, controller_str, cs) == 0) { if (k == cs && memcmp(word, controller_str, cs) == 0) {
found = true; found = true;
break; break;
} }
}
if (!found) if (!found)
continue; continue;
} }

View File

@ -539,8 +539,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
assert(format); assert(format);
for (e = format, i = 0; *e && i < n; e ++, i ++) { for (e = format, i = 0; *e && i < n; e ++, i ++)
switch (state) { switch (state) {
case WORD: case WORD:
@ -554,8 +553,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
if (!k) if (!k)
return NULL; return NULL;
free(r); free_and_replace(r, k);
r = k;
word = e-1; word = e-1;
state = VARIABLE; state = VARIABLE;
@ -565,8 +563,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
if (!k) if (!k)
return NULL; return NULL;
free(r); free_and_replace(r, k);
r = k;
word = e+1; word = e+1;
state = WORD; state = WORD;
@ -576,8 +573,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
if (!k) if (!k)
return NULL; return NULL;
free(r); free_and_replace(r, k);
r = k;
word = e-1; word = e-1;
state = VARIABLE_RAW; state = VARIABLE_RAW;
@ -596,8 +592,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
if (!k) if (!k)
return NULL; return NULL;
free(r); free_and_replace(r, k);
r = k;
word = e+1; word = e+1;
state = WORD; state = WORD;
@ -653,8 +648,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
if (!k) if (!k)
return NULL; return NULL;
free(r); free_and_replace(r, k);
r = k;
word = e+1; word = e+1;
state = WORD; state = WORD;
@ -673,8 +667,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
if (!k) if (!k)
return NULL; return NULL;
free(r); free_and_replace(r, k);
r = k;
word = e--; word = e--;
i--; i--;
@ -682,7 +675,6 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
} }
break; break;
} }
}
if (state == VARIABLE_RAW) { if (state == VARIABLE_RAW) {
const char *t; const char *t;

View File

@ -65,7 +65,7 @@ static int do_spawn(const char *path, char *argv[], int stdout_fd, pid_t *pid) {
/* If the fd happens to be in the right place, go along with that */ /* If the fd happens to be in the right place, go along with that */
if (stdout_fd != STDOUT_FILENO && if (stdout_fd != STDOUT_FILENO &&
dup2(stdout_fd, STDOUT_FILENO) < 0) dup2(stdout_fd, STDOUT_FILENO) < 0)
return -errno; _exit(EXIT_FAILURE);
(void) fd_cloexec(STDOUT_FILENO, false); (void) fd_cloexec(STDOUT_FILENO, false);
} }

View File

@ -107,7 +107,14 @@ int fgetxattr_malloc(int fd, const char *name, char **value) {
} }
} }
ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags) { int fgetxattrat_fake(
int dirfd,
const char *filename,
const char *attribute,
void *value, size_t size,
int flags,
size_t *ret_size) {
char fn[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; char fn[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];
_cleanup_close_ int fd = -1; _cleanup_close_ int fd = -1;
ssize_t l; ssize_t l;
@ -134,7 +141,8 @@ ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute,
if (l < 0) if (l < 0)
return -errno; return -errno;
return l; *ret_size = l;
return 0;
} }
static int parse_crtime(le64_t le, usec_t *usec) { static int parse_crtime(le64_t le, usec_t *usec) {
@ -154,7 +162,7 @@ int fd_getcrtime_at(int dirfd, const char *name, usec_t *ret, int flags) {
struct_statx sx; struct_statx sx;
usec_t a, b; usec_t a, b;
le64_t le; le64_t le;
ssize_t n; size_t n;
int r; int r;
assert(ret); assert(ret);
@ -180,13 +188,13 @@ int fd_getcrtime_at(int dirfd, const char *name, usec_t *ret, int flags) {
else else
a = USEC_INFINITY; a = USEC_INFINITY;
n = fgetxattrat_fake(dirfd, name, "user.crtime_usec", &le, sizeof(le), flags); r = fgetxattrat_fake(dirfd, name, "user.crtime_usec", &le, sizeof(le), flags, &n);
if (n < 0) if (r >= 0) {
r = -errno; if (n != sizeof(le))
else if (n != sizeof(le)) r = -EIO;
r = -EIO; else
else r = parse_crtime(le, &b);
r = parse_crtime(le, &b); }
if (r < 0) { if (r < 0) {
if (a != USEC_INFINITY) { if (a != USEC_INFINITY) {
*ret = a; *ret = a;

View File

@ -29,7 +29,13 @@
int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink); int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink);
int fgetxattr_malloc(int fd, const char *name, char **value); int fgetxattr_malloc(int fd, const char *name, char **value);
ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags); int fgetxattrat_fake(
int dirfd,
const char *filename,
const char *attribute,
void *value, size_t size,
int flags,
size_t *ret_size);
int fd_setcrtime(int fd, usec_t usec); int fd_setcrtime(int fd, usec_t usec);

View File

@ -80,7 +80,8 @@ int path_spec_watch(PathSpec *s, sd_event_io_handler_t handler) {
(void) sd_event_source_set_description(s->event_source, "path"); (void) sd_event_source_set_description(s->event_source, "path");
/* This assumes the path was passed through path_kill_slashes()! */ /* This function assumes the path was passed through path_kill_slashes()! */
assert(!strstr(s->path, "//"));
for (slash = strchr(s->path, '/'); ; slash = strchr(slash+1, '/')) { for (slash = strchr(s->path, '/'); ; slash = strchr(slash+1, '/')) {
char *cut = NULL; char *cut = NULL;

View File

@ -1699,7 +1699,7 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
format = unit_get_status_message_format(u, t); format = unit_get_status_message_format(u, t);
DISABLE_WARNING_FORMAT_NONLITERAL; DISABLE_WARNING_FORMAT_NONLITERAL;
snprintf(buf, sizeof buf, format, unit_description(u)); (void) snprintf(buf, sizeof buf, format, unit_description(u));
REENABLE_WARNING; REENABLE_WARNING;
mid = t == JOB_START ? "MESSAGE_ID=" SD_MESSAGE_UNIT_STARTING_STR : mid = t == JOB_START ? "MESSAGE_ID=" SD_MESSAGE_UNIT_STARTING_STR :

View File

@ -36,8 +36,9 @@ static void test_fgetxattrat_fake(void) {
char t[] = "/var/tmp/xattrtestXXXXXX"; char t[] = "/var/tmp/xattrtestXXXXXX";
_cleanup_close_ int fd = -1; _cleanup_close_ int fd = -1;
const char *x; const char *x;
char v[3] = {}; char v[3];
int r; int r;
size_t size;
assert_se(mkdtemp(t)); assert_se(mkdtemp(t));
x = strjoina(t, "/test"); x = strjoina(t, "/test");
@ -51,13 +52,14 @@ static void test_fgetxattrat_fake(void) {
fd = open(t, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY); fd = open(t, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
assert_se(fd >= 0); assert_se(fd >= 0);
assert_se(fgetxattrat_fake(fd, "test", "user.foo", v, 3, 0) >= 0); assert_se(fgetxattrat_fake(fd, "test", "user.foo", v, 3, 0, &size) >= 0);
assert_se(size == 3);
assert_se(memcmp(v, "bar", 3) == 0); assert_se(memcmp(v, "bar", 3) == 0);
safe_close(fd); safe_close(fd);
fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY); fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
assert_se(fd >= 0); assert_se(fd >= 0);
assert_se(fgetxattrat_fake(fd, "usr", "user.idontexist", v, 3, 0) == -ENODATA); assert_se(fgetxattrat_fake(fd, "usr", "user.idontexist", v, 3, 0, &size) == -ENODATA);
cleanup: cleanup:
assert_se(unlink(x) >= 0); assert_se(unlink(x) >= 0);