nsjail: make nsjail.c nsjail.cc

This commit is contained in:
Robert Swiecki 2018-02-08 15:24:17 +01:00
parent 750cf04916
commit 0a311af2ad
8 changed files with 59 additions and 11 deletions

View File

@ -35,8 +35,8 @@ LDFLAGS += -pie -Wl,-z,noexecstack -lpthread $(shell pkg-config --libs protobuf)
BIN = nsjail
LIBS = kafel/libkafel.a
SRCS_C = nsjail.c caps.c cmdline.c contain.c log.c cgroup.c mount.c net.c pid.c sandbox.c subproc.c user.c util.c uts.c cpu.c
SRCS_CXX = config.cc
SRCS_C = caps.c cmdline.c contain.c log.c cgroup.c mount.c net.c pid.c sandbox.c subproc.c user.c util.c uts.c cpu.c
SRCS_CXX = nsjail.cc config.cc
SRCS_PROTO = config.proto
SRCS_PB_CXX = $(SRCS_PROTO:.proto=.pb.cc)
SRCS_PB_H = $(SRCS_PROTO:.proto=.pb.h)
@ -60,7 +60,7 @@ endif
.PHONY: all clean depend indent
.c.o: %.c
$(CC) $(CFLAGS) $< -o $@
$(CXX) -xc $(CFLAGS) $< -o $@
.cc.o: %.cc
$(CXX) $(CXXFLAGS) $< -o $@

View File

@ -29,8 +29,16 @@
#include "nsjail.h"
#ifdef __cplusplus
extern "C" {
#endif
uint64_t cmdlineParseRLimit(int res, const char* optarg, unsigned long mul);
void cmdlineLogParams(struct nsjconf_t* nsjconf);
bool cmdlineParse(int argc, char* argv[], struct nsjconf_t* nsjconf);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* _CMDLINE_H */

8
log.h
View File

@ -42,9 +42,17 @@
#define PLOG_E(...) logLog(ERROR, __func__, __LINE__, true, __VA_ARGS__);
#define PLOG_F(...) logLog(FATAL, __func__, __LINE__, true, __VA_ARGS__);
#ifdef __cplusplus
extern "C" {
#endif
bool logInitLogFile(struct nsjconf_t* nsjconf);
void logLog(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt, ...)
__attribute__((format(printf, 5, 6)));
void logStop(int sig);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* NS_LOG_H */

8
net.h
View File

@ -27,6 +27,10 @@
#include "nsjail.h"
#ifdef __cplusplus
extern "C" {
#endif
bool netLimitConns(struct nsjconf_t* nsjconf, int connsock);
int netGetRecvSocket(const char* bindhost, int port);
int netAcceptConn(int listenfd);
@ -34,4 +38,8 @@ void netConnToText(int fd, bool remote, char* buf, size_t s, struct sockaddr_in6
bool netInitNsFromParent(struct nsjconf_t* nsjconf, int pid);
bool netInitNsFromChild(struct nsjconf_t* nsjconf);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* _NET_H */

View File

@ -58,12 +58,12 @@ static bool nsjailSetSigHandler(int sig) {
sigset_t smask;
sigemptyset(&smask);
struct sigaction sa = {
.sa_handler = nsjailSig,
.sa_mask = smask,
.sa_flags = 0,
.sa_restorer = NULL,
};
struct sigaction sa;
sa.sa_handler = nsjailSig;
sa.sa_mask = smask;
sa.sa_flags = 0;
sa.sa_restorer = NULL;
if (sigaction(sig, &sa, NULL) == -1) {
PLOG_E("sigaction(%d)", sig);
return false;
@ -86,12 +86,12 @@ static bool nsjailSetTimer(struct nsjconf_t* nsjconf) {
}
struct itimerval it = {
.it_value =
.it_interval =
{
.tv_sec = 1,
.tv_usec = 0,
},
.it_interval =
.it_value =
{
.tv_sec = 1,
.tv_usec = 0,

View File

@ -44,6 +44,10 @@
}))
#endif /* !defined(TEMP_FAILURE_RETRY) */
#ifdef __cplusplus
extern "C" {
#endif
static const int nssigs[] = {
SIGINT,
SIGQUIT,
@ -198,4 +202,8 @@ struct nsjconf_t {
caps;
};
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* _NSJAIL_H */

View File

@ -28,6 +28,10 @@
#include "nsjail.h"
#ifdef __cplusplus
extern "C" {
#endif
void subprocRunChild(struct nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err);
int subprocCount(struct nsjconf_t* nsjconf);
void subprocDisplay(struct nsjconf_t* nsjconf);
@ -39,4 +43,8 @@ void subprocCloneFlags(struct nsjconf_t* nsjconf);
/* Returns the exit code of the first failing subprocess, or 0 if none fail */
int subprocReap(struct nsjconf_t* nsjconf);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* NS_PROC_H */

8
util.h
View File

@ -28,6 +28,10 @@
#include "nsjail.h"
#ifdef __cplusplus
extern "C" {
#endif
void* utilMalloc(size_t sz);
void* utilCalloc(size_t sz);
char* utilStrDup(const char* str);
@ -43,4 +47,8 @@ uint64_t utilRnd64(void);
const char* utilSigName(int signo);
const char* utilTimeToStr(time_t t);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* NS_UTIL_H */