diff --git a/helpers.c b/helpers.c index 9c8e8210..0bc25eab 100644 --- a/helpers.c +++ b/helpers.c @@ -733,7 +733,11 @@ void set_hostname(char **hostname) if (fp) { struct stat st; - fstat(fileno(fp), &st); + if (fstat(fileno(fp), &st)) { + fclose(fp); + return; + } + *hostname = realloc(*hostname, st.st_size); if (!*hostname) { fclose(fp); diff --git a/helpers.h b/helpers.h index 47c943bc..3d1f639b 100644 --- a/helpers.h +++ b/helpers.h @@ -47,6 +47,12 @@ #ifndef makedir # define makedir(x, p) do { if (mkdir(x, p) && errno != EEXIST) _pe("Failed creating directory %s", x); } while (0) #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 # define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min))) #endif diff --git a/libite/copyfile.c b/libite/copyfile.c index 0a8a9d51..a7e5170d 100644 --- a/libite/copyfile.c +++ b/libite/copyfile.c @@ -344,7 +344,7 @@ int main(void) if (fexist(files[i + 2])) fprintf(stderr, "OK => %s\n", files[i + 2]); - remove(files[i + 2]); + erase(files[i + 2]); i += 3; } @@ -358,7 +358,7 @@ int main(void) if (fexist(files[i + 2])) fprintf(stderr, "OK => %s\n", files[i + 2]); - remove(files[i + 2]); + erase(files[i + 2]); i += 3; } diff --git a/libite/dir.c b/libite/dir.c index 631ffb99..fbb57b76 100644 --- a/libite/dir.c +++ b/libite/dir.c @@ -142,13 +142,13 @@ int simulate_files(int creat) if (creat) touch(files[i]); else - remove(files[i]); + erase(files[i]); } if (creat) symlink("config2.cfg", STARTUP_CONFIG); else - remove(STARTUP_CONFIG); + erase(STARTUP_CONFIG); return 0; } diff --git a/plugins/bootmisc.c b/plugins/bootmisc.c index f006cf7f..4a5d0f56 100644 --- a/plugins/bootmisc.c +++ b/plugins/bootmisc.c @@ -57,7 +57,6 @@ static void setup(void *UNUSED(arg)) _d("Setting up necessary UTMP files ..."); touch("/var/run/utmp"); chown("/var/run/utmp", 0, getgroup("utmp")); - chmod("/var/run/utmp", 0664); #ifdef RUNLEVEL memset(&entry, 0, sizeof(struct utmp)); @@ -71,7 +70,7 @@ static void setup(void *UNUSED(arg)) #ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE touch("/etc/network/run/ifstate"); #else - remove("/etc/network/run/ifstate"); + erase("/etc/network/run/ifstate"); #endif _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/quagga", 0755); /* Needed by Quagga */ makedir("/var/log/quagga", 0755); /* Needed by Quagga */ - makedir("/var/run/sshd", 01755); /* OpenSSH */ - mkfifo("/dev/xconsole", 0640); /* sysklogd */ + makedir("/var/run/sshd", 01755); /* OpenSSH */ + makefifo("/dev/xconsole", 0640); /* sysklogd */ chown("/dev/xconsole", 0, getgroup("tty")); } diff --git a/plugins/dbus.c b/plugins/dbus.c index 5351b1a8..0c3290fb 100644 --- a/plugins/dbus.c +++ b/plugins/dbus.c @@ -32,7 +32,7 @@ static void setup(void *UNUSED(arg)) makedir("/var/run/dbus", 0755); makedir("/var/lock/subsys/messagebus", 0755); run("dbus-uuidgen --ensure"); - remove("/var/run/dbus/pid"); + erase("/var/run/dbus/pid"); run_interactive("dbus-daemon --system", "Starting D-Bus"); #endif } diff --git a/plugins/initctl.c b/plugins/initctl.c index f27846c5..85a26380 100644 --- a/plugins/initctl.c +++ b/plugins/initctl.c @@ -124,7 +124,7 @@ static void parse(void *UNUSED(arg), int fd, int UNUSED(events)) PLUGIN_INIT(plugin_init) { _d("Setting up %s", FINIT_FIFO); - mkfifo(FINIT_FIFO, 0600); + makefifo(FINIT_FIFO, 0600); fifo_open(); plugin_register(&plugin); diff --git a/plugins/x11-common.c b/plugins/x11-common.c index a0277cf1..17a45044 100644 --- a/plugins/x11-common.c +++ b/plugins/x11-common.c @@ -36,7 +36,7 @@ static void setup(void *UNUSED(arg)) #endif char line[LINE_SIZE]; - makepath("/var/run/console"); + makedir("/var/run/console", 01777); snprintf(line, sizeof(line), "/var/run/console/%s", username); touch(line); diff --git a/sig.c b/sig.c index b81f0d92..930e4ea5 100644 --- a/sig.c +++ b/sig.c @@ -117,7 +117,7 @@ static void sigcont_handler(int sig, siginfo_t *info, void *UNUSED(ctx)) _d("Received SIGCONT(%d) from %s (PID %d)", sig, pid_get_name(info->si_pid, NULL, 0), info->si_pid); stopped = 0; - remove(SYNC_STOPPED); + erase(SYNC_STOPPED); } /* @@ -152,8 +152,8 @@ void sig_setup(void) _d("Setup signals"); /* Cleanup any stale finit control files */ - remove(SYNC_SHUTDOWN); - remove(SYNC_STOPPED); + erase(SYNC_SHUTDOWN); + erase(SYNC_STOPPED); /* Standard SysV init calls ctrl-alt-delete handler */ SETSIG(sa, SIGINT, shutdown_handler, 0); diff --git a/svc.c b/svc.c index 50f5530a..23b1ad1c 100644 --- a/svc.c +++ b/svc.c @@ -211,7 +211,7 @@ void svc_runlevel(int newlevel) if (runlevel == 1) touch("/etc/nologin"); /* Disable login in single-user mode */ else - remove("/etc/nologin"); + erase("/etc/nologin"); if (0 != prevlevel) tty_runlevel(runlevel);