install-printf.c revision cab6235f748e365198a7939f23c87ab3b8f59b2e
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2013 Zbigniew Jędrzejewski-Szmek
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poetteringstatic int specifier_prefix_and_instance(char specifier, void *data, void *userdata, char **ret) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return unit_name_to_prefix_and_instance(i->name, ret);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poetteringstatic int specifier_prefix(char specifier, void *data, void *userdata, char **ret) {
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering return unit_name_to_prefix(i->name, ret);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poetteringstatic int specifier_instance(char specifier, void *data, void *userdata, char **ret) {
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering r = unit_name_to_instance(i->name, &instance);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poetteringstatic int specifier_user_name(char specifier, void *data, void *userdata, char **ret) {
d15ad74251454d55b715958d8e6f50f45195904aLennart Poettering /* get USER env from env or our own uid */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* fish username from passwd */
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering r = get_user_creds(&username, &uid, NULL, NULL, NULL);
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering if (asprintf(&printed, UID_FMT, uid) < 0)
2001c80560e3dae69e14fd994d3978c187af48b8Lennart Poetteringint install_full_printf(UnitFileInstallInfo *i, const char *format, char **ret) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* This is similar to unit_full_printf() but does not support
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * anything path-related.
7b50eb2efa122200e39646c19a29abab302f7d24Lennart Poettering * %n: the full id of the unit (foo@bar.waldo)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * %N: the id of the unit without the suffix (foo@bar)
ee3d6aff9bd73c1b23e29d1fa1fa6f7a1ef0533bLennart Poettering * %p: the prefix (foo)
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * %i: the instance (bar)
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * %U the UID of the configured user or running user
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * %u the username of the configured user or running user
a8812dd7f161a3e459c1730ac92ff2bbc9986ff1Lennart Poettering * %m the machine ID of the running system
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * %H the host name of the running system
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * %b the boot ID of the running system
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * %v `uname -r` of the running system
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering { 'N', specifier_prefix_and_instance, NULL },