forked from litmuschaos/test-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mount ns support to nsutil (litmuschaos#499)
Signed-off-by: Shubham Chaudhary <[email protected]>
- Loading branch information
1 parent
f887e23
commit 9cea95d
Showing
7 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM arm64v8/ubuntu:latest | ||
|
||
# Install gcc for compiling C code | ||
RUN apt-get update && apt-get install -y gcc | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy your C code into the container | ||
COPY nsutil.c /app | ||
|
||
# Compile the C code | ||
RUN gcc -shared -fPIC nsutil.c -o nsutil.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#define _GNU_SOURCE | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <sched.h> | ||
#include <sys/stat.h> | ||
|
||
void nsenter() { | ||
char *mnt_path = getenv("MNT_PATH"); | ||
if (mnt_path != NULL) { | ||
int fd = open(mnt_path, O_RDONLY); | ||
if (fd == -1) { | ||
perror("open"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
int ns = setns(fd, 0); | ||
if (ns == -1) { | ||
perror("setns"); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
unsetenv("LD_PRELOAD"); | ||
} | ||
|
||
__attribute__((constructor)) void ctor() { | ||
nsenter(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters