• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ dbus_error_init函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中dbus_error_init函数的典型用法代码示例。如果您正苦于以下问题:C++ dbus_error_init函数的具体用法?C++ dbus_error_init怎么用?C++ dbus_error_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了dbus_error_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: dbus_message_new_method_call

nsresult
nsWifiScannerDBus::SendMessage(const char* aInterface,
                               const char* aPath,
                               const char* aFuncCall)
{
  DBusMessage* msg =
    dbus_message_new_method_call("org.freedesktop.NetworkManager",
                                 aPath, aInterface, aFuncCall);
  if (!msg) {
    return NS_ERROR_FAILURE;
  }

  DBusMessageIter argsIter;
  dbus_message_iter_init_append(msg, &argsIter);

  if (!strcmp(aFuncCall, "Get")) {
    const char* paramInterface = "org.freedesktop.NetworkManager.Device";
    if (!dbus_message_iter_append_basic(&argsIter, DBUS_TYPE_STRING,
                                        &paramInterface)) {
      return NS_ERROR_FAILURE;
    }

    const char* paramDeviceType = "DeviceType";
    if (!dbus_message_iter_append_basic(&argsIter, DBUS_TYPE_STRING,
                                        &paramDeviceType)) {
      return NS_ERROR_FAILURE;
    }
  } else if (!strcmp(aFuncCall, "GetAll")) {
    const char* param = "";
    if (!dbus_message_iter_append_basic(&argsIter, DBUS_TYPE_STRING, &param)) {
      return NS_ERROR_FAILURE;
    }
  }

  DBusError err;
  dbus_error_init(&err);

  // http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html
  // Refer to function dbus_connection_send_with_reply_and_block.
  const uint32_t DBUS_DEFAULT_TIMEOUT = -1;
  DBusMessage* reply = nullptr;
  reply = dbus_connection_send_with_reply_and_block(mConnection, msg,
                                                    DBUS_DEFAULT_TIMEOUT, &err);
  if (dbus_error_is_set(&err)) {
    dbus_error_free(&err);

    // In the GetAccessPoints case, if there are no access points, error is set.
    // We don't want to error out here.
    if (!strcmp(aFuncCall, "GetAccessPoints")) {
      return NS_OK;
    }
    return NS_ERROR_FAILURE;
  }

  nsresult rv;
  if (!strcmp(aFuncCall, "GetDevices")) {
    rv = IdentifyDevices(reply);
  } else if (!strcmp(aFuncCall, "Get")) {
    rv = IdentifyDeviceType(reply, aPath);
  } else if (!strcmp(aFuncCall, "GetAccessPoints")) {
    rv = IdentifyAccessPoints(reply);
  } else if (!strcmp(aFuncCall, "GetAll")) {
    rv = IdentifyAPProperties(reply);
  } else {
    rv = NS_ERROR_FAILURE;
  }
  dbus_message_unref(reply);
  return rv;
}
开发者ID:Nazi-Nigger,项目名称:gecko-dev,代码行数:69,代码来源:nsWifiScannerDBus.cpp


示例2: connect_hook

static void
connect_hook(DBusConnection *connection, void *data)
{
    struct systemd_logind_info *info = data;
    DBusError error;
    DBusMessage *msg = NULL;
    DBusMessage *reply = NULL;
    dbus_int32_t arg;
    char *session = NULL;

    dbus_error_init(&error);

    msg = dbus_message_new_method_call("org.freedesktop.login1",
            "/org/freedesktop/login1", "org.freedesktop.login1.Manager",
            "GetSessionByPID");
    if (!msg) {
        LogMessage(X_ERROR, "systemd-logind: out of memory\n");
        goto cleanup;
    }

    arg = getpid();
    if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &arg,
                                  DBUS_TYPE_INVALID)) {
        LogMessage(X_ERROR, "systemd-logind: out of memory\n");
        goto cleanup;
    }

    reply = dbus_connection_send_with_reply_and_block(connection, msg,
                                                      DBUS_TIMEOUT_USE_DEFAULT, &error);
    if (!reply) {
        LogMessage(X_ERROR, "systemd-logind: failed to get session: %s\n",
                   error.message);
        goto cleanup;
    }
    dbus_message_unref(msg);

    if (!dbus_message_get_args(reply, &error, DBUS_TYPE_OBJECT_PATH, &session,
                               DBUS_TYPE_INVALID)) {
        LogMessage(X_ERROR, "systemd-logind: GetSessionByPID: %s\n",
                   error.message);
        goto cleanup;
    }
    session = XNFstrdup(session);

    dbus_message_unref(reply);
    reply = NULL;


    msg = dbus_message_new_method_call("org.freedesktop.login1",
            session, "org.freedesktop.login1.Session", "TakeControl");
    if (!msg) {
        LogMessage(X_ERROR, "systemd-logind: out of memory\n");
        goto cleanup;
    }

    arg = FALSE; /* Don't forcibly take over over the session */
    if (!dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &arg,
                                  DBUS_TYPE_INVALID)) {
        LogMessage(X_ERROR, "systemd-logind: out of memory\n");
        goto cleanup;
    }

    reply = dbus_connection_send_with_reply_and_block(connection, msg,
                                                      DBUS_TIMEOUT_USE_DEFAULT, &error);
    if (!reply) {
        LogMessage(X_ERROR, "systemd-logind: TakeControl failed: %s\n",
                   error.message);
        goto cleanup;
    }

    dbus_bus_add_match(connection,
        "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus'",
        &error);
    if (dbus_error_is_set(&error)) {
        LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n",
                   error.message);
        goto cleanup;
    }

    dbus_bus_add_match(connection,
        "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='PauseDevice'",
        &error);
    if (dbus_error_is_set(&error)) {
        LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n",
                   error.message);
        goto cleanup;
    }

    dbus_bus_add_match(connection,
        "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='ResumeDevice'",
        &error);
    if (dbus_error_is_set(&error)) {
        LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n",
                   error.message);
        goto cleanup;
    }

    /*
     * HdG: This is not useful with systemd <= 208 since the signal only
     * contains invalidated property names there, rather than property, val
//.........这里部分代码省略.........
开发者ID:halfline,项目名称:xserver,代码行数:101,代码来源:systemd-logind.c


示例3: main

int main(int argc, char *argv[]) {
        int r, exit_code = 0;
        DBusConnection *bus = NULL;
        DBusError error;
        _cleanup_close_ int fd = -1;

        dbus_error_init(&error);

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
        if (!bus) {
                log_error("Failed to connect to bus: %s", bus_error_message(&error));
                r = -EIO;
                goto finish;
        }

        if (arg_action == ACTION_LIST) {

                r = print_inhibitors(bus, &error);
                if (r < 0) {
                        log_error("Failed to list inhibitors: %s", bus_error(&error, r));
                        goto finish;
                }

        } else {
                char *w = NULL;
                pid_t pid;

                if (!arg_who)
                        arg_who = w = strv_join(argv + optind, " ");

                fd = inhibit(bus, &error);
                free(w);

                if (fd < 0) {
                        log_error("Failed to inhibit: %s", bus_error(&error, r));
                        r = fd;
                        goto finish;
                }

                pid = fork();
                if (pid < 0) {
                        log_error("Failed to fork: %m");
                        r = -errno;
                        goto finish;
                }

                if (pid == 0) {
                        /* Child */

                        safe_close(fd);
                        close_all_fds(NULL, 0);

                        execvp(argv[optind], argv + optind);
                        log_error("Failed to execute %s: %m", argv[optind]);
                        _exit(EXIT_FAILURE);
                }

                r = wait_for_terminate_and_warn(argv[optind], pid);
                if (r >= 0)
                        exit_code = r;
        }

finish:
        if (bus) {
                dbus_connection_close(bus);
                dbus_connection_unref(bus);
        }

        dbus_error_free(&error);

        return r < 0 ? EXIT_FAILURE : exit_code;
}
开发者ID:systemdiet,项目名称:systemdiet,代码行数:79,代码来源:inhibit.c


示例4: dbus_error_init

Error::Error( const char* name, const char* message )
: Dbg::Error( NULL )
{
	dbus_error_init(&_error);
	set(name, message);
}
开发者ID:BackupTheBerlios,项目名称:bluetool-svn,代码行数:6,代码来源:cbuserror.cpp


示例5: systemd_logind_release_fd

void
systemd_logind_release_fd(int _major, int _minor, int fd)
{
    struct systemd_logind_info *info = &logind_info;
    InputInfoPtr pInfo;
    DBusError error;
    DBusMessage *msg = NULL;
    DBusMessage *reply = NULL;
    dbus_int32_t major = _major;
    dbus_int32_t minor = _minor;
    int matches = 0;

    if (!info->session || major == 0)
        goto close;

    /* Only release the fd if there is only 1 InputInfo left for this major
     * and minor, otherwise other InputInfo's are still referencing the fd. */
    pInfo = systemd_logind_find_info_ptr_by_devnum(xf86InputDevs, major, minor);
    while (pInfo) {
        matches++;
        pInfo = systemd_logind_find_info_ptr_by_devnum(pInfo->next, major, minor);
    }
    if (matches > 1) {
        LogMessage(X_INFO, "systemd-logind: not releasing fd for %u:%u, still in use\n", major, minor);
        return;
    }

    LogMessage(X_INFO, "systemd-logind: releasing fd for %u:%u\n", major, minor);

    dbus_error_init(&error);

    msg = dbus_message_new_method_call("org.freedesktop.login1", info->session,
            "org.freedesktop.login1.Session", "ReleaseDevice");
    if (!msg) {
        LogMessage(X_ERROR, "systemd-logind: out of memory\n");
        goto cleanup;
    }

    if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major,
                                       DBUS_TYPE_UINT32, &minor,
                                       DBUS_TYPE_INVALID)) {
        LogMessage(X_ERROR, "systemd-logind: out of memory\n");
        goto cleanup;
    }

    reply = dbus_connection_send_with_reply_and_block(info->conn, msg,
                                                      DBUS_TIMEOUT_USE_DEFAULT, &error);
    if (!reply)
        LogMessage(X_ERROR, "systemd-logind: failed to release device: %s\n",
                   error.message);

cleanup:
    if (msg)
        dbus_message_unref(msg);
    if (reply)
        dbus_message_unref(reply);
    dbus_error_free(&error);
close:
    if (fd != -1)
        close(fd);
}
开发者ID:halfline,项目名称:xserver,代码行数:61,代码来源:systemd-logind.c


示例6: battery_remove

static void
battery_remove(LibHalContext *ctx, const char *udi)
{
	DBusError error;

	HAL_DEBUG(("battery_remove() enter"));
	dbus_error_init(&error);
	libhal_device_remove_property(ctx, udi, "battery.remaining_time",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi,
	    "battery.charge_level.percentage", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.charge_level.rate",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi,
	    "battery.charge_level.last_full", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi,
	    "battery.charge_level.current", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.voltage.present",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.reporting.rate",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.reporting.current",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi,
	    "battery.rechargeable.is_discharging", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi,
	    "battery.rechargeable.is_charging", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.is_rechargeable",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.charge_level.unit",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi,
	    "battery.charge_level.granularity_2", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi,
	    "battery.charge_level.granularity_1", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.charge_level.low",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.charge_level.warning",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.charge_level.design",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.voltage.design",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi,
	    "battery.reporting.granularity_2", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi,
	    "battery.reporting.granularity_1", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.reporting.low",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.reporting.warning",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.reporting.design",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.reporting.last_full",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.reporting.unit",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.technology", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.reporting.technology",
	    &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.serial", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.model", &error);
	my_dbus_error_free(&error);
	libhal_device_remove_property(ctx, udi, "battery.vendor", &error);
	my_dbus_error_free(&error);
	HAL_DEBUG(("battery_remove() exit"));
}
开发者ID:alhazred,项目名称:onarm,代码行数:95,代码来源:battery.c


示例7: SendToTelepathy

/*****************************************************************************
 * SendToTelepathy
 *****************************************************************************/
static int SendToTelepathy( intf_thread_t *p_intf, const char *psz_msg )
{
    DBusConnection *p_conn;
    DBusMessage *p_msg;
    DBusMessage *p_reply;
    DBusMessageIter args;
    DBusError error;
    dbus_error_init( &error );
    dbus_uint32_t i_status;

    p_conn = p_intf->p_sys->p_conn;

    /* first we need to get the actual status */
    p_msg = dbus_message_new_method_call(
            "org.freedesktop.Telepathy.MissionControl",
           "/org/freedesktop/Telepathy/MissionControl",
            "org.freedesktop.Telepathy.MissionControl",
            "GetPresence" );
    if( !p_msg )
        return VLC_ENOMEM;

    p_reply = dbus_connection_send_with_reply_and_block( p_conn, p_msg,
        50, &error ); /* blocks 50ms maximum */

    dbus_message_unref( p_msg );
    if( p_reply == NULL )
    {   /* MC is not active, or too slow. Better luck next time? */
        return VLC_SUCCESS;
    }

    /* extract the status from the reply */
    if( dbus_message_get_args( p_reply, &error,
            DBUS_TYPE_UINT32, &i_status,
            DBUS_TYPE_INVALID ) == FALSE )
    {
        return VLC_ENOMEM;
    }

    p_msg = dbus_message_new_method_call(
            "org.freedesktop.Telepathy.MissionControl",
           "/org/freedesktop/Telepathy/MissionControl",
            "org.freedesktop.Telepathy.MissionControl",
            "SetPresence" );
    if( !p_msg )
        return VLC_ENOMEM;

    dbus_message_iter_init_append( p_msg, &args );

    /* first argument is the status */
    if( !dbus_message_iter_append_basic( &args, DBUS_TYPE_UINT32, &i_status ) )
    {
        dbus_message_unref( p_msg );
        return VLC_ENOMEM;
    }
    /* second argument is the message */
    if( !dbus_message_iter_append_basic( &args, DBUS_TYPE_STRING, &psz_msg ) )
    {
        dbus_message_unref( p_msg );
        return VLC_ENOMEM;
    }


    if( !dbus_connection_send( p_conn, p_msg, NULL ) )
        return VLC_ENOMEM;

    dbus_connection_flush( p_conn );
    dbus_message_unref( p_msg );

    return VLC_SUCCESS;
}
开发者ID:Italianmoose,项目名称:Stereoscopic-VLC,代码行数:73,代码来源:telepathy.c


示例8: virPolkitCheckAuth

int virPolkitCheckAuth(const char *actionid,
                       pid_t pid,
                       unsigned long long startTime ATTRIBUTE_UNUSED,
                       uid_t uid,
                       const char **details,
                       bool allowInteraction ATTRIBUTE_UNUSED)
{
    PolKitCaller *pkcaller = NULL;
    PolKitAction *pkaction = NULL;
    PolKitContext *pkcontext = NULL;
    PolKitError *pkerr = NULL;
    PolKitResult pkresult;
    DBusError err;
    DBusConnection *sysbus;
    int ret = -1;

    if (details) {
        virReportError(VIR_ERR_AUTH_FAILED, "%s",
                       _("Details not supported with polkit v0"));
        return -1;
    }

    if (!(sysbus = virDBusGetSystemBus()))
        goto cleanup;

    VIR_INFO("Checking PID %lld running as %d",
             (long long) pid, uid);
    dbus_error_init(&err);
    if (!(pkcaller = polkit_caller_new_from_pid(sysbus,
                                                pid, &err))) {
        VIR_DEBUG("Failed to lookup policy kit caller: %s", err.message);
        dbus_error_free(&err);
        goto cleanup;
    }

    if (!(pkaction = polkit_action_new())) {
        char ebuf[1024];
        VIR_DEBUG("Failed to create polkit action %s",
                  virStrerror(errno, ebuf, sizeof(ebuf)));
        goto cleanup;
    }
    polkit_action_set_action_id(pkaction, actionid);

    if (!(pkcontext = polkit_context_new()) ||
        !polkit_context_init(pkcontext, &pkerr)) {
        char ebuf[1024];
        VIR_DEBUG("Failed to create polkit context %s",
                  (pkerr ? polkit_error_get_error_message(pkerr)
                   : virStrerror(errno, ebuf, sizeof(ebuf))));
        if (pkerr)
            polkit_error_free(pkerr);
        dbus_error_free(&err);
        goto cleanup;
    }

# if HAVE_POLKIT_CONTEXT_IS_CALLER_AUTHORIZED
    pkresult = polkit_context_is_caller_authorized(pkcontext,
                                                   pkaction,
                                                   pkcaller,
                                                   0,
                                                   &pkerr);
    if (pkerr && polkit_error_is_set(pkerr)) {
        VIR_DEBUG("Policy kit failed to check authorization %d %s",
                  polkit_error_get_error_code(pkerr),
                  polkit_error_get_error_message(pkerr));
        goto cleanup;
    }
# else
    pkresult = polkit_context_can_caller_do_action(pkcontext,
                                                   pkaction,
                                                   pkcaller);
# endif
    if (pkresult != POLKIT_RESULT_YES) {
        VIR_DEBUG("Policy kit denied action %s from pid %lld, uid %d, result: %s",
                  actionid, (long long) pid, uid,
                  polkit_result_to_string_representation(pkresult));
        ret = -2;
        goto cleanup;
    }

    VIR_DEBUG("Policy allowed action %s from pid %lld, uid %d",
              actionid, (long long)pid, (int)uid);

    ret = 0;

 cleanup:
    if (ret < 0) {
        virResetLastError();
        virReportError(VIR_ERR_AUTH_FAILED, "%s",
                       _("authentication failed"));
    }
    if (pkcontext)
        polkit_context_unref(pkcontext);
    if (pkcaller)
        polkit_caller_unref(pkcaller);
    if (pkaction)
        polkit_action_unref(pkaction);
    return ret;
}
开发者ID:RWTH-OS,项目名称:libvirt,代码行数:99,代码来源:virpolkit.c


示例9: desktop_file_for_name

static BusDesktopFile *
desktop_file_for_name (BusConfigParser *parser,
                       const char *name,
                       DBusError  *error)
{
    BusDesktopFile *desktop_file;
    DBusList **service_dirs;
    DBusList *link;
    DBusError tmp_error;
    DBusString full_path;
    DBusString filename;
    const char *dir;

    _DBUS_ASSERT_ERROR_IS_CLEAR (error);

    desktop_file = NULL;

    if (!_dbus_string_init (&filename))
    {
        BUS_SET_OOM (error);
        goto out_all;
    }

    if (!_dbus_string_init (&full_path))
    {
        BUS_SET_OOM (error);
        goto out_filename;
    }

    if (!_dbus_string_append (&filename, name) ||
            !_dbus_string_append (&filename, ".service"))
    {
        BUS_SET_OOM (error);
        goto out;
    }

    service_dirs = bus_config_parser_get_service_dirs (parser);
    for (link = _dbus_list_get_first_link (service_dirs);
            link != NULL;
            link = _dbus_list_get_next_link (service_dirs, link))
    {
        dir = link->data;
        _dbus_verbose ("Looking at '%s'\n", dir);

        dbus_error_init (&tmp_error);

        /* clear the path from last time */
        _dbus_string_set_length (&full_path, 0);

        /* build the full path */
        if (!_dbus_string_append (&full_path, dir) ||
                !_dbus_concat_dir_and_file (&full_path, &filename))
        {
            BUS_SET_OOM (error);
            goto out;
        }

        _dbus_verbose ("Trying to load file '%s'\n", _dbus_string_get_data (&full_path));
        desktop_file = bus_desktop_file_load (&full_path, &tmp_error);
        if (desktop_file == NULL)
        {
            _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
            _dbus_verbose ("Could not load %s: %s: %s\n",
                           _dbus_string_get_const_data (&full_path),
                           tmp_error.name, tmp_error.message);

            /* we may have failed if the file is not found; this is not fatal */
            if (dbus_error_has_name (&tmp_error, DBUS_ERROR_NO_MEMORY))
            {
                dbus_move_error (&tmp_error, error);
                /* we only bail out on OOM */
                goto out;
            }
            dbus_error_free (&tmp_error);
        }

        /* did we find the desktop file we want? */
        if (desktop_file != NULL)
            break;
    }

    /* Didn't find desktop file; set error */
    if (desktop_file == NULL)
    {
        dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND,
                        "The name %s was not provided by any .service files",
                        name);
    }

out:
    _dbus_string_free (&full_path);
out_filename:
    _dbus_string_free (&filename);
out_all:
    return desktop_file;
}
开发者ID:mirsal,项目名称:dbus,代码行数:96,代码来源:activation-helper.c


示例10: selinux_access_check

/*
   This function communicates with the kernel to check whether or not it should
   allow the access.
   If the machine is in permissive mode it will return ok.  Audit messages will
   still be generated if the access would be denied in enforcing mode.
*/
int selinux_access_check(
                DBusConnection *connection,
                DBusMessage *message,
                const char *path,
                const char *permission,
                DBusError *error) {

        security_context_t scon = NULL, fcon = NULL;
        int r = 0;
        const char *tclass = NULL;
        struct auditstruct audit;

        assert(connection);
        assert(message);
        assert(permission);
        assert(error);

        if (!use_selinux())
                return 0;

        r = selinux_access_init(error);
        if (r < 0)
                return r;

        audit.uid = audit.loginuid = (uid_t) -1;
        audit.gid = (gid_t) -1;
        audit.cmdline = NULL;
        audit.path = path;

        r = get_calling_context(connection, message, &scon, error);
        if (r < 0) {
                log_error("Failed to get caller's security context on: %m");
                goto finish;
        }


        tclass = "service";
        if (path && !strneq(path,"system", strlen("system"))) {
                /* get the file context of the unit file */
                r = getfilecon(path, &fcon);
                if (r < 0) {
                        dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED, "Failed to get file context on %s.", path);
                        r = -errno;
                        log_error("Failed to get security context on %s: %m",path);
                        goto finish;
                }
        } else {
                if (path)
                        tclass = "system";
                r = getcon(&fcon);
                if (r < 0) {
                        dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED, "Failed to get current context.");
                        r = -errno;
                        log_error("Failed to get current process context on: %m");
                        goto finish;
                }
        }

        (void) get_audit_data(connection, message, &audit, error);

        errno = 0;
        r = selinux_check_access(scon, fcon, tclass, permission, &audit);
        if (r < 0) {
                dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED, "SELinux policy denies access.");
                r = -errno;
                log_error("SELinux policy denies access.");
        }

        log_debug("SELinux access check scon=%s tcon=%s tclass=%s perm=%s path=%s cmdline=%s: %i", scon, fcon, tclass, permission, path, audit.cmdline, r);

finish:
        free(audit.cmdline);
        freecon(scon);
        freecon(fcon);

        if (r && security_getenforce() != 1) {
                dbus_error_init(error);
                r = 0;
        }

        return r;
}
开发者ID:systemdiet,项目名称:systemdiet,代码行数:88,代码来源:selinux-access.c


示例11: send_dbus_signal

static int send_dbus_signal(DBusConnection *conn,
			const char *msg_name,
			const char *value) {
	DBusMessage *msg;
	DBusMessageIter args;
	DBusPendingCall *pending;
	int result = 0;

	/* create a signal and check for errors */
	msg = dbus_message_new_method_call(STE_MAD_DBUS_SERVICE,
					STE_MAD_DBUS_OBJECT_NAME,
					STE_MAD_DBUS_TXBO_IF_NAME,
					msg_name);

	if (msg == NULL) {
		ERR("failed to allocate memory\n");
		return -1;
	}

	/* append arguments onto signal */
	dbus_message_iter_init_append(msg, &args);
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &value)) {
		ERR("failed to allocate memory\n");
		result = -1;
		goto exit;
	}

	/* send the message and flush the connection */
	if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
		ERR("DBUS message sending failed\n");
		result = -1;
		goto exit;
	}

	/* send request */
	dbus_connection_flush(conn);
	dbus_message_unref(msg);

	/* wait for ACK from MAD */
	dbus_pending_call_block(pending);
	msg = dbus_pending_call_steal_reply(pending);
	dbus_pending_call_unref(pending);

	if (msg == NULL) {
		ERR("failed to receive MAD's ACK\n");
		goto exit;
	}

	if (dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_ERROR) {
		DBusError err;

		dbus_error_init(&err);
		dbus_set_error_from_message(&err, msg);
		ERR("MAD ACK failed: %s\n", err.message);
		dbus_error_free(&err);
		goto exit;
	}

exit:
	if (msg) {
		dbus_message_unref(msg);
	}
	return result;
}
开发者ID:12019,项目名称:vendor_st-ericsson_u8500,代码行数:64,代码来源:modem_mitigations.c


示例12: main

int main (int argc, char **argv)
{
    state     *st;
    GtkWidget *window;
    GtkWidget *drawing_area;

    GError    *error = NULL;

    DBusError dbus_error;

    gtk_set_locale();

    gtk_init_with_args(&argc, &argv,
                       parameter_string,
                       options,
                       "gnome-screensaver",
                       &error);

    if (error != NULL) {
        g_printerr ("%s. See --help for usage information.\n",
                  error->message);
        g_error_free (error);
        return EX_SOFTWARE;
    }

    copy_gifs();
    get_time_str();
    window = gs_theme_window_new();
    drawing_area = gtk_drawing_area_new();
    st = clock_init(window, drawing_area);
    init_weather(st);

    gtk_widget_show(drawing_area);
    gtk_container_add(GTK_CONTAINER (window), drawing_area);

    gtk_widget_show(window);

    loop = g_main_loop_new (NULL, FALSE);

    dbus_error_init (&dbus_error);
    bus = dbus_bus_get (DBUS_BUS_SESSION, &dbus_error);
    if (!bus) {
      g_warning ("Failed to connect to the D-BUS daemon: %s", dbus_error.message);
      dbus_error_free (&dbus_error);
      return 1;
    }
    dbus_connection_setup_with_g_main (bus, NULL);

    /* listening to messages from all objects as no path is specified */
    dbus_bus_add_match (bus, "type='signal',interface='org.freedesktop.MediaPlayer'", &dbus_error);
    dbus_bus_add_match (bus, "type='signal',interface='org.freedesktop.DBus.Properties'", &dbus_error);
    dbus_connection_add_filter (bus, signal_filter, loop, NULL);


    g_signal_connect(G_OBJECT (window), "delete-event",
                     GTK_SIGNAL_FUNC(quit_app), loop);
    g_signal_connect(GTK_OBJECT (drawing_area), "configure_event",
                     GTK_SIGNAL_FUNC (configure_event), st);
    g_signal_connect(GTK_OBJECT (drawing_area), "expose_event",
                     GTK_SIGNAL_FUNC (expose_event), st);

    g_signal_connect(GTK_OBJECT (window), "configure_event",
                     GTK_SIGNAL_FUNC (w_configure_event), st);

    g_random_set_seed(time (NULL));

    st->timer_id = g_timeout_add_seconds(1, clock_timer, st);

    g_main_loop_run (loop);

    clock_free (st);

    return EX_OK;
}
开发者ID:zhum,项目名称:simpleweather-screensaver,代码行数:74,代码来源:simpleclock.c


示例13: dbind_method_call_reentrant_va

dbus_bool_t
dbind_method_call_reentrant_va (DBusConnection *cnx,
                                const char     *bus_name,
                                const char     *path,
                                const char     *interface,
                                const char     *method,
                                DBusError      *opt_error,
                                const char     *arg_types,
                                va_list         args)
{
    dbus_bool_t success = FALSE;
    DBusMessage *msg = NULL, *reply = NULL;
    DBusMessageIter iter;
    DBusError *err, real_err;
    const char *p;
  va_list args_demarshal;

  va_copy (args_demarshal, args);
    if (opt_error)
        err = opt_error;
    else {
        dbus_error_init (&real_err);
        err = &real_err;
    }

    msg = dbus_message_new_method_call (bus_name, path, interface, method);
    if (!msg)
        goto out;

    p = arg_types;
    dbus_message_iter_init_append (msg, &iter);
    dbind_any_marshal_va (&iter, &p, args);

    reply = dbind_send_and_allow_reentry (cnx, msg, err);
    if (!reply)
        goto out;

    if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
    {
      const char *name = dbus_message_get_error_name (reply);
      goto out;
    }
    /* demarshal */
    if (p[0] == '=' && p[1] == '>')
    {
        DBusMessageIter iter;
        dbus_message_iter_init (reply, &iter);
        p = arg_types;
        dbind_any_demarshal_va (&iter, &p, args_demarshal);
    }

    success = TRUE;
out:
    if (msg)
        dbus_message_unref (msg);

    if (reply)
        dbus_message_unref (reply);

    if (err == &real_err)
        dbus_error_free (err);

    va_end (args_demarshal);
    return success;
}
开发者ID:gloob,项目名称:gloob-s-at-spi2-core,代码行数:65,代码来源:dbind.c


示例14: battery_dynamic_update

static void
battery_dynamic_update(LibHalContext *ctx, const char *udi, int fd)
{
	int reporting_rate;
	int reporting_current;
	int reporting_lastfull;
	int design_voltage;
	int present_voltage;
	char *reporting_unit;
	int remaining_time;
	int remaining_percentage;
	gboolean charging;
	gboolean discharging;
	acpi_bst_t bst;
	LibHalChangeSet *cs;
	DBusError error;
	static int counter = 0;

	HAL_DEBUG(("battery_dynamic_update() enter"));
	bzero(&bst, sizeof (bst));
	if (ioctl(fd, BATT_IOC_STATUS, &bst) < 0) {
		return;
	}

	charging = bst.bst_state & BATT_BST_CHARGING ? TRUE : FALSE;
	discharging = bst.bst_state & BATT_BST_DISCHARGING ? TRUE : FALSE;
	/* No need to continue if battery is essentially idle. */
	if (counter && !charging && !discharging) {
		return;
	}
	dbus_error_init(&error);
	libhal_device_set_property_bool(ctx, udi, "battery.is_rechargeable",
	    TRUE, &error);
	my_dbus_error_free(&error);
	if (libhal_device_property_exists(ctx, udi,
	    "battery.charge_level.percentage", &error)) {
		remaining_percentage = libhal_device_get_property_int(ctx, udi,
		    "battery.charge_level.percentage", &error);
		if ((remaining_percentage == 100) && charging) {
			charging = FALSE;
		}
	}
	libhal_device_set_property_bool(ctx, udi,
	    "battery.rechargeable.is_charging", charging, &error);
	my_dbus_error_free(&error);
	libhal_device_set_property_bool(ctx, udi,
	    "battery.rechargeable.is_discharging", discharging, &error);
	my_dbus_error_free(&error);
	reporting_current = bst.bst_rem_cap;
	libhal_device_set_property_int(ctx, udi, "battery.reporting.current",
	    bst.bst_rem_cap, &error);
	my_dbus_error_free(&error);
	reporting_rate = bst.bst_rate;
	libhal_device_set_property_int(ctx, udi, "battery.reporting.rate",
	    bst.bst_rate, &error);
	my_dbus_error_free(&error);
	present_voltage = bst.bst_voltage;
	libhal_device_set_property_int(ctx, udi, "battery.voltage.present",
	    bst.bst_voltage, &error);
	/* get all the data we know */
	my_dbus_error_free(&error);
	reporting_unit = libhal_device_get_property_string(ctx, udi,
	    "battery.reporting.unit", &error);
	my_dbus_error_free(&error);
	reporting_lastfull = libhal_device_get_property_int(ctx, udi,
	    "battery.reporting.last_full", &error);

	/*
	 * Convert mAh to mWh since util_compute_time_remaining() works
	 * for mWh.
	 */
	if (reporting_unit && strcmp(reporting_unit, "mAh") == 0) {
		my_dbus_error_free(&error);
		design_voltage = libhal_device_get_property_int(ctx, udi,
		    "battery.voltage.design", &error);
		/*
		 * If the present_voltage is inaccurate, set it to the
		 * design_voltage.
		 */
		if (((present_voltage * 10) < design_voltage) ||
		    (present_voltage <= 0) ||
		    (present_voltage > design_voltage)) {
			present_voltage = design_voltage;
		}
		reporting_rate = (reporting_rate * present_voltage) / 1000;
		reporting_lastfull = (reporting_lastfull * present_voltage) /
		    1000;
		reporting_current = (reporting_current * present_voltage) /
		    1000;
	}

	/* Make sure the current charge does not exceed the full charge */
	if (reporting_current > reporting_lastfull) {
		reporting_current = reporting_lastfull;
	}
	if (!charging && !discharging) {
		counter++;
		reporting_rate = 0;
	}

//.........这里部分代码省略.........
开发者ID:alhazred,项目名称:onarm,代码行数:101,代码来源:battery.c


示例15: device_added

static void
device_added(LibHalContext *hal_ctx, const char *udi)
{
    char **props;
    /* Cleverly, these are currently all leaked. */
    char *path = NULL, *driver = NULL, *name = NULL, *xkb_rules = NULL;
    char *xkb_model = NULL, *xkb_layout = NULL, *xkb_variant = NULL;
    char **xkb_options = NULL;
    DBusError error;
    struct xserver_option *options = NULL;
    int type = TYPE_NONE;
    int i;
    DeviceIntPtr dev = NULL;

    dbus_error_init(&error);

    props = libhal_device_get_property_strlist(hal_ctx, udi,
                                               "info.capabilities", &error);
    if (!props) {
        DebugF("[config/hal] couldn't get capabilities for %s: %s (%s)\n",
               udi, error.name, error.message);
        goto out_error;
    }
    for (i = 0; props[i]; i++) {
        /* input.keys is the new, of which input.keyboard is a subset, but
         * input.keyboard is the old 'we have keys', so we have to keep it
         * around. */
        if (strcmp(props[i], "input.keys") == 0 ||
            strcmp(props[i], "input.keyboard") == 0)
            type |= TYPE_KEYS;
        if (strcmp(props[i], "input.mouse") == 0)
            type |= TYPE_POINTER;
    }
    libhal_free_string_array(props);

    if (!type)
        goto out_error;

    driver = get_prop_string(hal_ctx, udi, "input.x11_driver");
    path = get_prop_string(hal_ctx, udi, "input.device");
    if (!driver || !path) {
        DebugF("[config/hal] no driver or path specified for %s\n", udi);
        goto unwind;
    }
    name = get_prop_string(hal_ctx, udi, "info.product");
    if (!name)
        name = xstrdup("(unnamed)");

    if (type & TYPE_KEYS) {
        xkb_rules = get_prop_string(hal_ctx, udi, "input.xkb.rules");
        xkb_model = get_prop_string(hal_ctx, udi, "input.xkb.model");
        xkb_layout = get_prop_string(hal_ctx, udi, "input.xkb.layout");
        xkb_variant = get_prop_string(hal_ctx, udi, "input.xkb.variant");
        xkb_options = get_prop_string_array(hal_ctx, udi, "input.xkb.options");
    }

    options = xcalloc(sizeof(*options), 1);
    options->key = xstrdup("_source");
    options->value = xstrdup("server/hal");
    if (!options->key || !options->value) {
        ErrorF("[config] couldn't allocate first key/value pair\n");
        goto unwind;
    }

    add_option(&options, "path", path);
    add_option(&options, "driver", driver);
    add_option(&options, "name", name);
    add_option(&options, "hal_udi", udi);

    if (xkb_model)
        add_option(&options, "xkb_model", xkb_model);
    if (xkb_layout)
        add_option(&options, "xkb_layout", xkb_layout);
    if (xkb_variant)
        add_option(&options, "xkb_variant", xkb_variant);
#if 0
    if (xkb_options)
        add_option(&options, "xkb_options", xkb_options);
#endif

    /* Maemo-specific hack.  Ugh. */
    if (type & TYPE_KEYS)
        add_option(&options, "type", "keyboard");
    else
        add_option(&options, "type", "pointer");

    if (NewInputDeviceRequest(options, &dev) != Success) {
        DebugF("[config/hal] NewInputDeviceRequest failed\n");
        goto unwind;
    }

    dbus_error_free(&error);

    return;

unwind:
    if (path)
        xfree(path);
    if (driver)
        xfree(driver);
//.........这里部分代码省略.........
开发者ID:GrahamCobb,项目名称:maemo-xsisusb,代码行数:101,代码来源:hal.c


示例16: battery_static_update


//.........这里部分代码省略.........
	DBusError error;

	HAL_DEBUG(("battery_static_update() enter"));
	bzero(&bif, sizeof (bif));
	if (ioctl(fd, BATT_IOC_INFO, &bif) < 0) {
		return (FALSE);
	}
	if ((cs = libhal_device_new_changeset(udi)) == NULL) {
		HAL_DEBUG(("Cannot allocate changeset"));
		return (FALSE);
	}

	libhal_changeset_set_property_string(cs, "battery.vendor",
	    bif.bif_oem_info);
	technology = bif.bif_type;
	if (technology != NULL) {
		libhal_changeset_set_property_string(cs,
		    "battery.reporting.technology", technology);
		libhal_changeset_set_property_string(cs, "battery.technology",
		    util_get_battery_technology(technology));
	}
	libhal_changeset_set_property_string(cs, "battery.serial",
	    bif.bif_serial);
	libhal_changeset_set_property_string(cs, "battery.model",
	    bif.bif_model);

	if (bif.bif_unit) {
		libhal_changeset_set_property_string(cs,
		    "battery.reporting.unit", "mAh");
		strlcpy(reporting_unit, "mAh", sizeof (reporting_unit));
	} else {
		libhal_changeset_set_property_string(cs,
		    "battery.reporting.unit", "mWh");
		strlcpy(reporting_unit, "mWh", sizeof (reporting_unit));
	}
	libhal_changeset_set_property_int(cs, "battery.reporting.last_full",
	    bif.bif_last_cap);
	libhal_changeset_set_property_int(cs, "battery.reporting.design",
	    bif.bif_design_cap);
	reporting_design = bif.bif_design_cap;
	libhal_changeset_set_property_int(cs, "battery.reporting.warning",
	    bif.bif_warn_cap);
	reporting_warning = bif.bif_warn_cap;
	libhal_changeset_set_property_int(cs, "battery.reporting.low",
	    bif.bif_low_cap);
	reporting_low = bif.bif_low_cap;
	libhal_changeset_set_property_int(cs,
	    "battery.reporting.granularity_1", bif.bif_gran1_cap);
	reporting_gran1 = bif.bif_gran1_cap;
	libhal_changeset_set_property_int(cs,
	    "battery.reporting.granularity_2", bif.bif_gran2_cap);
	reporting_gran2 = bif.bif_gran2_cap;
	libhal_changeset_set_property_int(cs, "battery.voltage.design",
	    bif.bif_voltage);
	voltage_design = bif.bif_voltage;

	if (reporting_unit && strcmp(reporting_unit, "mAh") == 0 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ dbus_error_is_set函数代码示例发布时间:2022-05-30
下一篇:
C++ dbus_error_has_name函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap