1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

Merge branch 'fix-superuser' into 'develop'

Several workarounds to start daemon without super-user privilges (closes #43)

Closes #43

See merge request !22
This commit is contained in:
Steffen Vogel 2017-05-24 16:49:50 +02:00
commit 243db44f2e
4 changed files with 16 additions and 6 deletions

View file

@ -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)

View file

@ -21,9 +21,12 @@
*********************************************************************************/
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
/* 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;
}

View file

@ -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;
}

View file

@ -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;