2010-08-14 19:59:25 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
2009-11-19 23:13:20 +01:00
|
|
|
|
2010-02-03 13:03:47 +01:00
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2010 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2010-02-03 13:03:47 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2010-02-03 13:03:47 +01:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2010-02-03 13:03:47 +01:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2010-01-26 21:39:06 +01:00
|
|
|
#include <linux/oom.h>
|
2009-11-19 23:13:20 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2010-01-26 21:39:06 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2010-01-30 01:55:42 +01:00
|
|
|
#include <sched.h>
|
|
|
|
#include <sys/prctl.h>
|
2010-04-21 22:15:06 +02:00
|
|
|
#include <sys/mount.h>
|
2010-04-24 05:05:01 +02:00
|
|
|
#include <linux/fs.h>
|
2010-07-17 00:57:51 +02:00
|
|
|
#include <sys/stat.h>
|
2011-04-04 18:15:13 +02:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
2009-11-19 23:13:20 +01:00
|
|
|
|
2010-01-26 21:39:06 +01:00
|
|
|
#include "unit.h"
|
2009-11-19 23:13:20 +01:00
|
|
|
#include "strv.h"
|
|
|
|
#include "conf-parser.h"
|
|
|
|
#include "load-fragment.h"
|
2010-01-20 19:19:53 +01:00
|
|
|
#include "log.h"
|
2010-01-29 20:46:22 +01:00
|
|
|
#include "ioprio.h"
|
2010-01-30 01:55:42 +01:00
|
|
|
#include "securebits.h"
|
|
|
|
#include "missing.h"
|
2010-04-15 03:11:11 +02:00
|
|
|
#include "unit-name.h"
|
2010-07-08 02:43:18 +02:00
|
|
|
#include "bus-errors.h"
|
2012-03-12 22:22:16 +01:00
|
|
|
#include "utf8.h"
|
2012-05-07 21:36:12 +02:00
|
|
|
#include "path-util.h"
|
2012-07-17 04:17:53 +02:00
|
|
|
#include "syscall-list.h"
|
2009-11-19 23:13:20 +01:00
|
|
|
|
2010-09-21 05:23:12 +02:00
|
|
|
#ifndef HAVE_SYSV_COMPAT
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_warn_compat(
|
2010-09-21 05:23:12 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-09-21 05:23:12 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
log_debug("[%s:%u] Support for option %s= has been disabled at compile time and is ignored", filename, line, lvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_unit_deps(
|
2009-11-19 23:13:20 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2009-11-19 23:13:20 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
UnitDependency d = ltype;
|
2010-01-26 21:39:06 +01:00
|
|
|
Unit *u = userdata;
|
2009-11-19 23:13:20 +01:00
|
|
|
char *w;
|
|
|
|
size_t l;
|
|
|
|
char *state;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
|
2010-07-07 20:58:41 +02:00
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
2010-04-15 03:11:11 +02:00
|
|
|
char *t, *k;
|
2009-11-19 23:13:20 +01:00
|
|
|
int r;
|
|
|
|
|
2012-01-06 23:08:54 +01:00
|
|
|
t = strndup(w, l);
|
|
|
|
if (!t)
|
2009-11-19 23:13:20 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-04-15 03:11:11 +02:00
|
|
|
k = unit_name_printf(u, t);
|
2009-11-19 23:13:20 +01:00
|
|
|
free(t);
|
2010-04-15 03:11:11 +02:00
|
|
|
if (!k)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-04-21 06:01:13 +02:00
|
|
|
r = unit_add_dependency_by_name(u, d, k, NULL, true);
|
2012-01-06 23:08:54 +01:00
|
|
|
if (r < 0)
|
|
|
|
log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r));
|
2010-08-17 03:30:53 +02:00
|
|
|
|
|
|
|
free(k);
|
2009-11-19 23:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_unit_string_printf(
|
2010-04-24 03:11:01 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-04-24 03:11:01 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Unit *u = userdata;
|
|
|
|
char *k;
|
2012-03-12 22:22:16 +01:00
|
|
|
int r;
|
2010-04-24 03:11:01 +02:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
2010-06-18 23:25:19 +02:00
|
|
|
assert(u);
|
2010-04-24 03:11:01 +02:00
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
k = unit_full_printf(u, rvalue);
|
|
|
|
if (!k)
|
2010-04-24 03:11:01 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
r = config_parse_string(filename, line, section, lvalue, ltype, k, data, userdata);
|
|
|
|
free (k);
|
2010-04-24 03:11:01 +02:00
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
return r;
|
2010-04-24 03:11:01 +02:00
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_unit_strv_printf(
|
2011-07-01 01:13:47 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Unit *u = userdata;
|
|
|
|
char *k;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(u);
|
|
|
|
|
|
|
|
k = unit_full_printf(u, rvalue);
|
|
|
|
if (!k)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = config_parse_strv(filename, line, section, lvalue, ltype, k, data, userdata);
|
|
|
|
free(k);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_unit_path_printf(
|
2011-05-18 01:07:31 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Unit *u = userdata;
|
|
|
|
char *k;
|
2012-03-12 22:22:16 +01:00
|
|
|
int r;
|
2011-05-18 01:07:31 +02:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(u);
|
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
k = unit_full_printf(u, rvalue);
|
|
|
|
if (!k)
|
2011-05-18 01:07:31 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
r = config_parse_path(filename, line, section, lvalue, ltype, k, data, userdata);
|
|
|
|
free(k);
|
2011-05-18 01:07:31 +02:00
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
return r;
|
2011-05-18 01:07:31 +02:00
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_socket_listen(
|
2010-01-19 02:56:37 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-19 02:56:37 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2011-04-16 03:42:18 +02:00
|
|
|
SocketPort *p, *tail;
|
2010-01-23 03:35:54 +01:00
|
|
|
Socket *s;
|
2010-01-20 19:19:53 +01:00
|
|
|
|
2010-01-19 02:56:37 +01:00
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2012-01-15 12:37:16 +01:00
|
|
|
s = SOCKET(data);
|
2010-01-23 03:35:54 +01:00
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
p = new0(SocketPort, 1);
|
|
|
|
if (!p)
|
2010-01-23 03:35:54 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (streq(lvalue, "ListenFIFO")) {
|
|
|
|
p->type = SOCKET_FIFO;
|
|
|
|
|
2011-07-01 00:55:34 +02:00
|
|
|
if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
|
2010-01-23 03:35:54 +01:00
|
|
|
free(p);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2010-05-24 05:25:33 +02:00
|
|
|
|
|
|
|
path_kill_slashes(p->path);
|
2011-04-20 05:02:23 +02:00
|
|
|
|
|
|
|
} else if (streq(lvalue, "ListenSpecial")) {
|
|
|
|
p->type = SOCKET_SPECIAL;
|
|
|
|
|
2011-07-01 00:55:34 +02:00
|
|
|
if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
|
2011-04-20 05:02:23 +02:00
|
|
|
free(p);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
path_kill_slashes(p->path);
|
|
|
|
|
2011-05-17 19:37:03 +02:00
|
|
|
} else if (streq(lvalue, "ListenMessageQueue")) {
|
|
|
|
|
|
|
|
p->type = SOCKET_MQUEUE;
|
|
|
|
|
2011-07-01 00:55:34 +02:00
|
|
|
if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
|
2011-05-17 19:37:03 +02:00
|
|
|
free(p);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
path_kill_slashes(p->path);
|
|
|
|
|
2011-04-10 03:27:00 +02:00
|
|
|
} else if (streq(lvalue, "ListenNetlink")) {
|
2011-07-01 00:55:34 +02:00
|
|
|
char *k;
|
|
|
|
int r;
|
|
|
|
|
2011-04-10 03:27:00 +02:00
|
|
|
p->type = SOCKET_SOCKET;
|
2011-07-01 00:55:34 +02:00
|
|
|
k = unit_full_printf(UNIT(s), rvalue);
|
|
|
|
r = socket_address_parse_netlink(&p->address, k);
|
|
|
|
free(k);
|
2011-04-10 03:27:00 +02:00
|
|
|
|
2011-07-01 00:55:34 +02:00
|
|
|
if (r < 0) {
|
2011-04-10 03:27:00 +02:00
|
|
|
log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
|
|
|
|
free(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-23 03:35:54 +01:00
|
|
|
} else {
|
2011-07-01 00:55:34 +02:00
|
|
|
char *k;
|
|
|
|
int r;
|
|
|
|
|
2010-01-23 03:35:54 +01:00
|
|
|
p->type = SOCKET_SOCKET;
|
2011-07-01 00:55:34 +02:00
|
|
|
k = unit_full_printf(UNIT(s), rvalue);
|
|
|
|
r = socket_address_parse(&p->address, k);
|
|
|
|
free(k);
|
2010-01-23 03:35:54 +01:00
|
|
|
|
2011-07-01 00:55:34 +02:00
|
|
|
if (r < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
|
2010-01-23 03:35:54 +01:00
|
|
|
free(p);
|
2010-08-17 03:30:53 +02:00
|
|
|
return 0;
|
2010-01-23 03:35:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (streq(lvalue, "ListenStream"))
|
|
|
|
p->address.type = SOCK_STREAM;
|
|
|
|
else if (streq(lvalue, "ListenDatagram"))
|
|
|
|
p->address.type = SOCK_DGRAM;
|
|
|
|
else {
|
|
|
|
assert(streq(lvalue, "ListenSequentialPacket"));
|
|
|
|
p->address.type = SOCK_SEQPACKET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (socket_address_family(&p->address) != AF_LOCAL && p->address.type == SOCK_SEQPACKET) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Address family not supported, ignoring: %s", filename, line, rvalue);
|
2010-01-23 03:35:54 +01:00
|
|
|
free(p);
|
2010-08-17 03:30:53 +02:00
|
|
|
return 0;
|
2010-01-23 03:35:54 +01:00
|
|
|
}
|
2010-01-20 19:19:53 +01:00
|
|
|
}
|
|
|
|
|
2010-01-23 03:35:54 +01:00
|
|
|
p->fd = -1;
|
2011-04-16 03:42:18 +02:00
|
|
|
|
|
|
|
if (s->ports) {
|
|
|
|
LIST_FIND_TAIL(SocketPort, port, s->ports, tail);
|
|
|
|
LIST_INSERT_AFTER(SocketPort, port, s->ports, tail, p);
|
|
|
|
} else
|
|
|
|
LIST_PREPEND(SocketPort, port, s->ports, p);
|
2010-01-23 03:35:54 +01:00
|
|
|
|
2010-01-20 19:19:53 +01:00
|
|
|
return 0;
|
2010-01-19 02:56:37 +01:00
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_socket_bind(
|
2010-01-19 02:56:37 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-19 02:56:37 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2010-01-23 03:35:54 +01:00
|
|
|
Socket *s;
|
2010-05-21 23:41:25 +02:00
|
|
|
SocketAddressBindIPv6Only b;
|
2010-01-19 02:56:37 +01:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2012-01-15 12:37:16 +01:00
|
|
|
s = SOCKET(data);
|
2010-01-23 03:35:54 +01:00
|
|
|
|
2010-05-21 23:41:25 +02:00
|
|
|
if ((b = socket_address_bind_ipv6_only_from_string(rvalue)) < 0) {
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if ((r = parse_boolean(rvalue)) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse bind IPv6 only value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-05-21 23:41:25 +02:00
|
|
|
}
|
2010-01-19 02:56:37 +01:00
|
|
|
|
2010-05-21 23:41:25 +02:00
|
|
|
s->bind_ipv6_only = r ? SOCKET_ADDRESS_IPV6_ONLY : SOCKET_ADDRESS_BOTH;
|
|
|
|
} else
|
|
|
|
s->bind_ipv6_only = b;
|
2010-01-23 03:35:54 +01:00
|
|
|
|
2010-01-19 02:56:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_nice(
|
2010-01-26 04:18:44 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-26 04:18:44 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2010-01-28 02:53:56 +01:00
|
|
|
ExecContext *c = data;
|
2011-01-22 02:18:59 +01:00
|
|
|
int priority;
|
2010-01-26 04:18:44 +01:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-01-22 02:18:59 +01:00
|
|
|
if (safe_atoi(rvalue, &priority) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse nice priority, ignoring: %s. ", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-01-26 04:18:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priority < PRIO_MIN || priority >= PRIO_MAX) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Nice priority out of range, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-01-26 04:18:44 +01:00
|
|
|
}
|
|
|
|
|
2010-01-28 02:53:56 +01:00
|
|
|
c->nice = priority;
|
2011-02-02 14:57:52 +01:00
|
|
|
c->nice_set = true;
|
2010-01-28 02:53:56 +01:00
|
|
|
|
2010-01-26 04:18:44 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_oom_score_adjust(
|
2010-01-26 04:18:44 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-26 04:18:44 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2010-01-28 02:53:56 +01:00
|
|
|
ExecContext *c = data;
|
2011-01-22 02:18:59 +01:00
|
|
|
int oa;
|
2010-01-26 04:18:44 +01:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-01-22 02:18:59 +01:00
|
|
|
if (safe_atoi(rvalue, &oa) < 0) {
|
2010-08-31 01:33:39 +02:00
|
|
|
log_error("[%s:%u] Failed to parse the OOM score adjust value, ignoring: %s", filename, line, rvalue);
|
2010-08-17 03:30:53 +02:00
|
|
|
return 0;
|
2010-01-26 04:18:44 +01:00
|
|
|
}
|
|
|
|
|
2010-08-31 01:33:39 +02:00
|
|
|
if (oa < OOM_SCORE_ADJ_MIN || oa > OOM_SCORE_ADJ_MAX) {
|
|
|
|
log_error("[%s:%u] OOM score adjust value out of range, ignoring: %s", filename, line, rvalue);
|
2010-08-17 03:30:53 +02:00
|
|
|
return 0;
|
2010-01-26 04:18:44 +01:00
|
|
|
}
|
|
|
|
|
2010-08-31 01:33:39 +02:00
|
|
|
c->oom_score_adjust = oa;
|
|
|
|
c->oom_score_adjust_set = true;
|
2010-01-28 02:53:56 +01:00
|
|
|
|
2010-01-26 04:18:44 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec(
|
2010-01-26 04:18:44 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-26 04:18:44 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
ExecCommand **e = data, *nce;
|
|
|
|
char *path, **n;
|
2010-01-26 04:18:44 +01:00
|
|
|
unsigned k;
|
2012-03-12 22:22:16 +01:00
|
|
|
int r;
|
2010-01-26 04:18:44 +01:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
2010-07-07 20:59:20 +02:00
|
|
|
assert(e);
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2010-05-19 21:51:53 +02:00
|
|
|
/* We accept an absolute path as first argument, or
|
|
|
|
* alternatively an absolute prefixed with @ to allow
|
|
|
|
* overriding of argv[0]. */
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
e += ltype;
|
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
for (;;) {
|
|
|
|
char *w;
|
|
|
|
size_t l;
|
|
|
|
char *state;
|
2010-07-12 02:25:42 +02:00
|
|
|
bool honour_argv0 = false, ignore = false;
|
2010-05-19 21:51:53 +02:00
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
path = NULL;
|
|
|
|
nce = NULL;
|
|
|
|
n = NULL;
|
2010-05-19 21:51:53 +02:00
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
rvalue += strspn(rvalue, WHITESPACE);
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
if (rvalue[0] == 0)
|
|
|
|
break;
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2010-07-12 02:25:42 +02:00
|
|
|
if (rvalue[0] == '-') {
|
|
|
|
ignore = true;
|
|
|
|
rvalue ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rvalue[0] == '@') {
|
|
|
|
honour_argv0 = true;
|
|
|
|
rvalue ++;
|
|
|
|
}
|
2010-07-07 20:59:20 +02:00
|
|
|
|
2010-07-12 02:25:42 +02:00
|
|
|
if (*rvalue != '/') {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Invalid executable path in command line, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-05-19 21:51:53 +02:00
|
|
|
}
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
k = 0;
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
2010-11-14 19:58:33 +01:00
|
|
|
if (strncmp(w, ";", MAX(l, 1U)) == 0)
|
2010-07-07 20:59:20 +02:00
|
|
|
break;
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
k++;
|
|
|
|
}
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
n = new(char*, k + !honour_argv0);
|
|
|
|
if (!n)
|
2010-07-07 20:59:20 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
2010-11-14 19:58:33 +01:00
|
|
|
if (strncmp(w, ";", MAX(l, 1U)) == 0)
|
2010-07-07 20:59:20 +02:00
|
|
|
break;
|
|
|
|
|
2010-07-12 02:25:42 +02:00
|
|
|
if (honour_argv0 && w == rvalue) {
|
|
|
|
assert(!path);
|
2012-03-12 22:22:16 +01:00
|
|
|
|
|
|
|
path = strndup(w, l);
|
|
|
|
if (!path) {
|
|
|
|
r = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!utf8_is_valid(path)) {
|
|
|
|
log_error("[%s:%u] Path is not UTF-8 clean, ignoring assignment: %s", filename, line, rvalue);
|
|
|
|
r = 0;
|
2010-07-07 20:59:20 +02:00
|
|
|
goto fail;
|
2012-03-12 22:22:16 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
} else {
|
2012-03-12 22:22:16 +01:00
|
|
|
char *c;
|
|
|
|
|
|
|
|
c = n[k++] = cunescape_length(w, l);
|
|
|
|
if (!c) {
|
|
|
|
r = -ENOMEM;
|
2010-07-07 20:59:20 +02:00
|
|
|
goto fail;
|
2012-03-12 22:22:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!utf8_is_valid(c)) {
|
|
|
|
log_error("[%s:%u] Path is not UTF-8 clean, ignoring assignment: %s", filename, line, rvalue);
|
|
|
|
r = 0;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-07-07 20:59:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n[k] = NULL;
|
|
|
|
|
|
|
|
if (!n[0]) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Invalid command line, ignoring: %s", filename, line, rvalue);
|
2012-03-12 22:22:16 +01:00
|
|
|
r = 0;
|
|
|
|
goto fail;
|
2010-07-07 20:59:20 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
if (!path) {
|
|
|
|
path = strdup(n[0]);
|
|
|
|
if (!path) {
|
|
|
|
r = -ENOMEM;
|
2010-07-07 20:59:20 +02:00
|
|
|
goto fail;
|
2012-03-12 22:22:16 +01:00
|
|
|
}
|
|
|
|
}
|
2010-05-19 21:51:53 +02:00
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
assert(path_is_absolute(path));
|
2010-05-19 21:51:53 +02:00
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
nce = new0(ExecCommand, 1);
|
|
|
|
if (!nce) {
|
|
|
|
r = -ENOMEM;
|
2010-07-07 20:59:20 +02:00
|
|
|
goto fail;
|
2012-03-12 22:22:16 +01:00
|
|
|
}
|
2010-07-07 20:59:20 +02:00
|
|
|
|
|
|
|
nce->argv = n;
|
|
|
|
nce->path = path;
|
2010-07-12 02:25:42 +02:00
|
|
|
nce->ignore = ignore;
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
path_kill_slashes(nce->path);
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
exec_command_append_list(e, nce);
|
2010-05-24 05:25:33 +02:00
|
|
|
|
2010-07-07 20:59:20 +02:00
|
|
|
rvalue = state;
|
|
|
|
}
|
2010-01-26 04:18:44 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2010-05-19 21:51:53 +02:00
|
|
|
n[k] = NULL;
|
|
|
|
strv_free(n);
|
|
|
|
free(path);
|
2010-01-26 04:18:44 +01:00
|
|
|
free(nce);
|
|
|
|
|
2012-03-12 22:22:16 +01:00
|
|
|
return r;
|
2010-01-26 04:18:44 +01:00
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type");
|
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier");
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_socket_bindtodevice(
|
2010-01-27 04:31:52 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-27 04:31:52 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Socket *s = data;
|
|
|
|
char *n;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
if (rvalue[0] && !streq(rvalue, "*")) {
|
|
|
|
if (!(n = strdup(rvalue)))
|
|
|
|
return -ENOMEM;
|
|
|
|
} else
|
|
|
|
n = NULL;
|
|
|
|
|
|
|
|
free(s->bind_to_device);
|
|
|
|
s->bind_to_device = n;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier");
|
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier");
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_io_class(
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
ExecContext *c = data;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2010-04-13 02:22:41 +02:00
|
|
|
if ((x = ioprio_class_from_string(rvalue)) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse IO scheduling class, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-04-13 02:22:41 +02:00
|
|
|
}
|
2010-01-30 01:55:42 +01:00
|
|
|
|
|
|
|
c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
|
|
|
|
c->ioprio_set = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_io_priority(
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
ExecContext *c = data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
if (safe_atoi(rvalue, &i) < 0 || i < 0 || i >= IOPRIO_BE_NR) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse io priority, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-01-28 02:06:20 +01:00
|
|
|
}
|
|
|
|
|
2010-01-30 01:55:42 +01:00
|
|
|
c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
|
|
|
|
c->ioprio_set = true;
|
|
|
|
|
2010-01-28 02:06:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_cpu_sched_policy(
|
2010-01-29 20:46:22 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-29 20:46:22 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2010-01-30 01:55:42 +01:00
|
|
|
|
|
|
|
ExecContext *c = data;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2010-04-13 02:22:41 +02:00
|
|
|
if ((x = sched_policy_from_string(rvalue)) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse CPU scheduling policy, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-04-13 02:22:41 +02:00
|
|
|
}
|
2010-01-30 01:55:42 +01:00
|
|
|
|
|
|
|
c->cpu_sched_policy = x;
|
|
|
|
c->cpu_sched_set = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_cpu_sched_prio(
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
2010-01-29 20:46:22 +01:00
|
|
|
|
|
|
|
ExecContext *c = data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2010-01-30 01:55:42 +01:00
|
|
|
/* On Linux RR/FIFO have the same range */
|
|
|
|
if (safe_atoi(rvalue, &i) < 0 || i < sched_get_priority_min(SCHED_RR) || i > sched_get_priority_max(SCHED_RR)) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse CPU scheduling priority, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-01-30 01:55:42 +01:00
|
|
|
}
|
2010-01-29 20:46:22 +01:00
|
|
|
|
2010-01-30 01:55:42 +01:00
|
|
|
c->cpu_sched_priority = i;
|
|
|
|
c->cpu_sched_set = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_cpu_affinity(
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
ExecContext *c = data;
|
|
|
|
char *w;
|
|
|
|
size_t l;
|
|
|
|
char *state;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2010-07-07 20:58:41 +02:00
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
2010-01-30 01:55:42 +01:00
|
|
|
char *t;
|
|
|
|
int r;
|
|
|
|
unsigned cpu;
|
|
|
|
|
|
|
|
if (!(t = strndup(w, l)))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-07-07 01:10:27 +02:00
|
|
|
r = safe_atou(t, &cpu);
|
|
|
|
free(t);
|
|
|
|
|
2010-07-04 16:44:58 +02:00
|
|
|
if (!(c->cpuset))
|
|
|
|
if (!(c->cpuset = cpu_set_malloc(&c->cpuset_ncpus)))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (r < 0 || cpu >= c->cpuset_ncpus) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse CPU affinity, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-01-29 20:46:22 +01:00
|
|
|
}
|
2010-01-30 01:55:42 +01:00
|
|
|
|
2010-07-04 16:44:58 +02:00
|
|
|
CPU_SET_S(cpu, CPU_ALLOC_SIZE(c->cpuset_ncpus), c->cpuset);
|
2010-01-29 20:46:22 +01:00
|
|
|
}
|
|
|
|
|
2010-01-30 01:55:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_capabilities(
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
ExecContext *c = data;
|
|
|
|
cap_t cap;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
if (!(cap = cap_from_text(rvalue))) {
|
|
|
|
if (errno == ENOMEM)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse capabilities, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-01-30 01:55:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c->capabilities)
|
|
|
|
cap_free(c->capabilities);
|
|
|
|
c->capabilities = cap;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_secure_bits(
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
ExecContext *c = data;
|
|
|
|
char *w;
|
|
|
|
size_t l;
|
|
|
|
char *state;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2010-07-07 20:58:41 +02:00
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
2010-01-30 01:55:42 +01:00
|
|
|
if (first_word(w, "keep-caps"))
|
|
|
|
c->secure_bits |= SECURE_KEEP_CAPS;
|
|
|
|
else if (first_word(w, "keep-caps-locked"))
|
|
|
|
c->secure_bits |= SECURE_KEEP_CAPS_LOCKED;
|
|
|
|
else if (first_word(w, "no-setuid-fixup"))
|
|
|
|
c->secure_bits |= SECURE_NO_SETUID_FIXUP;
|
|
|
|
else if (first_word(w, "no-setuid-fixup-locked"))
|
|
|
|
c->secure_bits |= SECURE_NO_SETUID_FIXUP_LOCKED;
|
|
|
|
else if (first_word(w, "noroot"))
|
|
|
|
c->secure_bits |= SECURE_NOROOT;
|
|
|
|
else if (first_word(w, "noroot-locked"))
|
|
|
|
c->secure_bits |= SECURE_NOROOT_LOCKED;
|
2010-01-29 20:46:22 +01:00
|
|
|
else {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse secure bits, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-01-29 20:46:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-30 01:55:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-24 04:00:56 +02:00
|
|
|
int config_parse_bounding_set(
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2012-05-24 04:00:56 +02:00
|
|
|
uint64_t *capability_bounding_set_drop = data;
|
2010-01-30 01:55:42 +01:00
|
|
|
char *w;
|
|
|
|
size_t l;
|
|
|
|
char *state;
|
2011-03-18 03:13:15 +01:00
|
|
|
bool invert = false;
|
|
|
|
uint64_t sum = 0;
|
2010-01-30 01:55:42 +01:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-03-18 03:13:15 +01:00
|
|
|
if (rvalue[0] == '~') {
|
|
|
|
invert = true;
|
|
|
|
rvalue++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that we store this inverted internally, since the
|
|
|
|
* kernel wants it like this. But we actually expose it
|
|
|
|
* non-inverted everywhere to have a fully normalized
|
|
|
|
* interface. */
|
|
|
|
|
2010-07-07 20:58:41 +02:00
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
2010-01-30 01:55:42 +01:00
|
|
|
char *t;
|
|
|
|
int r;
|
|
|
|
cap_value_t cap;
|
|
|
|
|
2012-05-24 04:00:56 +02:00
|
|
|
t = strndup(w, l);
|
|
|
|
if (!t)
|
2010-01-30 01:55:42 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = cap_from_name(t, &cap);
|
|
|
|
free(t);
|
|
|
|
|
|
|
|
if (r < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse capability bounding set, ignoring: %s", filename, line, rvalue);
|
2012-07-17 04:17:53 +02:00
|
|
|
continue;
|
2010-01-30 01:55:42 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 03:13:15 +01:00
|
|
|
sum |= ((uint64_t) 1ULL) << (uint64_t) cap;
|
2010-01-30 01:55:42 +01:00
|
|
|
}
|
2010-01-29 20:46:22 +01:00
|
|
|
|
2011-03-18 03:13:15 +01:00
|
|
|
if (invert)
|
2012-05-24 04:00:56 +02:00
|
|
|
*capability_bounding_set_drop |= sum;
|
2011-03-18 03:13:15 +01:00
|
|
|
else
|
2012-05-24 04:00:56 +02:00
|
|
|
*capability_bounding_set_drop |= ~sum;
|
2011-03-18 03:13:15 +01:00
|
|
|
|
2010-01-29 20:46:22 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_limit(
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-01-30 01:55:42 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
struct rlimit **rl = data;
|
|
|
|
unsigned long long u;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
rl += ltype;
|
|
|
|
|
2011-04-04 18:15:13 +02:00
|
|
|
if (streq(rvalue, "infinity"))
|
|
|
|
u = (unsigned long long) RLIM_INFINITY;
|
|
|
|
else if (safe_atollu(rvalue, &u) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse resource value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-01-30 01:55:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!*rl)
|
|
|
|
if (!(*rl = new(struct rlimit, 1)))
|
|
|
|
return -ENOMEM;
|
2010-01-29 20:46:22 +01:00
|
|
|
|
2010-01-30 01:55:42 +01:00
|
|
|
(*rl)->rlim_cur = (*rl)->rlim_max = (rlim_t) u;
|
2010-01-29 20:46:22 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_unit_cgroup(
|
2010-03-31 16:29:55 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-03-31 16:29:55 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Unit *u = userdata;
|
|
|
|
char *w;
|
|
|
|
size_t l;
|
|
|
|
char *state;
|
|
|
|
|
2010-07-07 20:58:41 +02:00
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
2011-06-30 02:39:29 +02:00
|
|
|
char *t, *k;
|
2010-03-31 16:29:55 +02:00
|
|
|
int r;
|
|
|
|
|
2011-06-30 02:39:29 +02:00
|
|
|
t = strndup(w, l);
|
|
|
|
if (!t)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
k = unit_full_printf(u, t);
|
|
|
|
free(t);
|
|
|
|
|
|
|
|
if (!k)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
t = cunescape(k);
|
|
|
|
free(k);
|
|
|
|
|
|
|
|
if (!t)
|
2010-03-31 16:29:55 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = unit_add_cgroup_from_text(u, t);
|
|
|
|
free(t);
|
|
|
|
|
2010-08-17 03:30:53 +02:00
|
|
|
if (r < 0) {
|
|
|
|
log_error("[%s:%u] Failed to parse cgroup value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-31 16:29:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-21 05:23:12 +02:00
|
|
|
#ifdef HAVE_SYSV_COMPAT
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_sysv_priority(
|
2010-04-06 02:40:10 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-04-06 02:40:10 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
int *priority = data;
|
2011-01-22 02:18:59 +01:00
|
|
|
int i;
|
2010-04-06 02:40:10 +02:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-01-22 02:18:59 +01:00
|
|
|
if (safe_atoi(rvalue, &i) < 0 || i < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse SysV start priority, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-04-06 02:40:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*priority = (int) i;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-21 05:23:12 +02:00
|
|
|
#endif
|
2010-04-06 02:40:10 +02:00
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_fsck_passno(
|
2010-10-20 14:22:23 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-10-20 14:22:23 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
int *passno = data;
|
2011-01-22 02:18:59 +01:00
|
|
|
int i;
|
2010-10-20 14:22:23 +02:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-01-22 02:18:59 +01:00
|
|
|
if (safe_atoi(rvalue, &i) || i < 0) {
|
2010-10-20 14:22:23 +02:00
|
|
|
log_error("[%s:%u] Failed to parse fsck pass number, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*passno = (int) i;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode");
|
2010-04-08 00:52:14 +02:00
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_kill_signal(
|
2010-07-10 04:49:37 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-07-10 04:49:37 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
int *sig = data;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(sig);
|
|
|
|
|
2010-10-22 16:11:50 +02:00
|
|
|
if ((r = signal_from_string_try_harder(rvalue)) <= 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse kill signal, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-07-10 04:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*sig = r;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_exec_mount_flags(
|
2010-04-21 22:15:06 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-04-21 22:15:06 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
ExecContext *c = data;
|
|
|
|
char *w;
|
|
|
|
size_t l;
|
|
|
|
char *state;
|
|
|
|
unsigned long flags = 0;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2010-07-07 20:58:41 +02:00
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
2010-11-14 19:58:33 +01:00
|
|
|
if (strncmp(w, "shared", MAX(l, 6U)) == 0)
|
2010-04-21 22:15:06 +02:00
|
|
|
flags |= MS_SHARED;
|
2010-11-14 19:58:33 +01:00
|
|
|
else if (strncmp(w, "slave", MAX(l, 5U)) == 0)
|
2010-04-21 22:15:06 +02:00
|
|
|
flags |= MS_SLAVE;
|
2010-11-14 19:58:33 +01:00
|
|
|
else if (strncmp(w, "private", MAX(l, 7U)) == 0)
|
2010-04-21 22:15:06 +02:00
|
|
|
flags |= MS_PRIVATE;
|
|
|
|
else {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse mount flags, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-04-21 22:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c->mount_flags = flags;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_timer(
|
2010-05-24 01:45:54 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-05-24 01:45:54 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Timer *t = data;
|
|
|
|
usec_t u;
|
|
|
|
TimerValue *v;
|
|
|
|
TimerBase b;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
if ((b = timer_base_from_string(lvalue)) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse timer base, ignoring: %s", filename, line, lvalue);
|
|
|
|
return 0;
|
2010-05-24 01:45:54 +02:00
|
|
|
}
|
|
|
|
|
2011-01-22 02:18:59 +01:00
|
|
|
if (parse_usec(rvalue, &u) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse timer value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-05-24 01:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(v = new0(TimerValue, 1)))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
v->base = b;
|
|
|
|
v->value = u;
|
|
|
|
|
|
|
|
LIST_PREPEND(TimerValue, value, t->values, v);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_timer_unit(
|
2010-05-24 01:45:54 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-05-24 01:45:54 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Timer *t = data;
|
|
|
|
int r;
|
2010-07-08 02:43:18 +02:00
|
|
|
DBusError error;
|
2012-01-06 23:08:54 +01:00
|
|
|
Unit *u;
|
2010-07-08 02:43:18 +02:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
2010-05-24 01:45:54 +02:00
|
|
|
|
|
|
|
if (endswith(rvalue, ".timer")) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Unit cannot be of type timer, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-05-24 01:45:54 +02:00
|
|
|
}
|
|
|
|
|
2012-01-15 12:25:20 +01:00
|
|
|
r = manager_load_unit(UNIT(t)->manager, rvalue, NULL, NULL, &u);
|
2012-01-06 23:08:54 +01:00
|
|
|
if (r < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
|
2010-07-08 02:43:18 +02:00
|
|
|
dbus_error_free(&error);
|
2010-08-17 03:30:53 +02:00
|
|
|
return 0;
|
2010-05-24 01:45:54 +02:00
|
|
|
}
|
|
|
|
|
2012-01-06 23:08:54 +01:00
|
|
|
unit_ref_set(&t->unit, u);
|
|
|
|
|
2010-05-24 01:45:54 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_path_spec(
|
2010-05-24 05:25:33 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-05-24 05:25:33 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Path *p = data;
|
|
|
|
PathSpec *s;
|
|
|
|
PathType b;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
if ((b = path_type_from_string(lvalue)) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse path type, ignoring: %s", filename, line, lvalue);
|
|
|
|
return 0;
|
2010-05-24 05:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!path_is_absolute(rvalue)) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Path is not absolute, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-05-24 05:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(s = new0(PathSpec, 1)))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (!(s->path = strdup(rvalue))) {
|
|
|
|
free(s);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
path_kill_slashes(s->path);
|
|
|
|
|
|
|
|
s->type = b;
|
|
|
|
s->inotify_fd = -1;
|
|
|
|
|
|
|
|
LIST_PREPEND(PathSpec, spec, p->specs, s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_path_unit(
|
2010-05-24 05:25:33 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-05-24 05:25:33 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Path *t = data;
|
|
|
|
int r;
|
2010-07-08 02:43:18 +02:00
|
|
|
DBusError error;
|
2012-01-06 23:08:54 +01:00
|
|
|
Unit *u;
|
2010-07-08 02:43:18 +02:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
2010-05-24 05:25:33 +02:00
|
|
|
|
|
|
|
if (endswith(rvalue, ".path")) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Unit cannot be of type path, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-05-24 05:25:33 +02:00
|
|
|
}
|
|
|
|
|
2012-01-15 12:25:20 +01:00
|
|
|
if ((r = manager_load_unit(UNIT(t)->manager, rvalue, NULL, &error, &u)) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
|
2010-07-08 02:43:18 +02:00
|
|
|
dbus_error_free(&error);
|
2010-08-17 03:30:53 +02:00
|
|
|
return 0;
|
2010-05-24 05:25:33 +02:00
|
|
|
}
|
|
|
|
|
2012-01-06 23:08:54 +01:00
|
|
|
unit_ref_set(&t->unit, u);
|
|
|
|
|
2010-05-24 05:25:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_socket_service(
|
2010-09-30 02:19:12 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-09-30 02:19:12 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Socket *s = data;
|
|
|
|
int r;
|
|
|
|
DBusError error;
|
2012-01-07 01:21:40 +01:00
|
|
|
Unit *x;
|
2010-09-30 02:19:12 +02:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
2010-10-05 19:49:15 +02:00
|
|
|
if (!endswith(rvalue, ".service")) {
|
|
|
|
log_error("[%s:%u] Unit must be of type service, ignoring: %s", filename, line, rvalue);
|
2010-09-30 02:19:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-15 12:25:20 +01:00
|
|
|
r = manager_load_unit(UNIT(s)->manager, rvalue, NULL, &error, &x);
|
2012-01-07 01:21:40 +01:00
|
|
|
if (r < 0) {
|
2010-09-30 02:19:12 +02:00
|
|
|
log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r));
|
|
|
|
dbus_error_free(&error);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-07 01:21:40 +01:00
|
|
|
unit_ref_set(&s->service, x);
|
|
|
|
|
2010-09-30 02:19:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_service_sockets(
|
2010-10-05 19:49:15 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-10-05 19:49:15 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Service *s = data;
|
|
|
|
int r;
|
|
|
|
char *state, *w;
|
|
|
|
size_t l;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
2012-01-06 23:08:54 +01:00
|
|
|
char *t, *k;
|
2010-10-05 19:49:15 +02:00
|
|
|
|
2012-01-06 23:08:54 +01:00
|
|
|
t = strndup(w, l);
|
|
|
|
if (!t)
|
2010-10-05 19:49:15 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-01-06 23:08:54 +01:00
|
|
|
k = unit_name_printf(UNIT(s), t);
|
2010-10-05 19:49:15 +02:00
|
|
|
free(t);
|
|
|
|
|
2012-01-06 23:08:54 +01:00
|
|
|
if (!k)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (!endswith(k, ".socket")) {
|
|
|
|
log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue);
|
|
|
|
free(k);
|
2010-10-05 19:49:15 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-01-06 23:08:54 +01:00
|
|
|
r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, NULL, true);
|
|
|
|
if (r < 0)
|
|
|
|
log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r));
|
2010-10-05 19:49:15 +02:00
|
|
|
|
2012-01-06 23:08:54 +01:00
|
|
|
r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, NULL, true);
|
|
|
|
if (r < 0)
|
2010-10-05 19:49:15 +02:00
|
|
|
return r;
|
2012-01-06 23:08:54 +01:00
|
|
|
|
|
|
|
free(k);
|
2010-10-05 19:49:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-14 17:07:07 +02:00
|
|
|
int config_parse_service_timeout(
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Service *s = userdata;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(s);
|
|
|
|
|
|
|
|
r = config_parse_usec(filename, line, section, lvalue, ltype, rvalue, data, userdata);
|
|
|
|
|
|
|
|
if (!r)
|
|
|
|
s->timeout_defined = true;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_unit_env_file(
|
2010-06-18 06:06:24 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-06-18 06:06:24 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2011-03-04 03:44:43 +01:00
|
|
|
char ***env = data, **k;
|
2011-07-01 01:13:47 +02:00
|
|
|
Unit *u = userdata;
|
|
|
|
char *s;
|
2010-06-18 06:06:24 +02:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-07-01 01:13:47 +02:00
|
|
|
s = unit_full_printf(u, rvalue);
|
|
|
|
if (!s)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (!path_is_absolute(s[0] == '-' ? s + 1 : s)) {
|
|
|
|
log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename, line, s);
|
|
|
|
free(s);
|
2011-01-06 01:39:08 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-01 01:13:47 +02:00
|
|
|
k = strv_append(*env, s);
|
|
|
|
free(s);
|
|
|
|
if (!k)
|
2011-03-04 03:44:43 +01:00
|
|
|
return -ENOMEM;
|
2010-06-18 06:06:24 +02:00
|
|
|
|
2011-03-04 03:44:43 +01:00
|
|
|
strv_free(*env);
|
|
|
|
*env = k;
|
2010-06-18 06:06:24 +02:00
|
|
|
|
2011-03-04 03:44:43 +01:00
|
|
|
return 0;
|
2010-06-18 06:06:24 +02:00
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_ip_tos(
|
2010-07-01 00:29:17 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-07-01 00:29:17 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
int *ip_tos = data, x;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
if ((x = ip_tos_from_string(rvalue)) < 0)
|
2011-01-22 02:18:59 +01:00
|
|
|
if (safe_atoi(rvalue, &x) < 0) {
|
2010-08-17 03:30:53 +02:00
|
|
|
log_error("[%s:%u] Failed to parse IP TOS value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
2010-07-01 00:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*ip_tos = x;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_unit_condition_path(
|
2010-10-13 02:15:41 +02:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-10-13 02:15:41 +02:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2011-03-25 05:07:20 +01:00
|
|
|
ConditionType cond = ltype;
|
2010-10-13 02:15:41 +02:00
|
|
|
Unit *u = data;
|
2011-03-08 03:04:47 +01:00
|
|
|
bool trigger, negate;
|
2010-10-13 02:15:41 +02:00
|
|
|
Condition *c;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-09-21 00:44:51 +02:00
|
|
|
trigger = rvalue[0] == '|';
|
|
|
|
if (trigger)
|
2011-03-08 03:04:47 +01:00
|
|
|
rvalue++;
|
|
|
|
|
2011-09-21 00:44:51 +02:00
|
|
|
negate = rvalue[0] == '!';
|
|
|
|
if (negate)
|
2010-10-13 02:15:41 +02:00
|
|
|
rvalue++;
|
|
|
|
|
|
|
|
if (!path_is_absolute(rvalue)) {
|
2010-11-10 22:28:19 +01:00
|
|
|
log_error("[%s:%u] Path in condition not absolute, ignoring: %s", filename, line, rvalue);
|
2010-10-13 02:15:41 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-21 00:44:51 +02:00
|
|
|
c = condition_new(cond, rvalue, trigger, negate);
|
|
|
|
if (!c)
|
2010-10-13 02:15:41 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
LIST_PREPEND(Condition, conditions, u->conditions, c);
|
2010-10-13 02:15:41 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_unit_condition_string(
|
2011-02-21 22:07:55 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2011-02-21 22:07:55 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
2011-04-03 18:16:54 +02:00
|
|
|
ConditionType cond = ltype;
|
2011-02-21 22:07:55 +01:00
|
|
|
Unit *u = data;
|
2011-03-08 03:04:47 +01:00
|
|
|
bool trigger, negate;
|
2011-02-21 22:07:55 +01:00
|
|
|
Condition *c;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-03-08 03:04:47 +01:00
|
|
|
if ((trigger = rvalue[0] == '|'))
|
|
|
|
rvalue++;
|
|
|
|
|
2011-02-21 22:07:55 +01:00
|
|
|
if ((negate = rvalue[0] == '!'))
|
|
|
|
rvalue++;
|
|
|
|
|
2011-04-03 18:16:54 +02:00
|
|
|
if (!(c = condition_new(cond, rvalue, trigger, negate)))
|
2011-02-21 22:07:55 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
LIST_PREPEND(Condition, conditions, u->conditions, c);
|
2011-02-21 22:07:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
int config_parse_unit_condition_null(
|
2010-11-10 22:28:19 +01:00
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
2011-03-25 05:07:20 +01:00
|
|
|
int ltype,
|
2010-11-10 22:28:19 +01:00
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Unit *u = data;
|
|
|
|
Condition *c;
|
2011-03-08 03:04:47 +01:00
|
|
|
bool trigger, negate;
|
2010-11-10 22:28:19 +01:00
|
|
|
int b;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
2011-03-08 03:04:47 +01:00
|
|
|
if ((trigger = rvalue[0] == '|'))
|
|
|
|
rvalue++;
|
|
|
|
|
2010-11-10 22:28:19 +01:00
|
|
|
if ((negate = rvalue[0] == '!'))
|
|
|
|
rvalue++;
|
|
|
|
|
|
|
|
if ((b = parse_boolean(rvalue)) < 0) {
|
|
|
|
log_error("[%s:%u] Failed to parse boolean value in condition, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!b)
|
|
|
|
negate = !negate;
|
|
|
|
|
2011-03-08 03:04:47 +01:00
|
|
|
if (!(c = condition_new(CONDITION_NULL, NULL, trigger, negate)))
|
2010-11-10 22:28:19 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
LIST_PREPEND(Condition, conditions, u->conditions, c);
|
2010-11-10 22:28:19 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier");
|
2012-02-09 13:05:23 +01:00
|
|
|
DEFINE_CONFIG_PARSE_ENUM(config_parse_start_limit_action, start_limit_action, StartLimitAction, "Failed to parse start limit action specifier");
|
2010-06-18 23:12:48 +02:00
|
|
|
|
2011-08-20 00:20:41 +02:00
|
|
|
int config_parse_unit_cgroup_attr(
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Unit *u = data;
|
|
|
|
char **l;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
l = strv_split_quoted(rvalue);
|
|
|
|
if (!l)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (strv_length(l) != 2) {
|
|
|
|
log_error("[%s:%u] Failed to parse cgroup attribute value, ignoring: %s", filename, line, rvalue);
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = unit_add_cgroup_attribute(u, NULL, l[0], l[1], NULL);
|
|
|
|
strv_free(l);
|
|
|
|
|
|
|
|
if (r < 0) {
|
|
|
|
log_error("[%s:%u] Failed to add cgroup attribute value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int config_parse_unit_cpu_shares(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) {
|
|
|
|
Unit *u = data;
|
|
|
|
int r;
|
|
|
|
unsigned long ul;
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
if (safe_atolu(rvalue, &ul) < 0 || ul < 1) {
|
|
|
|
log_error("[%s:%u] Failed to parse CPU shares value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asprintf(&t, "%lu", ul) < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = unit_add_cgroup_attribute(u, "cpu", "cpu.shares", t, NULL);
|
|
|
|
free(t);
|
|
|
|
|
|
|
|
if (r < 0) {
|
|
|
|
log_error("[%s:%u] Failed to add cgroup attribute value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int config_parse_unit_memory_limit(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) {
|
|
|
|
Unit *u = data;
|
|
|
|
int r;
|
|
|
|
off_t sz;
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
if (parse_bytes(rvalue, &sz) < 0 || sz <= 0) {
|
|
|
|
log_error("[%s:%u] Failed to parse memory limit value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asprintf(&t, "%llu", (unsigned long long) sz) < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = unit_add_cgroup_attribute(u,
|
|
|
|
"memory",
|
|
|
|
streq(lvalue, "MemorySoftLimit") ? "memory.soft_limit_in_bytes" : "memory.limit_in_bytes",
|
|
|
|
t, NULL);
|
|
|
|
free(t);
|
|
|
|
|
|
|
|
if (r < 0) {
|
|
|
|
log_error("[%s:%u] Failed to add cgroup attribute value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int device_map(const char *controller, const char *name, const char *value, char **ret) {
|
|
|
|
char **l;
|
|
|
|
|
2011-08-20 01:38:10 +02:00
|
|
|
assert(controller);
|
|
|
|
assert(name);
|
|
|
|
assert(value);
|
|
|
|
assert(ret);
|
|
|
|
|
2011-08-20 00:20:41 +02:00
|
|
|
l = strv_split_quoted(value);
|
|
|
|
if (!l)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
assert(strv_length(l) >= 1);
|
|
|
|
|
|
|
|
if (streq(l[0], "*")) {
|
|
|
|
|
|
|
|
if (asprintf(ret, "a *:*%s%s",
|
|
|
|
isempty(l[1]) ? "" : " ", strempty(l[1])) < 0) {
|
|
|
|
strv_free(l);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2011-08-20 01:38:10 +02:00
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(l[0], &st) < 0) {
|
2011-08-20 00:20:41 +02:00
|
|
|
log_warning("Couldn't stat device %s", l[0]);
|
|
|
|
strv_free(l);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode)) {
|
|
|
|
log_warning("%s is not a device.", l[0]);
|
|
|
|
strv_free(l);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (asprintf(ret, "%c %u:%u%s%s",
|
|
|
|
S_ISCHR(st.st_mode) ? 'c' : 'b',
|
|
|
|
major(st.st_rdev), minor(st.st_rdev),
|
|
|
|
isempty(l[1]) ? "" : " ", strempty(l[1])) < 0) {
|
|
|
|
|
|
|
|
strv_free(l);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int config_parse_unit_device_allow(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) {
|
|
|
|
Unit *u = data;
|
|
|
|
char **l;
|
|
|
|
int r;
|
|
|
|
unsigned k;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
l = strv_split_quoted(rvalue);
|
|
|
|
if (!l)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
k = strv_length(l);
|
|
|
|
if (k < 1 || k > 2) {
|
|
|
|
log_error("[%s:%u] Failed to parse device value, ignoring: %s", filename, line, rvalue);
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!streq(l[0], "*") && !path_startswith(l[0], "/dev")) {
|
|
|
|
log_error("[%s:%u] Device node path not absolute, ignoring: %s", filename, line, rvalue);
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isempty(l[1]) && !in_charset(l[1], "rwm")) {
|
|
|
|
log_error("[%s:%u] Device access string invalid, ignoring: %s", filename, line, rvalue);
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
strv_free(l);
|
|
|
|
|
|
|
|
r = unit_add_cgroup_attribute(u, "devices",
|
|
|
|
streq(lvalue, "DeviceAllow") ? "devices.allow" : "devices.deny",
|
|
|
|
rvalue, device_map);
|
|
|
|
|
|
|
|
if (r < 0) {
|
|
|
|
log_error("[%s:%u] Failed to add cgroup attribute value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-20 01:38:10 +02:00
|
|
|
static int blkio_map(const char *controller, const char *name, const char *value, char **ret) {
|
|
|
|
struct stat st;
|
|
|
|
char **l;
|
2011-08-21 00:28:30 +02:00
|
|
|
dev_t d;
|
2011-08-20 01:38:10 +02:00
|
|
|
|
|
|
|
assert(controller);
|
|
|
|
assert(name);
|
|
|
|
assert(value);
|
|
|
|
assert(ret);
|
|
|
|
|
|
|
|
l = strv_split_quoted(value);
|
|
|
|
if (!l)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
assert(strv_length(l) == 2);
|
|
|
|
|
|
|
|
if (stat(l[0], &st) < 0) {
|
|
|
|
log_warning("Couldn't stat device %s", l[0]);
|
|
|
|
strv_free(l);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
2011-08-21 00:28:30 +02:00
|
|
|
if (S_ISBLK(st.st_mode))
|
|
|
|
d = st.st_rdev;
|
|
|
|
else if (major(st.st_dev) != 0) {
|
|
|
|
/* If this is not a device node then find the block
|
|
|
|
* device this file is stored on */
|
|
|
|
d = st.st_dev;
|
|
|
|
|
|
|
|
/* If this is a partition, try to get the originating
|
|
|
|
* block device */
|
|
|
|
block_get_whole_disk(d, &d);
|
|
|
|
} else {
|
|
|
|
log_warning("%s is not a block device and file system block device cannot be determined or is not local.", l[0]);
|
2011-08-20 01:38:10 +02:00
|
|
|
strv_free(l);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2011-08-21 00:28:30 +02:00
|
|
|
if (asprintf(ret, "%u:%u %s", major(d), minor(d), l[1]) < 0) {
|
2011-08-20 01:38:10 +02:00
|
|
|
strv_free(l);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int config_parse_unit_blkio_weight(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) {
|
|
|
|
Unit *u = data;
|
|
|
|
int r;
|
|
|
|
unsigned long ul;
|
|
|
|
const char *device = NULL, *weight;
|
|
|
|
unsigned k;
|
|
|
|
char *t, **l;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
l = strv_split_quoted(rvalue);
|
|
|
|
if (!l)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
k = strv_length(l);
|
|
|
|
if (k < 1 || k > 2) {
|
|
|
|
log_error("[%s:%u] Failed to parse weight value, ignoring: %s", filename, line, rvalue);
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k == 1)
|
|
|
|
weight = l[0];
|
|
|
|
else {
|
|
|
|
device = l[0];
|
|
|
|
weight = l[1];
|
|
|
|
}
|
|
|
|
|
2011-08-21 00:28:30 +02:00
|
|
|
if (device && !path_is_absolute(device)) {
|
2011-08-20 01:38:10 +02:00
|
|
|
log_error("[%s:%u] Failed to parse block device node value, ignoring: %s", filename, line, rvalue);
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (safe_atolu(weight, &ul) < 0 || ul < 10 || ul > 1000) {
|
|
|
|
log_error("[%s:%u] Failed to parse block IO weight value, ignoring: %s", filename, line, rvalue);
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device)
|
|
|
|
r = asprintf(&t, "%s %lu", device, ul);
|
|
|
|
else
|
|
|
|
r = asprintf(&t, "%lu", ul);
|
|
|
|
strv_free(l);
|
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (device)
|
|
|
|
r = unit_add_cgroup_attribute(u, "blkio", "blkio.weight_device", t, blkio_map);
|
|
|
|
else
|
|
|
|
r = unit_add_cgroup_attribute(u, "blkio", "blkio.weight", t, NULL);
|
|
|
|
free(t);
|
|
|
|
|
|
|
|
if (r < 0) {
|
|
|
|
log_error("[%s:%u] Failed to add cgroup attribute value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int config_parse_unit_blkio_bandwidth(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata) {
|
|
|
|
Unit *u = data;
|
|
|
|
int r;
|
|
|
|
off_t bytes;
|
|
|
|
unsigned k;
|
|
|
|
char *t, **l;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
l = strv_split_quoted(rvalue);
|
|
|
|
if (!l)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
k = strv_length(l);
|
|
|
|
if (k != 2) {
|
|
|
|
log_error("[%s:%u] Failed to parse bandwidth value, ignoring: %s", filename, line, rvalue);
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-21 00:28:30 +02:00
|
|
|
if (!path_is_absolute(l[0])) {
|
2011-08-20 01:38:10 +02:00
|
|
|
log_error("[%s:%u] Failed to parse block device node value, ignoring: %s", filename, line, rvalue);
|
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parse_bytes(l[1], &bytes) < 0 || bytes <= 0) {
|
2012-07-15 10:41:40 +02:00
|
|
|
log_error("[%s:%u] Failed to parse block IO bandwidth value, ignoring: %s", filename, line, rvalue);
|
2011-08-20 01:38:10 +02:00
|
|
|
strv_free(l);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = asprintf(&t, "%s %llu", l[0], (unsigned long long) bytes);
|
|
|
|
strv_free(l);
|
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = unit_add_cgroup_attribute(u, "blkio",
|
|
|
|
streq(lvalue, "BlockIOReadBandwidth") ? "blkio.read_bps_device" : "blkio.write_bps_device",
|
|
|
|
t, blkio_map);
|
|
|
|
free(t);
|
|
|
|
|
|
|
|
if (r < 0) {
|
|
|
|
log_error("[%s:%u] Failed to add cgroup attribute value, ignoring: %s", filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-29 14:26:07 +02:00
|
|
|
int config_parse_unit_requires_mounts_for(
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Unit *u = userdata;
|
|
|
|
int r;
|
|
|
|
bool empty_before;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(data);
|
|
|
|
|
|
|
|
empty_before = !u->requires_mounts_for;
|
|
|
|
|
|
|
|
r = config_parse_path_strv(filename, line, section, lvalue, ltype, rvalue, data, userdata);
|
|
|
|
|
|
|
|
/* Make it easy to find units with requires_mounts set */
|
|
|
|
if (empty_before && u->requires_mounts_for)
|
|
|
|
LIST_PREPEND(Unit, has_requires_mounts_for, u->manager->has_requires_mounts_for, u);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2011-08-20 01:38:10 +02:00
|
|
|
|
2012-05-21 15:12:18 +02:00
|
|
|
int config_parse_documentation(
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
Unit *u = userdata;
|
|
|
|
int r;
|
|
|
|
char **a, **b;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(u);
|
|
|
|
|
|
|
|
r = config_parse_unit_strv_printf(filename, line, section, lvalue, ltype, rvalue, data, userdata);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
for (a = b = u->documentation; a && *a; a++) {
|
|
|
|
|
|
|
|
if (is_valid_documentation_url(*a))
|
|
|
|
*(b++) = *a;
|
|
|
|
else {
|
|
|
|
log_error("[%s:%u] Invalid URL, ignoring: %s", filename, line, *a);
|
|
|
|
free(*a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*b = NULL;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-07-17 04:17:53 +02:00
|
|
|
static void syscall_set(uint32_t *p, int nr) {
|
|
|
|
p[nr >> 4] |= 1 << (nr & 31);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void syscall_unset(uint32_t *p, int nr) {
|
|
|
|
p[nr >> 4] &= ~(1 << (nr & 31));
|
|
|
|
}
|
|
|
|
|
|
|
|
int config_parse_syscall_filter(
|
|
|
|
const char *filename,
|
|
|
|
unsigned line,
|
|
|
|
const char *section,
|
|
|
|
const char *lvalue,
|
|
|
|
int ltype,
|
|
|
|
const char *rvalue,
|
|
|
|
void *data,
|
|
|
|
void *userdata) {
|
|
|
|
|
|
|
|
ExecContext *c = data;
|
|
|
|
Unit *u = userdata;
|
|
|
|
bool invert;
|
|
|
|
char *w;
|
|
|
|
size_t l;
|
|
|
|
char *state;
|
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(lvalue);
|
|
|
|
assert(rvalue);
|
|
|
|
assert(u);
|
|
|
|
|
|
|
|
if (rvalue[0] == '~') {
|
|
|
|
invert = true;
|
|
|
|
rvalue++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!c->syscall_filter) {
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
n = (syscall_max() + 31) >> 4;
|
|
|
|
c->syscall_filter = new(uint32_t, n);
|
|
|
|
if (!c->syscall_filter)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(c->syscall_filter, invert ? 0xFF : 0, n * sizeof(uint32_t));
|
|
|
|
|
|
|
|
/* Add these by default */
|
|
|
|
syscall_set(c->syscall_filter, __NR_execve);
|
|
|
|
syscall_set(c->syscall_filter, __NR_rt_sigreturn);
|
|
|
|
#ifdef __NR_sigreturn
|
|
|
|
syscall_set(c->syscall_filter, __NR_sigreturn);
|
|
|
|
#endif
|
|
|
|
syscall_set(c->syscall_filter, __NR_exit_group);
|
|
|
|
syscall_set(c->syscall_filter, __NR_exit);
|
|
|
|
}
|
|
|
|
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
|
|
|
int id;
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
t = strndup(w, l);
|
|
|
|
if (!t)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
id = syscall_from_name(t);
|
|
|
|
free(t);
|
|
|
|
|
|
|
|
if (id < 0) {
|
|
|
|
log_error("[%s:%u] Failed to parse syscall, ignoring: %s", filename, line, rvalue);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invert)
|
|
|
|
syscall_unset(c->syscall_filter, id);
|
|
|
|
else
|
|
|
|
syscall_set(c->syscall_filter, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
c->no_new_privileges = true;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-28 02:06:20 +01:00
|
|
|
#define FOLLOW_MAX 8
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2010-04-15 03:11:11 +02:00
|
|
|
static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
|
2010-01-27 00:15:56 +01:00
|
|
|
unsigned c = 0;
|
2010-01-26 21:39:06 +01:00
|
|
|
int fd, r;
|
|
|
|
FILE *f;
|
2010-01-27 00:15:56 +01:00
|
|
|
char *id = NULL;
|
2010-01-26 21:39:06 +01:00
|
|
|
|
|
|
|
assert(filename);
|
|
|
|
assert(*filename);
|
|
|
|
assert(_f);
|
|
|
|
assert(names);
|
|
|
|
|
2010-01-27 00:15:56 +01:00
|
|
|
/* This will update the filename pointer if the loaded file is
|
|
|
|
* reached by a symlink. The old string will be freed. */
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2010-01-27 00:15:56 +01:00
|
|
|
for (;;) {
|
2010-06-16 01:56:00 +02:00
|
|
|
char *target, *name;
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2010-01-27 00:15:56 +01:00
|
|
|
if (c++ >= FOLLOW_MAX)
|
|
|
|
return -ELOOP;
|
|
|
|
|
2010-01-29 02:07:41 +01:00
|
|
|
path_kill_slashes(*filename);
|
|
|
|
|
2010-01-26 21:39:06 +01:00
|
|
|
/* Add the file name we are currently looking at to
|
2010-07-21 03:13:15 +02:00
|
|
|
* the names of this unit, but only if it is a valid
|
|
|
|
* unit name. */
|
2012-05-07 21:36:12 +02:00
|
|
|
name = path_get_file_name(*filename);
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2011-06-28 02:53:15 +02:00
|
|
|
if (unit_name_is_valid(name, true)) {
|
2010-07-21 03:13:15 +02:00
|
|
|
|
2011-06-28 02:53:15 +02:00
|
|
|
id = set_get(names, name);
|
|
|
|
if (!id) {
|
|
|
|
id = strdup(name);
|
|
|
|
if (!id)
|
2010-07-21 03:13:15 +02:00
|
|
|
return -ENOMEM;
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2011-06-28 02:53:15 +02:00
|
|
|
r = set_put(names, id);
|
|
|
|
if (r < 0) {
|
2010-07-21 03:13:15 +02:00
|
|
|
free(id);
|
|
|
|
return r;
|
|
|
|
}
|
2010-01-26 21:39:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-27 00:15:56 +01:00
|
|
|
/* Try to open the file name, but don't if its a symlink */
|
2012-07-03 16:09:36 +02:00
|
|
|
fd = open(*filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
|
|
|
|
if (fd >= 0)
|
2010-01-26 21:39:06 +01:00
|
|
|
break;
|
|
|
|
|
2010-01-27 00:15:56 +01:00
|
|
|
if (errno != ELOOP)
|
|
|
|
return -errno;
|
|
|
|
|
2010-01-26 21:39:06 +01:00
|
|
|
/* Hmm, so this is a symlink. Let's read the name, and follow it manually */
|
2012-07-03 16:09:36 +02:00
|
|
|
r = readlink_and_make_absolute(*filename, &target);
|
|
|
|
if (r < 0)
|
2010-01-27 00:15:56 +01:00
|
|
|
return r;
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2010-01-27 00:15:56 +01:00
|
|
|
free(*filename);
|
2010-06-16 01:56:00 +02:00
|
|
|
*filename = target;
|
2010-01-26 21:39:06 +01:00
|
|
|
}
|
|
|
|
|
2012-07-03 16:09:36 +02:00
|
|
|
f = fdopen(fd, "re");
|
|
|
|
if (!f) {
|
2010-01-26 21:39:06 +01:00
|
|
|
r = -errno;
|
2010-04-15 03:11:11 +02:00
|
|
|
close_nointr_nofail(fd);
|
2010-01-27 00:15:56 +01:00
|
|
|
return r;
|
2010-01-26 21:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
*_f = f;
|
2010-04-15 03:11:11 +02:00
|
|
|
*_final = id;
|
2010-01-27 00:15:56 +01:00
|
|
|
return 0;
|
2010-01-26 21:39:06 +01:00
|
|
|
}
|
|
|
|
|
2010-04-06 02:43:58 +02:00
|
|
|
static int merge_by_names(Unit **u, Set *names, const char *id) {
|
|
|
|
char *k;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(u);
|
|
|
|
assert(*u);
|
|
|
|
assert(names);
|
|
|
|
|
|
|
|
/* Let's try to add in all symlink names we found */
|
|
|
|
while ((k = set_steal_first(names))) {
|
|
|
|
|
|
|
|
/* First try to merge in the other name into our
|
|
|
|
* unit */
|
2012-07-03 16:09:36 +02:00
|
|
|
r = unit_merge_by_name(*u, k);
|
|
|
|
if (r < 0) {
|
2010-04-06 02:43:58 +02:00
|
|
|
Unit *other;
|
|
|
|
|
|
|
|
/* Hmm, we couldn't merge the other unit into
|
|
|
|
* ours? Then let's try it the other way
|
|
|
|
* round */
|
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
other = manager_get_unit((*u)->manager, k);
|
2010-04-06 02:43:58 +02:00
|
|
|
free(k);
|
|
|
|
|
2012-07-03 16:09:36 +02:00
|
|
|
if (other) {
|
|
|
|
r = unit_merge(other, *u);
|
|
|
|
if (r >= 0) {
|
2010-04-06 02:43:58 +02:00
|
|
|
*u = other;
|
|
|
|
return merge_by_names(u, names, NULL);
|
|
|
|
}
|
2012-07-03 16:09:36 +02:00
|
|
|
}
|
2010-04-06 02:43:58 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == k)
|
|
|
|
unit_choose_id(*u, id);
|
|
|
|
|
|
|
|
free(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-10 17:53:17 +02:00
|
|
|
static int load_from_path(Unit *u, const char *path) {
|
2010-01-27 00:15:56 +01:00
|
|
|
int r;
|
2010-01-26 21:39:06 +01:00
|
|
|
Set *symlink_names;
|
2010-04-06 02:43:58 +02:00
|
|
|
FILE *f = NULL;
|
|
|
|
char *filename = NULL, *id = NULL;
|
|
|
|
Unit *merged;
|
2010-07-17 00:57:51 +02:00
|
|
|
struct stat st;
|
2010-04-06 02:43:58 +02:00
|
|
|
|
|
|
|
assert(u);
|
2010-04-10 17:53:17 +02:00
|
|
|
assert(path);
|
2009-11-19 23:13:20 +01:00
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
symlink_names = set_new(string_hash_func, string_compare_func);
|
|
|
|
if (!symlink_names)
|
2010-01-26 21:39:06 +01:00
|
|
|
return -ENOMEM;
|
2009-11-19 23:13:20 +01:00
|
|
|
|
2010-02-13 01:07:02 +01:00
|
|
|
if (path_is_absolute(path)) {
|
|
|
|
|
2012-07-03 16:09:36 +02:00
|
|
|
filename = strdup(path);
|
|
|
|
if (!filename) {
|
2010-02-13 01:07:02 +01:00
|
|
|
r = -ENOMEM;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:09:36 +02:00
|
|
|
r = open_follow(&filename, &f, symlink_names, &id);
|
|
|
|
if (r < 0) {
|
2010-02-13 01:07:02 +01:00
|
|
|
free(filename);
|
|
|
|
filename = NULL;
|
|
|
|
|
|
|
|
if (r != -ENOENT)
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
char **p;
|
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
STRV_FOREACH(p, u->manager->lookup_paths.unit_path) {
|
2010-02-13 01:07:02 +01:00
|
|
|
|
|
|
|
/* Instead of opening the path right away, we manually
|
|
|
|
* follow all symlinks and add their name to our unit
|
|
|
|
* name set while doing so */
|
2012-07-03 16:09:36 +02:00
|
|
|
filename = path_make_absolute(path, *p);
|
|
|
|
if (!filename) {
|
2010-02-13 01:07:02 +01:00
|
|
|
r = -ENOMEM;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
if (u->manager->unit_path_cache &&
|
|
|
|
!set_get(u->manager->unit_path_cache, filename))
|
2010-07-11 00:52:00 +02:00
|
|
|
r = -ENOENT;
|
|
|
|
else
|
|
|
|
r = open_follow(&filename, &f, symlink_names, &id);
|
|
|
|
|
|
|
|
if (r < 0) {
|
2010-02-13 01:07:02 +01:00
|
|
|
free(filename);
|
|
|
|
filename = NULL;
|
|
|
|
|
|
|
|
if (r != -ENOENT)
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
/* Empty the symlink names for the next run */
|
2012-07-03 16:09:36 +02:00
|
|
|
set_clear_free(symlink_names);
|
2010-02-13 01:07:02 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-01-26 04:18:44 +01:00
|
|
|
|
2010-02-13 01:07:02 +01:00
|
|
|
if (!filename) {
|
2010-07-21 03:13:15 +02:00
|
|
|
/* Hmm, no suitable file found? */
|
2010-04-06 02:43:58 +02:00
|
|
|
r = 0;
|
2010-01-27 00:15:56 +01:00
|
|
|
goto finish;
|
|
|
|
}
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2010-04-06 02:43:58 +02:00
|
|
|
merged = u;
|
2012-07-03 16:09:36 +02:00
|
|
|
r = merge_by_names(&merged, symlink_names, id);
|
|
|
|
if (r < 0)
|
2010-01-27 00:15:56 +01:00
|
|
|
goto finish;
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2010-04-06 02:43:58 +02:00
|
|
|
if (merged != u) {
|
2012-01-15 12:04:08 +01:00
|
|
|
u->load_state = UNIT_MERGED;
|
2010-04-06 02:43:58 +02:00
|
|
|
r = 0;
|
|
|
|
goto finish;
|
2010-01-26 04:18:44 +01:00
|
|
|
}
|
|
|
|
|
2010-07-17 00:57:51 +02:00
|
|
|
zero(st);
|
|
|
|
if (fstat(fileno(f), &st) < 0) {
|
|
|
|
r = -errno;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2010-10-08 02:31:36 +02:00
|
|
|
if (null_or_empty(&st))
|
2012-01-15 12:04:08 +01:00
|
|
|
u->load_state = UNIT_MASKED;
|
2010-10-08 02:31:36 +02:00
|
|
|
else {
|
|
|
|
/* Now, parse the file contents */
|
2011-08-01 00:43:05 +02:00
|
|
|
r = config_parse(filename, f, UNIT_VTABLE(u)->sections, config_item_perf_lookup, (void*) load_fragment_gperf_lookup, false, u);
|
|
|
|
if (r < 0)
|
2010-10-08 02:31:36 +02:00
|
|
|
goto finish;
|
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
u->load_state = UNIT_LOADED;
|
2010-10-08 02:31:36 +02:00
|
|
|
}
|
2010-01-29 02:07:41 +01:00
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
free(u->fragment_path);
|
|
|
|
u->fragment_path = filename;
|
2010-01-27 00:15:56 +01:00
|
|
|
filename = NULL;
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
u->fragment_mtime = timespec_load(&st.st_mtim);
|
2010-07-17 00:57:51 +02:00
|
|
|
|
2012-05-22 23:08:24 +02:00
|
|
|
if (u->source_path) {
|
|
|
|
if (stat(u->source_path, &st) >= 0)
|
|
|
|
u->source_mtime = timespec_load(&st.st_mtim);
|
|
|
|
else
|
|
|
|
u->source_mtime = 0;
|
|
|
|
}
|
|
|
|
|
2010-04-06 02:43:58 +02:00
|
|
|
r = 0;
|
2010-01-26 21:39:06 +01:00
|
|
|
|
|
|
|
finish:
|
2010-06-15 02:45:26 +02:00
|
|
|
set_free_free(symlink_names);
|
2010-01-27 00:15:56 +01:00
|
|
|
free(filename);
|
|
|
|
|
2010-04-06 02:43:58 +02:00
|
|
|
if (f)
|
|
|
|
fclose(f);
|
|
|
|
|
2010-01-27 00:15:56 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-04-10 17:53:17 +02:00
|
|
|
int unit_load_fragment(Unit *u) {
|
2010-04-06 02:43:58 +02:00
|
|
|
int r;
|
2010-07-21 03:28:10 +02:00
|
|
|
Iterator i;
|
|
|
|
const char *t;
|
2010-01-27 00:15:56 +01:00
|
|
|
|
|
|
|
assert(u);
|
2012-01-15 12:04:08 +01:00
|
|
|
assert(u->load_state == UNIT_STUB);
|
|
|
|
assert(u->id);
|
2010-04-06 02:43:58 +02:00
|
|
|
|
2010-07-21 03:28:10 +02:00
|
|
|
/* First, try to find the unit under its id. We always look
|
|
|
|
* for unit files in the default directories, to make it easy
|
|
|
|
* to override things by placing things in /etc/systemd/system */
|
2012-07-03 16:09:36 +02:00
|
|
|
r = load_from_path(u, u->id);
|
|
|
|
if (r < 0)
|
2010-07-21 03:28:10 +02:00
|
|
|
return r;
|
|
|
|
|
|
|
|
/* Try to find an alias we can load this with */
|
2012-01-15 12:04:08 +01:00
|
|
|
if (u->load_state == UNIT_STUB)
|
|
|
|
SET_FOREACH(t, u->names, i) {
|
2010-07-21 03:28:10 +02:00
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
if (t == u->id)
|
2010-07-21 03:28:10 +02:00
|
|
|
continue;
|
|
|
|
|
2012-07-03 16:09:36 +02:00
|
|
|
r = load_from_path(u, t);
|
|
|
|
if (r < 0)
|
2010-07-21 03:28:10 +02:00
|
|
|
return r;
|
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
if (u->load_state != UNIT_STUB)
|
2010-07-21 03:28:10 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-04-06 02:43:58 +02:00
|
|
|
|
2010-07-21 03:28:10 +02:00
|
|
|
/* And now, try looking for it under the suggested (originally linked) path */
|
2012-01-15 12:04:08 +01:00
|
|
|
if (u->load_state == UNIT_STUB && u->fragment_path) {
|
2010-09-27 20:31:23 +02:00
|
|
|
|
2012-07-03 16:09:36 +02:00
|
|
|
r = load_from_path(u, u->fragment_path);
|
|
|
|
if (r < 0)
|
2010-04-06 02:43:58 +02:00
|
|
|
return r;
|
2010-01-27 00:15:56 +01:00
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
if (u->load_state == UNIT_STUB) {
|
2010-09-27 20:31:23 +02:00
|
|
|
/* Hmm, this didn't work? Then let's get rid
|
|
|
|
* of the fragment path stored for us, so that
|
|
|
|
* we don't point to an invalid location. */
|
2012-01-15 12:04:08 +01:00
|
|
|
free(u->fragment_path);
|
|
|
|
u->fragment_path = NULL;
|
2010-09-27 20:31:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-21 03:28:10 +02:00
|
|
|
/* Look for a template */
|
2012-01-15 12:04:08 +01:00
|
|
|
if (u->load_state == UNIT_STUB && u->instance) {
|
2010-07-21 03:28:10 +02:00
|
|
|
char *k;
|
|
|
|
|
2012-07-03 16:09:36 +02:00
|
|
|
k = unit_name_template(u->id);
|
|
|
|
if (!k)
|
2010-07-21 03:28:10 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = load_from_path(u, k);
|
|
|
|
free(k);
|
2010-01-27 00:15:56 +01:00
|
|
|
|
2010-07-21 03:28:10 +02:00
|
|
|
if (r < 0)
|
2010-04-15 03:11:11 +02:00
|
|
|
return r;
|
2010-02-14 01:08:20 +01:00
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
if (u->load_state == UNIT_STUB)
|
|
|
|
SET_FOREACH(t, u->names, i) {
|
2010-01-26 21:39:06 +01:00
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
if (t == u->id)
|
2010-04-06 02:43:58 +02:00
|
|
|
continue;
|
2010-01-28 02:06:20 +01:00
|
|
|
|
2012-07-03 16:09:36 +02:00
|
|
|
k = unit_name_template(t);
|
|
|
|
if (!k)
|
2010-07-21 03:28:10 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = load_from_path(u, k);
|
|
|
|
free(k);
|
|
|
|
|
|
|
|
if (r < 0)
|
2010-04-06 02:43:58 +02:00
|
|
|
return r;
|
2010-02-14 01:08:20 +01:00
|
|
|
|
2012-01-15 12:04:08 +01:00
|
|
|
if (u->load_state != UNIT_STUB)
|
2010-04-06 02:43:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-01-28 02:06:20 +01:00
|
|
|
}
|
|
|
|
|
2010-04-06 02:43:58 +02:00
|
|
|
return 0;
|
2009-11-19 23:13:20 +01:00
|
|
|
}
|
2010-04-10 17:53:17 +02:00
|
|
|
|
|
|
|
void unit_dump_config_items(FILE *f) {
|
2011-08-01 00:43:05 +02:00
|
|
|
static const struct {
|
|
|
|
const ConfigParserCallback callback;
|
|
|
|
const char *rvalue;
|
|
|
|
} table[] = {
|
|
|
|
{ config_parse_int, "INTEGER" },
|
|
|
|
{ config_parse_unsigned, "UNSIGNED" },
|
2012-01-31 20:53:34 +01:00
|
|
|
{ config_parse_bytes_size, "SIZE" },
|
2011-08-01 00:43:05 +02:00
|
|
|
{ config_parse_bool, "BOOLEAN" },
|
|
|
|
{ config_parse_string, "STRING" },
|
|
|
|
{ config_parse_path, "PATH" },
|
|
|
|
{ config_parse_unit_path_printf, "PATH" },
|
|
|
|
{ config_parse_strv, "STRING [...]" },
|
|
|
|
{ config_parse_exec_nice, "NICE" },
|
|
|
|
{ config_parse_exec_oom_score_adjust, "OOMSCOREADJUST" },
|
|
|
|
{ config_parse_exec_io_class, "IOCLASS" },
|
|
|
|
{ config_parse_exec_io_priority, "IOPRIORITY" },
|
|
|
|
{ config_parse_exec_cpu_sched_policy, "CPUSCHEDPOLICY" },
|
|
|
|
{ config_parse_exec_cpu_sched_prio, "CPUSCHEDPRIO" },
|
|
|
|
{ config_parse_exec_cpu_affinity, "CPUAFFINITY" },
|
|
|
|
{ config_parse_mode, "MODE" },
|
|
|
|
{ config_parse_unit_env_file, "FILE" },
|
|
|
|
{ config_parse_output, "OUTPUT" },
|
|
|
|
{ config_parse_input, "INPUT" },
|
|
|
|
{ config_parse_facility, "FACILITY" },
|
|
|
|
{ config_parse_level, "LEVEL" },
|
|
|
|
{ config_parse_exec_capabilities, "CAPABILITIES" },
|
|
|
|
{ config_parse_exec_secure_bits, "SECUREBITS" },
|
2012-05-24 04:00:56 +02:00
|
|
|
{ config_parse_bounding_set, "BOUNDINGSET" },
|
2011-08-01 00:43:05 +02:00
|
|
|
{ config_parse_limit, "LIMIT" },
|
|
|
|
{ config_parse_unit_cgroup, "CGROUP [...]" },
|
|
|
|
{ config_parse_unit_deps, "UNIT [...]" },
|
|
|
|
{ config_parse_exec, "PATH [ARGUMENT [...]]" },
|
|
|
|
{ config_parse_service_type, "SERVICETYPE" },
|
|
|
|
{ config_parse_service_restart, "SERVICERESTART" },
|
|
|
|
#ifdef HAVE_SYSV_COMPAT
|
|
|
|
{ config_parse_sysv_priority, "SYSVPRIORITY" },
|
|
|
|
#else
|
|
|
|
{ config_parse_warn_compat, "NOTSUPPORTED" },
|
|
|
|
#endif
|
|
|
|
{ config_parse_kill_mode, "KILLMODE" },
|
|
|
|
{ config_parse_kill_signal, "SIGNAL" },
|
|
|
|
{ config_parse_socket_listen, "SOCKET [...]" },
|
|
|
|
{ config_parse_socket_bind, "SOCKETBIND" },
|
|
|
|
{ config_parse_socket_bindtodevice, "NETWORKINTERFACE" },
|
|
|
|
{ config_parse_usec, "SECONDS" },
|
2012-05-31 04:27:03 +02:00
|
|
|
{ config_parse_nsec, "NANOSECONDS" },
|
2011-08-01 00:43:05 +02:00
|
|
|
{ config_parse_path_strv, "PATH [...]" },
|
2012-04-29 14:26:07 +02:00
|
|
|
{ config_parse_unit_requires_mounts_for, "PATH [...]" },
|
2011-08-01 00:43:05 +02:00
|
|
|
{ config_parse_exec_mount_flags, "MOUNTFLAG [...]" },
|
|
|
|
{ config_parse_unit_string_printf, "STRING" },
|
|
|
|
{ config_parse_timer, "TIMER" },
|
|
|
|
{ config_parse_timer_unit, "NAME" },
|
|
|
|
{ config_parse_path_spec, "PATH" },
|
|
|
|
{ config_parse_path_unit, "UNIT" },
|
|
|
|
{ config_parse_notify_access, "ACCESS" },
|
|
|
|
{ config_parse_ip_tos, "TOS" },
|
|
|
|
{ config_parse_unit_condition_path, "CONDITION" },
|
|
|
|
{ config_parse_unit_condition_string, "CONDITION" },
|
|
|
|
{ config_parse_unit_condition_null, "CONDITION" },
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *prev = NULL;
|
|
|
|
const char *i;
|
|
|
|
|
|
|
|
assert(f);
|
2010-04-10 17:53:17 +02:00
|
|
|
|
2011-08-01 00:43:05 +02:00
|
|
|
NULSTR_FOREACH(i, load_fragment_gperf_nulstr) {
|
|
|
|
const char *rvalue = "OTHER", *lvalue;
|
|
|
|
unsigned j;
|
|
|
|
size_t prefix_len;
|
|
|
|
const char *dot;
|
|
|
|
const ConfigPerfItem *p;
|
|
|
|
|
|
|
|
assert_se(p = load_fragment_gperf_lookup(i, strlen(i)));
|
|
|
|
|
|
|
|
dot = strchr(i, '.');
|
|
|
|
lvalue = dot ? dot + 1 : i;
|
|
|
|
prefix_len = dot-i;
|
|
|
|
|
|
|
|
if (dot)
|
|
|
|
if (!prev || strncmp(prev, i, prefix_len+1) != 0) {
|
|
|
|
if (prev)
|
|
|
|
fputc('\n', f);
|
|
|
|
|
|
|
|
fprintf(f, "[%.*s]\n", (int) prefix_len, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < ELEMENTSOF(table); j++)
|
|
|
|
if (p->parse == table[j].callback) {
|
|
|
|
rvalue = table[j].rvalue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(f, "%s=%s\n", lvalue, rvalue);
|
|
|
|
prev = i;
|
|
|
|
}
|
2010-04-10 17:53:17 +02:00
|
|
|
}
|