Fix various problems with unchecked return values from syscalls.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2014-11-27 00:12:07 +01:00
1 parent def759fe41
commit 02a97e8d7d
10 files changed
+25 -16

No files matched your search

+5 -1
View File
@@ -733,7 +733,11 @@ void set_hostname(char **hostname)
if (fp) { if (fp) {
struct stat st; struct stat st;
fstat(fileno(fp), &st); if (fstat(fileno(fp), &st)) {
fclose(fp);
return;
}
*hostname = realloc(*hostname, st.st_size); *hostname = realloc(*hostname, st.st_size);
if (!*hostname) { if (!*hostname) {
fclose(fp); fclose(fp);
+6
View File
@@ -47,6 +47,12 @@
#ifndef makedir #ifndef makedir
# define makedir(x, p) do { if (mkdir(x, p) && errno != EEXIST) _pe("Failed creating directory %s", x); } while (0) # define makedir(x, p) do { if (mkdir(x, p) && errno != EEXIST) _pe("Failed creating directory %s", x); } while (0)
#endif #endif
#ifndef makefifo
# define makefifo(x, p) do { if (mkfifo(x, p) && errno != EEXIST) _pe("Failed creating FIFO %s", x); } while (0)
#endif
#ifndef erase
# define erase(x) do { if (remove(x) && errno != ENOENT) _pe("Failed removing %s", x); } while (0)
#endif
#ifndef chardev #ifndef chardev
# define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min))) # define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
#endif #endif
+2 -2
View File
@@ -344,7 +344,7 @@ int main(void)
if (fexist(files[i + 2])) if (fexist(files[i + 2]))
fprintf(stderr, "OK => %s\n", files[i + 2]); fprintf(stderr, "OK => %s\n", files[i + 2]);
remove(files[i + 2]); erase(files[i + 2]);
i += 3; i += 3;
} }
@@ -358,7 +358,7 @@ int main(void)
if (fexist(files[i + 2])) if (fexist(files[i + 2]))
fprintf(stderr, "OK => %s\n", files[i + 2]); fprintf(stderr, "OK => %s\n", files[i + 2]);
remove(files[i + 2]); erase(files[i + 2]);
i += 3; i += 3;
} }
+2 -2
View File
@@ -142,13 +142,13 @@ int simulate_files(int creat)
if (creat) if (creat)
touch(files[i]); touch(files[i]);
else else
remove(files[i]); erase(files[i]);
} }
if (creat) if (creat)
symlink("config2.cfg", STARTUP_CONFIG); symlink("config2.cfg", STARTUP_CONFIG);
else else
remove(STARTUP_CONFIG); erase(STARTUP_CONFIG);
return 0; return 0;
} }
+3 -4
View File
@@ -57,7 +57,6 @@ static void setup(void *UNUSED(arg))
_d("Setting up necessary UTMP files ..."); _d("Setting up necessary UTMP files ...");
touch("/var/run/utmp"); touch("/var/run/utmp");
chown("/var/run/utmp", 0, getgroup("utmp")); chown("/var/run/utmp", 0, getgroup("utmp"));
chmod("/var/run/utmp", 0664);
#ifdef RUNLEVEL #ifdef RUNLEVEL
memset(&entry, 0, sizeof(struct utmp)); memset(&entry, 0, sizeof(struct utmp));
@@ -71,7 +70,7 @@ static void setup(void *UNUSED(arg))
#ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE #ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE
touch("/etc/network/run/ifstate"); touch("/etc/network/run/ifstate");
#else #else
remove("/etc/network/run/ifstate"); erase("/etc/network/run/ifstate");
#endif #endif
_d("Setting up misc files ..."); _d("Setting up misc files ...");
@@ -79,8 +78,8 @@ static void setup(void *UNUSED(arg))
makedir("/var/run/pluto", 0755); /* Needed by Openswan */ makedir("/var/run/pluto", 0755); /* Needed by Openswan */
makedir("/var/run/quagga", 0755); /* Needed by Quagga */ makedir("/var/run/quagga", 0755); /* Needed by Quagga */
makedir("/var/log/quagga", 0755); /* Needed by Quagga */ makedir("/var/log/quagga", 0755); /* Needed by Quagga */
makedir("/var/run/sshd", 01755); /* OpenSSH */ makedir("/var/run/sshd", 01755); /* OpenSSH */
mkfifo("/dev/xconsole", 0640); /* sysklogd */ makefifo("/dev/xconsole", 0640); /* sysklogd */
chown("/dev/xconsole", 0, getgroup("tty")); chown("/dev/xconsole", 0, getgroup("tty"));
} }
+1 -1
View File
@@ -32,7 +32,7 @@ static void setup(void *UNUSED(arg))
makedir("/var/run/dbus", 0755); makedir("/var/run/dbus", 0755);
makedir("/var/lock/subsys/messagebus", 0755); makedir("/var/lock/subsys/messagebus", 0755);
run("dbus-uuidgen --ensure"); run("dbus-uuidgen --ensure");
remove("/var/run/dbus/pid"); erase("/var/run/dbus/pid");
run_interactive("dbus-daemon --system", "Starting D-Bus"); run_interactive("dbus-daemon --system", "Starting D-Bus");
#endif #endif
} }
+1 -1
View File
@@ -124,7 +124,7 @@ static void parse(void *UNUSED(arg), int fd, int UNUSED(events))
PLUGIN_INIT(plugin_init) PLUGIN_INIT(plugin_init)
{ {
_d("Setting up %s", FINIT_FIFO); _d("Setting up %s", FINIT_FIFO);
mkfifo(FINIT_FIFO, 0600); makefifo(FINIT_FIFO, 0600);
fifo_open(); fifo_open();
plugin_register(&plugin); plugin_register(&plugin);
+1 -1
View File
@@ -36,7 +36,7 @@ static void setup(void *UNUSED(arg))
#endif #endif
char line[LINE_SIZE]; char line[LINE_SIZE];
makepath("/var/run/console"); makedir("/var/run/console", 01777);
snprintf(line, sizeof(line), "/var/run/console/%s", username); snprintf(line, sizeof(line), "/var/run/console/%s", username);
touch(line); touch(line);
+3 -3
View File
@@ -117,7 +117,7 @@ static void sigcont_handler(int sig, siginfo_t *info, void *UNUSED(ctx))
_d("Received SIGCONT(%d) from %s (PID %d)", _d("Received SIGCONT(%d) from %s (PID %d)",
sig, pid_get_name(info->si_pid, NULL, 0), info->si_pid); sig, pid_get_name(info->si_pid, NULL, 0), info->si_pid);
stopped = 0; stopped = 0;
remove(SYNC_STOPPED); erase(SYNC_STOPPED);
} }
/* /*
@@ -152,8 +152,8 @@ void sig_setup(void)
_d("Setup signals"); _d("Setup signals");
/* Cleanup any stale finit control files */ /* Cleanup any stale finit control files */
remove(SYNC_SHUTDOWN); erase(SYNC_SHUTDOWN);
remove(SYNC_STOPPED); erase(SYNC_STOPPED);
/* Standard SysV init calls ctrl-alt-delete handler */ /* Standard SysV init calls ctrl-alt-delete handler */
SETSIG(sa, SIGINT, shutdown_handler, 0); SETSIG(sa, SIGINT, shutdown_handler, 0);
+1 -1
View File
@@ -211,7 +211,7 @@ void svc_runlevel(int newlevel)
if (runlevel == 1) if (runlevel == 1)
touch("/etc/nologin"); /* Disable login in single-user mode */ touch("/etc/nologin"); /* Disable login in single-user mode */
else else
remove("/etc/nologin"); erase("/etc/nologin");
if (0 != prevlevel) if (0 != prevlevel)
tty_runlevel(runlevel); tty_runlevel(runlevel);