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:
commit
84df74c6f0
@ -1062,13 +1062,11 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
|
||||
continue;
|
||||
|
||||
*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) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
continue;
|
||||
}
|
||||
|
@ -539,8 +539,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
||||
|
||||
assert(format);
|
||||
|
||||
for (e = format, i = 0; *e && i < n; e ++, i ++) {
|
||||
|
||||
for (e = format, i = 0; *e && i < n; e ++, i ++)
|
||||
switch (state) {
|
||||
|
||||
case WORD:
|
||||
@ -554,8 +553,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
||||
if (!k)
|
||||
return NULL;
|
||||
|
||||
free(r);
|
||||
r = k;
|
||||
free_and_replace(r, k);
|
||||
|
||||
word = e-1;
|
||||
state = VARIABLE;
|
||||
@ -565,8 +563,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
||||
if (!k)
|
||||
return NULL;
|
||||
|
||||
free(r);
|
||||
r = k;
|
||||
free_and_replace(r, k);
|
||||
|
||||
word = e+1;
|
||||
state = WORD;
|
||||
@ -576,8 +573,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
||||
if (!k)
|
||||
return NULL;
|
||||
|
||||
free(r);
|
||||
r = k;
|
||||
free_and_replace(r, k);
|
||||
|
||||
word = e-1;
|
||||
state = VARIABLE_RAW;
|
||||
@ -596,8 +592,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
||||
if (!k)
|
||||
return NULL;
|
||||
|
||||
free(r);
|
||||
r = k;
|
||||
free_and_replace(r, k);
|
||||
|
||||
word = e+1;
|
||||
state = WORD;
|
||||
@ -653,8 +648,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
||||
if (!k)
|
||||
return NULL;
|
||||
|
||||
free(r);
|
||||
r = k;
|
||||
free_and_replace(r, k);
|
||||
|
||||
word = e+1;
|
||||
state = WORD;
|
||||
@ -673,8 +667,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
||||
if (!k)
|
||||
return NULL;
|
||||
|
||||
free(r);
|
||||
r = k;
|
||||
free_and_replace(r, k);
|
||||
|
||||
word = e--;
|
||||
i--;
|
||||
@ -682,7 +675,6 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (state == VARIABLE_RAW) {
|
||||
const char *t;
|
||||
|
@ -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 (stdout_fd != STDOUT_FILENO &&
|
||||
dup2(stdout_fd, STDOUT_FILENO) < 0)
|
||||
return -errno;
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
(void) fd_cloexec(STDOUT_FILENO, false);
|
||||
}
|
||||
|
@ -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];
|
||||
_cleanup_close_ int fd = -1;
|
||||
ssize_t l;
|
||||
@ -134,7 +141,8 @@ ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute,
|
||||
if (l < 0)
|
||||
return -errno;
|
||||
|
||||
return l;
|
||||
*ret_size = l;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
usec_t a, b;
|
||||
le64_t le;
|
||||
ssize_t n;
|
||||
size_t n;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
@ -180,13 +188,13 @@ int fd_getcrtime_at(int dirfd, const char *name, usec_t *ret, int flags) {
|
||||
else
|
||||
a = USEC_INFINITY;
|
||||
|
||||
n = fgetxattrat_fake(dirfd, name, "user.crtime_usec", &le, sizeof(le), flags);
|
||||
if (n < 0)
|
||||
r = -errno;
|
||||
else if (n != sizeof(le))
|
||||
r = -EIO;
|
||||
else
|
||||
r = parse_crtime(le, &b);
|
||||
r = fgetxattrat_fake(dirfd, name, "user.crtime_usec", &le, sizeof(le), flags, &n);
|
||||
if (r >= 0) {
|
||||
if (n != sizeof(le))
|
||||
r = -EIO;
|
||||
else
|
||||
r = parse_crtime(le, &b);
|
||||
}
|
||||
if (r < 0) {
|
||||
if (a != USEC_INFINITY) {
|
||||
*ret = a;
|
||||
|
@ -29,7 +29,13 @@
|
||||
int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink);
|
||||
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);
|
||||
|
||||
|
@ -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");
|
||||
|
||||
/* 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, '/')) {
|
||||
char *cut = NULL;
|
||||
|
@ -1699,7 +1699,7 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
|
||||
format = unit_get_status_message_format(u, t);
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
snprintf(buf, sizeof buf, format, unit_description(u));
|
||||
(void) snprintf(buf, sizeof buf, format, unit_description(u));
|
||||
REENABLE_WARNING;
|
||||
|
||||
mid = t == JOB_START ? "MESSAGE_ID=" SD_MESSAGE_UNIT_STARTING_STR :
|
||||
|
@ -36,8 +36,9 @@ static void test_fgetxattrat_fake(void) {
|
||||
char t[] = "/var/tmp/xattrtestXXXXXX";
|
||||
_cleanup_close_ int fd = -1;
|
||||
const char *x;
|
||||
char v[3] = {};
|
||||
char v[3];
|
||||
int r;
|
||||
size_t size;
|
||||
|
||||
assert_se(mkdtemp(t));
|
||||
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);
|
||||
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);
|
||||
|
||||
safe_close(fd);
|
||||
fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
|
||||
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:
|
||||
assert_se(unlink(x) >= 0);
|
||||
|
Loading…
Reference in New Issue
Block a user