lxc_snapshot_SOURCES = tools/lxc_snapshot.c tools/arguments.c
lxc_usernsexec_SOURCES = tools/lxc_usernsexec.c tools/arguments.c
lxc_checkpoint_SOURCES = tools/lxc_checkpoint.c tools/arguments.c
-lxc_user_nic_SOURCES = lxc_user_nic.c network.c network.h tools/arguments.c
+lxc_user_nic_SOURCES = lxc_user_nic.c namespace.c network.c tools/arguments.c
lxc_monitord_SOURCES = lxc_monitord.c tools/arguments.c
if ENABLE_DEPRECATED
if HAVE_STATIC_LIBCAP
sbin_PROGRAMS += init.lxc.static
-init_lxc_static_SOURCES = lxc_init.c error.c log.c initutils.c caps.c parse.c
+init_lxc_static_SOURCES = lxc_init.c error.c log.c initutils.c caps.c parse.c namespace.c
if !HAVE_GETLINE
if HAVE_FGETLN
#include <sys/un.h>
#include "log.h"
+#include "utils.h"
lxc_log_define(lxc_af_unix, lxc);
struct iovec iov;
struct cmsghdr *cmsg;
struct ucred cred = {
- .pid = getpid(), .uid = getuid(), .gid = getgid(),
+ .pid = lxc_raw_getpid(), .uid = getuid(), .gid = getgid(),
};
char cmsgbuf[CMSG_SPACE(sizeof(cred))] = {0};
char buf[1] = {0};
}
}
- pid = syscall(SYS_getpid);
+ pid = lxc_raw_getpid();
for (i = 0; i < LXC_NS_MAX; i++) {
int j, saved_errno;
struct cgroup_process_info *i;
i = lxc_cgroup_process_info_getx("/proc/self/cgroup", meta);
if (!i)
- i = lxc_cgroup_process_info_get(getpid(), meta);
+ i = lxc_cgroup_process_info_get(lxc_raw_getpid(), meta);
return i;
}
if (!f)
goto out;
- written = fprintf(f, "%d\n", getpid());
+ written = fprintf(f, "%d\n", lxc_raw_getpid());
fclose(f);
if (written < 0) {
SYSERROR("writing tasks failed\n");
#include "error.h"
#include "commands.h"
#include "list.h"
+#include "namespace.h"
#include "conf.h"
#include "utils.h"
#include "log.h"
static bool cgm_escape(void *hdata)
{
bool ret = true, cgm_needs_disconnect = false;
- pid_t me = getpid();
+ pid_t me = lxc_raw_getpid();
char **slist = subsystems;
int i;
uid_t newuid)
{
int sv[2] = {-1, -1}, optval = 1, ret = -1;
+ pid_t pid_self;
char buf[1];
struct pollfd fds;
ERROR("Error getting reply from server over socketpair");
goto out;
}
- if (send_creds(sv[0], getpid(), getuid(), getgid())) {
+
+ pid_self = lxc_raw_getpid();
+ if (send_creds(sv[0], pid_self, getuid(), getgid())) {
SYSERROR("Error sending pid over SCM_CREDENTIAL");
goto out;
}
ERROR("Error getting reply from server over socketpair");
goto out;
}
- if (send_creds(sv[0], getpid(), newuid, 0)) {
+ if (send_creds(sv[0], pid_self, newuid, 0)) {
SYSERROR("Error sending pid over SCM_CREDENTIAL");
goto out;
}
exit(1);
}
*cglast = '\0';
- if (!lxc_cgmanager_enter(getpid(), controller, cgroup, abs_cgroup_supported())) {
+ if (!lxc_cgmanager_enter(lxc_raw_getpid(), controller, cgroup, abs_cgroup_supported())) {
WARN("Failed to enter container cgroup %s:%s", controller, cgroup);
ret = write(outp, &len, sizeof(len));
if (ret != sizeof(len))
exit(1);
}
*cglast = '\0';
- if (!lxc_cgmanager_enter(getpid(), controller, cgroup, abs_cgroup_supported())) {
+ if (!lxc_cgmanager_enter(lxc_raw_getpid(), controller, cgroup, abs_cgroup_supported())) {
ERROR("Failed to enter container cgroup %s:%s", controller, cgroup);
ret = write(outp, &retval, sizeof(retval));
if (ret != sizeof(retval))
}
cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
- i = snprintf(tmpnam, 50, "lxcprobe-%d", getpid());
+ i = snprintf(tmpnam, 50, "lxcprobe-%d", lxc_raw_getpid());
if (i < 0 || i >= 50) {
ERROR("Attack - format string modified?");
return false;
console->peerpty.busy = sockfd;
lxc_console_mainloop_add_peer(console);
- DEBUG("%d %s peermaster:%d sockfd:%d", getpid(), __FUNCTION__, console->peerpty.master, sockfd);
+ DEBUG("%d %s peermaster:%d sockfd:%d", lxc_raw_getpid(), __FUNCTION__, console->peerpty.master, sockfd);
return 0;
err1:
*/
static bool apparmor_am_unconfined(void)
{
- char *p = apparmor_process_label_get(getpid());
+ char *p = apparmor_process_label_get(lxc_raw_getpid());
bool ret = false;
if (!p || strcmp(p, "unconfined") == 0)
ret = true;
return 0;
}
- curlabel = apparmor_process_label_get(getpid());
+ curlabel = apparmor_process_label_get(lxc_raw_getpid());
if (!aa_stacking_supported() && aa_needs_transition(curlabel)) {
// we're already confined, and stacking isn't supported
if (!shutdown) {
shutdown = 1;
prevent_forking();
- if (getpid() != 1) {
- kill_children(getpid());
+ if (lxc_raw_getpid() != 1) {
+ kill_children(lxc_raw_getpid());
} else {
ret = kill(-1, SIGTERM);
if (ret < 0)
break;
case SIGALRM:
prevent_forking();
- if (getpid() != 1) {
- kill_children(getpid());
+ if (lxc_raw_getpid() != 1) {
+ kill_children(lxc_raw_getpid());
} else {
ret = kill(-1, SIGTERM);
if (ret < 0)
}
NOTICE("lxc-monitord with pid %d is now monitoring lxcpath %s.",
- getpid(), mon.lxcpath);
+ lxc_raw_getpid(), mon.lxcpath);
for (;;) {
ret = lxc_mainloop(&mon.descr, 1000 * 30);
if (ret) {
#include <sys/types.h>
#include "config.h"
+#include "namespace.h"
#include "network.h"
#include "utils.h"
int *container_veth_ifidx)
{
int ret;
+ pid_t pid_self;
uid_t ruid, suid, euid;
char ifname[IFNAMSIZ];
char *string_ret = NULL, *name = NULL;
int fd = -1, ifindex = -1, ofd = -1;
- ofd = lxc_preserve_ns(getpid(), "net");
+ pid_self = lxc_raw_getpid();
+ ofd = lxc_preserve_ns(pid_self, "net");
if (ofd < 0) {
- usernic_error("Failed opening network namespace path for %d", getpid());
+ usernic_error("Failed opening network namespace path for %d", pid_self);
return NULL;
}
static bool is_privileged_over_netns(int netns_fd)
{
int ret;
+ pid_t pid_self;
uid_t euid, ruid, suid;
bool bret = false;
int ofd = -1;
- ofd = lxc_preserve_ns(getpid(), "net");
+ pid_self = lxc_raw_getpid();
+ ofd = lxc_preserve_ns(pid_self, "net");
if (ofd < 0) {
- usernic_error("Failed opening network namespace path for %d", getpid());
+ usernic_error("Failed opening network namespace path for %d", pid_self);
return false;
}
/* become session leader */
ret = setsid();
if (ret < 0)
- TRACE("Process %d is already process group leader", getpid());
+ TRACE("Process %d is already process group leader", lxc_raw_getpid());
} else {
if (!am_single_threaded()) {
ERROR("Cannot start non-daemonized container when threaded");
return false;
}
- if (fprintf(pid_fp, "%d\n", getpid()) < 0) {
+ if (fprintf(pid_fp, "%d\n", lxc_raw_getpid()) < 0) {
SYSERROR("Failed to write '%s'", c->pidfile);
fclose(pid_fp);
pid_fp = NULL;
return false;
}
- pid_outside = getpid();
+ pid_outside = lxc_raw_getpid();
pid = fork();
if (pid < 0) {
ERROR("Failed to fork");
}
ret = snprintf(netns_path, sizeof(netns_path), "/proc/%d/fd/%d",
- getpid(), handler->netnsfd);
+ lxc_raw_getpid(), handler->netnsfd);
if (ret < 0 || ret >= sizeof(netns_path))
return false;
TRACE("Moving physical network devices back to parent network namespace");
- oldfd = lxc_preserve_ns(getpid(), "net");
+ oldfd = lxc_preserve_ns(lxc_raw_getpid(), "net");
if (oldfd < 0) {
SYSERROR("Failed to preserve network namespace");
return -1;
{
int i, rc;
struct lxc_list *cur, *next;
- pid_t self = getpid();
+ pid_t self = lxc_raw_getpid();
char *namespaces[LXC_NS_MAX + 1];
size_t namespace_count = 0;
}
if (handler->clone_flags & CLONE_NEWCGROUP) {
- fd = lxc_preserve_ns(syscall(SYS_getpid), "cgroup");
+ fd = lxc_preserve_ns(lxc_raw_getpid(), "cgroup");
if (fd < 0) {
ERROR("%s - Failed to preserve cgroup namespace", strerror(errno));
close(handler->data_sock[0]);
INFO("Failed to pin the rootfs for container \"%s\".", handler->name);
}
- if (!preserve_ns(saved_ns_fd, preserve_mask, getpid()))
+ if (!preserve_ns(saved_ns_fd, preserve_mask, lxc_raw_getpid()))
goto out_delete_net;
if (attach_ns(handler->conf->inherit_ns_fd) < 0)
return -1;
}
- mypid = getpid();
+ mypid = lxc_raw_getpid();
INFO("I am %d, /proc/self points to \"%s\"", mypid, link);
if (lxc_safe_int(link, &link_to_pid) < 0)
return fd;
}
-uint64_t lxc_getpagesize(void)
-{
- int64_t pgsz;
-
- pgsz = sysconf(_SC_PAGESIZE);
- if (pgsz <= 0)
- pgsz = 1 << 12;
-
- return pgsz;
-}
-
int parse_byte_size_string(const char *s, int64_t *converted)
{
int ret, suffix_len;
extern bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);
extern bool lxc_nic_exists(char *nic);
extern int lxc_make_tmpfile(char *template, bool rm);
-extern uint64_t lxc_getpagesize(void);
+
+static inline uint64_t lxc_getpagesize(void)
+{
+ int64_t pgsz;
+
+ pgsz = sysconf(_SC_PAGESIZE);
+ if (pgsz <= 0)
+ pgsz = 1 << 12;
+
+ return pgsz;
+}
/* If n is not a power of 2 this function will return the next power of 2
* greater than that number. Note that this function always returns the *next*