X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=blobdiff_plain;f=launcher.c;h=02bc3eb4b549867f90d168f86bcd9aec160b6fb6;hp=f229469740bf506fd8ae1e046a3a8ad7da8f0dcd;hb=5b7e4808269f8247a7d147b387007e5d15e0d7c8;hpb=6b78dde6c6a57b7bcf5fe2cbfab467e24d8174bf diff --git a/launcher.c b/launcher.c index f229469..02bc3eb 100644 --- a/launcher.c +++ b/launcher.c @@ -1,7 +1,7 @@ /* * launcher.c -- functions for launching web browsers for browser-switchboard * - * Copyright (C) 2009 Steven Luo + * Copyright (C) 2009-2010 Steven Luo * Derived from a Python implementation by Jason Simpson and Steven Luo * * This program is free software; you can redistribute it and/or @@ -26,14 +26,12 @@ #include #include #include +#include +#include #include #ifdef FREMANTLE -#include -#include #include -#include -#include #endif #include "browser-switchboard.h" @@ -107,6 +105,20 @@ static DBusHandlerResult check_microb_finished(DBusConnection *connection, } #endif +/* Close stdin/stdout/stderr and replace with /dev/null */ +static int close_stdio(void) { + int fd; + + if ((fd = open("/dev/null", O_RDWR)) == -1) + return -1; + + if (dup2(fd, 0) == -1 || dup2(fd, 1) == -1 || dup2(fd, 2) == -1) + return -1; + + close(fd); + return 0; +} + static void launch_tear(struct swb_context *ctx, char *uri) { int status; static DBusGProxy *tear_proxy = NULL; @@ -126,12 +138,23 @@ static void launch_tear(struct swb_context *ctx, char *uri) { around by just invoking Tear with exec() if it's not running. */ status = system("pidof tear > /dev/null"); if (WIFEXITED(status) && !WEXITSTATUS(status)) { - if (!tear_proxy) - tear_proxy = dbus_g_proxy_new_for_name(ctx->session_bus, - "com.nokia.tear", "/com/nokia/tear", - "com.nokia.Tear"); - dbus_g_proxy_call(tear_proxy, "OpenAddress", &error, - G_TYPE_STRING, uri, G_TYPE_INVALID); + if (!tear_proxy) { + if (!(tear_proxy = dbus_g_proxy_new_for_name( + ctx->session_bus, + "com.nokia.tear", + "/com/nokia/tear", + "com.nokia.Tear"))) { + printf("Failed to create proxy for com.nokia.Tear D-Bus interface\n"); + exit(1); + } + } + + if (!dbus_g_proxy_call(tear_proxy, "OpenAddress", &error, + G_TYPE_STRING, uri, G_TYPE_INVALID, + G_TYPE_INVALID)) { + printf("Opening window failed: %s\n", error->message); + exit(1); + } if (!ctx->continuous_mode) exit(0); } else { @@ -143,6 +166,7 @@ static void launch_tear(struct swb_context *ctx, char *uri) { } /* Child process */ setsid(); + close_stdio(); } execl("/usr/bin/tear", "/usr/bin/tear", uri, (char *)NULL); } @@ -166,13 +190,13 @@ void launch_microb(struct swb_context *ctx, char *uri) { printf("launch_microb with uri '%s'\n", uri); /* Launch browserd if it's not running */ - status = system("pidof /usr/sbin/browserd > /dev/null"); + status = system("pidof browserd > /dev/null"); if (WIFEXITED(status) && WEXITSTATUS(status)) { kill_browserd = 1; #ifdef FREMANTLE - system("/usr/sbin/browserd -d -b"); + system("/usr/sbin/browserd -d -b > /dev/null 2>&1"); #else - system("/usr/sbin/browserd -d"); + system("/usr/sbin/browserd -d > /dev/null 2>&1"); #endif } @@ -362,6 +386,8 @@ void launch_microb(struct swb_context *ctx, char *uri) { g_object_unref(g_proxy); } else { /* Child process */ + close_stdio(); + /* exec maemo-invoker directly instead of relying on the /usr/bin/browser symlink, since /usr/bin/browser may have been replaced with a shell script calling us via D-Bus */ @@ -376,6 +402,8 @@ void launch_microb(struct swb_context *ctx, char *uri) { waitpid(pid, &status, 0); } else { /* Child process */ + close_stdio(); + /* exec maemo-invoker directly instead of relying on the /usr/bin/browser symlink, since /usr/bin/browser may have been replaced with a shell script calling us via D-Bus */ @@ -391,7 +419,7 @@ void launch_microb(struct swb_context *ctx, char *uri) { /* Kill off browserd if we started it */ if (kill_browserd) - system("kill `pidof /usr/sbin/browserd`"); + system("kill `pidof browserd`"); if (!ctx || !ctx->continuous_mode) exit(0); @@ -471,6 +499,7 @@ static void launch_other_browser(struct swb_context *ctx, char *uri) { } /* Child process */ setsid(); + close_stdio(); } execl("/bin/sh", "/bin/sh", "-c", command, (char *)NULL); }