analyze-verify: add --generators switch to enable generators again

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2017-09-16 11:29:34 +02:00
parent e0a3da1fd2
commit 641c0fd14e
4 changed files with 40 additions and 5 deletions

View file

@ -297,13 +297,23 @@
</varlistentry>
<varlistentry>
<term><option>--no-man</option></term>
<term><option>--man=no</option></term>
<listitem><para>Do not invoke man to verify the existence of
man pages listed in <varname>Documentation=</varname>.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--generators</option></term>
<listitem><para>Invoke unit generators, see
<citerefentry><refentrytitle>systemd.generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
Some generators require root privileges. When run under a
normal users, enabling generators will generally result in
some warnings.</para></listitem>
</varlistentry>
<xi:include href="user-system-options.xml" xpointer="host" />
<xi:include href="user-system-options.xml" xpointer="machine" />

View file

@ -242,7 +242,7 @@ static int verify_unit(Unit *u, bool check_man) {
return r;
}
int verify_units(char **filenames, UnitFileScope scope, bool check_man) {
int verify_units(char **filenames, UnitFileScope scope, bool check_man, bool run_generators) {
_cleanup_(sd_bus_error_free) sd_bus_error err = SD_BUS_ERROR_NULL;
_cleanup_free_ char *var = NULL;
Manager *m = NULL;
@ -253,6 +253,8 @@ int verify_units(char **filenames, UnitFileScope scope, bool check_man) {
Unit *units[strv_length(filenames)];
int i, count = 0;
const uint8_t flags = MANAGER_TEST_RUN_ENV_GENERATORS |
run_generators * MANAGER_TEST_RUN_GENERATORS;
if (strv_isempty(filenames))
return 0;
@ -264,7 +266,7 @@ int verify_units(char **filenames, UnitFileScope scope, bool check_man) {
assert_se(set_unit_path(var) >= 0);
r = manager_new(scope, MANAGER_TEST_RUN_ENV_GENERATORS, &m);
r = manager_new(scope, flags, &m);
if (r < 0)
return log_error_errno(r, "Failed to initialize manager: %m");

View file

@ -23,4 +23,8 @@
#include "path-lookup.h"
int verify_units(char **filenames, UnitFileScope scope, bool check_man);
int verify_units(
char **filenames,
UnitFileScope scope,
bool check_man,
bool run_generators);

View file

@ -79,6 +79,7 @@ static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
static char *arg_host = NULL;
static bool arg_user = false;
static bool arg_man = true;
static bool arg_generators = false;
struct boot_times {
usec_t firmware_time;
@ -1413,6 +1414,7 @@ static void help(void) {
" --fuzz=SECONDS Also print also services which finished SECONDS\n"
" earlier than the latest in the branch\n"
" --man[=BOOL] Do [not] check for existence of man pages\n\n"
" --generators[=BOOL] Do [not] run unit generators (requires privileges)\n\n"
"Commands:\n"
" time Print time spent in the kernel\n"
" blame Print list of running units ordered by time to init\n"
@ -1445,6 +1447,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_FUZZ,
ARG_NO_PAGER,
ARG_MAN,
ARG_GENERATORS,
};
static const struct option options[] = {
@ -1459,6 +1462,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "fuzz", required_argument, NULL, ARG_FUZZ },
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
{ "man", optional_argument, NULL, ARG_MAN },
{ "generators", optional_argument, NULL, ARG_GENERATORS },
{ "host", required_argument, NULL, 'H' },
{ "machine", required_argument, NULL, 'M' },
{}
@ -1541,6 +1545,20 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_GENERATORS:
if (optarg) {
r = parse_boolean(optarg);
if (r < 0) {
log_error("Failed to parse --generators= argument.");
return -EINVAL;
}
arg_generators = !!r;
} else
arg_generators = true;
break;
case '?':
return -EINVAL;
@ -1566,7 +1584,8 @@ int main(int argc, char *argv[]) {
if (streq_ptr(argv[optind], "verify"))
r = verify_units(argv+optind+1,
arg_user ? UNIT_FILE_USER : UNIT_FILE_SYSTEM,
arg_man);
arg_man,
arg_generators);
else {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;