fileio: drop "newline" parameter for env file parsers
Now that we don't (mis-)use the env file parser to parse kernel command lines there's no need anymore to override the used newline character set. Let's hence drop the argument and just "\n\r" always. This nicely simplifies our code.
This commit is contained in:
@@ -242,7 +242,7 @@ static int gather_environment_generate(int fd, void *arg) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
r = load_env_file_pairs(f, NULL, NULL, &new);
|
||||
r = load_env_file_pairs(f, NULL, &new);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+15
-29
@@ -368,7 +368,6 @@ int read_full_file(const char *fn, char **contents, size_t *size) {
|
||||
static int parse_env_file_internal(
|
||||
FILE *f,
|
||||
const char *fname,
|
||||
const char *newline,
|
||||
int (*push) (const char *filename, unsigned line,
|
||||
const char *key, char *value, void *userdata, int *n_pushed),
|
||||
void *userdata,
|
||||
@@ -394,8 +393,6 @@ static int parse_env_file_internal(
|
||||
COMMENT_ESCAPE
|
||||
} state = PRE_KEY;
|
||||
|
||||
assert(newline);
|
||||
|
||||
if (f)
|
||||
r = read_full_stream(f, &contents, NULL);
|
||||
else
|
||||
@@ -423,7 +420,7 @@ static int parse_env_file_internal(
|
||||
break;
|
||||
|
||||
case KEY:
|
||||
if (strchr(newline, c)) {
|
||||
if (strchr(NEWLINE, c)) {
|
||||
state = PRE_KEY;
|
||||
line++;
|
||||
n_key = 0;
|
||||
@@ -445,7 +442,7 @@ static int parse_env_file_internal(
|
||||
break;
|
||||
|
||||
case PRE_VALUE:
|
||||
if (strchr(newline, c)) {
|
||||
if (strchr(NEWLINE, c)) {
|
||||
state = PRE_KEY;
|
||||
line++;
|
||||
key[n_key] = 0;
|
||||
@@ -483,7 +480,7 @@ static int parse_env_file_internal(
|
||||
break;
|
||||
|
||||
case VALUE:
|
||||
if (strchr(newline, c)) {
|
||||
if (strchr(NEWLINE, c)) {
|
||||
state = PRE_KEY;
|
||||
line++;
|
||||
|
||||
@@ -528,7 +525,7 @@ static int parse_env_file_internal(
|
||||
case VALUE_ESCAPE:
|
||||
state = VALUE;
|
||||
|
||||
if (!strchr(newline, c)) {
|
||||
if (!strchr(NEWLINE, c)) {
|
||||
/* Escaped newlines we eat up entirely */
|
||||
if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
|
||||
return -ENOMEM;
|
||||
@@ -554,7 +551,7 @@ static int parse_env_file_internal(
|
||||
case SINGLE_QUOTE_VALUE_ESCAPE:
|
||||
state = SINGLE_QUOTE_VALUE;
|
||||
|
||||
if (!strchr(newline, c)) {
|
||||
if (!strchr(NEWLINE, c)) {
|
||||
if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -579,7 +576,7 @@ static int parse_env_file_internal(
|
||||
case DOUBLE_QUOTE_VALUE_ESCAPE:
|
||||
state = DOUBLE_QUOTE_VALUE;
|
||||
|
||||
if (!strchr(newline, c)) {
|
||||
if (!strchr(NEWLINE, c)) {
|
||||
if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -590,7 +587,7 @@ static int parse_env_file_internal(
|
||||
case COMMENT:
|
||||
if (c == '\\')
|
||||
state = COMMENT_ESCAPE;
|
||||
else if (strchr(newline, c)) {
|
||||
else if (strchr(NEWLINE, c)) {
|
||||
state = PRE_KEY;
|
||||
line++;
|
||||
}
|
||||
@@ -699,17 +696,13 @@ static int parse_env_file_push(
|
||||
int parse_env_filev(
|
||||
FILE *f,
|
||||
const char *fname,
|
||||
const char *newline,
|
||||
va_list ap) {
|
||||
|
||||
int r, n_pushed = 0;
|
||||
va_list aq;
|
||||
|
||||
if (!newline)
|
||||
newline = NEWLINE;
|
||||
|
||||
va_copy(aq, ap);
|
||||
r = parse_env_file_internal(f, fname, newline, parse_env_file_push, &aq, &n_pushed);
|
||||
r = parse_env_file_internal(f, fname, parse_env_file_push, &aq, &n_pushed);
|
||||
va_end(aq);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -720,14 +713,13 @@ int parse_env_filev(
|
||||
int parse_env_file(
|
||||
FILE *f,
|
||||
const char *fname,
|
||||
const char *newline,
|
||||
...) {
|
||||
|
||||
va_list ap;
|
||||
int r;
|
||||
|
||||
va_start(ap, newline);
|
||||
r = parse_env_filev(f, fname, newline, ap);
|
||||
va_start(ap, fname);
|
||||
r = parse_env_filev(f, fname, ap);
|
||||
va_end(ap);
|
||||
|
||||
return r;
|
||||
@@ -763,14 +755,11 @@ static int load_env_file_push(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int load_env_file(FILE *f, const char *fname, const char *newline, char ***rl) {
|
||||
int load_env_file(FILE *f, const char *fname, char ***rl) {
|
||||
char **m = NULL;
|
||||
int r;
|
||||
|
||||
if (!newline)
|
||||
newline = NEWLINE;
|
||||
|
||||
r = parse_env_file_internal(f, fname, newline, load_env_file_push, &m, NULL);
|
||||
r = parse_env_file_internal(f, fname, load_env_file_push, &m, NULL);
|
||||
if (r < 0) {
|
||||
strv_free(m);
|
||||
return r;
|
||||
@@ -812,14 +801,11 @@ static int load_env_file_push_pairs(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int load_env_file_pairs(FILE *f, const char *fname, const char *newline, char ***rl) {
|
||||
int load_env_file_pairs(FILE *f, const char *fname, char ***rl) {
|
||||
char **m = NULL;
|
||||
int r;
|
||||
|
||||
if (!newline)
|
||||
newline = NEWLINE;
|
||||
|
||||
r = parse_env_file_internal(f, fname, newline, load_env_file_push_pairs, &m, NULL);
|
||||
r = parse_env_file_internal(f, fname, load_env_file_push_pairs, &m, NULL);
|
||||
if (r < 0) {
|
||||
strv_free(m);
|
||||
return r;
|
||||
@@ -872,7 +858,7 @@ int merge_env_file(
|
||||
* plus "extended" substitutions, unlike other exported parsing functions.
|
||||
*/
|
||||
|
||||
return parse_env_file_internal(f, fname, NEWLINE, merge_env_file_push, env, NULL);
|
||||
return parse_env_file_internal(f, fname, merge_env_file_push, env, NULL);
|
||||
}
|
||||
|
||||
static void write_env_var(FILE *f, const char *v) {
|
||||
|
||||
+4
-4
@@ -42,10 +42,10 @@ int read_full_stream(FILE *f, char **contents, size_t *size);
|
||||
|
||||
int verify_file(const char *fn, const char *blob, bool accept_extra_nl);
|
||||
|
||||
int parse_env_filev(FILE *f, const char *fname, const char *separator, va_list ap);
|
||||
int parse_env_file(FILE *f, const char *fname, const char *separator, ...) _sentinel_;
|
||||
int load_env_file(FILE *f, const char *fname, const char *separator, char ***l);
|
||||
int load_env_file_pairs(FILE *f, const char *fname, const char *separator, char ***l);
|
||||
int parse_env_filev(FILE *f, const char *fname, va_list ap);
|
||||
int parse_env_file(FILE *f, const char *fname, ...) _sentinel_;
|
||||
int load_env_file(FILE *f, const char *fname, char ***l);
|
||||
int load_env_file_pairs(FILE *f, const char *fname, char ***l);
|
||||
|
||||
int merge_env_file(char ***env, FILE *f, const char *fname);
|
||||
|
||||
|
||||
+2
-2
@@ -98,7 +98,7 @@ int parse_os_release(const char *root, ...) {
|
||||
return r;
|
||||
|
||||
va_start(ap, root);
|
||||
r = parse_env_filev(f, p, NEWLINE, ap);
|
||||
r = parse_env_filev(f, p, ap);
|
||||
va_end(ap);
|
||||
|
||||
return r;
|
||||
@@ -113,5 +113,5 @@ int load_os_release_pairs(const char *root, char ***ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return load_env_file_pairs(f, p, NEWLINE, ret);
|
||||
return load_env_file_pairs(f, p, ret);
|
||||
}
|
||||
|
||||
+1
-1
@@ -248,7 +248,7 @@ int container_get_leader(const char *machine, pid_t *pid) {
|
||||
return -EINVAL;
|
||||
|
||||
p = strjoina("/run/systemd/machines/", machine);
|
||||
r = parse_env_file(NULL, p, NEWLINE, "LEADER", &s, "CLASS", &class, NULL);
|
||||
r = parse_env_file(NULL, p, "LEADER", &s, "CLASS", &class, NULL);
|
||||
if (r == -ENOENT)
|
||||
return -EHOSTDOWN;
|
||||
if (r < 0)
|
||||
|
||||
Reference in New Issue
Block a user