meson: Make default seatd socket path configurable

FreeBSD and Linux have different preferred socket locations. Expose an
option to set the location, and implement simple auto-logic for
linux/freebsd.
This commit is contained in:
Kenny Levinsen 2020-09-22 01:12:33 +02:00
parent a763e16f26
commit 884c1416b3
4 changed files with 17 additions and 6 deletions

View file

@ -67,9 +67,9 @@ static int seatd_connect(void) {
close(fd);
return -1;
}
char *path = getenv("SEATD_SOCK");
const char *path = getenv("SEATD_SOCK");
if (path == NULL) {
path = "/run/seatd.sock";
path = SEATD_DEFAULTPATH;
}
addr.unix.sun_family = AF_UNIX;
strncpy(addr.unix.sun_path, path, sizeof addr.unix.sun_path);

View file

@ -14,6 +14,16 @@ project(
# Bump whenever ABI-breaking changes occur.
libseat_soversion = 1
defaultpath = get_option('defaultpath')
if defaultpath == ''
system = target_machine.system()
if system == 'linux'
defaultpath = '/run/seatd.sock'
else
defaultpath = '/var/run/seatd.sock'
endif
endif
add_project_arguments(
[
'-Wundef',
@ -32,6 +42,7 @@ add_project_arguments(
'-D_XOPEN_SOURCE=700',
'-D__BSD_VISIBLE',
'-DSEATD_VERSION="@0@"'.format(meson.project_version()),
'-DSEATD_DEFAULTPATH="@0@"'.format(defaultpath)
],
language: 'c',
)

View file

@ -4,4 +4,4 @@ option('builtin', type: 'feature', value: 'disabled', description: 'builtin seat
option('server', type: 'feature', value: 'enabled', description: 'seatd server')
option('examples', type: 'feature', value: 'enabled', description: 'libseat example programs')
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
option('defaultpath', type: 'string', value: '', description: 'Default location for seatd socket (empty for default)')

View file

@ -17,7 +17,7 @@
#define LISTEN_BACKLOG 16
static int open_socket(char *path, int uid, int gid) {
static int open_socket(const char *path, int uid, int gid) {
union {
struct sockaddr_un unix;
struct sockaddr generic;
@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
int c;
int uid = 0, gid = 0;
char *socket_path = getenv("SEATD_SOCK");
const char *socket_path = getenv("SEATD_SOCK");
while ((c = getopt(argc, argv, "vhs:g:u:")) != -1) {
switch (c) {
case 's':
@ -119,7 +119,7 @@ int main(int argc, char *argv[]) {
}
if (socket_path == NULL) {
socket_path = "/run/seatd.sock";
socket_path = SEATD_DEFAULTPATH;
struct stat st;
if (stat(socket_path, &st) == 0) {
log_info("removing leftover seatd socket");