verify.c revision 78002a678106a9a4e0e9d747f54458ba84322f1a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Zbigniew Jędrzejewski-Szmek
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 <stdlib.h>
#include <getopt.h>
#include "manager.h"
#include "bus-util.h"
#include "log.h"
#include "strv.h"
#include "build.h"
#include "pager.h"
bool arg_no_man = false;
char **filename;
int r;
char *t;
t = dirname_malloc(*filename);
if (!t)
return -ENOMEM;
r = strv_consume(&ans, t);
if (r < 0)
return r;
}
if (r < 0)
return r;
if (!*var)
return -ENOMEM;
return 0;
}
static int verify_socket(Unit *u) {
int r;
assert(u);
if (u->type != UNIT_SOCKET)
return 0;
/* Cannot run this without the service being around */
/* This makes sure instance is created if necessary. */
r = socket_instantiate_service(SOCKET(u));
if (r < 0) {
u->id);
return r;
}
/* This checks both type of sockets */
return -ENOENT;
}
}
return 0;
}
return 0;
return -errno;
}
return 0;
}
static int verify_executables(Unit *u) {
int r = 0, k;
unsigned i;
assert(u);
k = verify_executable(u, exec);
if (k < 0 && r == 0)
r = k;
if (u->type == UNIT_SERVICE)
if (k < 0 && r == 0)
r = k;
}
if (u->type == UNIT_SOCKET)
if (k < 0 && r == 0)
r = k;
}
return r;
}
static int verify_documentation(Unit *u) {
char **p;
int r = 0, k;
if (arg_no_man)
return 0;
STRV_FOREACH(p, u->documentation) {
if (startswith(*p, "man:")) {
k = show_man_page(*p + 4, true);
if (k != 0) {
if (k < 0)
else {
u->id, *p + 4, k);
k = -ENOEXEC;
}
if (r == 0)
r = k;
}
}
}
/* Check remote URLs? */
return r;
}
Job *j;
int r, k;
assert(u);
if (log_get_max_level() >= LOG_DEBUG)
if (sd_bus_error_is_set(&err))
if (r < 0)
k = verify_socket(u);
if (k < 0 && r == 0)
r = k;
k = verify_executables(u);
if (k < 0 && r == 0)
r = k;
k = verify_documentation(u);
if (k < 0 && r == 0)
r = k;
return r;
}
static int test_units(char **filenames) {
_cleanup_free_ char *var;
char **filename;
int r = 0, k;
int i, count = 0;
/* set the path */
if (r < 0) {
return r;
}
r = manager_new(arg_running_as, true, &m);
if (r < 0) {
return r;
}
log_debug("Starting manager...");
if (r < 0) {
goto finish;
}
log_debug("Loading remaining units from the command line...");
if (k < 0) {
if (r == 0)
r = k;
}
count ++;
}
for (i = 0; i < count; i++) {
if (k < 0 && r == 0)
r = k;
}
manager_free(m);
return r;
}
static void help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Check if unit files can be correctly loaded.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --system Connect to system manager\n"
" --user Connect to user service manager\n"
" --no-man Do not check for existence of man pages\n"
}
enum {
ARG_VERSION = 0x100,
};
{}
};
int c;
opterr = 0;
switch (c) {
case 'h':
help();
return 0;
case ARG_VERSION:
return 0;
case ARG_USER:
break;
case ARG_SYSTEM:
break;
case ARG_NO_MAN:
arg_no_man = true;
break;
case '?':
return -EINVAL;
case ':':
return -EINVAL;
default:
assert_not_reached("Unhandled option code.");
}
return 1; /* work to do */
}
int r;
log_open();
if (r <= 0)
goto finish;
return r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}