X-Git-Url: http://git.maemo.org/git/?p=browser-switch;a=blobdiff_plain;f=launcher.c;h=8bffd71ebaaabe9efcf6853eb020112dad365093;hp=26676235622b6cc6fe9c7c825d6ae4f8200ec69b;hb=6f2522256b931713418b8d747612255c03481e21;hpb=d39042804d1ee8b5f57dd5c1af884ea4e208b30a diff --git a/launcher.c b/launcher.c index 2667623..8bffd71 100644 --- a/launcher.c +++ b/launcher.c @@ -26,10 +26,13 @@ #include #include #include +#include +#include #include #ifdef FREMANTLE #include +#include #endif #include "browser-switchboard.h" @@ -103,6 +106,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; @@ -139,6 +156,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); } @@ -162,13 +180,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 } @@ -279,6 +297,7 @@ void launch_microb(struct swb_context *ctx, char *uri) { exit(1); } } + g_object_unref(g_proxy); /* Workaround: the browser process we started is going to want to hang around forever, hogging the com.nokia.osso_browser @@ -342,22 +361,14 @@ void launch_microb(struct swb_context *ctx, char *uri) { dbus_connection_close(raw_connection); dbus_connection_unref(raw_connection); - /* Tell browser UI to exit nicely */ - printf("Closing MicroB\n"); - if (!dbus_g_proxy_call(g_proxy, "exit_browser", &gerror, - G_TYPE_INVALID, G_TYPE_INVALID)) { - /* We don't expect a reply; any other error indicates - a problem */ - if (gerror->domain != DBUS_GERROR || - gerror->code != DBUS_GERROR_NO_REPLY) { - printf("exit_browser failed: %s\n", - gerror->message); - exit(1); - } - } - g_object_unref(g_proxy); + /* Kill off browser UI + XXX: Hope we don't cause data loss here! */ + printf("Killing MicroB\n"); + kill(pid, SIGTERM); } 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 */ @@ -372,6 +383,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 */ @@ -387,7 +400,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); @@ -467,6 +480,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); }