[sheepdog] [PATCH] dog: use new environment variables for specifying IP address and port number

Liu Yuan namei.unix at gmail.com
Wed Jun 11 08:50:24 CEST 2014


On Wed, Jun 11, 2014 at 11:25:44AM +0900, Hitoshi Mitake wrote:
> New environment variables are used for specifying IP address and port
> number:
> - SHEEPDOG_DOG_ADDR for IP address
> - SHEEPDOG_DOG_PORT for port number
> 
> It is useful when sheep is launched with -b option.
> 
> If both of the variables and -a or -p option are specified, command
> line option is prioritized.
> 
> Related issue:
> https://bugs.launchpad.net/sheepdog-project/+bug/1322633
> 
> Cc: Valerio Pachera <sirio81 at gmail.com>
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> ---
>  dog/dog.c |   22 +++++++++++++++++++++-
>  1 files changed, 21 insertions(+), 1 deletions(-)
> 
> diff --git a/dog/dog.c b/dog/dog.c
> index 1eefbdc..7d1153d 100644
> --- a/dog/dog.c
> +++ b/dog/dog.c
> @@ -449,7 +449,7 @@ int main(int argc, char **argv)
>  	struct option *long_options;
>  	const struct command *commands;
>  	const char *short_options;
> -	char *p;
> +	char *p, *env;
>  	const struct sd_option *sd_opts;
>  	uint8_t sdhost[16];
>  	int sdport;
> @@ -471,6 +471,26 @@ int main(int argc, char **argv)
>  	long_options = build_long_options(sd_opts);
>  	short_options = build_short_options(sd_opts);
>  
> +	env = getenv("SHEEPDOG_DOG_ADDR");
> +	if (env) {
> +		if (!str_to_addr(env, sdhost)) {
> +			sd_err("Invalid ip address %s", env);
> +			return EXIT_FAILURE;
> +		}
> +		memcpy(sd_nid.addr, sdhost, sizeof(sdhost));
> +	}
> +
> +	env = getenv("SHEEPDOG_DOG_PORT");
> +	if (env) {
> +		sdport = strtol(env, &p, 10);
> +		if (env == p || sdport < 1 || sdport > UINT16_MAX
> +		    || !is_numeric(env)) {
> +			sd_err("Invalid port number '%s'", env);
> +			exit(EXIT_USAGE);
> +		}
> +		sd_nid.port = sdport;
> +	}
> +
>  	while ((ch = getopt_long(argc, argv, short_options, long_options,
>  				&longindex)) >= 0) {
>  
> -- 
> 1.7.1
> 
> -- 
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog

Applied thanks

Yuan



More information about the sheepdog mailing list