namespace.h 2.3 KB
Newer Older
O
overweight 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/******************************************************************************
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
 * iSulad licensed under the Mulan PSL v1.
 * You can use this software according to the terms and conditions of the Mulan PSL v1.
 * You may obtain a copy of Mulan PSL v1 at:
 *     http://license.coscl.org.cn/MulanPSL
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v1 for more details.
 * Author: tanyifeng
 * Create: 2018-11-08
 * Description: provide namespace definition
 ******************************************************************************/
#ifndef __NAMESPACE_H
#define __NAMESPACE_H

#include <stdbool.h>
#include <string.h>

#define SHARE_NAMESPACE_PREFIX "container:"
#define SHARE_NAMESPACE_HOST "host"
#define SHARE_NAMESPACE_NONE "none"

#define SHARE_NAMESPACE_PID_HOST_PATH "/proc/1/ns/pid"
#define SHARE_NAMESPACE_NET_HOST_PATH "/proc/1/ns/net"
#define SHARE_NAMESPACE_IPC_HOST_PATH "/proc/1/ns/ipc"
#define SHARE_NAMESPACE_UTS_HOST_PATH "/proc/1/ns/uts"
#define SHARE_NAMESPACE_MNT_HOST_PATH "/proc/1/ns/mnt"
#define SHARE_NAMESPACE_USER_HOST_PATH "/proc/1/ns/user"
#define SHARE_NAMESPACE_CGROUP_HOST_PATH "/proc/1/ns/cgroup"


#define TYPE_NAMESPACE_PID "pid"
#define TYPE_NAMESPACE_NETWORK "network"
#define TYPE_NAMESPACE_IPC "ipc"
#define TYPE_NAMESPACE_UTS "uts"
#define TYPE_NAMESPACE_MOUNT "mount"
#define TYPE_NAMESPACE_USER "user"
#define TYPE_NAMESPACE_CGROUP "cgroup"

#define ETC_HOSTS "/etc/hosts"
43
#define ETC_HOSTNAME "/etc/hostname"
O
overweight 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#define RESOLV_CONF_PATH "/etc/resolv.conf"

static inline bool is_host(const char *mode)
{
    if (mode != NULL && strcmp(mode, SHARE_NAMESPACE_HOST) == 0) {
        return true;
    }
    return false;
}

static inline bool is_none(const char *mode)
{
    if (mode != NULL && strcmp(mode, SHARE_NAMESPACE_NONE) == 0) {
        return true;
    }
    return false;
}

static inline bool is_container(const char *mode)
{
    if (mode != NULL &&
        strncmp(mode, SHARE_NAMESPACE_PREFIX, strlen(SHARE_NAMESPACE_PREFIX)) == 0) {
        return true;
    }
    return false;
}

char *get_share_namespace_path(const char *type, const char *src_path);

#endif
D
dogsheng 已提交
74