aboutsummaryrefslogtreecommitdiff
blob: 5c512a84aab8f8a6ee74ebddef9ef929315fdd51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# (c) 2017, Alice Ferrazzi <alice.ferrazzi@gmail.com>
# Distributed under the terms of the GNU General Public License v2 or later

import subprocess
import os

class PaTch(object):

    def __init__(self):
        self.config_file = None
        self.patch_file = None
        self.kernel_version = None
        self.livepatch_status = "Not started"
        self.kernel_dir = None

    def set_kernel_dir(self, kernel_dir):
        self.kernel_dir = kernel_dir

    def get_kernel_dir(self):
        return self.kernel_dir

    def set_lp_status(self, livepatch_status):
        self.livepatch_status = livepatch_status

    def get_lp_status(self):
        return self.livepatch_status

    def update_lp_status(self, livepatch):
        if os.path.isfile(livepatch):
            self.livepatch_status = 'done'
        return self.livepatch_status

    def set_kernel_version(self, kernel_version):
        self.kernel_version = kernel_version

    def get_kernel_version(self):
        return self.kernel_version

    def get_config(self):
        return self.config_file

    def set_config(self, config_file):
        self.config_file = config_file

    def set_patch(self, patch_file):
        self.patch_file = patch_file

    def get_patch(self):
        return self.patch_file

    def kernel_version(self):
        pass

    def compare_kernel_config(self):
        pass

    def recompile_kernel(self):
        pass

    def search_kernel_source_path(self):
        pass

    def get_kernel_source_path(self):
        self.kernel_path =''
        return self.kernel_path

    # kpatch-build/kpatch-build -s /usr/src/linux-4.9.16-gentoo/
    # -v /usr/src/linux-4.9.16-gentoo/vmlinux examples/test.patch
    # -c ../elivepatch/elivepatch_server/config --skip-gcc-check
    def build_livepatch(self, kernel_source, vmlinux):
        """
        
        :param kernel_source: 
        :param vmlinux: 
        :return: 
        """
        debug=True
        bashCommand = 'sudo kpatch-build'
        bashCommand += ' -s ' + kernel_source
        bashCommand += ' -v ' + vmlinux
        bashCommand += ' -c ' + self.config_file
        bashCommand += ' ' + self.patch_file
        bashCommand += ' --skip-gcc-check'
        if debug:
            bashCommand += ' --skip-cleanup'
            bashCommand += ' --debug'
        print(bashCommand)
        process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
        output, error = process.communicate()
        print(output)