From: Roy Marples Date: Wed, 18 Nov 2015 11:59:11 +0000 (+0000) Subject: -U, --dumplease now works with standard input. X-Git-Tag: v6.9.4~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72d87266c3516d15b10a22e5e01baab3c8bf55af;p=thirdparty%2Fdhcpcd.git -U, --dumplease now works with standard input. It no longer works with a filename. --- diff --git a/dhcp.c b/dhcp.c index 92b39055..12aba118 100644 --- 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 d8d72ee5..f3fa9cdb 100644 --- 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; diff --git a/dhcpcd.8.in b/dhcpcd.8.in index 6927693d..9617130f 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -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 diff --git a/dhcpcd.c b/dhcpcd.c index 9b6da58d..d5d497a3 100644 --- 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;