[CRIU] [PATCH] env: Introduce logging of runtime environment

Pavel Emelyanov xemul at parallels.com
Fri Sep 19 06:51:15 PDT 2014


On 09/17/2014 11:22 AM, Cyrill Gorcunov wrote:

> +void log_rt_env(unsigned int loglevel)
> +{
> +	if (pr_quelled(loglevel))
> +		return;
> +
> +	print_on_level(loglevel, "Run time environment info\n");
> +	print_on_level(loglevel, "  Command line: %s\n", rt_env.cmdline);
> +}
> +
> +int fill_rt_env(int argc, char *argv[])

Why do we need pre-fill? The getopt_long rearranges options, but
doesn't eat them :)

> +{
> +	size_t i, j;
> +
> +	/*
> +	 * The kernel itself allocates cmdline in one
> +	 * memory slab but before main executed() there
> +	 * might be a bunch of calls from system libs so
> +	 * we can't rely on cmdline memory continuity :(
> +	 */
> +	for (i = 0, j = 0; i < argc; i++) {
> +		size_t len = strlen(argv[i]);
> +
> +		if (len + j + 1 > sizeof(rt_env.cmdline))
> +			break;
> +		strcpy(&rt_env.cmdline[j], argv[i]);
> +		rt_env.cmdline[j + len] = ' ';
> +		j += len + 1;
> +	}
> +	rt_env.cmdline[j ? j - 1 : 0] = '\0';
> +
> +	return 0;
> +}



More information about the CRIU mailing list