Skip to content

Commit 0461d75

Browse files
authored
Merge pull request #1491 from andrew-sayers/multi-user-fixes
Fluidsynth includes a systemd user service, which listens on TCP port 9800 by default. So if a computer starts a second user session, that session's service immediately fails because port 9800 is already in use. Lightdm implements its login prompt as a user session, so this can happen just by misclicking the "switch user" button. I assume other display managers are the same, but haven't checked. This PR is a set of loosely-connected suggestions that would have helped as I went down this particular rabbit hole. I figure they're easier to review together, but happy to edit/split out/remove anything that doesn't fit.
2 parents e884404 + 96e5444 commit 0461d75

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

fluidsynth.service.in

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Description=FluidSynth Daemon
33
Documentation=man:fluidsynth(1)
44
After=sound.target
55
After=pipewire.service
6+
# If you need more than one instance, use `systemctl edit` to override this:
7+
ConditionPathExists=!/run/lock/fluidsynth.lock
68

79
[Service]
810
# added automatically, for details please see
@@ -23,6 +25,8 @@ Environment=OTHER_OPTS= SOUND_FONT=
2325
EnvironmentFile=@FLUID_DAEMON_ENV_FILE@
2426
EnvironmentFile=-%h/.config/fluidsynth
2527
ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/fluidsynth -is $OTHER_OPTS $SOUND_FONT
28+
ExecStartPre=touch /run/lock/fluidsynth.lock
29+
ExecStopPost=rm -f /run/lock/fluidsynth.lock
2630

2731
[Install]
2832
WantedBy=default.target

src/fluidsynth.c

+4
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,10 @@ int main(int argc, char **argv)
11371137
#endif
11381138
delete_fluid_server(server);
11391139
}
1140+
else if(with_server)
1141+
{
1142+
result = 1;
1143+
}
11401144

11411145
#endif /* NETWORK_SUPPORT */
11421146

src/utils/fluid_sys.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ static fluid_thread_return_t fluid_server_socket_run(void *data)
15671567
{
15681568
if(server_socket->cont)
15691569
{
1570-
FLUID_LOG(FLUID_ERR, "Failed to accept connection: %d", fluid_socket_get_error());
1570+
FLUID_LOG(FLUID_ERR, "Got error %d while trying to accept connection", fluid_socket_get_error());
15711571
}
15721572

15731573
server_socket->cont = 0;
@@ -1640,7 +1640,7 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void *data)
16401640

16411641
if(sock == INVALID_SOCKET)
16421642
{
1643-
FLUID_LOG(FLUID_WARN, "Failed to create IPv6 server socket: %d (will try with IPv4)", fluid_socket_get_error());
1643+
FLUID_LOG(FLUID_WARN, "Got error %d while trying to create IPv6 server socket (will try with IPv4)", fluid_socket_get_error());
16441644

16451645
sock = socket(AF_INET, SOCK_STREAM, 0);
16461646
addr = (const struct sockaddr *) &addr4;
@@ -1655,22 +1655,22 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void *data)
16551655

16561656
if(sock == INVALID_SOCKET)
16571657
{
1658-
FLUID_LOG(FLUID_ERR, "Failed to create server socket: %d", fluid_socket_get_error());
1658+
FLUID_LOG(FLUID_ERR, "Got error %d while trying to create server socket", fluid_socket_get_error());
16591659
fluid_socket_cleanup();
16601660
return NULL;
16611661
}
16621662

16631663
if(bind(sock, addr, (int) addr_size) == SOCKET_ERROR)
16641664
{
1665-
FLUID_LOG(FLUID_ERR, "Failed to bind server socket: %d", fluid_socket_get_error());
1665+
FLUID_LOG(FLUID_ERR, "Got error %d while trying to bind server socket", fluid_socket_get_error());
16661666
fluid_socket_close(sock);
16671667
fluid_socket_cleanup();
16681668
return NULL;
16691669
}
16701670

16711671
if(listen(sock, SOMAXCONN) == SOCKET_ERROR)
16721672
{
1673-
FLUID_LOG(FLUID_ERR, "Failed to listen on server socket: %d", fluid_socket_get_error());
1673+
FLUID_LOG(FLUID_ERR, "Got error %d while trying to listen on server socket", fluid_socket_get_error());
16741674
fluid_socket_close(sock);
16751675
fluid_socket_cleanup();
16761676
return NULL;

0 commit comments

Comments
 (0)