syslog(LOG_DEBUG, "%s: writing lease `%s'",
iface->name, iface->leasefile);
- fd = open(iface->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0400);
+ fd = open(iface->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0444);
if (fd == -1) {
syslog(LOG_ERR, "%s: open: %m", iface->name);
return -1;
if [ "$reason" = "TEST" ]; then
set | grep "^\(interface\|metric\|pid\|reason\|skip_hooks\)=" | sort
+fi
+if [ "$reason" = "TEST" -o "$reason" = "DUMP" ]; then
set | grep "^\(new_\|old_\)" | sort
fi
-.\" Copyright (c) 2006-2009 Roy Marples
+.\" Copyright (c) 2006-2010 Roy Marples
.\" All rights reserved
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd March 23, 2009
+.Dd August 24, 2010
.Dt DHCPCD-RUN-HOOKS 8 SMM
.Os
.Sh NAME
Static configuration and DHCP INFORM is still allowed.
.It Dv STOP
dhcpcd stopped running on the interface.
+.iT Dv DUMP
+dhcpcd has been asked to dump the last lease for the interface.
.It Dv TEST
dhcpcd received an OFFER from a DHCP server but will not configure the
interface.
This is primarily used to test the variables are filled correctly for the
script to process them.
+
.El
.Sh FILES
When
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 9, 2010
+.Dd August 24, 2010
.Dt DHCPCD 8 SMM
.Os
.Sh NAME
.Fl k , -release
.Op interface
.Nm
+.Fl U, -dumplease
+.Ar interface
+.Nm
.Fl x , -exit
.Op interface
.Sh DESCRIPTION
To test INFORM the interface needs to be configured with the desired address
before starting
.Nm .
+.It Fl U, -dumplease Ar interface
+Dumps the last lease for the
+.Ar interface
+to stdout.
.It Fl V, -variables
Display a list of option codes and the associated variable for use in
.Xr dhcpcd-run-hooks 8 .
case 'T':
i = 1;
break;
+ case 'U':
+ i = 2;
+ break;
case 'V':
print_options();
exit(EXIT_SUCCESS);
}
options = ifo->options;
if (i != 0) {
- options |= DHCPCD_TEST | DHCPCD_PERSISTENT;
+ if (i == 1)
+ options |= DHCPCD_TEST;
+ else
+ options |= DHCPCD_DUMPLEASE;
+ options |= DHCPCD_PERSISTENT;
options &= ~DHCPCD_DAEMONISE;
}
if (options & DHCPCD_QUIET)
close(STDERR_FILENO);
- if (!(options & DHCPCD_TEST)) {
+ if (!(options & (DHCPCD_TEST | DHCPCD_DUMPLEASE))) {
/* If we have any other args, we should run as a single dhcpcd
* instance for that interface. */
len = strlen(PIDFILE) + IF_NAMESIZE + 2;
syslog(LOG_ERR, "chdir `/': %m");
atexit(cleanup);
- if (!(options & (DHCPCD_MASTER | DHCPCD_TEST))) {
+ if (options & DHCPCD_DUMPLEASE) {
+ if (optind != argc - 1) {
+ syslog(LOG_ERR, "dumplease requires an interface");
+ exit(EXIT_FAILURE);
+ }
+ iface = xzalloc(sizeof(*iface));
+ strlcpy(iface->name, argv[optind], sizeof(iface->name));
+ snprintf(iface->leasefile, sizeof(iface->leasefile),
+ LEASEFILE, iface->name);
+ iface->state = xzalloc(sizeof(*iface->state));
+ select_profile(iface, NULL);
+ add_options(iface->state->options, argc, argv);
+ iface->state->new = read_lease(iface);
+ if (iface->state->new == NULL && errno == ENOENT) {
+ syslog(LOG_ERR, "%s: no lease to dump", iface->name);
+ exit(EXIT_FAILURE);
+ }
+ iface->state->reason = "DUMP";
+ run_script(iface);
+ exit(EXIT_SUCCESS);
+ }
+
+ if (!(options & (DHCPCD_MASTER | DHCPCD_TEST | DHCPCD_DUMPLEASE))) {
control_fd = open_control();
if (control_fd != -1) {
syslog(LOG_INFO,
{"require", required_argument, NULL, 'Q'},
{"static", required_argument, NULL, 'S'},
{"test", no_argument, NULL, 'T'},
+ {"dumplease", no_argument, NULL, 'U'},
{"variables", no_argument, NULL, 'V'},
{"whitelist", required_argument, NULL, 'W'},
{"blacklist", required_argument, NULL, 'X'},
case 'g': /* FALLTHROUGH */
case 'n': /* FALLTHROUGH */
case 'x': /* FALLTHROUGH */
- case 'T': /* We need to handle non interface options */
+ case 'T': /* FALLTHROUGH */
+ case 'U': /* We need to handle non interface options */
break;
case 'b':
ifo->options |= DHCPCD_BACKGROUND;
/* Don't set any optional arguments here so we retain POSIX
* compatibility with getopt */
-#define IF_OPTS "bc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:ABC:DEF:GHI:JKLO:Q:S:TVW:X:Z:"
+#define IF_OPTS "bc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:ABC:DEF:GHI:JKLO:Q:S:TUVW:X:Z:"
#define DEFAULT_TIMEOUT 30
#define DEFAULT_REBOOT 10
#define DHCPCD_CSR_WARNED (1 << 27)
#define DHCPCD_XID_HWADDR (1 << 28)
#define DHCPCD_BROADCAST (1 << 29)
+#define DHCPCD_DUMPLEASE (1 << 30)
extern const struct option cf_options[];