diff --git a/lib/kernel/if.c b/lib/kernel/if.c index 13528f703..bce032adc 100644 --- a/lib/kernel/if.c +++ b/lib/kernel/if.c @@ -86,6 +86,9 @@ int if_start(struct interface *i) if (mark == 0) return 0; + if (getuid() != 0) + error("Network emulation requires super-user privileges!"); + /* Replace root qdisc */ ret = tc_prio(i, &i->tc_qdisc, TC_HANDLE(1, 0), TC_H_ROOT, mark); if (ret) diff --git a/lib/memory.c b/lib/memory.c index 10983fff7..69839c873 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -21,9 +21,12 @@ *********************************************************************************/ #include +#include +#include #include #include #include +#include /* Required to allocate hugepages on Apple OS X */ #ifdef __MACH__ @@ -126,13 +129,16 @@ static void * memory_hugepage_alloc(struct memtype *m, size_t len, size_t alignm #ifdef __MACH__ flags |= VM_FLAGS_SUPERPAGE_SIZE_2MB; #elif defined(__linux__) - flags |= MAP_HUGETLB | MAP_LOCKED; + flags |= MAP_HUGETLB; + + if (getuid() == 0) + flags |= MAP_LOCKED; #endif void *ret = mmap(NULL, len, prot, flags, -1, 0); if (ret == MAP_FAILED) { - info("Failed to allocate huge pages: Check https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt"); + info("Failed to allocate huge pages: Check https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt (%s)", strerror(errno)); return NULL; } diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 503291b47..6025fff45 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -50,9 +50,6 @@ int socket_init(struct super_node *sn) { int ret; - if (getuid() != 0) - error("The 'socket' node-type requires super-user privileges!"); - nl_init(); /* Fill link cache */ list_init(&interfaces); @@ -510,7 +507,11 @@ int socket_parse(struct node *n, config_setting_t *cfg) int enabled = 1; if (!config_setting_lookup_bool(cfg_netem, "enabled", &enabled) || enabled) tc_parse(cfg_netem, &s->tc_qdisc); + else + s->tc_qdisc = NULL; } + else + s->tc_qdisc = NULL; return 0; } diff --git a/lib/web.c b/lib/web.c index c6d1b235b..b437bc27d 100644 --- a/lib/web.c +++ b/lib/web.c @@ -156,7 +156,7 @@ int web_init(struct web *w, struct api *a) w->api = a; /* Default values */ - w->port = 80; + w->port = getuid() > 0 ? 8080 : 80; /**< @todo Use libcap to check if user can bind to ports < 1024 */ w->htdocs = WEB_PATH; w->state = STATE_INITIALIZED;