summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2012-01-29 17:28:05 +0000
committerRoy Marples <roy@marples.name>2012-01-29 17:28:05 +0000
commite0c4d1587d18660ab5b1bc8b0c8b18f54973589b (patch)
treee87396449ed54c03f749391374d6daf2ad51907b
parent70b967d7d79d93d4a347b9437dbb1bccb4663f95 (diff)
downloaddhcpcd-e0c4d1587d18660ab5b1bc8b0c8b18f54973589b.tar.xz
Allow dhcpcd to run on a read-only filesystem.
You'll get a lot of errors, but you will get a working address and routing.
-rw-r--r--dhcp.c4
-rw-r--r--dhcpcd.c36
2 files changed, 16 insertions, 24 deletions
diff --git a/dhcp.c b/dhcp.c
index a88cb20c..28bf4383 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -1125,10 +1125,8 @@ write_lease(const struct interface *iface, const struct dhcp_message *dhcp)
iface->name, iface->leasefile);
fd = open(iface->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0444);
- if (fd == -1) {
- syslog(LOG_ERR, "%s: open: %m", iface->name);
+ if (fd == -1)
return -1;
- }
/* Only write as much as we need */
while (p < e) {
diff --git a/dhcpcd.c b/dhcpcd.c
index 819953b5..6a155f6f 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1934,29 +1934,25 @@ main(int argc, char **argv)
}
/* Ensure we have the needed directories */
- if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST) {
+ if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST)
syslog(LOG_ERR, "mkdir `%s': %m", RUNDIR);
- exit(EXIT_FAILURE);
- }
- if (mkdir(DBDIR, 0755) == -1 && errno != EEXIST) {
+ if (mkdir(DBDIR, 0755) == -1 && errno != EEXIST)
syslog(LOG_ERR, "mkdir `%s': %m", DBDIR);
- exit(EXIT_FAILURE);
- }
pidfd = open(pidfile, O_WRONLY | O_CREAT | O_NONBLOCK, 0664);
- if (pidfd == -1) {
+ if (pidfd == -1)
syslog(LOG_ERR, "open `%s': %m", pidfile);
- exit(EXIT_FAILURE);
- }
- /* Lock the file so that only one instance of dhcpcd runs
- * on an interface */
- if (flock(pidfd, LOCK_EX | LOCK_NB) == -1) {
- syslog(LOG_ERR, "flock `%s': %m", pidfile);
- exit(EXIT_FAILURE);
+ else {
+ /* Lock the file so that only one instance of dhcpcd
+ * runs on an interface */
+ if (flock(pidfd, LOCK_EX | LOCK_NB) == -1) {
+ syslog(LOG_ERR, "flock `%s': %m", pidfile);
+ exit(EXIT_FAILURE);
+ }
+ if (set_cloexec(pidfd) == -1)
+ exit(EXIT_FAILURE);
+ writepid(pidfd, getpid());
}
- if (set_cloexec(pidfd) == -1)
- exit(EXIT_FAILURE);
- writepid(pidfd, getpid());
}
syslog(LOG_INFO, "version " VERSION " starting");
@@ -1968,10 +1964,8 @@ main(int argc, char **argv)
add_event(signal_fd, handle_signal, NULL);
if (options & DHCPCD_MASTER) {
- if (start_control() == -1) {
+ if (start_control() == -1)
syslog(LOG_ERR, "start_control: %m");
- exit(EXIT_FAILURE);
- }
}
if (init_sockets() == -1) {
@@ -2045,7 +2039,7 @@ main(int argc, char **argv)
if (!(options & DHCPCD_BACKGROUND)) {
/* If we don't have a carrier, we may have to wait for a second
- * before one becomes available if we brought an interface up. */
+ * before one becomes available if we brought an interface up */
if (opt == 0 &&
options & DHCPCD_LINK &&
options & DHCPCD_WAITUP &&