Exemple #1
0
    def gen_prpsinfo(self):
        """
        Generate NT_PRPSINFO note for process pid.
        """

        if self.x86 is True:
            prpsinfo = elf.elf_prpsinfo32()
        else:
            prpsinfo = elf.elf_prpsinfo()

        ctypes.memset(ctypes.addressof(prpsinfo), 0, ctypes.sizeof(prpsinfo))

        TASK_ALIVE = 0x1
        TASK_DEAD = 0x2
        TASK_STOPPED = 0x3

        if self.task.state == TASK_ALIVE:
            prpsinfo.pr_state = 0
        if self.task.state == TASK_DEAD:
            prpsinfo.pr_state = 4
        if self.task.state == TASK_STOPPED:
            prpsinfo.pr_state = 3

        prpsinfo.pr_sname = '.' if prpsinfo.pr_state > 5 else "RSDTZW"[
            prpsinfo.pr_state]
        prpsinfo.pr_zomb = 1 if prpsinfo.pr_state == 4 else 0
        prpsinfo.pr_nice = 0  #default
        prpsinfo.pr_flag = 0  #default
        prpsinfo.pr_uid = self.task.uid
        prpsinfo.pr_gid = self.task.gid
        prpsinfo.pr_pid = self.task.pid
        prpsinfo.pr_ppid = self.task.parent.pid
        prpsinfo.pr_pgrp = self.task.parent.gid
        prpsinfo.pr_sid = 0  #default
        prpsinfo.pr_fname = self.task.comm
        prpsinfo.pr_psargs = self.task.get_commandline()

        if self.x86 is True:
            nhdr = elf.Elf32_Nhdr()
            nhdr.n_namesz = 5
            nhdr.n_descsz = ctypes.sizeof(elf.elf_prpsinfo32())
            nhdr.n_type = elf.NT_PRPSINFO

        else:
            nhdr = elf.Elf64_Nhdr()
            nhdr.n_namesz = 5
            nhdr.n_descsz = ctypes.sizeof(elf.elf_prpsinfo())
            nhdr.n_type = elf.NT_PRPSINFO

        note = elf_note()
        note.data = prpsinfo
        note.owner = "CORE"
        note.nhdr = nhdr

        return note
Exemple #2
0
    def _gen_prpsinfo(self, pid):
        """
		Generate NT_PRPSINFO note for process pid.
		"""
        pstree = self.pstree[pid]
        creds = self.creds[pid]
        core = self.cores[pid]

        prpsinfo = elf.elf_prpsinfo()
        ctypes.memset(ctypes.addressof(prpsinfo), 0, ctypes.sizeof(prpsinfo))

        # FIXME TASK_ALIVE means that it is either running or sleeping, need to
        # teach criu to distinguish them.
        TASK_ALIVE = 0x1
        # XXX A bit of confusion here, as in ps "dead" and "zombie"
        # state are two separate states, and we use TASK_DEAD for zombies.
        TASK_DEAD = 0x2
        TASK_STOPPED = 0x3
        if core["tc"]["task_state"] == TASK_ALIVE:
            prpsinfo.pr_state = 0
        if core["tc"]["task_state"] == TASK_DEAD:
            prpsinfo.pr_state = 4
        if core["tc"]["task_state"] == TASK_STOPPED:
            prpsinfo.pr_state = 3
        # Don't even ask me why it is so, just borrowed from linux
        # source and made pr_state match.
        prpsinfo.pr_sname = '.' if prpsinfo.pr_state > 5 else "RSDTZW"[
            prpsinfo.pr_state]
        prpsinfo.pr_zomb = 1 if prpsinfo.pr_state == 4 else 0
        prpsinfo.pr_nice = core["thread_core"][
            "sched_prio"] if "sched_prio" in core["thread_core"] else 0
        prpsinfo.pr_flag = core["tc"]["flags"]
        prpsinfo.pr_uid = creds["uid"]
        prpsinfo.pr_gid = creds["gid"]
        prpsinfo.pr_pid = pid
        prpsinfo.pr_ppid = pstree["ppid"]
        prpsinfo.pr_pgrp = pstree["pgid"]
        prpsinfo.pr_sid = pstree["sid"]
        prpsinfo.pr_fname = core["tc"]["comm"]
        prpsinfo.pr_psargs = self._gen_cmdline(pid)

        nhdr = elf.Elf64_Nhdr()
        nhdr.n_namesz = 5
        nhdr.n_descsz = ctypes.sizeof(elf.elf_prpsinfo())
        nhdr.n_type = elf.NT_PRPSINFO

        note = elf_note()
        note.data = prpsinfo
        note.owner = "CORE"
        note.nhdr = nhdr

        return note
Exemple #3
0
	def _gen_prpsinfo(self, pid):
		"""
		Generate NT_PRPSINFO note for process pid.
		"""
		pstree	= self.pstree[pid]
		core	= self.cores[pid]

		prpsinfo = elf.elf_prpsinfo()
		ctypes.memset(ctypes.addressof(prpsinfo), 0, ctypes.sizeof(prpsinfo))

		# FIXME TASK_ALIVE means that it is either running or sleeping, need to
		# teach criu to distinguish them.
		TASK_ALIVE	= 0x1
		# XXX A bit of confusion here, as in ps "dead" and "zombie"
		# state are two separate states, and we use TASK_DEAD for zombies.
		TASK_DEAD	= 0x2
		TASK_STOPPED	= 0x3
		if core["tc"]["task_state"] == TASK_ALIVE:
			prpsinfo.pr_state	= 0
		if core["tc"]["task_state"] == TASK_DEAD:
			prpsinfo.pr_state	= 4
		if core["tc"]["task_state"] == TASK_STOPPED:
			prpsinfo.pr_state	= 3
		# Don't even ask me why it is so, just borrowed from linux
		# source and made pr_state match.
		prpsinfo.pr_sname	= '.' if prpsinfo.pr_state > 5 else "RSDTZW"[prpsinfo.pr_state]
		prpsinfo.pr_zomb	= 1 if prpsinfo.pr_state == 4 else 0
		prpsinfo.pr_nice	= core["thread_core"]["sched_prio"] if "sched_prio" in core["thread_core"] else 0
		prpsinfo.pr_flag	= core["tc"]["flags"]
		prpsinfo.pr_uid		= core["thread_core"]["creds"]["uid"]
		prpsinfo.pr_gid		= core["thread_core"]["creds"]["gid"]
		prpsinfo.pr_pid		= pid
		prpsinfo.pr_ppid	= pstree["ppid"]
		prpsinfo.pr_pgrp	= pstree["pgid"]
		prpsinfo.pr_sid		= pstree["sid"]
		prpsinfo.pr_fname	= core["tc"]["comm"]
		prpsinfo.pr_psargs	= self._gen_cmdline(pid)

		nhdr = elf.Elf64_Nhdr()
		nhdr.n_namesz	= 5
		nhdr.n_descsz	= ctypes.sizeof(elf.elf_prpsinfo())
		nhdr.n_type	= elf.NT_PRPSINFO

		note = elf_note()
		note.data	= prpsinfo
		note.owner	= "CORE"
		note.nhdr 	= nhdr

		return note