[PATCH 5/9] restart: obtain pid_max from /proc/sys/kernel/pid_max

Oren Laadan orenl at cs.columbia.edu
Wed Jan 26 08:19:04 PST 2011


Signed-off-by: Oren Laadan <orenl at cs.columbia.edu>
---
 restart.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/restart.c b/restart.c
index 9535543..d998834 100644
--- a/restart.c
+++ b/restart.c
@@ -157,6 +157,9 @@ struct ckpt_ctx {
 	struct cr_restart_args *args;
 
 	char *freezer;
+
+	/* system limits */
+	pid_t pid_max;
 };
 
 struct pid_swap {
@@ -488,6 +491,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 */
@@ -499,6 +505,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)
@@ -1212,12 +1227,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



More information about the Containers mailing list