X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fload-fragment.c;h=7a51bf81c811b46000b111515b49de5703cc4f2e;hb=e4a9373fb3ddeadd6b847449186fadf5963695f7;hp=793c9525941a9c4fc307a10de93f342966e655be;hpb=2c7108c40abfb1f175391aa59cf1b07ab203e690;p=elogind.git diff --git a/src/load-fragment.c b/src/load-fragment.c index 793c95259..7a51bf81c 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -40,6 +40,9 @@ #include "missing.h" #include "unit-name.h" +#define COMMENTS "#;\n" +#define LINE_MAX 4096 + #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \ static int function( \ const char *filename, \ @@ -1143,6 +1146,64 @@ static int config_parse_path_unit( return 0; } +static int config_parse_env_file( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + FILE *f; + int r; + char ***env = data; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + if (!(f = fopen(rvalue, "re"))) { + log_error("[%s:%u] Failed to open environment file '%s': %m", filename, line, rvalue); + return -errno; + } + + while (!feof(f)) { + char l[LINE_MAX], *p; + char **t; + + if (!fgets(l, sizeof(l), f)) { + if (feof(f)) + break; + + r = -errno; + log_error("[%s:%u] Failed to read environment file '%s': %m", filename, line, rvalue); + goto finish; + } + + p = strstrip(l); + + if (!*p) + continue; + + if (strchr(COMMENTS, *p)) + continue; + + t = strv_env_set(*env, p); + strv_free(*env); + *env = t; + } + + r = 0; + +finish: + if (f) + fclose(f); + + return r; +} + #define FOLLOW_MAX 8 static int open_follow(char **filename, FILE **_f, Set *names, char **_final) { @@ -1272,6 +1333,7 @@ static void dump_items(FILE *f, const ConfigItem *items) { { config_parse_cpu_sched_prio, "CPUSCHEDPRIO" }, { config_parse_cpu_affinity, "CPUAFFINITY" }, { config_parse_mode, "MODE" }, + { config_parse_env_file, "FILE" }, { config_parse_output, "OUTPUT" }, { config_parse_input, "INPUT" }, { config_parse_facility, "FACILITY" }, @@ -1358,6 +1420,7 @@ static int load_from_path(Unit *u, const char *path) { { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \ { "UMask", config_parse_mode, &(context).umask, section }, \ { "Environment", config_parse_strv, &(context).environment, section }, \ + { "EnvironmentFile", config_parse_env_file, &(context).environment, section }, \ { "StandardInput", config_parse_input, &(context).std_input, section }, \ { "StandardOutput", config_parse_output, &(context).std_output, section }, \ { "StandardError", config_parse_output, &(context).std_error, section }, \ @@ -1391,7 +1454,9 @@ static int load_from_path(Unit *u, const char *path) { { "ReadOnlyDirectories", config_parse_path_strv, &(context).read_only_dirs, section }, \ { "InaccessibleDirectories",config_parse_path_strv, &(context).inaccessible_dirs, section }, \ { "PrivateTmp", config_parse_bool, &(context).private_tmp, section }, \ - { "MountFlags", config_parse_mount_flags, &(context), section } + { "MountFlags", config_parse_mount_flags, &(context), section }, \ + { "TCPWrapName", config_parse_string, &(context).tcpwrap_name, section }, \ + { "PAMName", config_parse_string, &(context).pam_name, section } const ConfigItem items[] = { { "Names", config_parse_names, u, "Unit" }, @@ -1471,12 +1536,17 @@ static int load_from_path(Unit *u, const char *path) { { "DirectoryNotEmpty", config_parse_path_spec, &u->path, "Path" }, { "Unit", config_parse_path_unit, &u->path, "Path" }, + /* The [Install] section is ignored here. */ + { "Alias", NULL, NULL, "Install" }, + { "WantedBy", NULL, NULL, "Install" }, + { "Also", NULL, NULL, "Install" }, + { NULL, NULL, NULL, NULL } }; #undef EXEC_CONTEXT_CONFIG_ITEMS - const char *sections[3]; + const char *sections[4]; int r; Set *symlink_names; FILE *f = NULL; @@ -1494,7 +1564,8 @@ static int load_from_path(Unit *u, const char *path) { sections[0] = "Unit"; sections[1] = section_table[u->meta.type]; - sections[2] = NULL; + sections[2] = "Install"; + sections[3] = NULL; if (!(symlink_names = set_new(string_hash_func, string_compare_func))) return -ENOMEM; @@ -1563,7 +1634,7 @@ static int load_from_path(Unit *u, const char *path) { } /* Now, parse the file contents */ - if ((r = config_parse(filename, f, sections, items, u)) < 0) + if ((r = config_parse(filename, f, sections, items, false, u)) < 0) goto finish; free(u->meta.fragment_path);