Fix API to always include socket name length.
This commit is contained in:
parent
cb70316105
commit
dc0f355f0a
@ -1042,7 +1042,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
wl_display_set_compositor(display, &ec->base);
|
wl_display_set_compositor(display, &ec->base);
|
||||||
|
|
||||||
if (wl_display_add_socket(display, socket_name)) {
|
if (wl_display_add_socket(display, socket_name, sizeof socket_name)) {
|
||||||
fprintf(stderr, "failed to add socket: %m\n");
|
fprintf(stderr, "failed to add socket: %m\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
2
flower.c
2
flower.c
@ -149,7 +149,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
loop = g_main_loop_new(NULL, FALSE);
|
loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
display = wl_display_create(socket_name);
|
display = wl_display_create(socket_name, sizeof socket_name);
|
||||||
if (display == NULL) {
|
if (display == NULL) {
|
||||||
fprintf(stderr, "failed to create display: %m\n");
|
fprintf(stderr, "failed to create display: %m\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -369,7 +369,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
wl_display_set_compositor(display, &gc->base);
|
wl_display_set_compositor(display, &gc->base);
|
||||||
|
|
||||||
if (wl_display_add_socket(display, socket_name)) {
|
if (wl_display_add_socket(display, socket_name, sizeof socket_name)) {
|
||||||
fprintf(stderr, "failed to add socket: %m\n");
|
fprintf(stderr, "failed to add socket: %m\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ int main(int argc, char *argv[])
|
|||||||
GSource *source;
|
GSource *source;
|
||||||
struct screenshooter *s;
|
struct screenshooter *s;
|
||||||
|
|
||||||
display = wl_display_create(socket_name);
|
display = wl_display_create(socket_name, sizeof socket_name);
|
||||||
if (display == NULL) {
|
if (display == NULL) {
|
||||||
fprintf(stderr, "failed to create display: %m\n");
|
fprintf(stderr, "failed to create display: %m\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -83,11 +83,11 @@ connection_update(struct wl_connection *connection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT struct wl_display *
|
WL_EXPORT struct wl_display *
|
||||||
wl_display_create(const char *address)
|
wl_display_create(const char *name, size_t name_size)
|
||||||
{
|
{
|
||||||
struct wl_display *display;
|
struct wl_display *display;
|
||||||
struct wl_global *global;
|
struct wl_global *global;
|
||||||
struct sockaddr_un name;
|
struct sockaddr_un addr;
|
||||||
socklen_t size;
|
socklen_t size;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
uint32_t id, length, count, i;
|
uint32_t id, length, count, i;
|
||||||
@ -103,12 +103,12 @@ wl_display_create(const char *address)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
name.sun_family = AF_LOCAL;
|
addr.sun_family = AF_LOCAL;
|
||||||
memcpy(name.sun_path, address, strlen(address + 1) + 2);
|
memcpy(addr.sun_path, name, name_size);
|
||||||
|
|
||||||
size = offsetof (struct sockaddr_un, sun_path) + sizeof socket_name;
|
size = offsetof (struct sockaddr_un, sun_path) + name_size;
|
||||||
|
|
||||||
if (connect(display->fd, (struct sockaddr *) &name, size) < 0) {
|
if (connect(display->fd, (struct sockaddr *) &addr, size) < 0) {
|
||||||
close(display->fd);
|
close(display->fd);
|
||||||
free(display);
|
free(display);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -38,7 +38,7 @@ struct wl_surface;
|
|||||||
|
|
||||||
typedef int (*wl_display_update_func_t)(uint32_t mask, void *data);
|
typedef int (*wl_display_update_func_t)(uint32_t mask, void *data);
|
||||||
|
|
||||||
struct wl_display *wl_display_create(const char *address);
|
struct wl_display *wl_display_create(const char *name, size_t name_size);
|
||||||
void wl_display_destroy(struct wl_display *display);
|
void wl_display_destroy(struct wl_display *display);
|
||||||
int wl_display_get_fd(struct wl_display *display,
|
int wl_display_get_fd(struct wl_display *display,
|
||||||
wl_display_update_func_t update, void *data);
|
wl_display_update_func_t update, void *data);
|
||||||
|
15
wayland.c
15
wayland.c
@ -90,7 +90,7 @@ struct wl_object_ref {
|
|||||||
struct wl_object *object;
|
struct wl_object *object;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wl_surface_destroy(struct wl_client *client,
|
wl_surface_destroy(struct wl_client *client,
|
||||||
struct wl_surface *surface)
|
struct wl_surface *surface)
|
||||||
@ -762,9 +762,10 @@ socket_data(int fd, uint32_t mask, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT int
|
WL_EXPORT int
|
||||||
wl_display_add_socket(struct wl_display *display, const char *socket_name)
|
wl_display_add_socket(struct wl_display *display,
|
||||||
|
const char *name, size_t name_size)
|
||||||
{
|
{
|
||||||
struct sockaddr_un name;
|
struct sockaddr_un addr;
|
||||||
int sock;
|
int sock;
|
||||||
socklen_t size;
|
socklen_t size;
|
||||||
|
|
||||||
@ -772,11 +773,11 @@ wl_display_add_socket(struct wl_display *display, const char *socket_name)
|
|||||||
if (sock < 0)
|
if (sock < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
name.sun_family = AF_LOCAL;
|
addr.sun_family = AF_LOCAL;
|
||||||
memcpy(name.sun_path, socket_name, sizeof socket_name);
|
memcpy(addr.sun_path, name, name_size);
|
||||||
|
|
||||||
size = offsetof (struct sockaddr_un, sun_path) + sizeof socket_name;
|
size = offsetof (struct sockaddr_un, sun_path) + name_size;
|
||||||
if (bind(sock, (struct sockaddr *) &name, size) < 0)
|
if (bind(sock, (struct sockaddr *) &addr, size) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (listen(sock, 1) < 0)
|
if (listen(sock, 1) < 0)
|
||||||
|
@ -119,7 +119,7 @@ wl_input_device_create(struct wl_display *display, const char *path);
|
|||||||
|
|
||||||
struct wl_display *wl_display_create(void);
|
struct wl_display *wl_display_create(void);
|
||||||
struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display);
|
struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display);
|
||||||
int wl_display_add_socket(struct wl_display *display, const char *socket_name);
|
int wl_display_add_socket(struct wl_display *display, const char *name, size_t name_size);
|
||||||
void wl_display_run(struct wl_display *display);
|
void wl_display_run(struct wl_display *display);
|
||||||
|
|
||||||
void
|
void
|
||||||
|
4
window.c
4
window.c
@ -270,7 +270,7 @@ event_handler(struct wl_display *display,
|
|||||||
buffer->name, buffer->stride,
|
buffer->name, buffer->stride,
|
||||||
0, 0, buffer->width, buffer->height);
|
0, 0, buffer->width, buffer->height);
|
||||||
wl_display_commit(window->display, 0);
|
wl_display_commit(window->display, 0);
|
||||||
window->gears_angle += 1;
|
window->gears_angle += 1;
|
||||||
|
|
||||||
} else if (object == 1) {
|
} else if (object == 1) {
|
||||||
fprintf(stderr, "unexpected event from display: %d\n",
|
fprintf(stderr, "unexpected event from display: %d\n",
|
||||||
@ -418,7 +418,7 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
display = wl_display_create(socket_name);
|
display = wl_display_create(socket_name, sizeof socket_name);
|
||||||
if (display == NULL) {
|
if (display == NULL) {
|
||||||
fprintf(stderr, "failed to create display: %m\n");
|
fprintf(stderr, "failed to create display: %m\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user