diff options
author | 2017-08-04 11:41:10 +0900 | |
---|---|---|
committer | 2017-08-04 11:41:10 +0900 | |
commit | 9263ca33c1d34f92684cdafcd20054abc49bf571 (patch) | |
tree | 051b006659c2f5a5b8b34f05b1834470a098705b | |
parent | initial work for sending multiple patches on the same post (diff) | |
download | elivepatch-9263ca33c1d34f92684cdafcd20054abc49bf571.tar.gz elivepatch-9263ca33c1d34f92684cdafcd20054abc49bf571.tar.bz2 elivepatch-9263ca33c1d34f92684cdafcd20054abc49bf571.zip |
added live patch loader
we need to know if a live patch as really been applied for doing that
the client can apply the patch and report back
TODO: probably would nice to make it optional in the elivepatch arguments
-rw-r--r-- | elivepatch_client/client/patch.py | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/elivepatch_client/client/patch.py b/elivepatch_client/client/patch.py index ba086b5..c09f0b9 100644 --- a/elivepatch_client/client/patch.py +++ b/elivepatch_client/client/patch.py @@ -1,24 +1,66 @@ import os - +import shutil +import tempfile +import subprocess class ManaGer(object): def __init__(self): - self.tmp_patch = os.path.join('/tmp', 'elivepatch') - if not os.path.exists(self.tmp_patch): - os.mkdir(self.tmp_patch) + self.tmp_patch_folder = os.path.join('/tmp', 'elivepatch') + if not os.path.exists(self.tmp_patch_folder): + os.mkdir(self.tmp_patch_folder) def list(self): patch_filename = [] - for (dirpath, dirnames, filenames) in os.walk(self.tmp_patch): + for (dirpath, dirnames, filenames) in os.walk(self.tmp_patch_folder): patch_filename.extend(filenames) break print('List of current patches:') print(patch_filename) - def save(self, patch): + def load(self, patch_fulldir, livepatch_fulldir): + try: + command(['sudo','kpatch','load',livepatch_fulldir]) + print('patch_fulldir:' + str(patch_fulldir) + ' livepatch_fulldir: '+ str(livepatch_fulldir)) + self.save(patch_fulldir, livepatch_fulldir) + except: + print('failed to load the livepatch') + + def save(self, patch, livepatch): i = 0 - while os.path.exists("elivepatch_%s.patch" % i): + while os.path.exists(os.path.join(self.tmp_patch_folder, "elivepatch_%s" % i)): i += 1 - fh = open("elivepatch_%s.patch" % i, "w")
\ No newline at end of file + path_folder = os.path.join(self.tmp_patch_folder, "elivepatch_%s" % i) + os.mkdir(path_folder) + shutil.copy(patch, os.path.join(path_folder, "elivepatch.patch")) + try: + shutil.copy(livepatch, os.path.join(path_folder, "elivepatch.ko")) + except: + pass + + +def command(bashCommand, kernel_source_dir=None, env=None): + """ + Popen override function + + :param bashCommand: List of command arguments to execute + :param kernel_source_dir: the source directory of the kernel + :return: void + """ + # Inherit the parent environment and update the private copy + if env: + process_env = os.environ.copy() + process_env.update(env) + env = process_env + + if kernel_source_dir: + print(bashCommand) + process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, cwd=kernel_source_dir, env=env) + output, error = process.communicate() + print(output) + else: + print(bashCommand) + process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, env=env) + output, error = process.communicate() + print(output) |