Ejemplo n.º 1
0
Archivo: xmem.c Proyecto: ariavie/bcm
cmd_result_t
cmd_xmem(int unit, args_t *a)
{
    char          *token;
    unsigned int   addr, data;

    if ((token = ARG_GET(a)) == NULL) {
        return CMD_USAGE;
    }

    if (sal_strcasecmp(token, "r") == 0) {
        if ((token = ARG_GET(a)) == NULL) {
            return CMD_USAGE;
        }
        addr = parse_integer(token);
        cli_out("0x%x: %08x\n", addr, *((unsigned int *)(INT_TO_PTR(addr))));
    } else if (sal_strcasecmp(token, "w") == 0) {
        if ((token = ARG_GET(a)) == NULL) {
            return CMD_USAGE;
        }
        addr = parse_integer(token);
        if ((token = ARG_GET(a)) == NULL) {
            return CMD_USAGE;
        }
        data = parse_integer(token);
        *((unsigned int *)(INT_TO_PTR(addr))) = data;
    } else {
        cli_out(cmd_xmem_usage);
        return CMD_FAIL;
    }
    return CMD_OK;
}
Ejemplo n.º 2
0
/** 
 * @internal Main entry point to resolve requests to mysql database
 * according to the operation requested.
 */
axlPointer mod_sasl_mysql_format_handler (TurbulenceCtx    * ctx,
					  VortexConnection * conn,
					  SaslAuthBackend  * sasl_backend,
					  axlNode          * auth_db_node_conf,
					  ModSaslOpType      op_type,
					  const char       * auth_id,
					  const char       * authorization_id,
					  const char       * formated_password,
					  const char       * password,
					  const char       * serverName,
					  const char       * sasl_method,
					  axlError        ** err,
					  VortexMutex      * mutex)
{
	switch (op_type) {
	case MOD_SASL_OP_TYPE_AUTH:
		/* request to auth user */
		return INT_TO_PTR (mod_sasl_mysql_do_auth (ctx, conn, auth_db_node_conf, 
							   auth_id, authorization_id, formated_password, password, serverName, sasl_method, err));
	case MOD_SASL_OP_TYPE_LOAD_AUTH_DB:
		/* request to load database (check we can connect with current settings) */
		return INT_TO_PTR (mod_sasl_mysql_load_auth_db (ctx, sasl_backend, auth_db_node_conf, err));
	}
	return NULL;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
        struct bus_match_node root;
        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
        enum bus_match_node_type i;

        zero(root);
        root.type = BUS_MATCH_ROOT;

        assert_se(bus_match_add(&root, "arg2='wal\\'do',sender='foo',type='signal',interface='bar',", filter, INT_TO_PTR(1), NULL) >= 0);
        assert_se(bus_match_add(&root, "arg2='wal\\'do2',sender='foo',type='signal',interface='bar',", filter, INT_TO_PTR(2), NULL) >= 0);
        assert_se(bus_match_add(&root, "arg3='test',sender='foo',type='signal',interface='bar',", filter, INT_TO_PTR(3), NULL) >= 0);
        assert_se(bus_match_add(&root, "arg3='test',sender='foo',type='method_call',interface='bar',", filter, INT_TO_PTR(4), NULL) >= 0);
        assert_se(bus_match_add(&root, "", filter, INT_TO_PTR(5), NULL) >= 0);
        assert_se(bus_match_add(&root, "interface='quux'", filter, INT_TO_PTR(6), NULL) >= 0);
        assert_se(bus_match_add(&root, "interface='bar'", filter, INT_TO_PTR(7), NULL) >= 0);
        assert_se(bus_match_add(&root, "member='waldo',path='/foo/bar'", filter, INT_TO_PTR(8), NULL) >= 0);
        assert_se(bus_match_add(&root, "path='/foo/bar'", filter, INT_TO_PTR(9), NULL) >= 0);
        assert_se(bus_match_add(&root, "path_namespace='/foo'", filter, INT_TO_PTR(10), NULL) >= 0);
        assert_se(bus_match_add(&root, "path_namespace='/foo/quux'", filter, INT_TO_PTR(11), NULL) >= 0);
        assert_se(bus_match_add(&root, "arg1='two'", filter, INT_TO_PTR(12), NULL) >= 0);
        assert_se(bus_match_add(&root, "member='waldo',arg2path='/prefix/'", filter, INT_TO_PTR(13), NULL) >= 0);
        assert_se(bus_match_add(&root, "member='waldo',path='/foo/bar',arg3namespace='prefix'", filter, INT_TO_PTR(14), NULL) >= 0);

        bus_match_dump(&root, 0);

        assert_se(sd_bus_message_new_signal(NULL, "/foo/bar", "bar", "waldo", &m) >= 0);
        assert_se(sd_bus_message_append(m, "ssss", "one", "two", "/prefix/three", "prefix.four") >= 0);
        assert_se(bus_message_seal(m, 1) >= 0);

        zero(mask);
        assert_se(bus_match_run(NULL, &root, 0, m) == 0);
        assert_se(mask_contains((unsigned[]) { 9, 8, 7, 5, 10, 12, 13, 14 }, 8));
Ejemplo n.º 4
0
bool exit_status_set_test(ExitStatusSet *x, int code, int status) {

        if (exit_status_set_is_empty(x))
                return false;

        if (code == CLD_EXITED && set_contains(x->status, INT_TO_PTR(status)))
                return true;

        if (IN_SET(code, CLD_KILLED, CLD_DUMPED) && set_contains(x->signal, INT_TO_PTR(status)))
                return true;

        return false;
}
Ejemplo n.º 5
0
Archivo: stk.c Proyecto: ariavie/bcm
cmd_result_t
cmd_stk_port_set(int unit, args_t *args)
{
    parse_table_t	pt;
    int rv;
    int stk_unit = unit;
    int stk_port = -1; /* This is intentionally a port */
    int capable = 0,
        enable = 1,
        inactive = 0,
        simplex = 0,
        internal = 0,
        duplex = 0;
    uint32 flags = 0;

    parse_table_init(unit, &pt);
    parse_table_add(&pt, "Unit", PQ_DFL|PQ_INT,
		    INT_TO_PTR(unit), &stk_unit, 0);
    parse_table_add(&pt, "Port", PQ_DFL|PQ_PORT, 0, &stk_port, 0);
    parse_table_add(&pt, "Capable", PQ_DFL|PQ_BOOL, 0, &capable, 0);
    parse_table_add(&pt, "Enable", PQ_DFL|PQ_BOOL, INT_TO_PTR(1), &enable, 0);
    parse_table_add(&pt, "Inactive", PQ_DFL|PQ_BOOL, 0, &inactive, 0);
    parse_table_add(&pt, "Simplex", PQ_DFL|PQ_BOOL, 0, &simplex, 0);
    parse_table_add(&pt, "Duplex", PQ_DFL|PQ_BOOL, 0, &duplex, 0);
    parse_table_add(&pt, "Internal", PQ_DFL|PQ_BOOL, 0, &internal, 0);
    if (parse_arg_eq(args, &pt) < 0) {
        parse_arg_eq_done(&pt);
        return CMD_USAGE;
    }
    parse_arg_eq_done(&pt);
    if (stk_port < 0) {
        printk("ERROR: Must specify port number > 0\n");
        return CMD_USAGE;
    }

    flags |= capable ?   BCM_STK_CAPABLE   : 0;
    flags |= enable ?    BCM_STK_ENABLE    : 0;
    flags |= inactive ?  BCM_STK_INACTIVE  : 0;
    flags |= simplex ?   BCM_STK_SIMPLEX   : 0;
    flags |= duplex ?    BCM_STK_DUPLEX    : 0;
    flags |= internal ?  BCM_STK_INTERNAL  : 0;

    rv = bcm_stk_port_set(stk_unit, stk_port, flags);
    if (rv < 0) {
        printk("ERROR: stk_port_set unit %d port %d flags 0x%x: %s\n",
               stk_unit, stk_port, flags, bcm_errmsg(rv));
        return CMD_FAIL;
    }

    return CMD_OK;
}
Ejemplo n.º 6
0
static void test_mnt_id(void) {
        _cleanup_fclose_ FILE *f = NULL;
        Hashmap *h;
        Iterator i;
        char *p;
        void *k;
        int r;

        log_info("/* %s */", __func__);

        assert_se(f = fopen("/proc/self/mountinfo", "re"));
        assert_se(h = hashmap_new(&trivial_hash_ops));

        for (;;) {
                _cleanup_free_ char *line = NULL, *path = NULL;
                int mnt_id;

                r = read_line(f, LONG_LINE_MAX, &line);
                if (r == 0)
                        break;
                assert_se(r > 0);

                assert_se(sscanf(line, "%i %*s %*s %*s %ms", &mnt_id, &path) == 2);

                log_debug("mountinfo: %s → %i", path, mnt_id);

                assert_se(hashmap_put(h, INT_TO_PTR(mnt_id), path) >= 0);
                path = NULL;
        }

        HASHMAP_FOREACH_KEY(p, k, h, i) {
                int mnt_id = PTR_TO_INT(k), mnt_id2;

                r = path_get_mnt_id(p, &mnt_id2);
                if (r < 0) {
                        log_debug_errno(r, "Failed to get the mnt id of %s: %m\n", p);
                        continue;
                }

                log_debug("mnt ids of %s are %i, %i\n", p, mnt_id, mnt_id2);

                if (mnt_id == mnt_id2)
                        continue;

                /* The ids don't match? If so, then there are two mounts on the same path, let's check if
                 * that's really the case */
                char *t = hashmap_get(h, INT_TO_PTR(mnt_id2));
                log_debug("the other path for mnt id %i is %s\n", mnt_id2, t);
                assert_se(path_equal(p, t));
        }
Ejemplo n.º 7
0
static struct health_channel *create_channel(struct health_app *app,
						uint8_t mdep_index,
						struct health_device *dev)
{
	struct mdep_cfg *mdep;
	struct health_channel *channel;
	static unsigned int channel_id = 1;

	DBG("mdep %u", mdep_index);

	if (!dev || !app)
		return NULL;

	mdep = queue_find(app->mdeps, match_mdep_by_id, INT_TO_PTR(mdep_index));
	if (!mdep) {
		if (mdep_index == MDEP_ECHO) {
			mdep = new0(struct mdep_cfg, 1);
			if (!mdep)
				return NULL;

			/* Leave other configuration zeroes */
			mdep->id = MDEP_ECHO;

			if (!queue_push_tail(app->mdeps, mdep)) {
				free_mdep_cfg(mdep);
				return NULL;
			}
		} else
			return NULL;
Ejemplo n.º 8
0
static int
bcm_regex_report_control(int unit, sal_usecs_t interval)
{
    _bcm_ft_report_ctrl_t *rctrl = _bcm_ft_report_ctrl[unit];
    char name[32];

    rctrl = _bcm_ft_report_ctrl[unit];

    sal_snprintf(name, sizeof(name), "bcmFtExportDma.%d", unit);

    rctrl->interval = interval;
    if (interval) {
        if (rctrl->pid == SAL_THREAD_ERROR) {
            rctrl->pid = sal_thread_create(name, SAL_THREAD_STKSZ,
                                                soc_property_get(unit, spn_BCM_FT_REPORT_THREAD_PRI, 50),
                                                _bcm_report_fifo_dma_thread,
                                                INT_TO_PTR(unit));
            if (rctrl->pid == SAL_THREAD_ERROR) {
                LOG_ERROR(BSL_LS_BCM_COMMON,
                          (BSL_META_U(unit,
                                      "%s: Could not start thread\n"),
                                      FUNCTION_NAME()));
                return BCM_E_MEMORY;
            }
        }
    } else {
        /* Wake up thread so it will check the changed interval value */
        sal_sem_give(SOC_CONTROL(unit)->ftreportIntr);
    }

    return BCM_E_NONE;
}
Ejemplo n.º 9
0
static void bt_health_unregister_app(const void *buf, uint16_t len)
{
	const struct hal_cmd_health_unreg_app *cmd = buf;
	struct health_app *app;

	DBG("");

	app = queue_remove_if(apps, match_app_by_id, INT_TO_PTR(cmd->app_id));
	if (!app) {
		ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HEALTH,
				HAL_OP_HEALTH_UNREG_APP, HAL_STATUS_INVALID);
		return;
	}

	send_app_reg_notify(app, HAL_HEALTH_APP_DEREG_SUCCESS);

	if (record_id > 0) {
		bt_adapter_remove_record(record_id);
		record_id = 0;
	}

	free_health_app(app);
	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_HEALTH,
				HAL_OP_HEALTH_UNREG_APP, HAL_STATUS_SUCCESS);
}
Ejemplo n.º 10
0
static struct health_channel *search_channel_by_id(uint16_t id)
{
	const struct queue_entry *apps_entry, *devices_entry;
	struct health_app *app;
	struct health_channel *channel;
	struct health_device *dev;

	DBG("");

	apps_entry = queue_get_entries(apps);
	while (apps_entry) {
		app = apps_entry->data;
		devices_entry = queue_get_entries(app->devices);
		while (devices_entry) {
			dev = devices_entry->data;
			channel = queue_find(dev->channels, match_channel_by_id,
								INT_TO_PTR(id));

			if (channel)
				return channel;

			devices_entry = devices_entry->next;
		}

		apps_entry = apps_entry->next;
	}

	return NULL;
}
Ejemplo n.º 11
0
/** 
 * @internal Handler called once the connection is about to be closed.
 * 
 * @param conn The connection to close.
 */
void myqttd_conn_mgr_on_close (MyQttConn * conn, 
				   axlPointer         user_data)
{
	/* get myqttd context */
	MyQttdCtx          * ctx = user_data;

	/* check if we are the last reference */
	if (myqtt_conn_ref_count (conn) == 1)
		return;

	/* do not remove if hash is not defined */
	if (ctx->conn_mgr_hash == NULL)
		return;

	/* new connection created: configure it */
	myqtt_mutex_lock (&ctx->conn_mgr_mutex);

	/* remove from the hash */
	axl_hash_remove (ctx->conn_mgr_hash, INT_TO_PTR (myqtt_conn_get_id (conn)));

	/* unlock */
	myqtt_mutex_unlock (&ctx->conn_mgr_mutex);


	return;
}
Ejemplo n.º 12
0
static bool disconnect_cb(struct io *io, void *user_data)
{
	struct bt_att *att = user_data;
	int err;
	socklen_t len;

	len = sizeof(err);

	if (getsockopt(att->fd, SOL_SOCKET, SO_ERROR, &err, &len) < 0) {
		util_debug(att->debug_callback, att->debug_data,
					"Failed to obtain disconnect error: %s",
					strerror(errno));
		err = 0;
	}

	util_debug(att->debug_callback, att->debug_data,
					"Physical link disconnected: %s",
					strerror(err));

	io_destroy(att->io);
	att->io = NULL;

	bt_att_cancel_all(att);

	bt_att_ref(att);

	queue_foreach(att->disconn_list, disconn_handler, INT_TO_PTR(err));

	bt_att_unregister_all(att);
	bt_att_unref(att);

	return false;
}
Ejemplo n.º 13
0
Link *link_free(Link *l) {
        if (!l)
                return NULL;

        /* Send goodbye messages. */
        dns_scope_announce(l->mdns_ipv4_scope, true);
        dns_scope_announce(l->mdns_ipv6_scope, true);

        link_flush_settings(l);

        while (l->addresses)
                (void) link_address_free(l->addresses);

        if (l->manager)
                hashmap_remove(l->manager->links, INT_TO_PTR(l->ifindex));

        dns_scope_free(l->unicast_scope);
        dns_scope_free(l->llmnr_ipv4_scope);
        dns_scope_free(l->llmnr_ipv6_scope);
        dns_scope_free(l->mdns_ipv4_scope);
        dns_scope_free(l->mdns_ipv6_scope);

        free(l->state_file);

        return mfree(l);
}
Ejemplo n.º 14
0
Archivo: ipoll.c Proyecto: ariavie/bcm
/*
 * Function:
 *      soc_ipoll_connect
 * Description:
 *      Install interrupt handler in polled IRQ mode
 * Parameters:
 *      dev - device number
 *      handler - interrupt handler
 *      data - interrupt handler data
 * Return Value:
 *      BCM_E_NONE
 *      BCM_E_XXX - an error occurred
 * Notes:
 *      The first handler installed be cause the polling
 *      thread to be created.
 */
int
soc_ipoll_connect(int dev, ipoll_handler_t handler, void *data)
{
    int spl;
    int udelay, prio;
    int start_thread = 0;

    if (dev >= SOC_MAX_NUM_DEVICES) {
        return SOC_E_PARAM;
    }

    spl = sal_splhi();

    if (_ictrl[dev].handler == NULL) {
        if (_ihandlers++ == 0) {
            /* Create thread if first handler */
            start_thread = 1;
        }
    }
    _ictrl[dev].handler = handler;
    _ictrl[dev].data = data;
    _ictrl[dev].paused = 0;

    sal_spl(spl);

    if (start_thread) {
        udelay = soc_property_get(dev, spn_POLLED_IRQ_DELAY, IPOLL_THREAD_DELAY);
        prio = soc_property_get(dev, spn_POLLED_IRQ_PRIORITY, IPOLL_THREAD_PRIO);
        sal_thread_create("bcmPOLL",
                          SAL_THREAD_STKSZ, prio,
                          soc_ipoll_thread, INT_TO_PTR(udelay));
    }

    return SOC_E_NONE;
}
Ejemplo n.º 15
0
int main(int argc, char **argv)
{
    iterations = (argc == 2) ? strtol(argv[1], NULL, 0) : ITERATIONS;

    pthread_t thread1, thread2;
    pthread_create(&thread1, NULL, tester, INT_TO_PTR(0));
    pthread_create(&thread2, NULL, tester, INT_TO_PTR(1));

    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);

    printf("collisions: 0 = %d, 1 = %d\n",
           collision_count[0], collision_count[1]);

    return 0;
}
Ejemplo n.º 16
0
/** 
 * @internal Function that makes a SQL connection to the configured
 * database and return a MYSQL_RES object that contains the result or
 * axl_true in the case non_query is axl_true.
 *
 * With the result created, the caller must do:
 *
 * \code
 * MYSQL_ROW row;
 *
 * // get a cell data
 * row = mysql_fetch_row (result);
 * row[i] -> each field.
 *
 * // to release 
 * mysql_free_result (result);
 * \endcode
 */
MYSQL_RES * mod_sasl_mysql_do_query (TurbulenceCtx  * ctx, 
				     axlNode        * auth_db_node_conf,
				     const char     * sql_query,
				     axl_bool         non_query,
				     axlError      ** err)
{  
	MYSQL     * conn;

	/* check sql connection */
	if (sql_query == NULL) {
		axl_error_report (err, -1, "Unable to run SQL query, received NULL content, failed to run SQL command");
		return NULL;
	} /* end if */

	/* get connection */
	conn = mod_sasl_mysql_get_connection (ctx, auth_db_node_conf, err);
	if (conn == NULL) {
		axl_error_report (err, -1, "Failed to get connection to MySQL database. Unable to execute query: %s", sql_query);
		return NULL;
	}

	/* now run query */
	if (mysql_query (conn, sql_query)) {
		axl_error_report (err, mysql_errno (conn), "Failed to run SQL query, error was %u: %s\n", mysql_errno (conn), mysql_error (conn));
		return NULL;
	} /* end if */
	
	/* check if this is a non query and return proper status now */
	if (non_query)
		return INT_TO_PTR (axl_true);

	/* return result created */
	return mysql_store_result (conn);
}
Ejemplo n.º 17
0
/** 
 * @brief Allows to get a reference to the registered connection with
 * the provided id. The function will return a reference to a
 * MyQttConn owned by the myqttd connection
 * manager. 
 *
 * @param ctx The myqttd conext where the connection reference will be looked up.
 * @param conn_id The connection id to lookup.
 *
 * @return A MyQttConn reference or NULL value it if fails.
 */
MyQttConn * myqttd_conn_mgr_find_by_id (MyQttdCtx * ctx,
						   int             conn_id)
{
	MyQttConn       * conn = NULL;
	MyQttdConnMgrState * state;

	v_return_val_if_fail (ctx, NULL);

	/* lock and send */
	myqtt_mutex_lock (&ctx->conn_mgr_mutex);
	
	/* get the connection */
	state = axl_hash_get (ctx->conn_mgr_hash, INT_TO_PTR (conn_id));
	
	/* set conection */
	/* msg ("Connection find_by_id for conn id=%d returned pointer %p (conn: %p)", conn_id, state, state ? state->conn : NULL); */
	if (state)
		conn = state->conn;

	/* unlock */
	myqtt_mutex_unlock (&ctx->conn_mgr_mutex);

	/* return list */
	return conn;
}
Ejemplo n.º 18
0
int link_new(Manager *m, Link **ret, int ifindex) {
        _cleanup_(link_freep) Link *l = NULL;
        int r;

        assert(m);
        assert(ifindex > 0);

        r = hashmap_ensure_allocated(&m->links, NULL);
        if (r < 0)
                return r;

        l = new0(Link, 1);
        if (!l)
                return -ENOMEM;

        l->ifindex = ifindex;
        l->llmnr_support = RESOLVE_SUPPORT_YES;
        l->mdns_support = RESOLVE_SUPPORT_NO;
        l->dnssec_mode = _DNSSEC_MODE_INVALID;

        r = hashmap_put(m->links, INT_TO_PTR(ifindex), l);
        if (r < 0)
                return r;

        l->manager = m;

        if (ret)
                *ret = l;
        l = NULL;

        return 0;
}
Ejemplo n.º 19
0
/** 
 * @brief Finishes the provided \ref TurbulenceLoop, releasing
 * resources and stopping its resources.
 *
 * @param loop The loop to finish.
 *
 * @param notify In the case the internal thread started by the loop
 * should be notified to be stopped.
 */
void             turbulence_loop_close (TurbulenceLoop * loop, axl_bool notify)
{
	if (loop == NULL)
		return;

	/* now finish log manager */
	if (notify && loop->queue != NULL) {
		vortex_async_queue_push (loop->queue, INT_TO_PTR (-4));
		vortex_thread_destroy (&loop->thread, axl_false);
	} /* end if */	
	
	axl_list_free (loop->list);
	loop->list = NULL;

	axl_list_cursor_free (loop->cursor);
	loop->cursor = NULL;

	vortex_async_queue_unref (loop->queue);
	loop->queue = NULL;

	__vortex_io_waiting_default_destroy (loop->fileset);
	loop->fileset = NULL;

	axl_free (loop);

	return;
}
Ejemplo n.º 20
0
bool is_clean_exit(int code, int status, ExitClean clean, ExitStatusSet *success_status) {

        if (code == CLD_EXITED)
                return status == 0 ||
                       (success_status &&
                        set_contains(success_status->status, INT_TO_PTR(status)));

        /* If a daemon does not implement handlers for some of the signals that's not considered an unclean shutdown */
        if (code == CLD_KILLED)
                return
                        (clean == EXIT_CLEAN_DAEMON && IN_SET(status, SIGHUP, SIGINT, SIGTERM, SIGPIPE)) ||
                        (success_status &&
                         set_contains(success_status->signal, INT_TO_PTR(status)));

        return false;
}
Ejemplo n.º 21
0
/*
 * Function: soc_i2c_max664x_monitor
 *
 * Purpose:
 *     Monitor configuration: start or stop a temperature probe
 *     task to monitor temperatures every nsecs.
 * Parameters:
 *    unit - StrataSwitch device number or I2C bus number
 *    enable - start or stop a temperature probe task
 *    nsecs - number of seconds delay, between succesive queries.
 *  Returns:
 *    None
 *  Notes:
 *    None
 */
void
soc_i2c_max664x_monitor(int unit, int enable, int nsecs)
{
    if (!soc_i2c_is_attached(unit)) {
        soc_i2c_attach(unit, 0, 0);
    }
    if (max664x_info[unit] == NULL) {
        return;
    }
    if (!enable) {
        max664x_info[unit]->sleep = 0;
        return;
    }
    if (max664x_info[unit]->sleep) {
        return;
    }
    max664x_info[unit]->sleep = nsecs;
    
    sal_thread_create("bcmTEMP",
                      SAL_THREAD_STKSZ,
                      50,
                      (void (*)(void*))max664x_thread,
                      INT_TO_PTR(unit));
    LOG_CLI((BSL_META_U(unit,
                        "unit %d: thermal monitoring enabled\n"), unit));
}
Ejemplo n.º 22
0
static int list_bus_names(sd_bus *bus, char **argv) {
        _cleanup_strv_free_ char **acquired = NULL, **activatable = NULL;
        _cleanup_free_ char **merged = NULL;
        _cleanup_hashmap_free_ Hashmap *names = NULL;
        char **i;
        int r;
        size_t max_i = 0;
        unsigned n = 0;
        void *v;
        char *k;
        Iterator iterator;

        assert(bus);

        r = sd_bus_list_names(bus, (arg_acquired || arg_unique) ? &acquired : NULL, arg_activatable ? &activatable : NULL);
        if (r < 0) {
                log_error("Failed to list names: %s", strerror(-r));
                return r;
        }

        pager_open_if_enabled();

        names = hashmap_new(&string_hash_ops);
        if (!names)
                return log_oom();

        STRV_FOREACH(i, acquired) {
                max_i = MAX(max_i, strlen(*i));

                r = hashmap_put(names, *i, INT_TO_PTR(1));
                if (r < 0) {
                        log_error("Failed to add to hashmap: %s", strerror(-r));
                        return r;
                }
        }
Ejemplo n.º 23
0
Archivo: alloc.c Proyecto: ariavie/bcm
void *
sal_dma_alloc(size_t sz, char *s)
{
    uint32	*p;

    /*
     * Round up size to accommodate corruption detection sentinels.
     * Place sentinels at the beginning and end of the data area to
     * detect memory corruption.  These are verified on free.
     */
    sz = (sz + 3) & ~3;

    if ((p = malloc(sz + 12)) == 0) {
        return p;
    }

    assert(INT_TO_PTR(PTR_TO_INT(p)) == p);

    p[0] = sz / 4;
    p[1] = 0xaaaaaaaa;
    p[2 + sz / 4] = 0xbbbbbbbb;
#ifdef BROADCOM_DEBUG
#ifdef INCLUDE_BCM_SAL_PROFILE
    SAL_DMA_ALLOC_RESOURCE_USAGE_INCR(
        _sal_dma_alloc_curr,
        _sal_dma_alloc_max,
        (sz),
        ilock);
#endif
#endif /* BROADCOM_DEBUG */

    MEMLOG_ALLOC("sal_dma_alloc", &p[0], orig_sz, s);

    return (void *) &p[2];
}
Ejemplo n.º 24
0
static int signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
        sd_event_source *p = NULL;
        sigset_t ss;
        pid_t pid;

        assert_se(s);
        assert_se(si);

        log_info("got signal on %c", PTR_TO_INT(userdata));

        assert_se(userdata == INT_TO_PTR('e'));

        assert_se(sigemptyset(&ss) >= 0);
        assert_se(sigaddset(&ss, SIGCHLD) >= 0);
        assert_se(sigprocmask(SIG_BLOCK, &ss, NULL) >= 0);

        pid = fork();
        assert_se(pid >= 0);

        if (pid == 0)
                _exit(0);

        assert_se(sd_event_add_child(sd_event_source_get_event(s), &p, pid, WEXITED, child_handler, INT_TO_PTR('f')) >= 0);
        assert_se(sd_event_source_set_enabled(p, SD_EVENT_ONESHOT) >= 0);

        sd_event_source_unref(s);

        return 1;
}
Ejemplo n.º 25
0
/** 
 * @internal Function used to unregister the connection from the
 * sequencer if it is found.
 */
void     vortex_sequencer_remove_channel           (VortexCtx        * ctx,
						    VortexChannel    * channel)
{
	vortex_log (VORTEX_LEVEL_DEBUG, "removing channel %p from sequencer supervision", channel);
	vortex_channel_set_data (channel, "vo:seq:del", INT_TO_PTR (axl_true));

	return;
}
Ejemplo n.º 26
0
static int
_dma_getb(uint32 addr)
{
    if (addr < MAX_DMA_MEMORY) {
	addr = (uint32)kluge_dma_memory + addr;
    }

    return *(uint8 *)INT_TO_PTR(addr);
}
Ejemplo n.º 27
0
        STRV_FOREACH(i, activatable) {
                max_i = MAX(max_i, strlen(*i));

                r = hashmap_put(names, *i, INT_TO_PTR(2));
                if (r < 0 && r != -EEXIST) {
                        log_error("Failed to add to hashmap: %s", strerror(-r));
                        return r;
                }
        }
Ejemplo n.º 28
0
static void *server(void *p) {
        struct context *c = p;
        sd_bus *bus = NULL;
        sd_id128_t id;
        int r;

        c->quit = false;

        assert_se(sd_id128_randomize(&id) >= 0);

        assert_se(sd_bus_new(&bus) >= 0);
        assert_se(sd_bus_set_fd(bus, c->fds[0], c->fds[0]) >= 0);
        assert_se(sd_bus_set_server(bus, 1, id) >= 0);

        assert_se(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.test", vtable, c) >= 0);
        assert_se(sd_bus_add_object_vtable(bus, NULL, "/foo", "org.freedesktop.systemd.test2", vtable, c) >= 0);
        assert_se(sd_bus_add_fallback_vtable(bus, NULL, "/value", "org.freedesktop.systemd.ValueTest", vtable2, NULL, UINT_TO_PTR(20)) >= 0);
        assert_se(sd_bus_add_node_enumerator(bus, NULL, "/value", enumerator_callback, NULL) >= 0);
        assert_se(sd_bus_add_node_enumerator(bus, NULL, "/value/a", enumerator2_callback, NULL) >= 0);
        assert_se(sd_bus_add_object_manager(bus, NULL, "/value") >= 0);
        assert_se(sd_bus_add_object_manager(bus, NULL, "/value/a") >= 0);

        assert_se(sd_bus_start(bus) >= 0);

        log_error("Entering event loop on server");

        while (!c->quit) {
                log_error("Loop!");

                r = sd_bus_process(bus, NULL);
                if (r < 0) {
                        log_error_errno(r, "Failed to process requests: %m");
                        goto fail;
                }

                if (r == 0) {
                        r = sd_bus_wait(bus, (uint64_t) -1);
                        if (r < 0) {
                                log_error_errno(r, "Failed to wait: %m");
                                goto fail;
                        }

                        continue;
                }
        }

        r = 0;

fail:
        if (bus) {
                sd_bus_flush(bus);
                sd_bus_unref(bus);
        }

        return INT_TO_PTR(r);
}
Ejemplo n.º 29
0
void btpan_set_flow_control(BOOLEAN enable) {
    if (btpan_cb.tap_fd == -1)
        return;

    btpan_cb.flow = enable;
    if (enable) {
        btsock_thread_add_fd(pan_pth, btpan_cb.tap_fd, 0, SOCK_THREAD_FD_RD, 0);
        bta_dmexecutecallback(btu_exec_tap_fd_read, INT_TO_PTR(btpan_cb.tap_fd));
    }
}
Ejemplo n.º 30
0
int button_open(Button *b) {
        char name[256], *p;
        struct epoll_event ev;
        int r;

        assert(b);

        if (b->fd >= 0) {
                close_nointr_nofail(b->fd);
                b->fd = -1;
        }

        p = strappend("/dev/input/", b->name);
        if (!p)
                return log_oom();

        b->fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
        free(p);
        if (b->fd < 0) {
                log_warning("Failed to open %s: %m", b->name);
                return -errno;
        }

        if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
                log_error("Failed to get input name: %m");
                r = -errno;
                goto fail;
        }

        zero(ev);
        ev.events = EPOLLIN;
        ev.data.u32 = FD_OTHER_BASE + b->fd;

        if (epoll_ctl(b->manager->epoll_fd, EPOLL_CTL_ADD, b->fd, &ev) < 0) {
                log_error("Failed to add to epoll: %m");
                r = -errno;
                goto fail;
        }

        r = hashmap_put(b->manager->button_fds, INT_TO_PTR(b->fd + 1), b);
        if (r < 0) {
                log_error("Failed to add to hash map: %s", strerror(-r));
                assert_se(epoll_ctl(b->manager->epoll_fd, EPOLL_CTL_DEL, b->fd, NULL) == 0);
                goto fail;
        }

        log_info("Watching system buttons on /dev/input/%s (%s)", b->name, name);

        return 0;

fail:
        close_nointr_nofail(b->fd);
        b->fd = -1;
        return r;
}