]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Allow dhcpcd to run on a read-only filesystem.
authorRoy Marples <roy@marples.name>
Sun, 29 Jan 2012 17:28:05 +0000 (17:28 +0000)
committerRoy Marples <roy@marples.name>
Sun, 29 Jan 2012 17:28:05 +0000 (17:28 +0000)
You'll get a lot of errors, but you will get a working address and routing.

dhcp.c
dhcpcd.c

diff --git a/dhcp.c b/dhcp.c
index a88cb20cd6265c07d828bcc9d7e69fbf5c824124..28bf4383d8bd43ee880c34eece0e220ba0a7ed02 100644 (file)
--- 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) {
index 819953b5b37216f109c3726cf71220a22b79c60e..6a155f6f4eda1af06136c7282b1bdfd443775cb8 100644 (file)
--- 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 &&