Commit 7640a5de authored by Lennart Poettering's avatar Lennart Poettering
Browse files

hostnamed: introduce systemd-hostnamed

http://www.freedesktop.org/wiki/Software/systemd/hostnamed
parent 25e3655a
systemd-hostnamed
systemd-binfmt
systemd-getty-generator
systemd-nspawn
......
......@@ -144,7 +144,8 @@ rootlibexec_PROGRAMS = \
systemd-ac-power \
systemd-detect-virt \
systemd-sysctl \
systemd-binfmt
systemd-binfmt \
systemd-hostnamed
systemgenerator_PROGRAMS = \
systemd-getty-generator
......@@ -177,10 +178,12 @@ dist_pkgsysconf_DATA = \
src/system.conf
dist_dbuspolicy_DATA = \
src/org.freedesktop.systemd1.conf
src/org.freedesktop.systemd1.conf \
src/org.freedesktop.hostname1.conf
dist_dbussystemservice_DATA = \
src/org.freedesktop.systemd1.service
src/org.freedesktop.systemd1.service \
src/org.freedesktop.hostname1.service
dist_udevrules_DATA = \
src/99-systemd.rules
......@@ -282,6 +285,7 @@ nodist_systemunit_DATA = \
units/systemd-initctl.service \
units/systemd-logger.service \
units/systemd-shutdownd.service \
units/systemd-hostnamed.service \
units/systemd-kmsg-syslogd.service \
units/systemd-modules-load.service \
units/systemd-vconsole-setup.service \
......@@ -326,6 +330,7 @@ EXTRA_DIST = \
units/systemd-initctl.service.in \
units/systemd-logger.service.in \
units/systemd-shutdownd.service.in \
units/systemd-hostnamed.service.in \
units/systemd-kmsg-syslogd.service.in \
units/systemd-modules-load.service.in \
units/systemd-vconsole-setup.service.in \
......@@ -406,9 +411,12 @@ dist_doc_DATA = \
pkgconfigdata_DATA = \
systemd.pc
polkitpolicy_DATA = \
nodist_polkitpolicy_DATA = \
src/org.freedesktop.systemd1.policy
dist_polkitpolicy_DATA = \
src/org.freedesktop.hostname1.policy
noinst_LTLIBRARIES = \
libsystemd-basic.la \
libsystemd-core.la \
......@@ -571,6 +579,7 @@ MANPAGES = \
man/vconsole.conf.5 \
man/locale.conf.5 \
man/os-release.5 \
man/machine-info.5 \
man/modules-load.d.5 \
man/binfmt.d.5 \
man/sysctl.d.5 \
......@@ -754,6 +763,19 @@ systemd_shutdownd_LDADD = \
libsystemd-basic.la \
libsystemd-daemon.la
systemd_hostnamed_SOURCES = \
src/hostnamed.c \
src/dbus-common.c
systemd_hostnamed_CFLAGS = \
$(AM_CFLAGS) \
$(DBUS_CFLAGS)
systemd_hostnamed_LDADD = \
libsystemd-basic.la \
libsystemd-daemon.la \
$(DBUS_LIBS)
systemd_shutdown_SOURCES = \
src/mount-setup.c \
src/umount.c \
......@@ -1346,9 +1368,10 @@ install-data-hook:
$(LN_S) graphical.target runlevel5.target && \
$(LN_S) reboot.target runlevel6.target )
( cd $(DESTDIR)$(systemunitdir) && \
rm -f default.target ctrl-alt-del.target && \
rm -f default.target ctrl-alt-del.target dbus-org.freedesktop.hostname1.service && \
$(LN_S) graphical.target default.target && \
$(LN_S) reboot.target ctrl-alt-del.target )
$(LN_S) reboot.target ctrl-alt-del.target && \
$(LN_S) systemd-hostnamed.service dbus-org.freedesktop.hostname1.service )
( cd $(DESTDIR)$(systemunitdir)/multi-user.target.wants && \
rm -f getty.target systemd-user-sessions.service systemd-ask-password-wall.path && \
$(LN_S) ../getty.target getty.target && \
......
......@@ -44,7 +44,7 @@
<refnamediv>
<refname>hostname</refname>
<refpurpose>local host name configuration file</refpurpose>
<refpurpose>Local host name configuration file</refpurpose>
</refnamediv>
<refsynopsisdiv>
......@@ -62,10 +62,10 @@
newline-terminated host name string. The
host name may be a free-form string up to 64 characters
in length, however it is recommended that it consists
only of 7bit ASCII characters and no spaces or dots,
and limit itself to the format allowed for DNS domain
only of 7bit ASCII lower-case characters and no spaces or dots,
and limits itself to the format allowed for DNS domain
name labels, even though this is not a
requirement.</para>
strict requirement.</para>
<para>Depending on the operating system other
configuration files might be checked for configuration
......@@ -85,7 +85,10 @@
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sethostname</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
<citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>1</manvolnum></citerefentry>
<citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>
</para>
</refsect1>
......
......@@ -76,7 +76,7 @@
with a globally unique ID in the network, that does
not change even if the local network configuration
changes. Due to this and its greater length it is
a more useful replacement than the
a more useful replacement for the
<citerefentry><refentrytitle>gethostid</refentrytitle><manvolnum>3</manvolnum></citerefentry>
call POSIX specifies.</para>
</refsect1>
......@@ -97,7 +97,9 @@
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>gethostid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>
<citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>
</para>
</refsect1>
......
<?xml version='1.0'?> <!--*-nxml-*-->
<?xml-stylesheet type="text/xsl" href="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!--
This file is part of systemd.
Copyright 2010 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
-->
<refentry id="machine-info">
<refentryinfo>
<title>machine-info</title>
<productname>systemd</productname>
<authorgroup>
<author>
<contrib>Developer</contrib>
<firstname>Lennart</firstname>
<surname>Poettering</surname>
<email>lennart@poettering.net</email>
</author>
</authorgroup>
</refentryinfo>
<refmeta>
<refentrytitle>machine-info</refentrytitle>
<manvolnum>5</manvolnum>
</refmeta>
<refnamediv>
<refname>machine-info</refname>
<refpurpose>Local machine information file</refpurpose>
</refnamediv>
<refsynopsisdiv>
<para><filename>/etc/machine-info</filename></para>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>The <filename>/etc/machine-info</filename> file
contains machine meta data.</para>
<para>The basic file format of
<filename>machine-info</filename> is a
newline-separated list of environment-like
shell-compatible variable assignments. It is possible
to source the configuration from shell scripts,
however, beyond mere variable assignments no shell
features are supported, allowing applications to read
the file without implementing a shell compatible
execution engine.</para>
<para><filename>/etc/machine-info</filename> contains
meta data about the machine that is set by the user or
administrator.</para>
<para>Depending on the operating system other
configuration files might be checked for machine
information as well, however only as fallback.</para>
</refsect1>
<refsect1>
<title>Options</title>
<para>The following machine meta data parameters may
be set using
<filename>/etc/machine-info</filename>:</para>
<variablelist>
<varlistentry>
<term><varname>PRETTY_HOSTNAME=</varname></term>
<listitem><para>A pretty
human-readable UTF8 machine identifier
string. This should contain a name
like <literal>Lennart's
Laptop</literal> which is useful to
present to the user and does not
suffer by the syntax limitations of
internet domain names. If possible the
internet host name as configured in
<filename>/etc/hostname</filename>
should be kept similar to this
one. Example: if this value is
<literal>Lennart's Computer</literal>
an Internet host name of
<literal>lennarts-computer</literal>
might be a good choice. If this
parameter is not set an application
should fall back to the Internet host
name for presentation
purposes.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>ICON_NAME=</varname></term>
<listitem><para>An icon identifying
this machine according to the <ulink
url="http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html">XDG
Icon Naming Specification</ulink>. If
this parameter is not set an
application should fall back to
<literal>computer</literal> or a
similar icon name.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Example</title>
<programlisting>PRETTY_NAME="Lennart's Computer"
ICON_NAME=computer-laptop</programlisting>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>
......@@ -182,10 +182,10 @@
<title>Example</title>
<programlisting>NAME=Fedora
VERSION=15 (Rawhide)
VERSION="15 (Rawhide)"
ID=fedora
VERSION_ID=15
PRETTY_NAME=Fedora 15 (Rawhide)
PRETTY_NAME="Fedora 15 (Rawhide)"
ANSI_COLOR=0;34</programlisting>
</refsect1>
......@@ -193,7 +193,10 @@ ANSI_COLOR=0;34</programlisting>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>lsb_release</refentrytitle><manvolnum>1</manvolnum></citerefentry>
<citerefentry><refentrytitle>lsb_release</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>hostname</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>machine-info</refentrytitle><manvolnum>5</manvolnum></citerefentry>
</para>
</refsect1>
......
This diff is collapsed.
<?xml version="1.0"?> <!--*-nxml-*-->
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<!--
This file is part of systemd.
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-->
<busconfig>
<policy user="root">
<allow own="org.freedesktop.hostname1"/>
<allow send_destination="org.freedesktop.hostname1"/>
<allow receive_sender="org.freedesktop.hostname1"/>
</policy>
<policy context="default">
<allow send_destination="org.freedesktop.hostname1"/>
<allow receive_sender="org.freedesktop.hostname1"/>
</policy>
</busconfig>
<?xml version="1.0" encoding="UTF-8"?> <!--*-nxml-*-->
<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<!--
This file is part of systemd.
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-->
<policyconfig>
<vendor>The systemd Project</vendor>
<vendor_url>http://www.freedesktop.org/wiki/Software/systemd</vendor_url>
<action id="org.freedesktop.hostname1.set-hostname">
<description>Set host name</description>
<message>Authentication is required to set the local host name.</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
<action id="org.freedesktop.hostname1.set-static-hostname">
<description>Set static host name</description>
<message>Authentication is required to set the statically configured local host name.</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
<action id="org.freedesktop.hostname1.set-machine-info">
<description>Set machine information</description>
<message>Authentication is required to set local machine information.</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_inactive>auth_admin_keep</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
</action>
</policyconfig>
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
[D-BUS Service]
Name=org.freedesktop.hostname1
Exec=/bin/false
User=root
SystemdService=dbus-org.freedesktop.hostname1.service
......@@ -525,6 +525,32 @@ char **strv_env_delete(char **x, unsigned n_lists, ...) {
return r;
}
char **strv_env_unset(char **l, const char *p) {
char **f, **t;
if (!l)
return NULL;
assert(p);
/* Drops every occurrence of the env var setting p in the
* string list. edits in-place. */
for (f = t = l; *f; f++) {
if (env_match(*f, p)) {
free(*f);
continue;
}
*(t++) = *f;
}
*t = NULL;
return l;
}
char **strv_env_set(char **x, const char *p) {
char **k, **r;
......
......@@ -59,6 +59,7 @@ char **strv_env_merge(unsigned n_lists, ...);
char **strv_env_delete(char **x, unsigned n_lists, ...);
char **strv_env_set(char **x, const char *p);
char **strv_env_unset(char **l, const char *p);
char *strv_env_get_with_length(char **l, const char *name, size_t k);
char *strv_env_get(char **x, const char *n);
......
......@@ -496,6 +496,64 @@ int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
return 0;
}
int get_starttime_of_pid(pid_t pid, unsigned long long *st) {
int r;
FILE *f;
char fn[PATH_MAX], line[LINE_MAX], *p;
assert(pid > 0);
assert(st);
assert_se(snprintf(fn, sizeof(fn)-1, "/proc/%lu/stat", (unsigned long) pid) < (int) (sizeof(fn)-1));
char_array_0(fn);
if (!(f = fopen(fn, "r")))
return -errno;
if (!(fgets(line, sizeof(line), f))) {
r = -errno;
fclose(f);
return r;
}
fclose(f);
/* Let's skip the pid and comm fields. The latter is enclosed
* in () but does not escape any () in its value, so let's
* skip over it manually */
if (!(p = strrchr(line, ')')))
return -EIO;
p++;
if (sscanf(p, " "
"%*c " /* state */
"%*d " /* ppid */
"%*d " /* pgrp */
"%*d " /* session */
"%*d " /* tty_nr */
"%*d " /* tpgid */
"%*u " /* flags */
"%*u " /* minflt */
"%*u " /* cminflt */
"%*u " /* majflt */
"%*u " /* cmajflt */
"%*u " /* utime */
"%*u " /* stime */
"%*d " /* cutime */
"%*d " /* cstime */
"%*d " /* priority */
"%*d " /* nice */
"%*d " /* num_threads */
"%*d " /* itrealvalue */
"%llu " /* starttime */,
st) != 1)
return -EIO;
return 0;
}
int write_one_line_file(const char *fn, const char *line) {
FILE *f;
int r;
......@@ -776,6 +834,29 @@ finish:
return r;
}
int write_env_file(const char *fname, char **l) {
char **i;
FILE *f;
int r;
f = fopen(fname, "we");
if (!f)
return -errno;
STRV_FOREACH(i, l) {
fputs(*i, f);
fputc('\n', f);
}
fflush(f);
r = ferror(f) ? -errno : 0;
fclose(f);
return r;
}
char *truncate_nl(char *s) {
assert(s);
......
......@@ -196,6 +196,7 @@ char *split_quoted(const char *c, size_t *l, char **state);
char **split_path_and_make_absolute(const char *p);
pid_t get_parent_of_pid(pid_t pid, pid_t *ppid);
int get_starttime_of_pid(pid_t pid, unsigned long long *st);
int write_one_line_file(const char *fn, const char *line);
int read_one_line_file(const char *fn, char **line);
......@@ -203,6 +204,7 @@ int read_full_file(const char *fn, char **contents);
int parse_env_file(const char *fname, const char *separator, ...) _sentinel_;
int load_env_file(const char *fname, char ***l);
int write_env_file(const char *fname, char **l);
char *strappend(const char *s, const char *suffix);
char *strnappend(const char *s, const char *suffix, size_t length);
......
systemd-hostnamed.service
console-shell.service
systemd-sysctl.service
systemd-ask-password-console.service
......
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# See systemd.special(7) for details
[Unit]
Description=Hostname Service
[Service]
ExecStart=@rootlibexecdir@/systemd-hostnamed
Type=dbus
BusName=org.freedesktop.hostname1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment