diff --git a/daemon/check_integrity.c b/daemon/check_integrity.c new file mode 100644 index 00000000..56899bdd --- /dev/null +++ b/daemon/check_integrity.c @@ -0,0 +1,139 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2010 Nedko Arnaudov + * + ************************************************************************** + * This file contains the code that checks data integrity + ************************************************************************** + * + * LADI Session Handler is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LADI Session Handler is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LADI Session Handler. If not, see + * or write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include /* usleep() */ +#include "studio.h" +#include "../proxies/notify_proxy.h" + +struct ladish_check_vgraph_integrity_context +{ + ladish_graph_handle jack_graph; +}; + +static void ladish_check_integrity_fail(const char * message) +{ + log_error("Integirity check failed: %s", message); + ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH, "ladish daemon integrity check failed", LADISH_CHECK_LOG_TEXT); + usleep(3 * 1000000); + ASSERT_NO_PASS; +} + +#define ctx_ptr ((struct ladish_check_vgraph_integrity_context *)context) + +bool +ladish_check_vgraph_integrity_client_begin_callback( + void * context, + ladish_graph_handle graph_handle, + ladish_client_handle client_handle, + const char * client_name, + void ** client_iteration_context_ptr_ptr) +{ + return true; +} + +bool +ladish_check_vgraph_integrity_port_callback( + void * context, + ladish_graph_handle vgraph, + void * client_iteration_context_ptr, + ladish_client_handle client_handle, + const char * client_name, + ladish_port_handle vport, + const char * port_name, + uint32_t port_type, + uint32_t port_flags) +{ + uuid_t uuid; + ladish_port_handle jport; + char uuid_str[37]; + bool link; + + ladish_port_get_uuid(vport, uuid); + uuid_unparse(uuid, uuid_str); + + link = ladish_port_is_link(vport); + if (link) + { + return true; + } + + jport = ladish_graph_find_port_by_uuid(ctx_ptr->jack_graph, uuid, false, vgraph); + if (jport == NULL) + { + log_error("vgraph: %s", ladish_graph_get_description(vgraph)); + log_error("client name: %s", client_name); + log_error("port name: %s", port_name); + log_error("port uuid: %s", uuid_str); + log_error("port ptr: %p", vport); + log_error("port type: 0x%"PRIX32, port_type); + log_error("port flags: 0x%"PRIX32, port_flags); + ladish_check_integrity_fail("vgraph port not found in JACK graph."); + } + + return true; +} + +bool +ladish_check_vgraph_integrity_client_end_callback( + void * context, + ladish_graph_handle graph_handle, + ladish_client_handle client_handle, + const char * client_name, + void * client_iteration_context_ptr) +{ + return true; +} + +#undef ctx_ptr + +bool ladish_check_vgraph_integrity(void * context, ladish_graph_handle graph, ladish_app_supervisor_handle app_supervisor) +{ + ladish_graph_iterate_nodes( + graph, + true, + context, + ladish_check_vgraph_integrity_client_begin_callback, + ladish_check_vgraph_integrity_port_callback, + ladish_check_vgraph_integrity_client_end_callback); + + return true; +} + +void ladish_check_integrity(void) +{ + struct ladish_check_vgraph_integrity_context ctx; + + //ladish_check_integrity_fail("test"); + + if (!ladish_studio_is_loaded()) + { + return; + } + + ctx.jack_graph = ladish_studio_get_jack_graph(); + + ladish_studio_iterate_virtual_graphs(&ctx, ladish_check_vgraph_integrity); +} diff --git a/daemon/cmd_save_studio.c b/daemon/cmd_save_studio.c index d7ec5e3d..e9509e6a 100644 --- a/daemon/cmd_save_studio.c +++ b/daemon/cmd_save_studio.c @@ -220,6 +220,8 @@ static bool run(void * command_context) goto exit; } + ladish_check_integrity(); + if (!ladish_studio_compose_filename(cmd_ptr->studio_name, &filename, &bak_filename)) { log_error("failed to compose studio filename"); diff --git a/daemon/common.h b/daemon/common.h index 9747898b..f459d59a 100644 --- a/daemon/common.h +++ b/daemon/common.h @@ -59,4 +59,6 @@ struct connection extern bool g_quit; +void ladish_check_integrity(void); + #endif /* #ifndef COMMON_H__CFDC869A_31AE_4FA3_B2D3_DACA8488CA55__INCLUDED */ diff --git a/daemon/main.c b/daemon/main.c index ada5e41f..8257f8c5 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -382,6 +382,7 @@ int main(int argc, char ** argv, char ** envp) dbus_connection_read_write_dispatch(g_dbus_connection, 50); loader_run(); ladish_studio_run(); + ladish_check_integrity(); } emit_clean_exit(); diff --git a/daemon/room_save.c b/daemon/room_save.c index 38db5913..60a7e9c1 100644 --- a/daemon/room_save.c +++ b/daemon/room_save.c @@ -53,6 +53,8 @@ static bool ladish_room_save_project_do(struct ladish_room * room_ptr) log_info("Saving project '%s' in room '%s' to '%s'", room_ptr->project_name, room_ptr->name, room_ptr->project_dir); + ladish_check_integrity(); + time(×tamp); ctime_r(×tamp, timestamp_str); timestamp_str[24] = 0; diff --git a/daemon/save.c b/daemon/save.c index 7a0422be..4f532031 100644 --- a/daemon/save.c +++ b/daemon/save.c @@ -672,6 +672,8 @@ bool ladish_write_vgraph(int fd, int indent, ladish_graph_handle vgraph, ladish_ { struct ladish_write_context context; + ladish_check_integrity(); + context.fd = fd; context.indent = indent + 1; @@ -735,6 +737,8 @@ bool ladish_write_room_link_ports(int fd, int indent, ladish_room_handle room) { struct ladish_write_context context; + ladish_check_integrity(); + context.fd = fd; context.indent = indent; @@ -939,6 +943,8 @@ bool ladish_write_jgraph(int fd, int indent, ladish_graph_handle vgraph) { struct ladish_write_jack_context context; + ladish_check_integrity(); + if (!ladish_write_indented_string(fd, indent, "\n")) { return false; diff --git a/wscript b/wscript index 983b5ff2..06fd66ce 100644 --- a/wscript +++ b/wscript @@ -364,6 +364,7 @@ def build(bld): 'room_load.c', 'recent_store.c', 'recent_projects.c', + 'check_integrity.c', ]: daemon.source.append(os.path.join("daemon", source))