Skip to content

Commit

Permalink
API - int signal + CLI - support with signal name
Browse files Browse the repository at this point in the history
  • Loading branch information
ohadshai committed Sep 13, 2021
1 parent d1d7379 commit 596b16c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pymobiledevice3/cli/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import shlex
from collections import namedtuple
from dataclasses import asdict
import signal

import click
from click.exceptions import MissingParameter, UsageError
from pykdebugparser.pykdebugparser import PyKdebugParser
from termcolor import colored

Expand Down Expand Up @@ -99,9 +101,15 @@ def applist(lockdown, color):

@dvt.command('signal', cls=Command)
@click.argument('pid', type=click.INT)
@click.argument('sig', type=click.INT)
def signal(lockdown, pid, sig):
@click.argument('sig', type=click.INT, required=False)
@click.option('-s', '--signal-name', type=click.Choice([s.name for s in signal.Signals]))
def send_signal(lockdown, pid, sig, signal_name):
""" Send SIGNAL to process by its PID """
if not sig and not signal_name:
raise MissingParameter(param_type="argument|option", param_hint="\"SIG|SIGNAL-NAME\"")
if sig and signal_name:
raise UsageError(message="Cannot give SIG and SIGNAL-NAME together")
sig = sig or signal.Signals[signal_name].value
with DvtSecureSocketProxyService(lockdown=lockdown) as dvt:
ProcessControl(dvt).signal(pid, sig)

Expand Down
4 changes: 2 additions & 2 deletions pymobiledevice3/services/dvt/instruments/process_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class ProcessControl:
def __init__(self, dvt):
self._channel = dvt.make_channel(self.IDENTIFIER)

def signal(self, pid: int, sig: signal.Signals):
def signal(self, pid: int, sig: int):
"""
Send signal to process
:param pid: PID of process to send signal.
:param sig: SIGNAL to send
"""
self._channel.sendSignal_toPid_(MessageAux().append_obj(int(sig)).append_obj(pid), expects_reply=True)
self._channel.sendSignal_toPid_(MessageAux().append_obj(sig).append_obj(pid), expects_reply=True)
return self._channel.receive_plist()

def kill(self, pid: int):
Expand Down

0 comments on commit 596b16c

Please sign in to comment.