improve name alignment and fix names_count bug
This commit is contained in:
parent
0529fd1dde
commit
c112f9416e
4 changed files with 13 additions and 9 deletions
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ CFLAGS_RELEASE=-O2 -fgraphite-identity -funroll-loops -ftree-vectorize -flto -gg
|
||||||
|
|
||||||
CFLAGS+=-pipe -Wall -Wextra -Wshadow -pedantic -std=c99
|
CFLAGS+=-pipe -Wall -Wextra -Wshadow -pedantic -std=c99
|
||||||
|
|
||||||
CFLAGS+=$(CFLAGS_RELEASE)
|
CFLAGS+=$(CFLAGS_DEV)
|
||||||
|
|
||||||
jitterbug: util.c wire.c match.c server.c main.c
|
jitterbug: util.c wire.c match.c server.c main.c
|
||||||
$(CC) $(CFLAGS) -o $@ $^
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|
8
server.c
8
server.c
|
@ -225,9 +225,9 @@ BusName *bus_client_assign_unique_name(Bus *s, BusClient *client)
|
||||||
if (client->unique_name) {
|
if (client->unique_name) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
uint8_t id = 0;
|
uint16_t id = 0;
|
||||||
|
|
||||||
if (read(s->urandom_fd, &id, sizeof(uint8_t)) != sizeof(uint8_t)) {
|
if (read(s->urandom_fd, &id, sizeof(uint16_t)) != sizeof(uint16_t)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ BusName *bus_client_assign_unique_name(Bus *s, BusClient *client)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (snprintf(name_str, UNIQUE_NAME_LENGTH, ":%05"PRIu16".%03"PRIu8, client->fd_index, id) != (UNIQUE_NAME_LENGTH - 1)) {
|
if (snprintf(name_str, UNIQUE_NAME_LENGTH, ":%05"PRIu16".000%05"PRIu16, client->fd_index + 1, id) != (UNIQUE_NAME_LENGTH - 1)) {
|
||||||
free(name_str);
|
free(name_str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ void bus_client_remove(Bus *s, BusClient *c)
|
||||||
c->owned_names[j] = NULL;
|
c->owned_names[j] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bus_name_remove(s, c->unique_name);
|
// unique_name is included in owned_names, so we don't need to remove it again here
|
||||||
c->unique_name = NULL;
|
c->unique_name = NULL;
|
||||||
c->match_count = 0;
|
c->match_count = 0;
|
||||||
c->fd = -1;
|
c->fd = -1;
|
||||||
|
|
10
wire.c
10
wire.c
|
@ -449,18 +449,22 @@ int wire_compose_unicast_reply(WireCtx *msg_c, WireMsg *msg, char *sender_unique
|
||||||
TRYPTR(wire_set_u32(header_ctx, msg->serial)); /* serial */
|
TRYPTR(wire_set_u32(header_ctx, msg->serial)); /* serial */
|
||||||
uint32_t *header_fields_length = TRYPTR(wire_set_u32(header_ctx, 0)); /* header_fields_length */
|
uint32_t *header_fields_length = TRYPTR(wire_set_u32(header_ctx, 0)); /* header_fields_length */
|
||||||
|
|
||||||
TRYPTR(wire_write_align(header_ctx, 8));
|
// We don't need to do this because at this point we will always end up on an 8 byte alignment.
|
||||||
|
//TRYPTR(wire_write_align(header_ctx, 8));
|
||||||
|
|
||||||
uint32_t header_fields_start = header_ctx->byte_cursor;
|
uint32_t header_fields_start = header_ctx->byte_cursor;
|
||||||
|
|
||||||
TRYPTR(wire_set_u8(header_ctx, DBUS_HEADER_FIELD_SENDER));
|
TRYPTR(wire_set_u8(header_ctx, DBUS_HEADER_FIELD_SENDER));
|
||||||
TRYPTR(wire_set_signature_single_char(header_ctx, 's'));
|
TRYPTR(wire_set_signature_single_char(header_ctx, 's'));
|
||||||
TRYPTR(wire_set_string_fixed(header_ctx, sender_unique_name, UNIQUE_NAME_LENGTH));
|
TRYPTR(wire_set_string_fixed(header_ctx, sender_unique_name, UNIQUE_NAME_LENGTH));
|
||||||
TRYPTR(wire_write_align(header_ctx, 8));
|
|
||||||
|
// We don't need to do this because the unique names are fixed-size, such that we always end up on an 8 byte alignment here.
|
||||||
|
//TRYPTR(wire_write_align(header_ctx, 8));
|
||||||
|
|
||||||
*header_fields_length = header_ctx->byte_cursor - header_fields_start + msg->header_fields_length;
|
*header_fields_length = header_ctx->byte_cursor - header_fields_start + msg->header_fields_length;
|
||||||
|
|
||||||
if (msg_c->byte_cursor + msg->body_length >= msg_c->data_len) {
|
// TODO: is this right?
|
||||||
|
if (unlikely(msg_c->byte_cursor + msg->body_length >= msg_c->data_len)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
wire.h
2
wire.h
|
@ -20,7 +20,7 @@
|
||||||
#define DBUS_FLAG_NO_AUTO_START 0x1
|
#define DBUS_FLAG_NO_AUTO_START 0x1
|
||||||
#define DBUS_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION 0x1
|
#define DBUS_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION 0x1
|
||||||
|
|
||||||
#define UNIQUE_NAME_LENGTH 11
|
#define UNIQUE_NAME_LENGTH 16
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DBUS_HEADER_FIELD_INVALID = 0,
|
DBUS_HEADER_FIELD_INVALID = 0,
|
||||||
|
|
Loading…
Reference in a new issue