#include <sys/stat.h>
#include <pthread.h>
#include <dirent.h>
+#include <stdarg.h>
#include <sys/socket.h>
#include <asm/unistd.h>
+#include "logger/logger.hpp"
+#include "logger/logger-scope.hpp"
+
#define UNUSED(x) ((void)(x))
extern "C" {
// find_container_by_pid
API char *find_container_by_pid(pid_t /*pid*/) {
+ LOGS("");
return NULL;
}
// get_domain_pid
API pid_t get_domain_pid(const char * /*name*/, const char * /*target*/) {
+ LOGS("");
return -1;
}
-// mainloop_add_watch
-int mainloop_add_watch(struct mainloop * /*mainloop*/, int /*fd*/, mainloop_event /*event*/, mainloop_callback /*callback*/, void * /*data*/) {
- return 0;
-}
-// mainloop_cleanup
-int mainloop_cleanup(struct mainloop * /*mainloop*/) {
- return 0;
-}
-// mainloop_create
-struct mainloop *mainloop_create(void) {
- struct mainloop *mainloop = (struct mainloop *)malloc(sizeof(struct mainloop));
- mainloop->epfd = -1; // epoll_create(2);
- pthread_mutex_init(&mainloop->ml_mutex, NULL);
- pthread_rwlock_init(&mainloop->lock, NULL);
- adt_init_list(&mainloop->watches);
- return mainloop;
-}
-// mainloop_dispatch
-int mainloop_dispatch(struct mainloop * /*mainloop*/, int /*timeout*/) {
- return 0;
-}
-// mainloop_remove_watch
-int mainloop_remove_watch(struct mainloop * /*mainloop*/, int /*fd*/) {
- return 0;
-}
-// mainloop_run
-int mainloop_run(struct mainloop * /*mainloop*/, int /*timeout*/) {
- return 0;
-}
-// mxe_alloc_endpoint
-struct mxe_endpoint *mxe_alloc_endpoint(struct mxe_engine * /*engine*/, int /*fd*/, mainloop_callback /*callback*/, int /*type*/) {
- return NULL;
-}
-// mxe_broadcast
-int mxe_broadcast(struct mxe_engine * /*engine*/, struct mxe_emple * /*emple*/, ...) {
- return 0;
-}
-// mxe_create_client
-struct mxe_endpoint *mxe_create_client(struct mxe_engine *engine, const char * /*addr*/) {
- struct mxe_endpoint *ep = (struct mxe_endpoint *)malloc(sizeof(struct mxe_endpoint));
- ep->type = 1; //MXE_EPT_SLAVE
- ep->fd = -1; //sock_connect(addr);
- ep->engine = engine;
- pthread_rwlock_init(&ep->queue_lock, NULL);
- pthread_mutex_init(&ep->rd_mutex, NULL);
- pthread_mutex_init(&ep->wr_mutex, NULL);
- adt_init_list(&ep->queue);
- adt_init_list(&ep->list);
- return ep;
-}
-// mxe_create_server
-struct mxe_endpoint *mxe_create_server(struct mxe_engine * /*engine*/, const char * /*addr*/) {
- return NULL;
-}
-// mxe_emple_factory
-struct mxe_emple *mxe_emple_factory(struct mxe_proxy * /*proxy*/) {
- return NULL;
-}
-// mxe_finalize_engine
-int mxe_finalize_engine(struct mxe_engine * /*engine*/) {
- return 0;
-}
-// mxe_free_endpoint
-int mxe_free_endpoint(struct mxe_endpoint * /*ep*/) {
- return 0;
-}
-// mxe_invoke
-int mxe_invoke(struct mxe_endpoint * /*ep*/, struct mxe_emple * /*emple*/, ...) {
- return 0;
-}
-// mxe_lookup_emple
-struct mxe_emple *mxe_lookup_emple(struct mxe_endpoint * /*ep*/, int /*signature*/) {
- return NULL;
-}
-// mxe_lookup_proxy
-struct mxe_proxy *mxe_lookup_proxy(struct mxe_engine * /*engine*/, int /*id*/) {
- return NULL;
-}
-// mxe_pop_integer
-int mxe_pop_integer(struct mxe_message * /*msg*/) {
- return 0;
-}
-// mxe_pop_string
-char *mxe_pop_string(struct mxe_message * /*msg*/) {
- return NULL;
-}
-// mxe_prepare_engine
-struct mxe_engine *mxe_prepare_engine(struct mainloop *mainloop, void *data) {
- struct mxe_engine *engine = (struct mxe_engine *)malloc(sizeof(struct mxe_engine));
- engine->data = data;
- engine->mainloop = mainloop;
- pthread_rwlock_init(&engine->endpoint_lock, NULL);
- adt_init_list(&engine->endpoints);
-
- return engine;
-}
-// mxe_push_integer
-int mxe_push_integer(struct mxe_message * /*msg*/, int /*value*/) {
- return 0;
-}
-// mxe_push_string
-int mxe_push_string(struct mxe_message * /*msg*/, const char * /*str*/) {
- return 0;
-}
-// mxe_register_proxy
-int mxe_register_proxy(struct mxe_engine * /*engine*/, struct mxe_proxy * /*proxy*/) {
- return 0;
-}
-// mxe_reply_message (intenal)
-int mxe_reply_message(struct mxe_endpoint * /*ep*/, struct mxe_message * /*origin*/, ...) {
- return 0;
-}
-// mxe_reset_payload
-void mxe_reset_payload(struct mxe_message * /*msg*/) {
-}
-// mxe_wait_for_event
-int mxe_wait_for_event(struct mxe_endpoint * /*ep*/, struct mxe_emple * /*emple*/) {
- return 0;
-}
-// sock_close_socket (intern)
-int sock_close_socket(int /*fd*/) {
+// sock_close_socket
+API int sock_close_socket(int /*fd*/) {
+ LOGS("");
return 0;
}
// sock_connect
API int sock_connect(const char * /*path*/) {
- return 0;
+ LOGS("");
+ return -1;
}
// sock_create_socket
API int sock_create_socket(const char * /*path*/, int /*type*/, int /*flags*/) {
- return 0;
+ LOGS("");
+ return -1;
}
// sock_monitor_address
API int sock_monitor_address(char * /*buffer*/, int /*len*/, const char * /*lxcpath*/) {
+ LOGS("");
return 0;
}
// sock_recv_fd (intern)
API int sock_recv_fd(int /*fd*/, int * /*recvfd*/, void * /*data*/, size_t /*size*/) {
+ LOGS("");
return 0;
}
// sock_send_fd
API int sock_send_fd(int /*fd*/, int /*sendfd*/, void * /*data*/, size_t /*size*/) {
+ LOGS("");
return 0;
}
// vasum_log
-API void vasum_log(int /*type*/, const char * /*tag*/, const char * /*fmt*/ , ...) {
+API void vasum_log(int type, const char *tag, const char *fmt, ...) {
+ va_list arg_ptr;
+ char buf[100];
+ va_start(arg_ptr, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, arg_ptr);
+ va_end(arg_ptr);
+ LOGS("type=" << type << " tag=" << tag << " msg=" << buf);
}
#define MAX_ERROR_MSG 0x1000
API const char *fso_type_to_string(vsm_fso_type_t fso)
{
+ LOGS("");
if (fso < 0 || fso > VSM_FSO_MAX_TYPE) {
return NULL;
}
API int wait_for_pid_status(pid_t pid)
{
+ LOGS("");
int status, ret;
again:
if (errno == EINTR) {
goto again;
} else {
- ERROR("waitpid- pid : %d error : %s", pid,
- strerror(errno));
+ ERROR("waitpid pid : %d error : %s", pid, strerror(errno));
return -1;
}
}
API vsm_fso_type_t fso_string_to_type(char *str)
{
+ LOGS("");
int len;
int i;
for (i = 0; i <= VSM_FSO_MAX_TYPE; i++) {
API int mkdir_p(const char *dir, mode_t mode)
{
+ LOGS("");
const char *tmp = dir;
const char *orig = dir;
char *makeme;
API int lock_fd(int fd, int wait)
{
+ LOGS("");
int ret;
struct flock f;
API int unlock_fd(int fd)
{
+ LOGS("");
struct flock f;
f.l_type = F_UNLCK;
f.l_whence = SEEK_SET;
API int copy_smacklabel(const char * /*source*/, const char * /*dest*/)
{
+ LOGS("");
return 0;
}
API int remove_file(char *path)
{
+ LOGS("");
struct stat path_stat;
DIR *dp;
struct dirent *d;
API int copy_file(const char *source, const char *dest, int /*flags*/)
{
+ LOGS("");
int ret;
FILE *sfp, *dfp;
size_t nread, nwritten, size = BUF_SIZE;
API int regex_compile(regex_t * r, const char *regex_text)
{
+ LOGS("");
int status = regcomp(r, regex_text, REG_EXTENDED | REG_NEWLINE);
if (status != 0) {
API int regex_match(regex_t * r, const char *to_match)
{
+ LOGS("");
const char *p = to_match;
const int n_matches = 10;
regmatch_t m[n_matches];
API int get_peer_pid(int fd)
{
+ LOGS("");
struct ucred cred;
socklen_t cr_len = sizeof(cred);
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &cr_len) < 0) {
API pid_t gettid(void)
{
+ LOGS("");
return syscall(__NR_gettid);
}
API int set_smacklabel_fd(int fd, const char *xattr_name, const char *label)
{
+ LOGS("");
size_t len;
int ret;
- if(fd < 0)
+ if (fd < 0)
return -1;
len = strnlen(label, SMACK_LABEL_LEN + 1);
if (len > SMACK_LABEL_LEN)
return -1;
- ret = fsetxattr(fd, xattr_name, label, len+1, 0);
- if(ret != 0) {
+ ret = fsetxattr(fd, xattr_name, label, len + 1, 0);
+ if (ret != 0) {
ERROR("Set Smack lable error : %s", strerror(errno));
}
return ret;
API int set_smacklabel(const char *path, const char *xattr_name, const char *label)
{
+ LOGS("");
size_t len;
int ret;
- if(path == NULL)
+ if (path == NULL)
return -1;
len = strnlen(label, SMACK_LABEL_LEN + 1);
if (len > SMACK_LABEL_LEN)
return -1;
- ret = lsetxattr(path, xattr_name, label, len+1, 0);
- if(ret != 0) {
+ ret = lsetxattr(path, xattr_name, label, len + 1, 0);
+ if (ret != 0) {
ERROR("Set Smack lable error : %s", strerror(errno));
}
return ret;
}
API char *get_self_smacklabel(void)
{
+ LOGS("");
int ret;
int fd;
const char *attr_path = "/proc/self/attr/current";
- char buffer[SMACK_LABEL_LEN+1];
+ char buffer[SMACK_LABEL_LEN + 1];
- bzero(buffer, SMACK_LABEL_LEN+1);
+ bzero(buffer, SMACK_LABEL_LEN + 1);
fd = open(attr_path, O_RDONLY);
- if( fd < 0) {
+ if (fd < 0) {
return NULL;
}
- ret = read(fd, buffer, SMACK_LABEL_LEN+1);
+ ret = read(fd, buffer, SMACK_LABEL_LEN + 1);
close(fd);
if (ret < 0) {
return NULL;
}
- if( ret > SMACK_LABEL_LEN) {
+ if (ret > SMACK_LABEL_LEN) {
//return NULL;
}
- buffer[SMACK_LABEL_LEN]=0;
+ buffer[SMACK_LABEL_LEN] = 0;
return strdup(buffer);
}
API int get_self_cpuset(char *name, int buf_sz)
{
+ LOGS("");
int fd;
int lxc_len, ret;
char cpuset_path[] = "/proc/self/cpuset";
close(fd);
lxc_len = sizeof("/lxc");
- if( ret < lxc_len) {
+ if (ret < lxc_len) {
name[0] = '/';
name[1] = 0;
return 1;
char *p;
p = current_name + lxc_len;
- while(*p != '\0') {
- if(*p == '/') {
+ while (*p != '\0') {
+ if (*p == '/') {
*p = '\0';
break;
}
p++;
}
- snprintf(name, buf_sz, "%s", current_name+lxc_len);
+ snprintf(name, buf_sz, "%s", current_name + lxc_len);
}
return ret - lxc_len;
API char * get_pid_cpuset(int pid)
{
+ LOGS("");
int fd;
int ret;
char cpuset_path[PATH_MAX];
snprintf(cpuset_path, PATH_MAX, "/proc/%d/cpuset", pid);
ret = access(cpuset_path, F_OK | R_OK);
- if( ret != 0 )
+ if (ret != 0)
return NULL;
fd = open(cpuset_path, O_RDONLY);
API char * read_namespace_link(const char *ns, int pid)
{
+ LOGS("");
char ns_path[PATH_MAX];
char buf[NAME_MAX];
int ret;
snprintf(ns_path, PATH_MAX, "/proc/%d/ns/%s", pid, ns);
ret = access(ns_path, F_OK);
- if(ret != 0)
+ if (ret != 0)
return NULL;
ret = readlink(ns_path, buf, NAME_MAX);
- if( ret == -1 ) {
+ if (ret == -1) {
ERROR("Failed to readlink ns file - [%s]", ns_path);
return NULL;
}
API int dev_enumerate_nodes(const char *cname, dev_enumerator enumerator,
void *data)
{
+ LOGS("");
int ret;
FILE *fp;;
char path[PATH_MAX], entry[64];
API int dev_terminal_enumerator(int type, int major, int minor, void *data)
{
+ LOGS("");
int *dev = (int*)data;
*dev = minor;
// libs/namespace.c
API pid_t get_init_pid(const char *name)
{
+ LOGS("");
char filename[PATH_MAX];
FILE *fp;
pid_t ret = -1;
API pid_t get_zone_pid(const char *name, const char *target)
{
+ LOGS("");
char path[PATH_MAX];
char cmd[PATH_MAX];
int res = 0, len;
API int open_ns(pid_t pid, const char *name)
{
+ LOGS("");
int fd, ret;
char path[PATH_MAX];
#include <linux/vt.h>
static int is_console(int fd)
{
+ LOGS("");
char arg;
return (isatty(fd) &&
API int get_console_fd(const char *path)
{
+ LOGS("");
int fd;
if (path) {
API int vt_switch_terminal(int id)
{
+ LOGS("");
int fd, ret = -1;
fd = get_console_fd(NULL);
API int vt_find_unused_terminal(void)
{
+ LOGS("");
int fd, nr = -1;
fd = get_console_fd(NULL);
API int vt_query_active_terminal(void)
{
+ LOGS("");
int fd, ret = -1;
struct vt_stat vtstat;
API int parse_stream_core(struct parser_context *ctx, char *s)
{
+ LOGS("");
struct unit_keyword_callback *kw;
struct parser_state state;
char *args[PARSER_MAXARGS];
API int parse_stream(const char *name, struct unit_parser *parser)
{
+ LOGS("");
char *stream;
struct parser_context *ctx;
return 0;
}
+API struct vsm_netdev *alloc_netdev(struct vsm_zone * /*zone*/, vsm_netdev_type_t /*type*/, const char * /*netdev_name*/) {
+ LOGS("");
+ return NULL;
+}
+API void enter_to_ns(pid_t /*pid*/, char * /*name*/) {
+ LOGS("");
+}
// dummy-ops
static int dummy_create_zone(vsm_context_h /*ctx*/, const char * /*zone_name*/,
static int dummy_iterate_zone(vsm_context_h ctx, vsm_zone_iter_cb callback, void *user_data)
{
- if( callback) {
+ if (callback) {
callback(ctx->root_zone, user_data);
}
return VSM_ERROR_NONE;
vsm_attach_command_s * command,
vsm_attach_options_s * opts)
{
- pid_t pid=0;
+ pid_t pid = 0;
int ret, status;
ret = dummy_attach_zone(ctx, zone_name, command, opts, &pid);
static int dummy_get_host_pid(vsm_zone_h zone, pid_t pid)
{
- if(zone == zone->parent)
+ if (zone == zone->parent)
return pid;
return -VSM_ERROR_NO_OBJECT;
}
struct vasum_ops dummy_ops;
-static int dummy_ops_init(){
+static int dummy_ops_init() {
dummy_ops.create_zone = dummy_create_zone;
dummy_ops.destroy_zone = dummy_destroy_zone;
dummy_ops.start_zone = dummy_start_zone;
}
int dummy_ops_init_i = dummy_ops_init();
+
} //extern "C"
int glib_stop;
} wrap;
-extern "C" {
-API void vsm_string_free(VsmString string);
-API void vsm_array_string_free(VsmArrayString astring);
-}
#ifndef offsetof
#define offsetof(type, memb) ((size_t)&((type *)0)->memb)
#define vsm_attach_command_t vsm_attach_command_s
#define vsm_attach_options_t vsm_attach_options_s
-#define vsm_zone_state_cb vsm_zone_state_changed_cb
void __attribute__ ((constructor)) wrapper_load(void);
void __attribute__ ((destructor)) wrapper_unload(void);
void init_wrapper()
{
if (wrap.done) return ;
- memset(&wrap,0,sizeof(wrap));
+ memset(&wrap, 0, sizeof(wrap));
wrap.done = 1;
- LOGS("WRAP:");
+ LOGS("");
}
static struct vsm_zone* wrap_vsm_zone(WrappedContext *w, VsmZone zone, bool create = false)
zw.client = w->client;
zw.zone = zone;
zw.vz.name = zone->id;
+ zw.vz.id = 0;
zw.vz.type = NULL;
zw.vz.user_data = NULL;
zw.vz.rootfs_path = zone->rootfs_path;
static int wrap_error(VsmStatus st, const Client *c)
{
if (st == VSMCLIENT_SUCCESS) LOGI("return success " << st);
- else LOGE("return error " << st << "m=" << (c ? c->vsm_get_status_message() : "n/a"));
+ else LOGE("return error=" << st << ", msg=" << (c ? c->vsm_get_status_message() : "n/a"));
switch (st) {
case VSMCLIENT_SUCCESS: return VSM_ERROR_NONE;
case VSMCLIENT_CUSTOM_ERROR: return -VSM_ERROR_GENERIC;
//init root_zone
ctx->root_zone = &w->hq_root;
ctx->root_zone->name = (char*)"";
- ctx->root_zone->id=0;
+ ctx->root_zone->id = 0;
ctx->root_zone->rootfs_path = (char*)"/";
ctx->root_zone->terminal = -1;
//ctx->data = ep;
}
+extern "C" {
+API void vsm_string_free(VsmString string);
+API void vsm_array_string_free(VsmArrayString astring);
+
API vsm_context_h vsm_create_context(void)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedContext *w = new WrappedContext();
init_context_wrap(w);
API int vsm_cleanup_context(vsm_context_h ctx)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
if (w->client != NULL) {
zw.netdevs.clear();
}
w->zones.clear();
+ pthread_rwlock_destroy(&ctx->lock);
delete w;
return VSM_ERROR_NONE;
}
API int vsm_get_poll_fd(struct vsm_context *ctx)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
UNUSED(w);
}
API int vsm_enter_eventloop(struct vsm_context *ctx, int flags, int timeout)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
UNUSED(flags);
UNUSED(timeout);
API int vsm_create_zone(struct vsm_context *ctx, const char *zone_name, const char *template_name, int flag)
{
- LOGS("WRAP:create_zone " << zone_name);
+ LOGS("create_zone " << zone_name);
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
UNUSED(flag);
API int vsm_destroy_zone(struct vsm_context *ctx, const char *zone_name, int force)
{
- LOGS("WRAP:zone=" << zone_name);
+ LOGS("zone=" << zone_name);
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
UNUSED(force);
API int vsm_start_zone(struct vsm_context *ctx, const char *zone_name)
{
- LOGS("WRAP:zone=" << zone_name);
+ LOGS("zone=" << zone_name);
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
if (!w->client) return VSM_ERROR_GENERIC;
API int vsm_shutdown_zone(struct vsm_context *ctx, const char *zone_name, int force)
{
- LOGS("WRAP:zone=" << zone_name);
+ LOGS("zone=" << zone_name);
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
UNUSED(force);
API int vsm_lock_zone(struct vsm_context *ctx, const char *zone_name, int shutdown)
{
- LOGS("WRAP:zone=" << zone_name);
+ LOGS("zone=" << zone_name);
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
UNUSED(shutdown);
API int vsm_unlock_zone(struct vsm_context *ctx, const char *zone_name)
{
- LOGS("WRAP:zone=" << zone_name);
+ LOGS("zone=" << zone_name);
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
if (!w->client) return VSM_ERROR_GENERIC;
API int vsm_set_foreground(struct vsm_zone *zone)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedZone *w = container_of(zone, WrappedZone, vz);
if (!w->client) return VSM_ERROR_GENERIC;
API int vsm_iterate_zone(struct vsm_context *ctx, void (*callback)(struct vsm_zone *zone, void *user_data), void *user_data)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
if (!w->client) return -VSM_ERROR_GENERIC;
callback(ctx->root_zone, user_data);
for (auto& z : w->zones) {
+ LOGI("iterate callback zone: " << z.zone->id);
callback(&z.vz, user_data);
}
return 0;
API struct vsm_zone *vsm_lookup_zone_by_name(struct vsm_context *ctx, const char *path)
{
- LOGS("WRAP:name=" << path);
+ LOGS("name=" << path);
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
VsmZone zone;
//supposed return ref to internal struct
API struct vsm_zone *vsm_lookup_zone_by_pid(struct vsm_context *ctx, pid_t pid)
{
- LOGS("WRAP: pid=" << pid);
+ LOGS("pid=" << pid);
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
VsmZone zone;
VsmString id;
+ VsmStatus st;
if (!w->client) return NULL;
- if (w->client->vsm_lookup_zone_by_pid(pid, &id) != VSMCLIENT_SUCCESS) {
- LOGE("vsm_lookup_zone_by_pid(" << pid << ") error");
+ if ((st = w->client->vsm_lookup_zone_by_pid(pid, &id)) != VSMCLIENT_SUCCESS) {
+ wrap_error(st, w->client);
return NULL;
}
+ LOGI("found zone(pid=" << pid << ")='" << id << "'");
if (::strcmp(id, "host") == 0) {
return w->hq_ctx.root_zone;
}
return wrap_vsm_zone(w, zone);
}
-API int vsm_add_state_changed_callback(struct vsm_context *ctx, vsm_zone_state_cb callback, void *user_data)
+API int vsm_add_state_changed_callback(struct vsm_context *ctx, vsm_zone_state_changed_cb callback, void *user_data)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
VsmSubscriptionId subscriptionId;
void {
VsmZone zone;
//TODO what are valid state, event
- vsm_zone_state_t t=VSM_ZONE_STATE_RUNNING;
+ vsm_zone_state_t t = VSM_ZONE_STATE_RUNNING;
UNUSED(dbusAddress);
w->client->vsm_lookup_zone_by_id(id, &zone);
callback(wrap_vsm_zone(w, zone), t, data);
API int vsm_del_state_changed_callback(struct vsm_context *ctx, int handle)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
VsmSubscriptionId subscriptionId = (VsmSubscriptionId)handle;
API int vsm_grant_device(struct vsm_zone *dom, const char *name, uint32_t flags)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedZone *w = container_of(dom, WrappedZone, vz);
const char *id = dom->name;
API int vsm_revoke_device(struct vsm_zone *dom, const char *name)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedZone *w = container_of(dom, WrappedZone, vz);
const char *id = dom->name;
API struct vsm_netdev *vsm_create_netdev(struct vsm_zone *zone, vsm_netdev_type_t type, const char *target, const char *netdev)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
UNUSED(zone);
UNUSED(type);
return &w->netdevs.back(); //pointer to struct on vector
}
-API int vsm_destroy_netdev(struct vsm_zone *zone, struct vsm_netdev *netdev)
+API int vsm_destroy_netdev(vsm_netdev_h)
{
- LOGS("WRAP:");
- callcheck();
- WrappedZone *w = container_of(zone, WrappedZone, vz);
-
- VsmStatus st = w->client->vsm_destroy_netdev(zone->name, netdev->name);
- if (st == VSMCLIENT_SUCCESS) {
- auto devbyname = [netdev](const vsm_netdev& v) {return ::strcmp(v.name, netdev->name) == 0;};
- auto devlist = std::find_if(w->netdevs.begin(), w->netdevs.end(), devbyname);
- if (devlist != w->netdevs.end()) {
- w->netdevs.erase(devlist);
- }
- }
- return wrap_error(st, w->client);
+ LOGS("");
+ return 0;
}
API int vsm_iterate_netdev(struct vsm_zone *zone, void (*callback)(struct vsm_netdev *, void *user_data), void *user_data)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedZone *w = container_of(zone, WrappedZone, vz);
for (auto nd : w->netdevs) {
API struct vsm_netdev *vsm_lookup_netdev_by_name(struct vsm_zone *zone, const char *name)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
WrappedZone *w = container_of(zone, WrappedZone, vz);
VsmNetdev nd;
API int vsm_declare_file(struct vsm_context *ctx, vsm_fso_type_t ftype, const char *path, int flags, vsm_mode_t mode)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
/* Old implementation is following: (but implemented in server)
args.oldpath = oldpath;
API int vsm_declare_link(struct vsm_context *ctx, const char *source, const char *target)
{
- LOGS("WRAP:src=" << source << ", dst=" << target);
+ LOGS("src=" << source << ", dst=" << target);
callcheck();
/* Old implementation is following: (but implemented in server)
args.oldpath = oldpath;
unsigned long flags,
const void *data)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
/* Old implementation is following: (but implemented in server)
args.oldpath = oldpath;
return VSM_ERROR_NONE;
}
-API const char * vsm_get_zone_rootpath(vsm_zone_h /*zone*/)
+API const char * vsm_get_zone_rootpath(vsm_zone_h zone)
{
- LOGS("WRAP:");
- return NULL;
+ LOGS("");
+ return zone == NULL ? NULL : zone->rootfs_path;
}
-API const char * vsm_get_zone_name(vsm_zone_h /*zone*/)
+API const char * vsm_get_zone_name(vsm_zone_h zone)
{
- LOGS("WRAP:");
- return NULL;
+ LOGS("");
+ return zone == NULL ? NULL : zone->name;
}
-API int vsm_is_host_zone(vsm_zone_h /*zone*/)
+API int vsm_is_host_zone(vsm_zone_h zone)
{
- LOGS("WRAP:");
- return VSM_ERROR_NONE;
+ LOGS("");
+ if (zone == NULL)
+ return -VSM_ERROR_INVALID;
+
+ return zone->parent == zone ? 1 : 0;
}
API vsm_zone_h vsm_join_zone(vsm_zone_h /*zone*/)
{
- LOGS("WRAP:");
+ LOGS("");
return NULL;
}
-API int vsm_canonicalize_path(const char * /*input_path*/, char ** /*output_path*/)
-{
- LOGS("WRAP:");
- return VSM_ERROR_NONE;
-}
-
-static int is_valid_context(void * /*v*/)
-{
- return 1;
-}
-static const char *vsm_error_string_v0_34(struct vsm_context *ctx)
-{
- vsm_error_e error = ctx->error;
- if (error < 0 || error > VSM_MAX_ERROR) {
- return NULL;
- }
- return vsm_error_strtab[error];
-}
-static const char *vsm_error_string_v0_3_1(vsm_error_e error)
+API int vsm_canonicalize_path(const char *input_path, char **output_path)
{
- if (error < 0 || error > VSM_MAX_ERROR) {
- return NULL;
- }
- return vsm_error_strtab[error];
+ LOGS(""<<input_path);
+ *output_path = strdup(input_path);
+ int len = strlen(input_path);
+ return len;
}
-extern "C" {
-// Note: incomaptible API, try support both
+// Note: incomaptible API, support newer
// API(v0.34) const char *vsm_error_string(struct vsm_context *ctx)
// API(v0.3.1) const char *vsm_error_string(vsm_error_e error)
-API const char *vsm_error_string(vsm_error_e e)
+API const char *vsm_error_string(vsm_error_e error)
{
- LOGS("WRAP:");
+ LOGS("");
callcheck();
- struct vsm_context *ctx=(struct vsm_context *)e;
- if (is_valid_context(ctx)) {
- return vsm_error_string_v0_34((struct vsm_context *)ctx);
- }
- else {
- return vsm_error_string_v0_3_1(e);
+ if (error < 0 || error > VSM_MAX_ERROR) {
+ return NULL;
}
+ return vsm_error_strtab[error];
}
API struct vsm_zone *vsm_lookup_zone_by_terminal_id(struct vsm_context *ctx, int terminal)
{
- LOGS("WRAP:terminal=" << terminal);
+ LOGS("terminal=" << terminal);
callcheck();
WrappedContext *w = container_of(ctx, WrappedContext, hq_ctx);
VsmZone zone;
free(string);
}
+API int vsm_add_event_callback(vsm_context_h, vsm_zone_event_cb, void*) {
+ LOGS("");
+ return 0;
+}
+API int vsm_del_event_callback(vsm_context_h, int) {
+ LOGS("");
+ return 0;
+}
+API int vsm_add_state_callback(vsm_context_h , vsm_zone_state_cb , void *) {
+ LOGS("");
+ return 0;
+}
+API int vsm_del_state_callback(vsm_context_h , int ) {
+ LOGS("");
+ return 0;
+}
+API int vsm_down_netdev(vsm_netdev_h) {
+ LOGS("");
+ return 0;
+}
+API vsm_zone* vsm_get_foreground(vsm_context_h ctx) {
+ LOGS("");
+ //return ((struct vasum_ops *)(ctx->vsm_ops))->get_foreground(ctx);
+ return dummy_ops.get_foreground(ctx);
+}
+API int vsm_get_host_pid(vsm_zone_h, pid_t) {
+ LOGS("");
+ return 0;
+}
+API int vsm_get_ip_addr_netdev(vsm_netdev_h, vsm_netdev_addr_t, char*, int) {
+ LOGS("");
+ return 0;
+}
+API void* vsm_get_userdata(vsm_zone_h) {
+ LOGS("");
+ return NULL;
+}
+API int vsm_get_zone_id(vsm_zone_h zone) {
+ LOGS("");
+ if (zone == NULL)
+ return -VSM_ERROR_INVALID;
+ return zone->id;
+}
+API vsm_zone_state_t vsm_get_zone_state(vsm_zone_h zone) {
+ LOGS("");
+ if (zone == NULL)
+ return static_cast<vsm_zone_state_t>(-VSM_ERROR_INVALID);
+ return zone->state;
+}
+API int vsm_get_zone_terminal(vsm_zone_h) {
+ LOGS("");
+ return -VSM_ERROR_NOT_SUPPORTED;
+}
+API const char *vsm_get_zone_type(vsm_zone_h zone) {
+ LOGS("");
+ return zone == NULL ? NULL : zone->type;
+}
+API int vsm_is_equivalent_zone(vsm_context_h, pid_t) {
+ LOGS("");
+ return 0;
+}
+API int vsm_is_virtualized() {
+ LOGS("");
+ return 0; /* Running in Host */
+}
+// libs/network.c
+API int vsm_set_ip_addr_netdev(vsm_netdev_h, vsm_netdev_addr_t, const char*, int) {
+ LOGS("");
+ return 0;
+}
+API int vsm_up_netdev(vsm_netdev_h) {
+ LOGS("");
+ return 0;
+}
+// libs/zone.c
+API int vsm_set_userdata(vsm_zone_h, void*) {
+ LOGS("");
+ return 0;
+}
+API int vsm_state_change_watch_callback(struct vsm_context * /*ctx*/, char * /*name*/,
+ int /*state*/, int /*event*/) {
+ LOGS("");
+ return 0;
+}
+// libs/vsm_signal.c
+API int vsm_signal_state_broadcast(struct mxe_engine * /*engine*/, const char * /*zone_name*/, int /*state*/) {
+ LOGS("");
+ return 0;
+}
+API int vsm_signal_event_broadcast(struct mxe_engine * /*engine*/, const char * /*zone_name*/, int /*event*/) {
+ LOGS("");
+ return 0;
+}
} // extern "C"