Serenity Operating System
at master 38 lines 1.4 kB view raw
1/* 2 * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> 3 * Copyright (c) 2021, kleines Filmröllchen <filmroellchen@serenityos.org> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#include "Mixer.h" 9#include <LibCore/ConfigFile.h> 10#include <LibCore/LocalServer.h> 11#include <LibCore/System.h> 12#include <LibMain/Main.h> 13 14ErrorOr<int> serenity_main(Main::Arguments) 15{ 16 TRY(Core::System::pledge("stdio recvfd thread accept cpath rpath wpath unix")); 17 18 auto config = TRY(Core::ConfigFile::open_for_app("Audio", Core::ConfigFile::AllowWriting::Yes)); 19 TRY(Core::System::unveil(config->filename(), "rwc"sv)); 20 TRY(Core::System::unveil("/dev/audio", "wc")); 21 TRY(Core::System::unveil(nullptr, nullptr)); 22 23 Core::EventLoop event_loop; 24 auto mixer = TRY(AudioServer::Mixer::try_create(config)); 25 auto server = TRY(Core::LocalServer::try_create()); 26 TRY(server->take_over_from_system_server()); 27 28 server->on_accept = [&](NonnullOwnPtr<Core::LocalSocket> client_socket) { 29 static int s_next_client_id = 0; 30 int client_id = ++s_next_client_id; 31 (void)IPC::new_client_connection<AudioServer::ConnectionFromClient>(move(client_socket), client_id, *mixer); 32 }; 33 34 TRY(Core::System::pledge("stdio recvfd thread accept cpath rpath wpath")); 35 TRY(Core::System::unveil(nullptr, nullptr)); 36 37 return event_loop.exec(); 38}