Blob Blame History Raw
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>org.freedesktop.Problems2</title><link rel="stylesheet" type="text/css" href="style.css"><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Problems API"><link rel="up" href="ch02.html" title="Chapter 2. Interfaces"><link rel="prev" href="ch02.html" title="Chapter 2. Interfaces"><link rel="next" href="re02.html" title="org.freedesktop.Problems2.Entry"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">
          <code class="literal">org.freedesktop.Problems2</code>
        </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02.html">Prev</a> </td><th width="60%" align="center">Chapter 2. Interfaces</th><td width="20%" align="right"> <a accesskey="n" href="re02.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="org.freedesktop.Problems2"></a><div class="titlepage"></div><div class="refnamediv"><h2><span class="refentrytitle">
          <code class="literal">org.freedesktop.Problems2</code>
        </span></h2><p>org.freedesktop.Problems2 — The Problems Service manages all the crashes.</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="refsect2"><a name="methods"></a><h3>Methods</h3><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">NewProblem</b>
              (</code></td><td>IN Dict&lt;String,Variant&gt; <var class="pdparam">problem_data</var>, </td></tr><tr><td> </td><td>IN Int32 <var class="pdparam">flags</var>, </td></tr><tr><td> </td><td>OUT ObjectPath <var class="pdparam">task</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">GetSession</b>
              (</code></td><td>OUT ObjectPath <var class="pdparam">session</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">GetProblems</b>
              (</code></td><td>IN Int32 <var class="pdparam">flags</var>, </td></tr><tr><td> </td><td>IN Dict&lt;String,Variant&gt; <var class="pdparam">options</var>, </td></tr><tr><td> </td><td>OUT Array&lt;ObjectPath&gt; <var class="pdparam">response</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">GetProblemData</b>
              (</code></td><td>IN ObjectPath <var class="pdparam">problem_object</var>, </td></tr><tr><td> </td><td>OUT Dict&lt;String,Struct&lt;Int32,UInt64,String&gt;&gt; <var class="pdparam">problem_data</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">DeleteProblems</b>
              (</code></td><td>IN Array&lt;ObjectPath&gt; <var class="pdparam">problem_objects</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect2"><a name="signals"></a><h3>Signals</h3><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">Crash</b>
              (</code></td><td>OUT ObjectPath <var class="pdparam">problem_object</var>, </td></tr><tr><td> </td><td>OUT Int32 <var class="pdparam">uid</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div></div><div class="refsection"><a name="methods"></a><h2>Methods</h2><div class="refsection"><a name="org.freedesktop.Problems2.NewProblem"></a><h3>
            <code class="literal">org.freedesktop.Problems2.NewProblem</code>
          </h3><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">NewProblem</b>
              (</code></td><td>IN Dict&lt;String,Variant&gt; <var class="pdparam">problem_data</var>, </td></tr><tr><td> </td><td>IN Int32 <var class="pdparam">flags</var>, </td></tr><tr><td> </td><td>OUT ObjectPath <var class="pdparam">task</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><p>Creates a new problem and returns it's identifier.</p><p>
                    </p><div class="example"><a name="NewProblem_example_python"></a><p class="title"><b>Example 2.1. How to create a new problems in Python</b></p><div class="example-contents"><pre class="programlisting">

#!/usr/bin/python3
import sys
import dbus
from functools import partial
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib

PROBLEMS_BUS="org.freedesktop.problems"
PROBLEMS_PATH="/org/freedesktop/Problems2"
PROBLEMS_IFACE="org.freedesktop.Problems2"
TASK_IFACE="org.freedesktop.Problems2.Task"


def on_task_properties_changed(loop, iface, changed_properties, invalidated_properties):
    if changed_properties['status'] in [2, 3, 4, 5]:
        loop.quit()


DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()

proxy = bus.get_object(PROBLEMS_BUS, PROBLEMS_PATH)
problems = dbus.Interface(proxy, dbus_interface=PROBLEMS_IFACE)

task_pah = None
with open("/etc/services", "r") as services_file:
    description = {"analyzer"    : "libreport",
                   "reason"      : "Application has been killed",
                   "backtrace"   : "die()",
                   "executable"  : "/usr/bin/foo",
                   "services"    : dbus.types.UnixFd(services_file)}

    task_path = problems.NewProblem(description, 0x1)

loop = GLib.MainLoop()

task_proxy = bus.get_object(PROBLEMS_BUS, task_path)
task = dbus.Interface(task_proxy, dbus_interface=TASK_IFACE)
task_properties = dbus.Interface(task_proxy, dbus_interface="org.freedesktop.DBus.Properties")
task_properties.connect_to_signal("PropertiesChanged", partial(on_task_properties_changed, loop))
task.Start(dict())

GLib.timeout_add(30000, loop.quit)
loop.run()

status = task_properties.Get(TASK_IFACE, "Status")
if status in [0, 1]:
    print("Timed-out")
    task.Cancel(0)
    sys.exit(1)

if status &lt; 5:
    print("Unexpected status: {}".format(status))
    sys.exit(1)

if status == 5:
    results, code = task.Finish()
    if code in [0, 2]:
        print("New problem: {}".format(results["NewProblem.Entry"]))
        sys.exit(0)
    else:
        print(results["Error.Message"])
        sys.exit(1)

                        </pre></div></div><p><br class="example-break">
                    </p><div class="example"><a name="NewProblem_example_bash"></a><p class="title"><b>Example 2.2. How to create a new problems in Bash</b></p><div class="example-contents"><pre class="programlisting">

#!/usr/bin/bash
dbus-send --system --type=method_call --print-reply \
          --dest=org.freedesktop.problems /org/freedesktop/problems2 \
          org.freedesktop.Problems2.NewProblem \
          dict:string:string:analyzer,libreport,reason,"Application has been killed",backtrace,"die()",executable,"/usr/bin/true"

                        </pre></div></div><p><br class="example-break">
                </p><div class="glosslist"><dl><dt><span class="glossterm">
                <code class="literal">problem_data</code>
              </span></dt><dd class="glossdef"><p>
                        A dictionary describing problem where values are either file descriptors or strings. There are few commonly recognized fields but the dictionary can hold anything you need.
                        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">type, </span><span class="term">analyzer</span></dt><dd><p>This field should be always present. The field defines a type of problem. If the item is not provided, <span class="bold"><strong>libreport</strong></span> string is used by default. This element must not be passed as plain String. Some values can passed only by authorized users, check the implementation details to find the real values.</p><p>This field should be always present. The field defines a type of problem. If the item is not provided, <span class="bold"><strong>libreport</strong></span> string is used by default. This element must not be passed as plain String. Some values can passed only by authorized users, check the implementation details to find the real values.</p></dd><dt><span class="term">reason</span></dt><dd><p>This field should contain a short human readable text describing the problem.</p></dd><dt><span class="term">time</span></dt><dd><p>This field is filled automaticaly.</p></dd><dt><span class="term">uid</span></dt><dd><p>Only a user with root privileges can pass this field. For all other users the field is filled by caller's uid.</p></dd><dt><span class="term">executable</span></dt><dd><p>This is mandatory field and must contain a valid path to an executable.</p></dd><dt><span class="term">component</span></dt><dd><p>A name of package which a problematic application belongs to. If this field is provided, <span class="bold"><strong>the executable field becomes optional</strong></span>.</p></dd><dt><span class="term">uuid</span></dt><dd><p>Machine readable identifier of a kind of the problem. ABRT uses this field for <span class="bold"><strong>local duplicates searching</strong></span>.</p></dd><dt><span class="term">duphash</span></dt><dd><p>Machine readable identifier of a kind of the problem. ABRT uses this field for <span class="bold"><strong>global duplicates searching</strong></span>.</p></dd></dl></div><p>

                        The value can be one of the following types: string (s), binary array (ay) or file handle (h - will be read in non-blocking mode).

                        The task details will contain object path of a temporary Entry under the key "NewProblem.TemporaryEntry". The temporary entry object implements the org.freedesktop.Problems2.Entry interface. The task results will contain object path of the Entry representing the processed problem data under the key "NewProblem.Entry".
                    </p></dd><dt><span class="glossterm">
                <code class="literal">flags</code>
              </span></dt><dd class="glossdef"><p>
                        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">0x1</span></dt><dd><p>the task will be created</p></dd><dt><span class="term">0x2</span></dt><dd><p>the task will be stopped after the temporary directory is created</p></dd><dt><span class="term">0x4</span></dt><dd><p>the task will be automatically started</p></dd></dl></div><p>
                    </p></dd><dt><span class="glossterm">
                <code class="literal">task</code>
              </span></dt><dd class="glossdef"><p>
                        Object path of the task processing the new problem data.

                        The task can finish with one of the following codes:
                        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">0</span></dt><dd><p>ABRT_P2_TASK_NEW_PROBLEM_ACCEPTED - a new problem was created</p></dd><dt><span class="term">1</span></dt><dd><p>ABRT_P2_TASK_NEW_PROBLEM_FAILED - the processing failed</p></dd><dt><span class="term">2</span></dt><dd><p>ABRT_P2_TASK_NEW_PROBLEM_DUPLICATE - the problem data was dropped and a duplicated problem was updated</p></dd><dt><span class="term">3</span></dt><dd><p>ABRT_P2_TASK_NEW_PROBLEM_DROPPED - the problem data couldn't be saved</p></dd><dt><span class="term">4</span></dt><dd><p>ABRT_P2_TASK_NEW_PROBLEM_INVALID_DATA - the problem data contained abandoned values</p></dd></dl></div><p>
                    </p></dd></dl></div></div><div class="refsection"><a name="org.freedesktop.Problems2.GetSession"></a><h3>
            <code class="literal">org.freedesktop.Problems2.GetSession</code>
          </h3><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">GetSession</b>
              (</code></td><td>OUT ObjectPath <var class="pdparam">session</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><p>Returns a session object which implements the org.freedesktop.Problems2.Session interface.</p><div class="glosslist"><dl><dt><span class="glossterm">
                <code class="literal">session</code>
              </span></dt><dd class="glossdef"><p>An object path</p></dd></dl></div></div><div class="refsection"><a name="org.freedesktop.Problems2.GetProblems"></a><h3>
            <code class="literal">org.freedesktop.Problems2.GetProblems</code>
          </h3><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">GetProblems</b>
              (</code></td><td>IN Int32 <var class="pdparam">flags</var>, </td></tr><tr><td> </td><td>IN Dict&lt;String,Variant&gt; <var class="pdparam">options</var>, </td></tr><tr><td> </td><td>OUT Array&lt;ObjectPath&gt; <var class="pdparam">response</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><p>Returns a list of problem identifiers for problems visible by the caller. If the session is authorized (GetSession), then the method returns all detected problems (system problems and problems of other users).</p><p>
                    </p><div class="example"><a name="GetProblems_example_python"></a><p class="title"><b>Example 2.3. How to get the list of problems in Python</b></p><div class="example-contents"><pre class="programlisting">

#!/usr/bin/python3
import dbus

PROBLEMS_BUS="org.freedesktop.problems"
PROBLEMS_PATH="/org/freedesktop/Problems2"
PROBLEMS_IFACE="org.freedesktop.Problems2"
ENTRY_IFACE="org.freedesktop.Problems2.Entry"

bus = dbus.SystemBus()

proxy = bus.get_object(PROBLEMS_BUS, PROBLEMS_PATH)
problems = dbus.Interface(proxy, dbus_interface=PROBLEMS_IFACE)
prblms = problems.GetProblems(0x0, {})

for path in prblms:
prblm_proxy = bus.get_object(PROBLEMS_BUS, path)
props = dbus.Interface(prblm_proxy, "org.freedesktop.DBus.Properties")

print("{}: {}".format(props.Get(ENTRY_IFACE, "Executable"),
                      props.Get(ENTRY_IFACE, "Reason")))

                        </pre></div></div><p><br class="example-break">
                </p><p>
                    </p><div class="example"><a name="GetProblems_authorized_example_python"></a><p class="title"><b>Example 2.4. How to get the list of user problems and system problems in Python</b></p><div class="example-contents"><pre class="programlisting">

#!/usr/bin/python3
import sys
import dbus
from functools import partial
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib

PROBLEMS_BUS="org.freedesktop.problems"
PROBLEMS_PATH="/org/freedesktop/Problems2"
PROBLEMS_IFACE="org.freedesktop.Problems2"
ENTRY_IFACE="org.freedesktop.Problems2.Entry"
SESSION_IFACE="org.freedesktop.Problems2.Session"


def on_session_authorization_signal(mainloop, status):
    if status == 0:
        mainloop.quit()
    if status == 3:
        print("Authorization failed")
        sys.exit(1)


DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()

proxy = bus.get_object(PROBLEMS_BUS, PROBLEMS_PATH)
problems = dbus.Interface(proxy, dbus_interface=PROBLEMS_IFACE)

session_path = problems.GetSession()
session_proxy = bus.get_object(PROBLEMS_BUS, session_path)
session = dbus.Interface(session_proxy, dbus_interface=SESSION_IFACE)

mainloop = GLib.MainLoop()
session_proxy.connect_to_signal("AuthorizationChanged",
                                partial(on_session_authorization_signal,
                                        mainloop))
result = session.Authorize({})

if result &lt; 0:
    print("Cannot authorize")
    sys.exit(1)

if result &gt; 0:
    mainloop.run()

prblms = problems.GetProblems(0x1, {})
for path in prblms:
    prblm_proxy = bus.get_object(PROBLEMS_BUS, path)
    props = dbus.Interface(prblm_proxy, "org.freedesktop.DBus.Properties")

    print("{}: {}".format(props.Get(ENTRY_IFACE, "Executable"),
                          props.Get(ENTRY_IFACE, "Reason")))

                        </pre></div></div><p><br class="example-break">
                </p><div class="glosslist"><dl><dt><span class="glossterm">
                <code class="literal">flags</code>
              </span></dt><dd class="glossdef"><p>
                        Allows to specify what kind of problems to include in the response

                        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">0x0</span></dt><dd><p>Only problems that can be viewed and modified by the caller</p></dd><dt><span class="term">0x1</span></dt><dd><p>Include problems of other users</p></dd><dt><span class="term">0x2</span></dt><dd><p>Include problems being processed</p></dd></dl></div><p>
                    </p></dd><dt><span class="glossterm">
                <code class="literal">options</code>
              </span></dt><dd class="glossdef"><p>For future needs</p></dd><dt><span class="glossterm">
                <code class="literal">response</code>
              </span></dt><dd class="glossdef"><p>List of problem objects paths</p></dd></dl></div></div><div class="refsection"><a name="org.freedesktop.Problems2.GetProblemData"></a><h3>
            <code class="literal">org.freedesktop.Problems2.GetProblemData</code>
          </h3><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">GetProblemData</b>
              (</code></td><td>IN ObjectPath <var class="pdparam">problem_object</var>, </td></tr><tr><td> </td><td>OUT Dict&lt;String,Struct&lt;Int32,UInt64,String&gt;&gt; <var class="pdparam">problem_data</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><p>Gets an equivalent of libreport's ProblemData for the given problem entry ($INCLUDE_DIR/libreport/problem_data.h).</p><div class="glosslist"><dl><dt><span class="glossterm">
                <code class="literal">problem_object</code>
              </span></dt><dd class="glossdef"><p>Problem Entry path used to get the problem data.</p></dd><dt><span class="glossterm">
                <code class="literal">problem_data</code>
              </span></dt><dd class="glossdef"><p>The results is a dictionary where the key is problem element name (e.g. package, maps, coredump) and the value is a structure with three members:
                    </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>libreport flags ($INCLUDE_DIR/libreport/problem_data.h)</p></li><li class="listitem"><p>real file size in Bytes</p></li><li class="listitem"><p>a representation of the element depending on the libreport flags</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">CD_FLAG_TXT</span></dt><dd><p>file contents</p></dd><dt><span class="term">CD_FLAG_BIN</span></dt><dd><p>file path</p></dd><dt><span class="term">CD_FLAG_BIGTXT</span></dt><dd><p>file path</p></dd></dl></div></li></ol></div><p>
                    </p></dd></dl></div></div><div class="refsection"><a name="org.freedesktop.Problems2.DeleteProblems"></a><h3>
            <code class="literal">org.freedesktop.Problems2.DeleteProblems</code>
          </h3><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">DeleteProblems</b>
              (</code></td><td>IN Array&lt;ObjectPath&gt; <var class="pdparam">problem_objects</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><p>Deletes specified problems. The problems are specified as array of problem objects.</p><div class="glosslist"><dl><dt><span class="glossterm">
                <code class="literal">problem_objects</code>
              </span></dt><dd class="glossdef"><p>An array of problem objects to deleted.</p></dd></dl></div></div></div><div class="refsection"><a name="signals"></a><h2>Signals</h2><div class="refsection"><a name="org.freedesktop.Problems2.Crash"></a><h3>
            <code class="literal">org.freedesktop.Problems2.Crash</code>
          </h3><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">
                <b class="fsfunc">Crash</b>
              (</code></td><td>OUT ObjectPath <var class="pdparam">problem_object</var>, </td></tr><tr><td> </td><td>OUT Int32 <var class="pdparam">uid</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><p>A new system problem has been detected.</p><div class="glosslist"><dl><dt><span class="glossterm">
                <code class="literal">problem_object</code>
              </span></dt><dd class="glossdef"><p>An identifier of the detected problem.</p></dd><dt><span class="glossterm">
                <code class="literal">uid</code>
              </span></dt><dd class="glossdef"><p>UID of user who reported this problem.</p></dd></dl></div></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="re02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 2. Interfaces </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 
          <code class="literal">org.freedesktop.Problems2.Entry</code>
        </td></tr></table></div></body></html>