mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-06 13:29:48 -05:00
wayland-server: reduce use of magic numbers
Make it clear what the significance of '5' and '113' actually is. Also drop an unneeded function argument.
This commit is contained in:
parent
9de9e39f87
commit
bb6e48b1b0
1 changed files with 15 additions and 6 deletions
|
|
@ -46,11 +46,21 @@
|
||||||
#include "wayland-server-protocol.h"
|
#include "wayland-server-protocol.h"
|
||||||
#include "wayland-os.h"
|
#include "wayland-os.h"
|
||||||
|
|
||||||
|
/* This is the size of the char array in struct sock_addr_un.
|
||||||
|
No Wayland socket can be created with a path longer than this,
|
||||||
|
including the null terminator. */
|
||||||
|
#ifndef UNIX_PATH_MAX
|
||||||
|
#define UNIX_PATH_MAX 108
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LOCK_SUFFIX ".lock"
|
||||||
|
#define LOCK_SUFFIXLEN 5
|
||||||
|
|
||||||
struct wl_socket {
|
struct wl_socket {
|
||||||
int fd;
|
int fd;
|
||||||
int fd_lock;
|
int fd_lock;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
char lock_addr[113];
|
char lock_addr[UNIX_PATH_MAX + LOCK_SUFFIXLEN];
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
struct wl_event_source *source;
|
struct wl_event_source *source;
|
||||||
};
|
};
|
||||||
|
|
@ -1100,13 +1110,12 @@ socket_data(int fd, uint32_t mask, void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_socket_lock(struct wl_socket *socket, socklen_t name_size)
|
get_socket_lock(struct wl_socket *socket)
|
||||||
{
|
{
|
||||||
struct stat socket_stat;
|
struct stat socket_stat;
|
||||||
int lock_size = name_size + 5;
|
|
||||||
|
|
||||||
snprintf(socket->lock_addr, lock_size,
|
snprintf(socket->lock_addr, sizeof socket->lock_addr,
|
||||||
"%s.lock", socket->addr.sun_path);
|
"%s%s", socket->addr.sun_path, LOCK_SUFFIX);
|
||||||
|
|
||||||
socket->fd_lock = open(socket->lock_addr, O_CREAT | O_CLOEXEC,
|
socket->fd_lock = open(socket->lock_addr, O_CREAT | O_CLOEXEC,
|
||||||
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
|
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
|
||||||
|
|
@ -1177,7 +1186,7 @@ wl_display_add_socket(struct wl_display *display, const char *name)
|
||||||
"%s/%s", runtime_dir, name) + 1;
|
"%s/%s", runtime_dir, name) + 1;
|
||||||
wl_log("using socket %s\n", s->addr.sun_path);
|
wl_log("using socket %s\n", s->addr.sun_path);
|
||||||
|
|
||||||
if (get_socket_lock(s,name_size) < 0) {
|
if (get_socket_lock(s) < 0) {
|
||||||
close(s->fd);
|
close(s->fd);
|
||||||
free(s);
|
free(s);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue