Skip to content

Commit

Permalink
Get daemon names from dbus (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
sean797 committed May 16, 2017
1 parent 20f23c6 commit ee1c7f7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 64 deletions.
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: python
sudo: false
dist: trusty
sudo: required

python:
- "2.7"
Expand All @@ -8,7 +9,19 @@ python:
- "3.5"
- "nightly"

before_install:
- sudo apt-get update
- >
sudo apt-get -yq install
libdbus-1-dev
libdbus-glib-1-dev
dbus
install:
# These first 2 lines are a nasty Travis hack, see https://github.com/travis-ci/travis-ci/issues/653
- which python3.3-config && sed -i "s|not getvar('Py_ENABLE_SHARED')|True|" $(which python3.3-config) || true
- sed -i "s|not getvar('Py_ENABLE_SHARED')|True|" $(which python)-config || true

- pip install -r requirements.txt
- pip install . # See setup.py
- pip install coveralls
Expand Down
60 changes: 0 additions & 60 deletions data/applications.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,61 +76,6 @@
- Common applications
-->

<group type="daemon">
<app name="apache2" />
<app name="abrtd" />
<app name="acpid" />
<app name="atd" />
<app name="auditd" />
<app name="crond" />
<app name="cups-browsed" />
<app name="cups" />
<app name="docker" />
<app name="httpd" />
<app name="iceccd" />
<app name="libvirtd" />
<app name="mcelog" />
<app name="mpd" />
<app name="mysqld" />
<app name="NetworkManager" />
<app name="nmbd" />
<app name="ntpd" />
<app name="openvpn" />
<app name="proftpd" />
<app name="rhnsd" />
<app name="samba" />
<app name="smbd" helper="service smb restart" />
<app name="sendmail" />
<app name="sm-client" />
<app name="sshd" />
<app name="vixie-cron" />
<app name="wicd" />
<app name="firewalld" />
<app name="accounts-daemon" />
<app name="dhclient" rename="NetworkManager" />
<app name="nm-vpnc-service" rename="NetworkManager" />
<app name="cupsd" rename="cups" />
<app name="bluetoothd" rename="bluetooth" />
<app name="sssd_autofs" rename="sssd" />
<app name="sssd_be" rename="sssd" />
<app name="sssd_nss" rename="sssd" />
<app name="sssd_pac" rename="sssd" />
<app name="sssd_pam" rename="sssd" />
<app name="sssd_secrets" rename="sssd" />
<app name="sssd_ssh" rename="sssd" />
<app name="sssd_sudo" rename="sssd" />
<app name="qmgr" rename="postfix" />
<app name="pickup" rename="postfix" />
<app name="master" rename="postfix" />
<app name="tlsmgr" rename="postfix" />
<app name="lvmetad" rename="lvm2-lvmetad" />
<app name="polkitd" rename="polkit"/>
<app name="udisksd" rename="udisks2"/>
<app name="upowerd" rename="upower"/>
<app name="packagekitd" rename="packagekit"/>
<app name="lvmetad" rename="lvm2-lvmetad"/>
</group>

<group type="static">
<app name="dbus-daemon" />
<app name="gvfsd-metadata" />
Expand All @@ -153,16 +98,11 @@
<app name="nm-applet" />
</group>

<app name="console-kit-daemon" helper="service consolekit restart" />
<app name="dropbox" helper="dropbox stop; dropbox start" />
<app name="pulseaudio" helper="pulseaudio --kill; pulseaudio --start" />
<app name="gnome-shell" helper="killall -3 gnome-shell" />
<app name="tracker-store" helper="tracker daemon --terminate=store; tracker daemon --start store" />

<app name="abrt-dump-journal-oops" rename="abrtd" />
<app name="abrt-watch-log" rename="abrtd" />


<!--
- Login Managers
-->
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ BeautifulSoup4
sphinx_rtd_theme
Pygments
lxml
dbus-python
1 change: 1 addition & 0 deletions tracer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Requires: rpm-python3
Requires: python3-beautifulsoup4
Requires: python3-psutil
Requires: python3-lxml
Requires: python3-dbus
Requires: %{name}-common = %{version}-%{release}
%if %{with suggest}
Suggests: python3-argcomplete
Expand Down
47 changes: 47 additions & 0 deletions tracer/resources/SystemdDbus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SystemdUnit.py
# Module for getting data from Systemd about Units

# Copyright (C) 2017 Sean O'Keeffe
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

import dbus

class SystemdDbus(object):
def __init__(self):
self.__systemd = dbus.SystemBus().get_object('org.freedesktop.systemd1','/org/freedesktop/systemd1')
self.__manager = dbus.Interface(self.__systemd, dbus_interface='org.freedesktop.systemd1.Manager')

def unit_path_from_pid(self, pid):
try:
return self.__manager.GetUnitByPID(pid)
except dbus.exceptions.DBusException:
return False

def unit_path_from_id(self, Id):
try:
return self.__manager.GetUnit(Id)
except dbus.exceptions.DBusException:
return False

def has_service_property_from_pid(self, pid, attr):
try:
proxy = dbus.SystemBus().get_object('org.freedesktop.systemd1', self.unit_path_from_pid(pid))
propty = proxy.Get('org.freedesktop.systemd1.Service', attr, dbus_interface='org.freedesktop.DBus.Properties')
except dbus.exceptions.DBusException:
return False
return bool(propty)

def get_unit_property_from_pid(self, pid, attr):
proxy = dbus.SystemBus().get_object('org.freedesktop.systemd1', self.unit_path_from_pid(pid))
return proxy.Get('org.freedesktop.systemd1.Unit', attr, dbus_interface='org.freedesktop.DBus.Properties')
15 changes: 12 additions & 3 deletions tracer/resources/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from tracer.resources.lang import _
from tracer.resources.processes import Processes
from tracer.resources.system import System
from tracer.resources.SystemdDbus import SystemdDbus
import os
import re

Expand Down Expand Up @@ -197,14 +198,15 @@ def is_session(self):
def type(self):
if self.is_session:
return Applications.TYPES["SESSION"]
elif self.has_service_file:
elif self.is_service:
return Applications.TYPES["DAEMON"]
else:
return self._attributes["type"]

@property
def has_service_file(self):
return os.path.isfile("/usr/lib/systemd/system/{0}.service".format(self.name))
def is_service(self):
if System.init_system() == "systemd":
return SystemdDbus().unit_path_from_id("{0}.service".format(self.name))

# @TODO rename to helper_format
@property
Expand Down Expand Up @@ -260,6 +262,13 @@ def instances(self):
class AffectedApplication(Application):
@property
def name(self):
if System.init_system() == "systemd":
bus = SystemdDbus()
if bus.unit_path_from_pid(self.instances[0].pid):
if not bus.has_service_property_from_pid(self.instances[0].pid,'PAMName'):
Id = bus.get_unit_property_from_pid(self.instances[0].pid,'Id')
if re.search("\.service$", Id):
return re.sub('\.service$', '', Id)
if self.is_interpreted:
return self.instances[0].real_name
return self._attributes["name"]

0 comments on commit ee1c7f7

Please sign in to comment.