From 7abecb48babe6a6f09bf6692ba55076546cfced9 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Mon, 1 Dec 2008 17:39:58 -0600 Subject: Second Life viewer sources 1.22.0-RC --- linden/indra/newview/llappviewerlinux.cpp | 307 ++++++++++++++++++++++++++---- 1 file changed, 270 insertions(+), 37 deletions(-) (limited to 'linden/indra/newview/llappviewerlinux.cpp') diff --git a/linden/indra/newview/llappviewerlinux.cpp b/linden/indra/newview/llappviewerlinux.cpp index 0a4a9cf..643013b 100644 --- a/linden/indra/newview/llappviewerlinux.cpp +++ b/linden/indra/newview/llappviewerlinux.cpp @@ -1,6 +1,6 @@ /** * @file llappviewerlinux.cpp - * @brief The LLAppViewerWin32 class definitions + * @brief The LLAppViewerLinux class definitions * * $LicenseInfo:firstyear=2007&license=viewergpl$ * @@ -36,8 +36,10 @@ #include "llcommandlineparser.h" #include "llmemtype.h" +#include "llurldispatcher.h" // SLURL from other app instance #include "llviewernetwork.h" #include "llviewercontrol.h" +#include "llwindowsdl.h" #include "llmd5.h" #include "llfindlocale.h" @@ -60,6 +62,17 @@ # include "ELFIO/ELFIO.h" // for better backtraces #endif +#if LL_DBUS_ENABLED +# include "llappviewerlinux_api_dbus.h" + +// regrettable hacks to give us better runtime compatibility with older systems inside llappviewerlinux_api.h: +#define llg_return_if_fail(COND) do{if (!(COND)) return;}while(0) +#undef g_return_if_fail +#define g_return_if_fail(COND) llg_return_if_fail(COND) +// The generated API +# include "llappviewerlinux_api.h" +#endif + namespace { int gArgC = 0; @@ -321,6 +334,193 @@ bool LLAppViewerLinux::init() return LLAppViewer::init(); } +bool LLAppViewerLinux::restoreErrorTrap() +{ + // *NOTE:Mani there is a case for implementing this or the mac. + // Linux doesn't need it to my knowledge. + return true; +} + +///////////////////////////////////////// +#if LL_DBUS_ENABLED + +typedef struct +{ + GObjectClass parent_class; +} ViewerAppAPIClass; + +static void viewerappapi_init(ViewerAppAPI *server); +static void viewerappapi_class_init(ViewerAppAPIClass *klass); + +/// + +// regrettable hacks to give us better runtime compatibility with older systems in general +static GType llg_type_register_static_simple_ONCE(GType parent_type, + const gchar *type_name, + guint class_size, + GClassInitFunc class_init, + guint instance_size, + GInstanceInitFunc instance_init, + GTypeFlags flags) +{ + static GTypeInfo type_info; + memset(&type_info, 0, sizeof(type_info)); + + type_info.class_size = class_size; + type_info.class_init = class_init; + type_info.instance_size = instance_size; + type_info.instance_init = instance_init; + + return g_type_register_static(parent_type, type_name, &type_info, flags); +} +#define llg_intern_static_string(S) (S) +#define g_intern_static_string(S) llg_intern_static_string(S) +#define g_type_register_static_simple(parent_type, type_name, class_size, class_init, instance_size, instance_init, flags) llg_type_register_static_simple_ONCE(parent_type, type_name, class_size, class_init, instance_size, instance_init, flags) + +G_DEFINE_TYPE(ViewerAppAPI, viewerappapi, G_TYPE_OBJECT); + +void viewerappapi_class_init(ViewerAppAPIClass *klass) +{ +} + +static bool dbus_server_init = false; + +void viewerappapi_init(ViewerAppAPI *server) +{ + // Connect to the default DBUS, register our service/API. + + if (!dbus_server_init) + { + GError *error = NULL; + + server->connection = lldbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (server->connection) + { + lldbus_g_object_type_install_info(viewerappapi_get_type(), &dbus_glib_viewerapp_object_info); + + lldbus_g_connection_register_g_object(server->connection, VIEWERAPI_PATH, G_OBJECT(server)); + + DBusGProxy *serverproxy = lldbus_g_proxy_new_for_name(server->connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + + guint request_name_ret_unused; + // akin to org_freedesktop_DBus_request_name + if (lldbus_g_proxy_call(serverproxy, "RequestName", &error, G_TYPE_STRING, VIEWERAPI_SERVICE, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &request_name_ret_unused, G_TYPE_INVALID)) + { + // total success. + dbus_server_init = true; + } + else + { + llwarns << "Unable to register service name: " << error->message << llendl; + } + + g_object_unref(serverproxy); + } + else + { + g_warning("Unable to connect to dbus: %s", error->message); + } + + if (error) + g_error_free(error); + } +} + +gboolean viewer_app_api_GoSLURL(ViewerAppAPI *obj, gchar *slurl, gboolean **success_rtn, GError **error) +{ + bool success = false; + + llinfos << "Was asked to go to slurl: " << slurl << llendl; + + const bool from_external_browser = true; + if (LLURLDispatcher::dispatch(slurl, from_external_browser)) + { + // bring window to foreground, as it has just been "launched" from a URL + // todo: hmm, how to get there from here? + //xxx->mWindow->bringToFront(); + success = true; + } + + *success_rtn = g_new (gboolean, 1); + (*success_rtn)[0] = (gboolean)success; + + return TRUE; // the invokation succeeded, even if the actual dispatch didn't. +} + +/// + +//virtual +bool LLAppViewerLinux::initSLURLHandler() +{ + if (!grab_dbus_syms(DBUSGLIB_DYLIB_DEFAULT_NAME)) + { + return false; // failed + } + + g_type_init(); + + //ViewerAppAPI *api_server = (ViewerAppAPI*) + g_object_new(viewerappapi_get_type(), NULL); + + return true; +} + +//virtual +bool LLAppViewerLinux::sendURLToOtherInstance(const std::string& url) +{ + if (!grab_dbus_syms(DBUSGLIB_DYLIB_DEFAULT_NAME)) + { + return false; // failed + } + + bool success = false; + DBusGConnection *bus; + GError *error = NULL; + + g_type_init(); + + bus = lldbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (bus) + { + gboolean rtn = FALSE; + DBusGProxy *remote_object = + lldbus_g_proxy_new_for_name(bus, VIEWERAPI_SERVICE, VIEWERAPI_PATH, VIEWERAPI_INTERFACE); + + if (lldbus_g_proxy_call(remote_object, "GoSLURL", &error, + G_TYPE_STRING, url.c_str(), G_TYPE_INVALID, + G_TYPE_BOOLEAN, &rtn, G_TYPE_INVALID)) + { + success = rtn; + } + else + { + llinfos << "Call-out to other instance failed (perhaps not running): " << error->message << llendl; + } + + g_object_unref(G_OBJECT(remote_object)); + } + else + { + llwarns << "Couldn't connect to session bus: " << error->message << llendl; + } + + if (error) + g_error_free(error); + + return success; +} + +#else // LL_DBUS_ENABLED +bool LLAppViewerLinux::initSLURLHandler() +{ + return false; // not implemented without dbus +} +bool LLAppViewerLinux::sendURLToOtherInstance(const std::string& url) +{ + return false; // not implemented without dbus +} +#endif // LL_DBUS_ENABLED + void LLAppViewerLinux::handleSyncCrashTrace() { // This backtrace writes into stack_trace.log @@ -331,57 +531,90 @@ void LLAppViewerLinux::handleSyncCrashTrace() # endif // LL_ELFBIN } -void LLAppViewerLinux::handleCrashReporting() +void LLAppViewerLinux::handleCrashReporting(bool reportFreeze) { - const S32 cb = gCrashSettings.getS32(CRASH_BEHAVIOR_SETTING); - - // Always generate the report, have the logger do the asking, and - // don't wait for the logger before exiting (-> total cleanup). - if (CRASH_BEHAVIOR_NEVER_SEND != cb) - { - // launch the actual crash logger - const char* ask_dialog = "-dialog"; - if (CRASH_BEHAVIOR_ASK != cb) - ask_dialog = ""; // omit '-dialog' option - std::string cmd =gDirUtilp->getAppRODataDir(); - cmd += gDirUtilp->getDirDelimiter(); - cmd += "linux-crash-logger.bin"; - const char * cmdargv[] = - {cmd.c_str(), - ask_dialog, - "-user", - (char*)LLViewerLogin::getInstance()->getGridLabel().c_str(), - "-name", - LLAppViewer::instance()->getSecondLifeTitle().c_str(), + std::string cmd =gDirUtilp->getAppRODataDir(); + cmd += gDirUtilp->getDirDelimiter(); +#if LL_LINUX + cmd += "linux-crash-logger.bin"; +#else // LL_SOLARIS + cmd += "bin/solaris-crash-logger"; +#endif // LL_LINUX + + if(reportFreeze) + { + char* const cmdargv[] = + {(char*)cmd.c_str(), + (char*)"-previous", NULL}; - fflush(NULL); + + fflush(NULL); // flush all buffers before the child inherits them pid_t pid = fork(); if (pid == 0) { // child - execv(cmd.c_str(), (char* const*) cmdargv); /* Flawfinder: ignore */ + execv(cmd.c_str(), cmdargv); /* Flawfinder: Ignore */ llwarns << "execv failure when trying to start " << cmd << llendl; _exit(1); // avoid atexit() - } - else - { + } else { if (pid > 0) { - // DO NOT wait for child proc to die; we want - // the logger to outlive us while we quit to - // free up the screen/keyboard/etc. - ////int childExitStatus; - ////waitpid(pid, &childExitStatus, 0); + // wait for child proc to die + int childExitStatus; + waitpid(pid, &childExitStatus, 0); + } else { + llwarns << "fork failure." << llendl; + } + } + } + else + { + const S32 cb = gCrashSettings.getS32(CRASH_BEHAVIOR_SETTING); + + // Always generate the report, have the logger do the asking, and + // don't wait for the logger before exiting (-> total cleanup). + if (CRASH_BEHAVIOR_NEVER_SEND != cb) + { + // launch the actual crash logger + const char* ask_dialog = "-dialog"; + if (CRASH_BEHAVIOR_ASK != cb) + ask_dialog = ""; // omit '-dialog' option + const char * cmdargv[] = + {cmd.c_str(), + ask_dialog, + "-user", + (char*)LLViewerLogin::getInstance()->getGridLabel().c_str(), + "-name", + LLAppViewer::instance()->getSecondLifeTitle().c_str(), + NULL}; + fflush(NULL); + pid_t pid = fork(); + if (pid == 0) + { // child + execv(cmd.c_str(), (char* const*) cmdargv); /* Flawfinder: ignore */ + llwarns << "execv failure when trying to start " << cmd << llendl; + _exit(1); // avoid atexit() } else { - llwarns << "fork failure." << llendl; + if (pid > 0) + { + // DO NOT wait for child proc to die; we want + // the logger to outlive us while we quit to + // free up the screen/keyboard/etc. + ////int childExitStatus; + ////waitpid(pid, &childExitStatus, 0); + } + else + { + llwarns << "fork failure." << llendl; + } } } + // Sometimes signals don't seem to quit the viewer. Also, we may + // have been called explicitly instead of from a signal handler. + // Make sure we exit so as to not totally confuse the user. + _exit(1); // avoid atexit(), else we may re-crash in dtors. } - // Sometimes signals don't seem to quit the viewer. Also, we may - // have been called explicitly instead of from a signal handler. - // Make sure we exit so as to not totally confuse the user. - _exit(1); // avoid atexit(), else we may re-crash in dtors. } bool LLAppViewerLinux::beingDebugged() -- cgit v1.1 From a87e38229921b48c32187c672a942516722f1b52 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sun, 11 Jan 2009 16:10:39 -0600 Subject: Second Life viewer sources 1.22.5-RC --- linden/indra/newview/llappviewerlinux.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'linden/indra/newview/llappviewerlinux.cpp') diff --git a/linden/indra/newview/llappviewerlinux.cpp b/linden/indra/newview/llappviewerlinux.cpp index 643013b..ad90b82 100644 --- a/linden/indra/newview/llappviewerlinux.cpp +++ b/linden/indra/newview/llappviewerlinux.cpp @@ -4,7 +4,7 @@ * * $LicenseInfo:firstyear=2007&license=viewergpl$ * - * Copyright (c) 2007-2008, Linden Research, Inc. + * Copyright (c) 2007-2009, Linden Research, Inc. * * Second Life Viewer Source Code * The source code in this file ("Source Code") is provided by Linden Lab -- cgit v1.1