OpenVZ Forum


Home » Mailing lists » Devel » [PATCH 0/11] user-cr: support for pids as shared objects (v2)
[PATCH 05/11] restart: obtain pid_max from /proc/sys/kernel/pid_max [message #41568 is a reply to message #41565] Mon, 07 February 2011 17:21 Go to previous messageGo to previous message
Oren Laadan is currently offline  Oren Laadan
Messages: 71
Registered: August 2007
Member
Signed-off-by: Oren Laadan <orenl@cs.columbia.edu>
---
restart.c | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/restart.c b/restart.c
index a1af631..05d101b 100644
--- a/restart.c
+++ b/restart.c
@@ -158,6 +158,9 @@ struct ckpt_ctx {
struct cr_restart_args *args;

char *freezer;
+
+ /* system limits */
+ pid_t pid_max;
};

struct pid_swap {
@@ -489,6 +492,9 @@ int process_args(struct cr_restart_args *args)

static void init_ctx(struct ckpt_ctx *ctx)
{
+ FILE *file;
+ char buf[1024];
+
memset(ctx, 0, sizeof(*ctx));

/* mark all fds as unused */
@@ -500,6 +506,15 @@ static void init_ctx(struct ckpt_ctx *ctx)
ctx->pipe_feed[1] = -1;
ctx->pipe_coord[0] = -1;
ctx->pipe_coord[1] = -1;
+
+ /* system limits */
+ ctx->pid_max = SHRT_MAX; /* default */
+ file = fopen("/proc/sys/kernel/pid_max", "r");
+ if (file) {
+ if (fgets(buf, 1024, file))
+ ctx->pid_max = atoi(buf);
+ fclose(file);
+ }
}

static void exit_ctx(struct ckpt_ctx *ctx)
@@ -1223,12 +1238,12 @@ static int ckpt_alloc_pid(struct ckpt_ctx *ctx)
* (this will become inefficient if pid-space is exhausted)
*/
do {
- if (ctx->tasks_pid == INT_MAX)
+ if (ctx->tasks_pid == ctx->pid_max)
ctx->tasks_pid = CKPT_RESERVED_PIDS;
else
ctx->tasks_pid++;

- if (n++ == INT_MAX) { /* ohhh... */
+ if (n++ == ctx->pid_max) { /* ohhh... */
ckpt_err("pid namsepace exhausted");
return -1;
}
--
1.7.1

_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containe rs
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [PATCH 06/11] restart: rename 'ctx-&gt;tasks_arr' to 'ctx-&gt;tasks'
Next Topic: [PATCH v3] cgroup/freezer: add per freezer duty ratio control
Goto Forum:
  


Current Time: Fri Oct 18 22:02:21 GMT 2024

Total time taken to generate the page: 0.04945 seconds