summaryrefslogtreecommitdiffstats
path: root/dhcpcd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2010-08-24 09:16:07 +0000
committerRoy Marples <roy@marples.name>2010-08-24 09:16:07 +0000
commitdc60cba4ed8b4c63b1329f03027e0f65458fbb05 (patch)
tree6ce78714a39802aeedc34e05fc4331eafee6f6b7 /dhcpcd.c
parent1a4e7a5eaceba7d2acbb1bf5cb0d54966c20b963 (diff)
downloaddhcpcd-dc60cba4ed8b4c63b1329f03027e0f65458fbb05.tar.xz
-U, --dumplease now dumps the lease for the specified interface
dhcpcd does not have to be running for this to work
Diffstat (limited to 'dhcpcd.c')
-rw-r--r--dhcpcd.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/dhcpcd.c b/dhcpcd.c
index 3759722d..fe5fa1a7 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1707,6 +1707,9 @@ main(int argc, char **argv)
case 'T':
i = 1;
break;
+ case 'U':
+ i = 2;
+ break;
case 'V':
print_options();
exit(EXIT_SUCCESS);
@@ -1727,7 +1730,11 @@ main(int argc, char **argv)
}
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;
}
@@ -1740,7 +1747,7 @@ main(int argc, char **argv)
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;
@@ -1757,7 +1764,29 @@ main(int argc, char **argv)
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,