Fix GCC warnings with _FORTIFY_SOURCE=2

- Decleare some return values with (void)fn(), for cases where
  we don't care (dropping table headers), or best effor
- Check return value from fgets() and chdir() in some cases that
  are valid, i.e., continuing execution is pointless

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-03-05 12:36:48 +01:00
parent 774a24cdd8
commit 3ed291789c
5 changed files with 13 additions and 10 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ void cgroup_init(void)
}
/* Skip first line, header */
fgets(buf, sizeof(buf), fp);
(void)fgets(buf, sizeof(buf), fp);
while (fgets(buf, sizeof(buf), fp)) {
char *cgroup;
char rc[80];
+3 -3
View File
@@ -432,14 +432,14 @@ void set_hostname(char **hostname)
return;
}
fgets(*hostname, st.st_size, fp);
chomp(*hostname);
if (fgets(*hostname, st.st_size, fp))
chomp(*hostname);
fclose(fp);
}
done:
if (*hostname)
sethostname(*hostname, strlen(*hostname));
(void)sethostname(*hostname, strlen(*hostname));
}
/*
+4 -2
View File
@@ -58,7 +58,9 @@ static void do_list(const char *path)
glob_t gl;
size_t i;
chdir(path);
if (chdir(path))
return;
if (glob("*.conf", 0, NULL, &gl))
return;
@@ -213,7 +215,7 @@ int do_disable(char *arg, int check)
if (chdir(FINIT_RCSD))
err(1, "failed cd %s", FINIT_RCSD);
chdir("enabled"); /* System *may* have enabled/ dir. */
(void)chdir("enabled"); /* System *may* have enabled/ dir. */
if (check && stat(arg, &st))
errx(1, "%s not (an) enabled (service).", arg);
+4 -3
View File
@@ -464,17 +464,18 @@ static int service_start(svc_t *svc)
/* Set desired user+group */
if (gid >= 0)
setgid(gid);
(void)setgid(gid);
if (uid >= 0) {
setuid(uid);
(void)setuid(uid);
/* Set default path for regular users */
if (uid > 0)
setenv("PATH", _PATH_DEFPATH, 1);
if (home) {
setenv("HOME", home, 1);
chdir(home);
if (chdir(home))
(void)chdir("/");
}
}
+1 -1
View File
@@ -97,7 +97,7 @@ static int logrotate(char *file, int num, off_t sz)
(void)rename(file, nfile);
create(file, st.st_mode, st.st_uid, st.st_gid);
} else {
truncate(file, 0);
(void)truncate(file, 0);
}
}