setup file-max by default

Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
Gao feng
2016-08-29 16:06:14 +08:00
parent cb71f43ed1
commit 1e4711d898
4 changed files with 35 additions and 22 deletions
+4 -21
View File
@@ -384,41 +384,24 @@ static int container_setup_init_layer(struct hyper_container *container,
static int container_setup_sysctl(struct hyper_container *container)
{
int i, size, len, l, fd;
int i;
struct sysctl *sys;
for (i = 0; i < container->sys_num; i++) {
char path[256];
len = 0;
sys = &container->sys[i];
size = strlen(sys->value);
sprintf(path, "/proc/sys/%s", sys->path);
fprintf(stdout, "sysctl %s value %s\n", sys->path, sys->value);
fd = open(path, O_WRONLY);
if (fd < 0) {
perror("open file failed");
goto out;
if (hyper_write_file(path, sys->value, strlen(sys->value)) < 0) {
fprintf(stderr, "sysctl: write %s to %s failed\n", sys->value, path);
return -1;
}
while (len < size) {
l = write(fd, sys->value + len, size - len);
if (l < 0) {
perror("fail to write sysctl");
close(fd);
goto out;
}
len += l;
}
close(fd);
}
return 0;
out:
return -1;
}
static int container_setup_dns(struct hyper_container *container)
+7 -1
View File
@@ -1146,6 +1146,7 @@ static int hyper_loop(void)
struct hyper_pod *pod = &global_pod;
sigset_t mask, omask;
struct rlimit limit;
char *filemax = "1000000";
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
@@ -1164,8 +1165,13 @@ static int hyper_loop(void)
sigdelset(&omask, SIGCHLD);
signal(SIGCHLD, hyper_init_sigchld);
if (hyper_write_file("/proc/sys/fs/file-max", filemax, strlen(filemax)) < 0) {
fprintf(stderr, "sysctl: setup default file-max(%s) failed\n", filemax);
return -1;
}
// setup open file limit
limit.rlim_cur = limit.rlim_max = 1000000;
limit.rlim_cur = limit.rlim_max = atoi(filemax);
if (setrlimit(RLIMIT_NOFILE, &limit) < 0) {
perror("set rlimit for NOFILE failed");
return -1;
+23
View File
@@ -208,6 +208,29 @@ int hyper_getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroup
return ret;
}
int hyper_write_file(const char *path, const char *value, size_t len)
{
size_t size = 0, l;
int fd = open(path, O_WRONLY);
if (fd < 0) {
perror("open file failed");
return -1;
}
while (size < len) {
l = write(fd, value + size, len - size);
if (l < 0) {
perror("fail to write to file");
close(fd);
return -1;
}
size += l;
}
close(fd);
return 0;
}
/* Trim all trailing '/' of a hyper_path except for the prefix one. */
void hyper_filize(char *hyper_path)
{
+1
View File
@@ -28,6 +28,7 @@ int hyper_cmd(char *cmd);
int hyper_create_file(const char *hyper_path);
void hyper_filize(char *hyper_path);
int hyper_mkdir(char *path, mode_t mode);
int hyper_write_file(const char *path, const char *value, size_t len);
int hyper_open_channel(char *channel, int mode);
int hyper_open_serial_dev(char *tty);
int hyper_setfd_cloexec(int fd);