]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
-U, --dumplease now works with standard input.
authorRoy Marples <roy@marples.name>
Wed, 18 Nov 2015 11:59:11 +0000 (11:59 +0000)
committerRoy Marples <roy@marples.name>
Wed, 18 Nov 2015 11:59:11 +0000 (11:59 +0000)
It no longer works with a filename.

dhcp.c
dhcp6.c
dhcpcd.8.in
dhcpcd.c

diff --git a/dhcp.c b/dhcp.c
index 92b390553634fd7daed1421186a5ed3ca27830d7..12aba1183ce159dbcb69ab413b81affd3d994041 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -1126,15 +1126,21 @@ read_lease(struct interface *ifp)
        uint8_t type;
        size_t auth_len;
 
-       fd = open(state->leasefile, O_RDONLY);
+       if (state->leasefile[0] == '\0')
+               fd = fileno(stdin);
+       else
+               fd = open(state->leasefile, O_RDONLY);
        if (fd == -1) {
                if (errno != ENOENT)
                        logger(ifp->ctx, LOG_ERR, "%s: open `%s': %m",
                            ifp->name, state->leasefile);
                return NULL;
        }
-       logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
-           ifp->name, state->leasefile);
+       if (state->leasefile[0] == '\0')
+               logger(ifp->ctx, LOG_DEBUG, "reading standard input");
+       else
+               logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
+                   ifp->name, state->leasefile);
        dhcp = calloc(1, sizeof(*dhcp));
        if (dhcp == NULL) {
                close(fd);
diff --git a/dhcp6.c b/dhcp6.c
index d8d72ee554bda313a25e8dfbcc9a8c74323f5f7a..f3fa9cdb36cfc37205d6560b0a1cafdfc77be16b 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -2187,15 +2187,23 @@ dhcp6_readlease(struct interface *ifp, int validate)
        int retval;
 
        state = D6_STATE(ifp);
-       if (stat(state->leasefile, &st) == -1)
-               return -1;
-       logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
-           ifp->name, state->leasefile);
+       if (state->leasefile[0] == '\0')
+               logger(ifp->ctx, LOG_DEBUG, "reading standard input");
+       else {
+               if (stat(state->leasefile, &st) == -1)
+                       return -1;
+               logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
+                   ifp->name, state->leasefile);
+       }
        if (st.st_size > UINT32_MAX) {
                errno = E2BIG;
                return -1;
        }
-       if ((fd = open(state->leasefile, O_RDONLY)) == -1)
+       if (state->leasefile[0] == '\0')
+               fd = fileno(stdin);
+       else
+               fd = open(state->leasefile, O_RDONLY);
+       if (fd == -1)
                return -1;
        if ((state->new = malloc((size_t)st.st_size)) == NULL)
                return -1;
index 6927693dd5f6ce8355ae894b03c73bbdabb58ffa..9617130ff11419a3ee5bd3ad87b21c153c2c1cba 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd November 13, 2015
+.Dd November 18, 2015
 .Dt DHCPCD 8
 .Os
 .Sh NAME
@@ -633,8 +633,7 @@ before starting
 Dumps the last lease for the
 .Ar interface
 to stdout.
-.Ar interface
-could also be a path to a DHCP wire formatted file.
+If omitted, standard input is used to read a DHCP wire formatted message.
 Use the
 .Fl 4
 or
index 9b6da58dc35122b0610504826a5bb1ddeff09b1d..d5d497a35b580dbce3d05905f9986336d6f393f0 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1628,15 +1628,15 @@ main(int argc, char **argv)
        }
 
        if (ctx.options & DHCPCD_DUMPLEASE) {
-               if (optind != argc - 1) {
-                       logger(&ctx, LOG_ERR,
-                           "dumplease requires an interface");
-                       goto exit_failure;
+               if (optind != argc) {
+                       /* We need to try and find the interface so we can load
+                        * the hardware address to compare automated IAID */
+                       ctx.ifaces = if_discover(&ctx,
+                           argc - optind, argv + optind);
+               } else {
+                       if ((ctx.ifaces = malloc(sizeof(ctx.ifaces))) != NULL)
+                               TAILQ_INIT(ctx.ifaces);
                }
-               i = 0;
-               /* We need to try and find the interface so we can
-                * load the hardware address to compare automated IAID */
-               ctx.ifaces = if_discover(&ctx, 1, argv + optind);
                if (ctx.ifaces == NULL) {
                        logger(&ctx, LOG_ERR, "if_discover: %m");
                        goto exit_failure;
@@ -1648,7 +1648,9 @@ main(int argc, char **argv)
                                logger(&ctx, LOG_ERR, "%s: %m", __func__);
                                goto exit_failure;
                        }
-                       strlcpy(ctx.pidfile, argv[optind], sizeof(ctx.pidfile));
+                       if (optind != argc)
+                               strlcpy(ctx.pidfile, argv[optind],
+                                   sizeof(ctx.pidfile));
                        ifp->ctx = &ctx;
                        TAILQ_INSERT_HEAD(ctx.ifaces, ifp, next);
                        if (family == 0) {
@@ -1659,6 +1661,7 @@ main(int argc, char **argv)
                        }
                }
                configure_interface(ifp, ctx.argc, ctx.argv, 0);
+               i = 0;
                if (family == 0 || family == AF_INET) {
                        if (dhcp_dump(ifp) == -1)
                                i = 1;