]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/debug-generator/debug-generator.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "alloc-util.h"
24 #include "parse-util.h"
25 #include "proc-cmdline.h"
26 #include "string-util.h"
28 #include "unit-name.h"
31 static const char *arg_dest
= "/tmp";
32 static char **arg_mask
= NULL
;
33 static char **arg_wants
= NULL
;
34 static bool arg_debug_shell
= false;
36 static int parse_proc_cmdline_item(const char *key
, const char *value
) {
41 if (streq(key
, "systemd.mask")) {
44 log_error("Missing argument for systemd.mask= kernel command line parameter.");
48 r
= unit_name_mangle(value
, UNIT_NAME_NOGLOB
, &n
);
50 return log_error_errno(r
, "Failed to glob unit name: %m");
52 r
= strv_consume(&arg_mask
, n
);
57 } else if (streq(key
, "systemd.wants")) {
60 log_error("Missing argument for systemd.want= kernel command line parameter.");
64 r
= unit_name_mangle(value
, UNIT_NAME_NOGLOB
, &n
);
66 return log_error_errno(r
, "Failed to glob unit name: %m");
68 r
= strv_consume(&arg_wants
, n
);
73 } else if (streq(key
, "systemd.debug-shell")) {
76 r
= parse_boolean(value
);
78 log_error("Failed to parse systemd.debug-shell= argument '%s', ignoring.", value
);
82 arg_debug_shell
= true;
88 static int generate_mask_symlinks(void) {
92 if (strv_isempty(arg_mask
))
95 STRV_FOREACH(u
, arg_mask
) {
96 _cleanup_free_
char *p
= NULL
;
98 p
= strjoin(arg_dest
, "/", *u
, NULL
);
102 if (symlink("/dev/null", p
) < 0)
103 r
= log_error_errno(errno
,
104 "Failed to create mask symlink %s: %m",
111 static int generate_wants_symlinks(void) {
115 if (strv_isempty(arg_wants
))
118 STRV_FOREACH(u
, arg_wants
) {
119 _cleanup_free_
char *p
= NULL
, *f
= NULL
;
121 p
= strjoin(arg_dest
, "/default.target.wants/", *u
, NULL
);
125 f
= strappend(SYSTEM_DATA_UNIT_PATH
"/", *u
);
129 mkdir_parents_label(p
, 0755);
131 if (symlink(f
, p
) < 0)
132 r
= log_error_errno(errno
,
133 "Failed to create wants symlink %s: %m",
140 int main(int argc
, char *argv
[]) {
143 if (argc
> 1 && argc
!= 4) {
144 log_error("This program takes three or no arguments.");
151 log_set_target(LOG_TARGET_SAFE
);
152 log_parse_environment();
157 r
= parse_proc_cmdline(parse_proc_cmdline_item
);
159 log_warning_errno(r
, "Failed to parse kernel command line, ignoring: %m");
161 if (arg_debug_shell
) {
162 r
= strv_extend(&arg_wants
, "debug-shell.service");
169 r
= generate_mask_symlinks();
171 q
= generate_wants_symlinks();
176 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;