analyze-verify.c revision 4bd29fe5cec9d744a4e39240c76b85d999bd2cf7
/*-*- 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 "alloc-util.h"
#include "analyze-verify.h"
#include "bus-error.h"
#include "bus-util.h"
#include "log.h"
#include "manager.h"
#include "pager.h"
#include "path-util.h"
#include "strv.h"
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) {
log_unit_error_errno(u, r, "Socket cannot be started, failed to create instance: %m");
return r;
}
/* This checks both type of sockets */
return -ENOENT;
}
}
return 0;
}
return 0;
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;
}
char **p;
int r = 0, k;
STRV_FOREACH(p, u->documentation) {
log_unit_debug(u, "Found documentation item: %s", *p);
k = show_man_page(*p + 4, true);
if (k != 0) {
if (k < 0)
log_unit_error_errno(u, r, "Can't show %s: %m", *p);
else {
k = -ENOEXEC;
}
if (r == 0)
r = k;
}
}
}
/* Check remote URLs? */
return r;
}
int r, k;
assert(u);
if (log_get_max_level() >= LOG_DEBUG)
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, check_man);
if (k < 0 && r == 0)
r = k;
return r;
}
char **filename;
int r = 0, k;
int i, count = 0;
if (strv_isempty(filenames))
return 0;
/* set the path */
if (r < 0)
return log_error_errno(r, "Failed to generate unit load path: %m");
r = manager_new(running_as, true, &m);
if (r < 0)
return log_error_errno(r, "Failed to initialize manager: %m");
log_debug("Starting manager...");
if (r < 0) {
log_error_errno(r, "Failed to start manager: %m");
goto finish;
}
log_debug("Loading remaining units from the command line...");
/* manager_load_unit does not like pure basenames, so prepend
* the local directory, but only for valid names. manager_load_unit
* will print the error for other ones. */
} else
if (k < 0) {
if (r == 0)
r = k;
} else
count ++;
}
for (i = 0; i < count; i++) {
if (k < 0 && r == 0)
r = k;
}
manager_free(m);
return r;
}