From: Roy Marples Date: Thu, 14 Jan 2016 17:05:16 +0000 (+0000) Subject: Add the -1, --oneshot option which causes dhcpcd to exit once an X-Git-Tag: v6.10.1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df57499917d220a9ef834c372ee499d6d6d012c2;p=thirdparty%2Fdhcpcd.git Add the -1, --oneshot option which causes dhcpcd to exit once an interface has been configured. --- diff --git a/dhcpcd.8.in b/dhcpcd.8.in index f5039980..890e5a7d 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 January 7, 2016 +.Dd January 14, 2016 .Dt DHCPCD 8 .Os .Sh NAME @@ -30,7 +30,7 @@ .Nd a DHCP client .Sh SYNOPSIS .Nm -.Op Fl 46ABbDdEGgHJKLMNPpqTV +.Op Fl 146ABbDdEGgHJKLMNPpqTV .Op Fl C , Fl Fl nohook Ar hook .Op Fl c , Fl Fl script Ar script .Op Fl e , Fl Fl env Ar value @@ -569,6 +569,11 @@ However, there are sometimes situations where you don't want the things to be configured exactly how the the DHCP server wants. Here are some options that deal with turning these bits off. .Bl -tag -width indent +.It Fl 1 , Fl Fl oneshot +Exit after configuring an interface. +Use the +.Fl w , Fl Fl waitip +option to specify which protocol(s) to configure before exiting. .It Fl 4 , Fl Fl ipv4only Configure IPv4 only. .It Fl 6 , Fl Fl ipv6only diff --git a/dhcpcd.c b/dhcpcd.c index 0edc2446..5ca9f321 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -318,6 +318,12 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) return 0; } + if (ctx->options & DHCPCD_ONESHOT) { + logger(ctx, LOG_INFO, "exiting due to oneshot"); + eloop_exit(ctx->eloop, EXIT_SUCCESS); + return 0; + } + eloop_timeout_delete(ctx->eloop, handle_exit_timeout, ctx); if (ctx->options & DHCPCD_DAEMONISED || !(ctx->options & DHCPCD_DAEMONISE)) diff --git a/if-options.c b/if-options.c index de0c3ab7..9b662aad 100644 --- a/if-options.c +++ b/if-options.c @@ -153,6 +153,9 @@ const struct option cf_options[] = { {"whitelist", required_argument, NULL, 'W'}, {"blacklist", required_argument, NULL, 'X'}, {"denyinterfaces", required_argument, NULL, 'Z'}, + {"oneshot", no_argument, NULL, '1'}, + {"ipv4only", no_argument, NULL, '4'}, + {"ipv6only", no_argument, NULL, '6'}, {"arping", required_argument, NULL, O_ARPING}, {"destination", required_argument, NULL, O_DESTINATION}, {"fallback", required_argument, NULL, O_FALLBACK}, @@ -164,8 +167,6 @@ const struct option cf_options[] = { {"ipv6ra_own", no_argument, NULL, O_IPV6RA_OWN}, {"ipv6ra_own_default", no_argument, NULL, O_IPV6RA_OWN_D}, {"ipv6ra_accept_nopublic", no_argument, NULL, O_IPV6RA_ACCEPT_NOPUBLIC}, - {"ipv4only", no_argument, NULL, '4'}, - {"ipv6only", no_argument, NULL, '6'}, {"ipv4", no_argument, NULL, O_IPV4}, {"noipv4", no_argument, NULL, O_NOIPV4}, {"ipv6", no_argument, NULL, O_IPV6}, @@ -1178,6 +1179,9 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, if (ifname == NULL) ctx->ifdv = splitv(ctx, &ctx->ifdc, ctx->ifdv, arg); break; + case '1': + ifo->options |= DHCPCD_ONESHOT; + break; case '4': ifo->options &= ~DHCPCD_IPV6; ifo->options |= DHCPCD_IPV4; diff --git a/if-options.h b/if-options.h index a6a98f8a..66b87d8d 100644 --- a/if-options.h +++ b/if-options.h @@ -41,7 +41,7 @@ /* Don't set any optional arguments here so we retain POSIX * compatibility with getopt */ -#define IF_OPTS "46bc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \ +#define IF_OPTS "146bc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \ "ABC:DEF:GHI:JKLMNO:PQ:S:TUVW:X:Z:" #define NOERR_IF_OPTS ":" IF_OPTS @@ -114,6 +114,7 @@ #define DHCPCD_BOOTP (1ULL << 57) #define DHCPCD_INITIAL_DELAY (1ULL << 58) #define DHCPCD_PRINT_PIDFILE (1ULL << 59) +#define DHCPCD_ONESHOT (1ULL << 60) #define DHCPCD_NODROP (DHCPCD_EXITING | DHCPCD_PERSISTENT)