Changeset 2693
- Timestamp:
- 03/01/08 01:26:31 (9 months ago)
- Files:
-
- trunk/src/rpm-fake.c (modified) (6 diffs)
- trunk/src/vnamespace.c (modified) (3 diffs)
- trunk/src/vspace.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/rpm-fake.c
r2690 r2693 26 26 #include <lib/vserver.h> 27 27 #include <lib/internal.h> 28 #include <lib_internal/sys_ unshare.h>28 #include <lib_internal/sys_clone.h> 29 29 30 30 #include <sys/socket.h> … … 50 50 #include <pwd.h> 51 51 #include <grp.h> 52 #include <sched.h> 52 53 53 54 54 // from selinux.h … … 630 630 } 631 631 632 struct ExecvParams 633 { 634 char const * path; 635 char * const * argv; 636 char * const * envp; 637 char const * mnts; 638 }; 639 632 640 static int 633 removeNamespaceMounts (char const *mnts)634 { 635 char buf[strlen( mnts)+1], *ptr;636 637 strcpy(buf, mnts);641 removeNamespaceMountsChild(struct ExecvParams const *params) 642 { 643 char buf[strlen(params->mnts)+1], *ptr; 644 645 strcpy(buf, params->mnts); 638 646 ptr = strtok(buf, ":"); 639 647 while (ptr) { … … 649 657 } 650 658 651 return 0;659 return execvWorker(params->path, params->argv, params->envp); 652 660 } 653 661 654 662 static int 655 execv_main(char const *path, char * const argv[], char * const envp[]) 656 { 657 int rc = 0; 658 659 if (sys_unshare(CLONE_NEWNS)==-1) { 660 perror("unshare()"); 663 removeNamespaceMounts(char const *path, 664 char * const argv[], char * const envp[]) 665 { 666 if (mnts==0) return execvWorker(path, argv, envp); 667 668 { 669 int status; 670 pid_t p, pid; 671 struct ExecvParams params; 672 673 params.path = path; 674 params.argv = argv; 675 params.envp = envp; 676 params.mnts = mnts; 677 678 // the rpmlib signal-handler is still active; use the default one to 679 // make wait4() working... 680 signal(SIGCHLD, SIG_DFL); 681 682 #ifdef NDEBUG 683 pid = sys_clone(CLONE_NEWNS|SIGCHLD|CLONE_VFORK, 0); 684 #else 685 pid = sys_clone(CLONE_NEWNS|SIGCHLD, 0); 686 #endif 687 688 switch (pid) { 689 case -1 : return -1; 690 case 0 : _exit(removeNamespaceMountsChild(¶ms)); 691 default : break; 692 } 693 694 while ((p=wait4(pid, &status, 0,0))==-1 && 695 (errno==EINTR || errno==EAGAIN)) ; 696 697 if (p==-1) return -1; 698 699 if (WIFEXITED(status)) _exit(WEXITSTATUS(status)); 700 if (WIFSIGNALED(status)) kill(getpid(), WTERMSIG(status)); 701 661 702 return -1; 662 703 } 663 664 if (mnts) 665 rc = removeNamespaceMounts(mnts); 666 667 if (rc!=0) 668 return rc; 669 670 return execvWorker(path, argv, envp); 671 } 704 } 705 672 706 673 707 int … … 682 716 } 683 717 684 return execv_main(path, argv, environ);718 return removeNamespaceMounts(path, argv, environ); 685 719 } 686 720 … … 696 730 } 697 731 698 return execv_main(filename, argv, envp);732 return removeNamespaceMounts(filename, argv, envp); 699 733 } 700 734 trunk/src/vnamespace.c
r2690 r2693 22 22 23 23 #include "util.h" 24 #include <lib_internal/sys_ unshare.h>24 #include <lib_internal/sys_clone.h> 25 25 26 26 #include <vserver.h> … … 89 89 90 90 static void 91 newNamespace( void)91 newNamespace(char const *cmd) 92 92 { 93 int rc;93 pid_t pid; 94 94 95 rc = sys_unshare(CLONE_NEWNS); 96 if (rc!=0) { 97 perror("vnamespace: unshare()"); 98 exit(wrapper_exit_code); 95 signal(SIGCHLD, SIG_DFL); 96 97 #ifdef NDEBUG 98 pid = sys_clone(CLONE_NEWNS|CLONE_VFORK|SIGCHLD, 0); 99 #else 100 pid = sys_clone(CLONE_NEWNS|SIGCHLD, 0); 101 #endif 102 103 switch (pid) { 104 case -1 : 105 perror("vnamespace: clone()"); 106 exit(wrapper_exit_code); 107 case 0 : 108 break; 109 default : 110 exitLikeProcess(pid, cmd, wrapper_exit_code); 99 111 } 100 112 } … … 170 182 WRITE_MSG(2, "No command specified; try '--help' for more information\n"); 171 183 else { 172 if (do_new) newNamespace( );184 if (do_new) newNamespace(argv[optind]); 173 185 else if (do_set) setNamespace(VC_SAMECTX, CLONE_NEWNS|CLONE_FS); 174 186 else if (do_cleanup) cleanupNamespace(); trunk/src/vspace.c
r2690 r2693 23 23 24 24 #include "util.h" 25 #include <lib_internal/sys_ unshare.h>25 #include <lib_internal/sys_clone.h> 26 26 27 27 #include <vserver.h> … … 107 107 108 108 static void 109 newSpaces(uint_least64_t mask) 110 { 111 int rc; 112 113 rc = sys_unshare(mask); 114 if (rc) { 115 perror(ENSC_WRAPPERS_PREFIX "unshare()"); 116 exit(wrapper_exit_code); 109 newSpaces(uint_least64_t mask, const char *cmd) 110 { 111 pid_t pid; 112 113 /* optimize default case */ 114 if (mask == 0) 115 return; 116 117 signal(SIGCHLD, SIG_DFL); 118 119 #ifdef NDEBUG 120 pid = sys_clone((int) mask | CLONE_VFORK|SIGCHLD, 0); 121 #else 122 pid = sys_clone((int) mask | SIGCHLD, 0); 123 #endif 124 125 switch (pid) { 126 case -1 : 127 perror(ENSC_WRAPPERS_PREFIX "clone()"); 128 exit(wrapper_exit_code); 129 case 0 : 130 break; 131 default : 132 exitLikeProcess(pid, cmd, wrapper_exit_code); 117 133 } 118 134 } … … 196 212 WRITE_MSG(2, "No command specified; try '--help' for more information\n"); 197 213 else { 198 if (do_new) newSpaces(mask );214 if (do_new) newSpaces(mask, argv[optind]); 199 215 else if (do_set) setSpaces(VC_SAMECTX, mask); 200 216 else if (do_enter) enterSpaces(xid, mask);
