Merge pull request #12137 from poettering/socket-var-run

warn about sockets in /var/run/ too
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-03-29 15:00:25 +01:00 committed by GitHub
commit 983616735e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 29 deletions

3
TODO
View File

@ -69,9 +69,6 @@ Features:
* bootctl,sd-boot: actually honour the "architecture" key
* when a socket unit is spawned with an AF_UNIX path in /var/run, complain and
patch it to use /run instead
* set memory.oom.group in cgroup v2 for all leaf cgroups (kernel v4.19+)
* add a new syscall group "@esoteric" for more esoteric stuff such as bpf() and

View File

@ -312,23 +312,50 @@ int config_parse_unit_path_strv_printf(
if (r < 0)
return 0;
r = strv_push(x, k);
r = strv_consume(x, TAKE_PTR(k));
if (r < 0)
return log_oom();
k = NULL;
}
}
int config_parse_socket_listen(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
static int patch_var_run(
const char *unit,
const char *filename,
unsigned line,
const char *lvalue,
char **path) {
const char *e;
char *z;
e = path_startswith(*path, "/var/run/");
if (!e)
return 0;
z = path_join("/run/", e);
if (!z)
return log_oom();
log_syntax(unit, LOG_NOTICE, filename, line, 0,
"%s= references a path below legacy directory /var/run/, updating %s → %s; "
"please update the unit file accordingly.", lvalue, *path, z);
free_and_replace(*path, z);
return 1;
}
int config_parse_socket_listen(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
_cleanup_free_ SocketPort *p = NULL;
SocketPort *tail;
@ -365,6 +392,12 @@ int config_parse_socket_listen(const char *unit,
if (r < 0)
return 0;
if (ltype == SOCKET_FIFO) {
r = patch_var_run(unit, filename, line, lvalue, &k);
if (r < 0)
return r;
}
free_and_replace(p->path, k);
p->type = ltype;
@ -394,6 +427,12 @@ int config_parse_socket_listen(const char *unit,
return 0;
}
if (k[0] == '/') { /* Only for AF_UNIX file system sockets… */
r = patch_var_run(unit, filename, line, lvalue, &k);
if (r < 0)
return r;
}
r = socket_address_parse_and_warn(&p->address, k);
if (r < 0) {
if (r != -EAFNOSUPPORT)
@ -4259,7 +4298,6 @@ int config_parse_pid_file(
_cleanup_free_ char *k = NULL, *n = NULL;
Unit *u = userdata;
char **s = data;
const char *e;
int r;
assert(filename);
@ -4289,20 +4327,11 @@ int config_parse_pid_file(
if (r < 0)
return r;
e = path_startswith(n, "/var/run/");
if (e) {
char *z;
z = strjoin("/run/", e);
if (!z)
return log_oom();
log_syntax(unit, LOG_NOTICE, filename, line, 0, "PIDFile= references path below legacy directory /var/run/, updating %s → %s; please update the unit file accordingly.", n, z);
free_and_replace(*s, z);
} else
free_and_replace(*s, n);
r = patch_var_run(unit, filename, line, lvalue, &n);
if (r < 0)
return r;
free_and_replace(*s, n);
return 0;
}