Skip to content

Commit

Permalink
samples: rename some functions
Browse files Browse the repository at this point in the history
Rename some functions to make them more descriptive.

Signed-off-by: Daniel Mack <daniel@zonque.org>
  • Loading branch information
zonque committed Mar 1, 2015
1 parent 3e71737 commit 00f042a
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions samples/kdbus-workers.c
Expand Up @@ -129,12 +129,12 @@ struct bus {
uint8_t *pool;
};

static int bus_open(struct bus **out, uid_t uid, const char *name,
uint64_t recv_flags);
static void bus_close(struct bus *b);
static void bus_release(struct bus *b, uint64_t offset);
static int bus_acquire(struct bus *b, const char *name);
static int bus_install(struct bus *b, const char *name);
static int bus_open_connection(struct bus **out, uid_t uid, const char *name,
uint64_t recv_flags);
static void bus_close_connection(struct bus *b);
static void bus_poool_free_slice(struct bus *b, uint64_t offset);
static int bus_acquire_name(struct bus *b, const char *name);
static int bus_install_name_loss_match(struct bus *b, const char *name);
static int bus_poll(struct bus *b);
static int bus_make(uid_t uid, const char *name);

Expand Down Expand Up @@ -250,7 +250,8 @@ static int master_new(struct master **out)
* The current UID is needed to compute the name of the bus node to
* connect to.
*/
r = bus_open(&m->bus, getuid(), arg_busname, KDBUS_ATTACH_PIDS);
r = bus_open_connection(&m->bus, getuid(),
arg_busname, KDBUS_ATTACH_PIDS);
if (r < 0)
goto error;

Expand All @@ -259,7 +260,7 @@ static int master_new(struct master **out)
* messages to the master using KDBUS_DST_ID_NAME as destination-ID
* of messages.
*/
r = bus_acquire(m->bus, arg_master);
r = bus_acquire_name(m->bus, arg_master);
if (r < 0)
goto error;

Expand All @@ -277,7 +278,7 @@ static void master_free(struct master *m)
if (!m)
return;

bus_close(m->bus);
bus_close_connection(m->bus);
if (m->control_fd >= 0)
close(m->control_fd);
prime_free(m->prime);
Expand All @@ -303,15 +304,15 @@ static int master_run(struct master *m)
}

if (r < 0) {
bus_close(m->bus);
bus_close_connection(m->bus);
m->bus = NULL;
}

while (m->n_workers > 0) {
res = master_poll(m);
if (res < 0) {
if (m->bus) {
bus_close(m->bus);
bus_close_connection(m->bus);
m->bus = NULL;
}
r = res;
Expand Down Expand Up @@ -523,7 +524,7 @@ static int master_handle_bus(struct master *m)
* recv.msg.offset. Tell the kernel it can use it for other content
* in the future. See kdbus.pool(7).
*/
bus_release(m->bus, recv.msg.offset);
bus_poool_free_slice(m->bus, recv.msg.offset);
return r;
}

Expand Down Expand Up @@ -680,15 +681,16 @@ static int child_new(struct child **out, struct prime *p)
* owns. The current UID is needed in order to determine the name of the
* bus bus node to connect to.
*/
r = bus_open(&c->bus, getuid(), arg_busname, KDBUS_ATTACH_NAMES);
r = bus_open_connection(&c->bus, getuid(),
arg_busname, KDBUS_ATTACH_NAMES);
if (r < 0)
goto error;

/*
* Install a kdbus match so the child's connection gets notified when
* the master loses its well-known name.
*/
r = bus_install(c->bus, arg_master);
r = bus_install_name_loss_match(c->bus, arg_master);
if (r < 0)
goto error;

Expand All @@ -705,7 +707,7 @@ static void child_free(struct child *c)
if (!c)
return;

bus_close(c->bus);
bus_close_connection(c->bus);
prime_free(c->prime);
free(c);
}
Expand Down Expand Up @@ -900,7 +902,7 @@ static int child_run(struct child *c)
* cmd.reply.offset. Tell the kernel it can use it for other content
* in the future. See kdbus.pool(7).
*/
bus_release(c->bus, cmd.reply.offset);
bus_poool_free_slice(c->bus, cmd.reply.offset);
return r;
}

Expand Down Expand Up @@ -1010,8 +1012,8 @@ static void prime_print(struct prime *p)
fprintf(stderr, "\nEND\n");
}

static int bus_open(struct bus **out, uid_t uid, const char *name,
uint64_t recv_flags)
static int bus_open_connection(struct bus **out, uid_t uid, const char *name,
uint64_t recv_flags)
{
struct kdbus_cmd_hello hello;
char path[128];
Expand Down Expand Up @@ -1078,7 +1080,7 @@ static int bus_open(struct bus **out, uid_t uid, const char *name,
goto error;
}

bus_release(b, hello.offset);
bus_poool_free_slice(b, hello.offset);

/*
* Map the pool of the connection. Its size has been set in the
Expand All @@ -1094,11 +1096,11 @@ static int bus_open(struct bus **out, uid_t uid, const char *name,
return 0;

error:
bus_close(b);
bus_close_connection(b);
return r;
}

static void bus_close(struct bus *b)
static void bus_close_connection(struct bus *b)
{
if (!b)
return;
Expand All @@ -1116,7 +1118,7 @@ static void bus_close(struct bus *b)
free(b);
}

static void bus_release(struct bus *b, uint64_t offset)
static void bus_poool_free_slice(struct bus *b, uint64_t offset)
{
struct kdbus_cmd_free cmd = {
.size = sizeof(cmd),
Expand All @@ -1137,7 +1139,7 @@ static void bus_release(struct bus *b, uint64_t offset)
err_r(r, "cannot free pool slice");
}

static int bus_acquire(struct bus *b, const char *name)
static int bus_acquire_name(struct bus *b, const char *name)
{
struct kdbus_item *item;
struct kdbus_cmd *cmd;
Expand Down Expand Up @@ -1175,7 +1177,7 @@ static int bus_acquire(struct bus *b, const char *name)
return 0;
}

static int bus_install(struct bus *b, const char *name)
static int bus_install_name_loss_match(struct bus *b, const char *name)
{
struct kdbus_cmd_match *match;
struct kdbus_item *item;
Expand Down

0 comments on commit 00f042a

Please sign in to comment.