c - Wrong /proc/self/root after unshare(CLONE_NEWNS) syscall -


i have armv7 device linux kernel 4.4 , have simple test case:

/* thread.c */ #define _gnu_source #include <pthread.h> #include <unistd.h> #include <stdio.h> #include <sched.h>  void readlink_my(const char* when) {     char buf[100];     int len = readlink("/proc/self/root", buf, sizeof(buf));     buf[len] = '\0';     printf("%s: %s\n", when, buf); }  void *first_func(void * ptr) {     readlink_my("before unshare()..");     if(unshare(clone_newns) == -1)         perror("error in unshare()..\n");     readlink_my("after unshare()..");     return null; }  int main() {     pthread_t first_t;     pthread_create(&first_t, null, first_func, null);     pthread_join(first_t, null);     return 0; } 

after executing binary have output:

# before unshare()..: / # after unshare()..: /new_root 

if i'm removing multithreading test case:

/* thread.c */ #include <unistd.h> #include <stdio.h> #include <sched.h>  void readlink_my(const char* when) {     char buf[100];     int len = readlink("/proc/self/root", buf, sizeof(buf));     buf[len] = '\0';     printf("%s: %s\n", when, buf); }  int main() {     readlink_my("before unshare()..");     if(unshare(clone_newns) == -1)         perror("error in unshare()..\n");     readlink_my("after unshare()..");     return 0; } 

i ouput without /new_root after unshare():

# before unshare()..: / # after unshare()..: / 

as think after unshare(clone_newns) copy mount namespace.

where did /new_root in first multithreading example?


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -