Commit e6c88abd authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Cyrill Gorcunov

check: Add some basic checks

* /proc/<pid>/map_files
* sock diag
* ns_last_pid sysctl
* SO_PEEK_OFF sockoptions
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent c39e7590
#include <unistd.h>
#include <sys/socket.h>
#include "sockets.h"
#include "crtools.h"
#include "log.h"
#include "util-net.h"
static int check_map_files(void)
{
int ret;
ret = access("/proc/self/map_files", R_OK);
if (!ret)
return 0;
pr_msg("/proc/<pid>/map_files directory is missing.\n");
return -1;
}
static int check_sock_diag(void)
{
int ret;
ret = collect_sockets();
if (!ret)
return 0;
pr_msg("sock diag infrastructure is incomplete.\n");
return -1;
}
static int check_ns_last_pid(void)
{
int ret;
ret = access(LAST_PID_PATH, W_OK);
if (!ret)
return 0;
pr_msg("%s sysctl is missing.\n", LAST_PID_PATH);
return -1;
}
static int check_sock_peek_off(void)
{
int sk;
int ret, off, sz;
sk = socket(PF_UNIX, SOCK_DGRAM, 0);
if (sk < 0) {
pr_perror("Can't create unix socket for check");
return -1;
}
ret = getsockopt(sk, SOL_SOCKET, SO_PEEK_OFF, &off, (socklen_t *)&sz);
close(sk);
if ((ret == 0) && (off == -1) && (sz == sizeof(int)))
return 0;
pr_msg("SO_PEEK_OFF sockoption doesn't work.\n");
return -1;
}
int cr_check(void)
{
return 0;
int ret = 0;
ret |= check_map_files();
ret |= check_sock_diag();
ret |= check_ns_last_pid();
ret |= check_sock_peek_off();
if (!ret)
pr_msg("Looks good.\n");
return ret;
}
......@@ -4,6 +4,10 @@
#define UNIX_PATH_MAX (sizeof(struct sockaddr_un) - \
(size_t)((struct sockaddr_un *) 0)->sun_path)
#ifndef SO_PEEK_OFF
#define SO_PEEK_OFF 42
#endif
extern int send_fd(int sock, struct sockaddr_un *saddr, int len, int fd);
extern int recv_fd(int sock);
#endif
......@@ -11,10 +11,6 @@
#ifdef CONFIG_X86_64
#ifndef SO_PEEK_OFF
#define SO_PEEK_OFF 42
#endif
static void *brk_start, *brk_end, *brk_tail;
static struct page_entry page;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment