Blame doc/problems-service/html/re01.html

Packit 8ea169
<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">
Packit 8ea169
          org.freedesktop.Problems2
Packit 8ea169
        Prev Chapter 2. Interfaces Next

Packit 8ea169
          org.freedesktop.Problems2
Packit 8ea169
        

org.freedesktop.Problems2 — The Problems Service manages all the crashes.

Synopsis

Methods

Packit 8ea169
                NewProblem
Packit 8ea169
              (IN Dict<String,Variant> problem_data,  IN Int32 flags,  OUT ObjectPath task);
 
Packit 8ea169
                GetSession
Packit 8ea169
              (OUT ObjectPath session);
 
Packit 8ea169
                GetProblems
Packit 8ea169
              (IN Int32 flags,  IN Dict<String,Variant> options,  OUT Array<ObjectPath> response);
 
Packit 8ea169
                GetProblemData
Packit 8ea169
              (IN ObjectPath problem_object,  OUT Dict<String,Struct<Int32,UInt64,String>> problem_data);
 
Packit 8ea169
                DeleteProblems
Packit 8ea169
              (IN Array<ObjectPath> problem_objects);
 

Signals

Packit 8ea169
                Crash
Packit 8ea169
              (OUT ObjectPath problem_object,  OUT Int32 uid);
 

Methods

Packit 8ea169
            org.freedesktop.Problems2.NewProblem
Packit 8ea169
          
Packit 8ea169
                NewProblem
Packit 8ea169
              (IN Dict<String,Variant> problem_data,  IN Int32 flags,  OUT ObjectPath task);
 

Creates a new problem and returns it's identifier.

Packit 8ea169
                    

Example 2.1. How to create a new problems in Python

Packit 8ea169
Packit 8ea169
#!/usr/bin/python3
Packit 8ea169
import sys
Packit 8ea169
import dbus
Packit 8ea169
from functools import partial
Packit 8ea169
from dbus.mainloop.glib import DBusGMainLoop
Packit 8ea169
from gi.repository import GLib
Packit 8ea169
Packit 8ea169
PROBLEMS_BUS="org.freedesktop.problems"
Packit 8ea169
PROBLEMS_PATH="/org/freedesktop/Problems2"
Packit 8ea169
PROBLEMS_IFACE="org.freedesktop.Problems2"
Packit 8ea169
TASK_IFACE="org.freedesktop.Problems2.Task"
Packit 8ea169
Packit 8ea169
Packit 8ea169
def on_task_properties_changed(loop, iface, changed_properties, invalidated_properties):
Packit 8ea169
    if changed_properties['status'] in [2, 3, 4, 5]:
Packit 8ea169
        loop.quit()
Packit 8ea169
Packit 8ea169
Packit 8ea169
DBusGMainLoop(set_as_default=True)
Packit 8ea169
bus = dbus.SystemBus()
Packit 8ea169
Packit 8ea169
proxy = bus.get_object(PROBLEMS_BUS, PROBLEMS_PATH)
Packit 8ea169
problems = dbus.Interface(proxy, dbus_interface=PROBLEMS_IFACE)
Packit 8ea169
Packit 8ea169
task_pah = None
Packit 8ea169
with open("/etc/services", "r") as services_file:
Packit 8ea169
    description = {"analyzer"    : "libreport",
Packit 8ea169
                   "reason"      : "Application has been killed",
Packit 8ea169
                   "backtrace"   : "die()",
Packit 8ea169
                   "executable"  : "/usr/bin/foo",
Packit 8ea169
                   "services"    : dbus.types.UnixFd(services_file)}
Packit 8ea169
Packit 8ea169
    task_path = problems.NewProblem(description, 0x1)
Packit 8ea169
Packit 8ea169
loop = GLib.MainLoop()
Packit 8ea169
Packit 8ea169
task_proxy = bus.get_object(PROBLEMS_BUS, task_path)
Packit 8ea169
task = dbus.Interface(task_proxy, dbus_interface=TASK_IFACE)
Packit 8ea169
task_properties = dbus.Interface(task_proxy, dbus_interface="org.freedesktop.DBus.Properties")
Packit 8ea169
task_properties.connect_to_signal("PropertiesChanged", partial(on_task_properties_changed, loop))
Packit 8ea169
task.Start(dict())
Packit 8ea169
Packit 8ea169
GLib.timeout_add(30000, loop.quit)
Packit 8ea169
loop.run()
Packit 8ea169
Packit 8ea169
status = task_properties.Get(TASK_IFACE, "Status")
Packit 8ea169
if status in [0, 1]:
Packit 8ea169
    print("Timed-out")
Packit 8ea169
    task.Cancel(0)
Packit 8ea169
    sys.exit(1)
Packit 8ea169
Packit 8ea169
if status < 5:
Packit 8ea169
    print("Unexpected status: {}".format(status))
Packit 8ea169
    sys.exit(1)
Packit 8ea169
Packit 8ea169
if status == 5:
Packit 8ea169
    results, code = task.Finish()
Packit 8ea169
    if code in [0, 2]:
Packit 8ea169
        print("New problem: {}".format(results["NewProblem.Entry"]))
Packit 8ea169
        sys.exit(0)
Packit 8ea169
    else:
Packit 8ea169
        print(results["Error.Message"])
Packit 8ea169
        sys.exit(1)
Packit 8ea169
Packit 8ea169
                        


Packit 8ea169
                    

Example 2.2. How to create a new problems in Bash

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


Packit 8ea169
                

Packit 8ea169
                problem_data
Packit 8ea169
              

Packit 8ea169
                        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.
Packit 8ea169
                        

type, analyzer

This field should be always present. The field defines a type of problem. If the item is not provided, libreport 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.

This field should be always present. The field defines a type of problem. If the item is not provided, libreport 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.

reason

This field should contain a short human readable text describing the problem.

time

This field is filled automaticaly.

uid

Only a user with root privileges can pass this field. For all other users the field is filled by caller's uid.

executable

This is mandatory field and must contain a valid path to an executable.

component

A name of package which a problematic application belongs to. If this field is provided, the executable field becomes optional.

uuid

Machine readable identifier of a kind of the problem. ABRT uses this field for local duplicates searching.

duphash

Machine readable identifier of a kind of the problem. ABRT uses this field for global duplicates searching.

Packit 8ea169
Packit 8ea169
                        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).
Packit 8ea169
Packit 8ea169
                        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".
Packit 8ea169
                    

Packit 8ea169
                flags
Packit 8ea169
              

Packit 8ea169
                        

0x1

the task will be created

0x2

the task will be stopped after the temporary directory is created

0x4

the task will be automatically started

Packit 8ea169
                    

Packit 8ea169
                task
Packit 8ea169
              

Packit 8ea169
                        Object path of the task processing the new problem data.
Packit 8ea169
Packit 8ea169
                        The task can finish with one of the following codes:
Packit 8ea169
                        

0

ABRT_P2_TASK_NEW_PROBLEM_ACCEPTED - a new problem was created

1

ABRT_P2_TASK_NEW_PROBLEM_FAILED - the processing failed

2

ABRT_P2_TASK_NEW_PROBLEM_DUPLICATE - the problem data was dropped and a duplicated problem was updated

3

ABRT_P2_TASK_NEW_PROBLEM_DROPPED - the problem data couldn't be saved

4

ABRT_P2_TASK_NEW_PROBLEM_INVALID_DATA - the problem data contained abandoned values

Packit 8ea169
                    

Packit 8ea169
            org.freedesktop.Problems2.GetSession
Packit 8ea169
          
Packit 8ea169
                GetSession
Packit 8ea169
              (OUT ObjectPath session);
 

Returns a session object which implements the org.freedesktop.Problems2.Session interface.

Packit 8ea169
                session
Packit 8ea169
              

An object path

Packit 8ea169
            org.freedesktop.Problems2.GetProblems
Packit 8ea169
          
Packit 8ea169
                GetProblems
Packit 8ea169
              (IN Int32 flags,  IN Dict<String,Variant> options,  OUT Array<ObjectPath> response);
 

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).

Packit 8ea169
                    

Example 2.3. How to get the list of problems in Python

Packit 8ea169
Packit 8ea169
#!/usr/bin/python3
Packit 8ea169
import dbus
Packit 8ea169
Packit 8ea169
PROBLEMS_BUS="org.freedesktop.problems"
Packit 8ea169
PROBLEMS_PATH="/org/freedesktop/Problems2"
Packit 8ea169
PROBLEMS_IFACE="org.freedesktop.Problems2"
Packit 8ea169
ENTRY_IFACE="org.freedesktop.Problems2.Entry"
Packit 8ea169
Packit 8ea169
bus = dbus.SystemBus()
Packit 8ea169
Packit 8ea169
proxy = bus.get_object(PROBLEMS_BUS, PROBLEMS_PATH)
Packit 8ea169
problems = dbus.Interface(proxy, dbus_interface=PROBLEMS_IFACE)
Packit 8ea169
prblms = problems.GetProblems(0x0, {})
Packit 8ea169
Packit 8ea169
for path in prblms:
Packit 8ea169
prblm_proxy = bus.get_object(PROBLEMS_BUS, path)
Packit 8ea169
props = dbus.Interface(prblm_proxy, "org.freedesktop.DBus.Properties")
Packit 8ea169
Packit 8ea169
print("{}: {}".format(props.Get(ENTRY_IFACE, "Executable"),
Packit 8ea169
                      props.Get(ENTRY_IFACE, "Reason")))
Packit 8ea169
Packit 8ea169
                        


Packit 8ea169
                

Packit 8ea169
                    

Example 2.4. How to get the list of user problems and system problems in Python

Packit 8ea169
Packit 8ea169
#!/usr/bin/python3
Packit 8ea169
import sys
Packit 8ea169
import dbus
Packit 8ea169
from functools import partial
Packit 8ea169
from dbus.mainloop.glib import DBusGMainLoop
Packit 8ea169
from gi.repository import GLib
Packit 8ea169
Packit 8ea169
PROBLEMS_BUS="org.freedesktop.problems"
Packit 8ea169
PROBLEMS_PATH="/org/freedesktop/Problems2"
Packit 8ea169
PROBLEMS_IFACE="org.freedesktop.Problems2"
Packit 8ea169
ENTRY_IFACE="org.freedesktop.Problems2.Entry"
Packit 8ea169
SESSION_IFACE="org.freedesktop.Problems2.Session"
Packit 8ea169
Packit 8ea169
Packit 8ea169
def on_session_authorization_signal(mainloop, status):
Packit 8ea169
    if status == 0:
Packit 8ea169
        mainloop.quit()
Packit 8ea169
    if status == 3:
Packit 8ea169
        print("Authorization failed")
Packit 8ea169
        sys.exit(1)
Packit 8ea169
Packit 8ea169
Packit 8ea169
DBusGMainLoop(set_as_default=True)
Packit 8ea169
bus = dbus.SystemBus()
Packit 8ea169
Packit 8ea169
proxy = bus.get_object(PROBLEMS_BUS, PROBLEMS_PATH)
Packit 8ea169
problems = dbus.Interface(proxy, dbus_interface=PROBLEMS_IFACE)
Packit 8ea169
Packit 8ea169
session_path = problems.GetSession()
Packit 8ea169
session_proxy = bus.get_object(PROBLEMS_BUS, session_path)
Packit 8ea169
session = dbus.Interface(session_proxy, dbus_interface=SESSION_IFACE)
Packit 8ea169
Packit 8ea169
mainloop = GLib.MainLoop()
Packit 8ea169
session_proxy.connect_to_signal("AuthorizationChanged",
Packit 8ea169
                                partial(on_session_authorization_signal,
Packit 8ea169
                                        mainloop))
Packit 8ea169
result = session.Authorize({})
Packit 8ea169
Packit 8ea169
if result < 0:
Packit 8ea169
    print("Cannot authorize")
Packit 8ea169
    sys.exit(1)
Packit 8ea169
Packit 8ea169
if result > 0:
Packit 8ea169
    mainloop.run()
Packit 8ea169
Packit 8ea169
prblms = problems.GetProblems(0x1, {})
Packit 8ea169
for path in prblms:
Packit 8ea169
    prblm_proxy = bus.get_object(PROBLEMS_BUS, path)
Packit 8ea169
    props = dbus.Interface(prblm_proxy, "org.freedesktop.DBus.Properties")
Packit 8ea169
Packit 8ea169
    print("{}: {}".format(props.Get(ENTRY_IFACE, "Executable"),
Packit 8ea169
                          props.Get(ENTRY_IFACE, "Reason")))
Packit 8ea169
Packit 8ea169
                        


Packit 8ea169
                

Packit 8ea169
                flags
Packit 8ea169
              

Packit 8ea169
                        Allows to specify what kind of problems to include in the response
Packit 8ea169
Packit 8ea169
                        

0x0

Only problems that can be viewed and modified by the caller

0x1

Include problems of other users

0x2

Include problems being processed

Packit 8ea169
                    

Packit 8ea169
                options
Packit 8ea169
              

For future needs

Packit 8ea169
                response
Packit 8ea169
              

List of problem objects paths

Packit 8ea169
            org.freedesktop.Problems2.GetProblemData
Packit 8ea169
          
Packit 8ea169
                GetProblemData
Packit 8ea169
              (IN ObjectPath problem_object,  OUT Dict<String,Struct<Int32,UInt64,String>> problem_data);
 

Gets an equivalent of libreport's ProblemData for the given problem entry ($INCLUDE_DIR/libreport/problem_data.h).

Packit 8ea169
                problem_object
Packit 8ea169
              

Problem Entry path used to get the problem data.

Packit 8ea169
                problem_data
Packit 8ea169
              

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:

Packit 8ea169
                    

  1. libreport flags ($INCLUDE_DIR/libreport/problem_data.h)

  2. real file size in Bytes

  3. a representation of the element depending on the libreport flags

    CD_FLAG_TXT

    file contents

    CD_FLAG_BIN

    file path

    CD_FLAG_BIGTXT

    file path

Packit 8ea169
                    

Packit 8ea169
            org.freedesktop.Problems2.DeleteProblems
Packit 8ea169
          
Packit 8ea169
                DeleteProblems
Packit 8ea169
              (IN Array<ObjectPath> problem_objects);
 

Deletes specified problems. The problems are specified as array of problem objects.

Packit 8ea169
                problem_objects
Packit 8ea169
              

An array of problem objects to deleted.

Signals

Packit 8ea169
            org.freedesktop.Problems2.Crash
Packit 8ea169
          
Packit 8ea169
                Crash
Packit 8ea169
              (OUT ObjectPath problem_object,  OUT Int32 uid);
 

A new system problem has been detected.

Packit 8ea169
                problem_object
Packit 8ea169
              

An identifier of the detected problem.

Packit 8ea169
                uid
Packit 8ea169
              

UID of user who reported this problem.

Packit 8ea169
          org.freedesktop.Problems2.Entry
Packit 8ea169
        </body></html>