mirror of
git://github.com/lxc/lxc
synced 2025-08-31 20:57:02 +00:00
confile: preserve newlines
Users were confused when the config file created during cloning or copying a container suddenly missed all newlines. Let's keep them. Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
@@ -1920,42 +1920,51 @@ struct parse_line_conf {
|
|||||||
|
|
||||||
static int parse_line(char *buffer, void *data)
|
static int parse_line(char *buffer, void *data)
|
||||||
{
|
{
|
||||||
struct lxc_config_t *config;
|
|
||||||
char *dot, *key, *line, *linep, *value;
|
char *dot, *key, *line, *linep, *value;
|
||||||
struct parse_line_conf *plc = data;
|
bool empty_line;
|
||||||
|
struct lxc_config_t *config;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
char *dup = buffer;
|
||||||
|
struct parse_line_conf *plc = data;
|
||||||
|
|
||||||
if (lxc_is_line_empty(buffer))
|
/* If there are newlines in the config file we should keep them. */
|
||||||
return 0;
|
empty_line = lxc_is_line_empty(dup);
|
||||||
|
if (empty_line)
|
||||||
|
dup = "\n";
|
||||||
|
|
||||||
/* We have to dup the buffer otherwise, at the re-exec for reboot we
|
/* We have to dup the buffer otherwise, at the re-exec for reboot we
|
||||||
* modified the original string on the stack by replacing '=' by '\0'
|
* modified the original string on the stack by replacing '=' by '\0'
|
||||||
* below.
|
* below.
|
||||||
*/
|
*/
|
||||||
linep = line = strdup(buffer);
|
linep = line = strdup(dup);
|
||||||
if (!line)
|
if (!line)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!plc->from_include)
|
if (!plc->from_include) {
|
||||||
if ((ret = append_unexp_config_line(line, plc->conf)))
|
ret = append_unexp_config_line(line, plc->conf);
|
||||||
goto out;
|
if (ret < 0)
|
||||||
|
goto on_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty_line)
|
||||||
|
return 0;
|
||||||
|
|
||||||
line += lxc_char_left_gc(line, strlen(line));
|
line += lxc_char_left_gc(line, strlen(line));
|
||||||
|
|
||||||
/* ignore comments */
|
/* ignore comments */
|
||||||
if (line[0] == '#')
|
if (line[0] == '#')
|
||||||
goto out;
|
goto on_error;
|
||||||
|
|
||||||
/* martian option - don't add it to the config itself */
|
/* martian option - don't add it to the config itself */
|
||||||
if (strncmp(line, "lxc.", 4))
|
if (strncmp(line, "lxc.", 4))
|
||||||
goto out;
|
goto on_error;
|
||||||
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
dot = strstr(line, "=");
|
dot = strchr(line, '=');
|
||||||
if (!dot) {
|
if (!dot) {
|
||||||
ERROR("invalid configuration line: %s", line);
|
ERROR("Invalid configuration line: %s", line);
|
||||||
goto out;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
*dot = '\0';
|
*dot = '\0';
|
||||||
@@ -1980,7 +1989,7 @@ static int parse_line(char *buffer, void *data)
|
|||||||
config = lxc_get_config(key);
|
config = lxc_get_config(key);
|
||||||
if (!config) {
|
if (!config) {
|
||||||
ERROR("Unknown configuration key \"%s\"", key);
|
ERROR("Unknown configuration key \"%s\"", key);
|
||||||
goto out;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* [START]: REMOVE IN LXC 3.0 */
|
/* [START]: REMOVE IN LXC 3.0 */
|
||||||
@@ -1998,7 +2007,7 @@ static int parse_line(char *buffer, void *data)
|
|||||||
|
|
||||||
ret = config->set(key, value, plc->conf, NULL);
|
ret = config->set(key, value, plc->conf, NULL);
|
||||||
|
|
||||||
out:
|
on_error:
|
||||||
free(linep);
|
free(linep);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user