5#if !__has_include(<dbus/dbus.h>) 
    6#error "Missing <dbus/dbus.h> from libdbus-dev, please set CXXFLAGS and LDFLAGS" 
   15  static DBusConnection *bcon = [] () {
 
   17    dbus_error_init (&error);
 
   18    DBusConnection *bcon = dbus_bus_get_private (DBUS_BUS_SYSTEM, &error);
 
   20      dbus_connection_set_exit_on_disconnect (bcon, 
false);
 
   21    dbus_error_free (&error);
 
   28rtkit_make_high_priority (pid_t thread, 
int nice_level)
 
   30  const String realtimekit1 = 
"org.freedesktop.RealtimeKit1";
 
   31  const char *
const DISABLE_RTKIT = 
getenv (
"DISABLE_RTKIT");
 
   32  if (DISABLE_RTKIT && DISABLE_RTKIT[0])
 
   33    return string_format (
"%s: %s", realtimekit1, strerror (ENOTSUP));
 
   34  DBusConnection *bcon = get_system_dbus();
 
   36    return string_format (
"%s: %s", realtimekit1, strerror (ECONNREFUSED));
 
   38  DBusMessage *m = dbus_message_new_method_call (realtimekit1.c_str(),                  
 
   39                                                 "/org/freedesktop/RealtimeKit1",       
 
   40                                                 "org.freedesktop.RealtimeKit1",        
 
   41                                                 "MakeThreadHighPriority");             
 
   44      dbus_uint64_t tid = thread;
 
   45      dbus_int32_t prio = nice_level;
 
   46      if (!dbus_message_append_args (m, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &prio, DBUS_TYPE_INVALID)) {
 
   47        dbus_message_unref (m);
 
   52    return string_format (
"%s: %s", realtimekit1, strerror (ENOMEM));
 
   55  dbus_error_init (&error);
 
   56  DBusMessage *r = dbus_connection_send_with_reply_and_block (bcon, m, -1, &error);
 
   57  dbus_message_unref (m);
 
   61      if (dbus_set_error_from_message (&error, r))
 
   63      dbus_message_unref (r);
 
   67  dbus_error_free (&error);
 
   68  return emsg.empty() ? 
"" : 
string_format (
"%s: %s", realtimekit1, emsg);
 
   72rtkit_get_min_nice_level ()
 
   74  const char *
const DISABLE_RTKIT = 
getenv (
"DISABLE_RTKIT");
 
   75  if (DISABLE_RTKIT && DISABLE_RTKIT[0])
 
   77  DBusConnection *bcon = get_system_dbus();
 
   81  DBusMessage *m = dbus_message_new_method_call (
"org.freedesktop.RealtimeKit1",        
 
   82                                                 "/org/freedesktop/RealtimeKit1",       
 
   83                                                 "org.freedesktop.DBus.Properties",     
 
   87      const char *rtkinterface = 
"org.freedesktop.RealtimeKit1";
 
   88      const char *proeprty = 
"MinNiceLevel";
 
   89      if (!dbus_message_append_args (m, DBUS_TYPE_STRING, &rtkinterface, DBUS_TYPE_STRING, &proeprty, DBUS_TYPE_INVALID)) {
 
   90        dbus_message_unref (m);
 
   98  dbus_error_init (&error);
 
   99  DBusMessage *r = dbus_connection_send_with_reply_and_block (bcon, m, -1, &error);
 
  100  dbus_message_unref (m);
 
  104      if (!dbus_set_error_from_message (&error, r))
 
  107          dbus_message_iter_init (r, &mit);
 
  108          for (
int mtype; mtype = dbus_message_iter_get_arg_type (&mit), mtype != DBUS_TYPE_INVALID; dbus_message_iter_next (&mit))
 
  109            if (mtype == DBUS_TYPE_VARIANT)
 
  112                dbus_message_iter_recurse (&mit, &rit);
 
  113                for (
int rtype; rtype = dbus_message_iter_get_arg_type (&rit), rtype != DBUS_TYPE_INVALID; dbus_message_iter_next (&rit))
 
  115                    DBusBasicValue u = {};
 
  116                    dbus_message_iter_get_basic (&rit, &u);
 
  117                    if (rtype == DBUS_TYPE_INT32)
 
  119                    if (rtype == DBUS_TYPE_INT64)
 
  124      dbus_message_unref (r);
 
  126  dbus_error_free (&error);
 
std::string string_format(const char *format, const Args &...args) __attribute__((__format__(__printf__
Format a string similar to sprintf(3) with support for std::string and std::ostringstream convertible...
 
std::string String
Convenience alias for std::string.