-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from arkane-systems/dev-0.14
Dev 0.14
- Loading branch information
Showing
27 changed files
with
581 additions
and
149 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
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,91 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
|
||
import mountie | ||
|
||
def print_help_message(): | ||
"""Display a help message for imp-executor.""" | ||
|
||
print ("""imp-executor: internal functions for bottle-imp | ||
You should not use this directly under normal circumstances. | ||
It should only be called by bottle-imp provided services. | ||
Operations: | ||
help Display this message. | ||
rrfs Remount root filesystem shared. | ||
devshm Fix /dev/shm mount. | ||
pstore Mount pstore filesystem. | ||
security Mount security filesystem. | ||
wslg Bind mount WSL .X11-unix. | ||
""") | ||
|
||
|
||
def fix_dev_shm(): | ||
"""Move the tmpfs for shared memory to /dev/shm and bind mount it from /run/shm.""" | ||
os.unlink ("/dev/shm") | ||
os.mkdir ("/dev/shm") | ||
mountie.mount ("/run/shm", "/dev/shm", "", mountie.MS_MOVE) | ||
mountie.mount ("/dev/shm", "/run/shm", "", mountie.MS_BIND) | ||
# os.rmdir ("/run/shm") | ||
# os.symlink ("/dev/shm", "/run/shm") | ||
|
||
|
||
def mount_pstore_filesystem(): | ||
"""Mount the pstore filesystem.""" | ||
mountie.mount ("pstore", "/sys/fs/pstore", "pstore", | ||
mountie.MS_NOSUID | mountie.MS_NODEV | mountie.MS_NOEXEC) | ||
|
||
|
||
def mount_security_filesystem(): | ||
"""Mount the security filesystem.""" | ||
mountie.mount ("securityfs", "/sys/kernel/security", "securityfs", | ||
mountie.MS_NOSUID | mountie.MS_NODEV | mountie.MS_NOEXEC) | ||
|
||
|
||
def remount_root_shared(): | ||
"""Remount the root filesystem shared.""" | ||
mountie.mount ("none", "/", "", mountie.MS_REC | mountie.MS_SHARED, "") | ||
|
||
|
||
def remount_wslg(): | ||
"""Remount the WSLg socket in the appropriate place.""" | ||
mountie.mount ("/mnt/wslg/.X11-unix", "/tmp/.X11-unix", "", | ||
mountie.MS_BIND | mountie.MS_RDONLY) | ||
# required because flags other than MS_BIND ignored in first call. | ||
mountie.mount ("none", "/tmp/.X11-unix", "", | ||
mountie.MS_REMOUNT | mountie.MS_BIND | mountie.MS_RDONLY) | ||
|
||
|
||
def entrypoint(): | ||
"""Entry point for the imp-executor.""" | ||
|
||
# Check the command-line arguments. | ||
if (len (sys.argv) < 2): | ||
sys.exit ("imp-executor requires the operation to perform") | ||
|
||
operation = sys.argv[1] | ||
|
||
if operation == "help": | ||
print_help_message() | ||
elif operation == "rrfs": | ||
remount_root_shared() | ||
elif operation == "pstore": | ||
mount_pstore_filesystem() | ||
elif operation == "security": | ||
mount_security_filesystem() | ||
elif operation == "devshm": | ||
fix_dev_shm() | ||
elif operation == "wslg": | ||
remount_wslg() | ||
else: | ||
print ("imp-executor: operation not recognized") | ||
|
||
|
||
entrypoint() | ||
|
||
# End of file. |
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 @@ | ||
../shared/configuration.py |
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,62 @@ | ||
# Mount/unmount helper functions | ||
|
||
import ctypes | ||
import ctypes.util | ||
import os | ||
|
||
|
||
# Mount flags | ||
MS_NONE = 0 # No flags. | ||
MS_RDONLY = 1 # Mount read-only. | ||
MS_NOSUID = 2 # Ignore suid and sgid bits. | ||
MS_NODEV = 4 # Disallow access to device special files. | ||
MS_NOEXEC = 8 # Disallow program execution. | ||
MS_SYNCHRONOUS = 16 # Writes are synced at once. | ||
MS_REMOUNT = 32 # Alter flags of a mounted filesystem. | ||
MS_MANDLOCK = 64 # Allow mandatory locks on an FS. | ||
MS_DIRSYNC = 128 # Directory modifications are synchronous. | ||
MS_NOSYMFOLLOW = 256 # Do not follow symlinks. | ||
MS_NOATIME = 1024 # Do not update access times. | ||
MS_NODIRATIME = 2048 # Do not update directory access times. | ||
MS_BIND = 4096 # Bind directory at different place. | ||
MS_MOVE = 8192 | ||
MS_REC = 16384 | ||
MS_SILENT = 32768 | ||
MS_POSIXACL = 1 << 16 # VFS does not apply the umask. | ||
MS_UNBINDABLE = 1 << 17 # Change to unbindable. | ||
MS_PRIVATE = 1 << 18 # Change to private. | ||
MS_SLAVE = 1 << 19 # Change to slave. | ||
MS_SHARED = 1 << 20 # Set propagation type to shared. | ||
MS_RELATIME = 1 << 21 # Update atime relative to mtime/ctime. | ||
MS_KERNMOUNT = 1 << 22 # This is a kern_mount call. | ||
MS_I_VERSION = 1 << 23 # Update inode I_version field. | ||
MS_STRICTATIME = 1 << 24 # Always perform atime updates. | ||
MS_LAZYTIME = 1 << 25 # Update the on-disk [acm]times lazily. | ||
MS_ACTIVE = 1 << 30 | ||
MS_NOUSER = 1 << 31 | ||
|
||
|
||
# Unmount flags | ||
MU_NONE = 0 # No flags. | ||
# ... TODO: add these | ||
|
||
|
||
libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True) | ||
libc.mount.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_char_p) | ||
libc.umount2.argtypes = (ctypes.c_char_p, ctypes.c_int) | ||
|
||
|
||
def mount (source: str, target: str, fs: str, flags: int = MS_NONE, options=''): | ||
"""Mount a filesystem.""" | ||
ret = libc.mount(source.encode(), target.encode(), fs.encode(), flags, options.encode()) | ||
if ret < 0: | ||
errno = ctypes.get_errno() | ||
raise OSError(errno, f"Error mounting {source} ({fs}) on {target} with flags {flags} and options '{options}': {os.strerror(errno)}") | ||
|
||
|
||
def unmount (target: str, flags: int = MU_NONE): | ||
"""Unmount a filesystem.""" | ||
ret = libc.umount2(target.encode(), flags) | ||
if ret < 0: | ||
errno = ctypes.get_errno() | ||
raise OSError(errno, f"Error unmounting {target}: {os.strerror(errno)}") |
Empty file.
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,33 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
|
||
from definitions import Generatee | ||
|
||
import genhelper | ||
import generatees | ||
|
||
def entrypoint(): | ||
"""Entry point for the imp-generator.""" | ||
|
||
# Check the command-line arguments; test the resulting normal dir path. | ||
if (len (sys.argv) < 2): | ||
sys.exit ("imp-generator requires the path of the target directory") | ||
|
||
normal_dir = os.path.abspath(sys.argv[1]) | ||
|
||
if not os.path.exists(normal_dir): | ||
sys.exit ("generated-file directory must exist") | ||
|
||
# Create generator helper. | ||
gh = genhelper.GeneratorHelper(normal_dir) | ||
|
||
# Iterate through generatees. | ||
for g in generatees.generatees: | ||
g.generate(gh) | ||
|
||
|
||
entrypoint() | ||
|
||
# End of file. |
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 @@ | ||
../shared/configuration.py |
Oops, something went wrong.