Skip to contentSkip to conversation

use syscall(NR_getpid) to avoid cached pid

PATCH In review Serge E. Hallyn 2 participants 2 messages Feb 17, 2010 – Feb 18, 2010 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use syscall(NR_getpid) to avoid cached pid

otherwise glibc caches getpid() result and we put the parent process in the new cgroup, in the case of 'nsexec -cg /bin/sleep 10'

---
 nsexec.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
nsexec.c +2 -2
index 3a825f1..79fcc70 100644
@@ -154,7 +154,7 @@ int move_to_new_cgroup(int newcgroup)
 	fout = fopen(tasksfname, "w");
 	if (!fout)
 		return 0;
-	fprintf(fout, "%d\n", getpid());
+	fprintf(fout, "%d\n", syscall(__NR_getpid));
 	fclose(fout);
 	return 1;
 }
@@ -193,7 +193,7 @@ int do_child(void *vargv)
 
 	/* if pid == 1 then remount /proc */
 	/* But if the container has no /proc don't fret */
-	if (getpid() == 1) {
+	if (syscall(__NR_getpid) == 1) {
 		umount2("/proc", MNT_DETACH);
 		mount("proc", "/proc", "proc", 0, NULL);
 	}
Signature · 1 line
1.6.4.4

A message that is not in the archive (sent off-list or not yet received): 20100217002409.GA3267-r/[email protected]

#2 lore raw

Got it, thanks.

Quoted 30 lines · Serge E. Hallyn

otherwise glibc caches getpid() result and we put the parent process in the new cgroup, in the case of 'nsexec -cg /bin/sleep 10'

---
 nsexec.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
nsexec.c +2 -2
index 3a825f1..79fcc70 100644
@@ -154,7 +154,7 @@ int move_to_new_cgroup(int newcgroup)
 	fout = fopen(tasksfname, "w");
 	if (!fout)
 		return 0;
-	fprintf(fout, "%d\n", getpid());
+	fprintf(fout, "%d\n", syscall(__NR_getpid));
 	fclose(fout);
 	return 1;
 }
@@ -193,7 +193,7 @@ int do_child(void *vargv)
 
 	/* if pid == 1 then remount /proc */
 	/* But if the container has no /proc don't fret */
-	if (getpid() == 1) {
+	if (syscall(__NR_getpid) == 1) {
 		umount2("/proc", MNT_DETACH);
 		mount("proc", "/proc", "proc", 0, NULL);
 	}