debug-generator.c revision 94c156cd452424ea59931920df2454d9da7cb774
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
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
(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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "util.h"
#include "strv.h"
#include "unit-name.h"
#include "mkdir.h"
static const char *arg_dest = "/tmp";
static bool arg_debug_shell = false;
int r;
if (!value)
log_error("Missing argument for systemd.mask= kernel command line parameter.");
else {
char *n;
if (r < 0)
return log_error_errno(r, "Failed to glob unit name: %m");
r = strv_consume(&arg_mask, n);
if (r < 0)
return log_oom();
}
if (!value)
log_error("Missing argument for systemd.want= kernel command line parameter.");
else {
char *n;
if (r < 0)
return log_error_errno(r, "Failed to glob unit name: %m");
r = strv_consume(&arg_wants, n);
if (r < 0)
return log_oom();
}
if (value) {
r = parse_boolean(value);
if (r < 0)
else
arg_debug_shell = r;
} else
arg_debug_shell = true;
}
return 0;
}
static int generate_mask_symlinks(void) {
char **u;
int r = 0;
if (strv_isempty(arg_mask))
return 0;
STRV_FOREACH(u, arg_mask) {
_cleanup_free_ char *p = NULL;
if (!p)
return log_oom();
r = log_error_errno(errno,
"Failed to create mask symlink %s: %m",
p);
}
}
return r;
}
static int generate_wants_symlinks(void) {
char **u;
int r = 0;
if (strv_isempty(arg_wants))
return 0;
STRV_FOREACH(u, arg_wants) {
if (!p)
return log_oom();
if (!f)
return log_oom();
mkdir_parents_label(p, 0755);
if (symlink(f, p) < 0) {
r = log_error_errno(errno,
"Failed to create wants symlink %s: %m",
p);
}
}
return r;
}
int r, q;
log_error("This program takes three or no arguments.");
return EXIT_FAILURE;
}
if (argc > 1)
log_open();
umask(0022);
if (r < 0)
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
if (arg_debug_shell) {
if (r < 0) {
r = log_oom();
goto finish;
}
}
r = generate_mask_symlinks();
q = generate_wants_symlinks();
if (q < 0)
r = q;
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}