#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <dbus/dbus-glib.h>
#ifdef FREMANTLE
}
#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;
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 {
}
/* Child process */
setsid();
+ close_stdio();
}
execl("/usr/bin/tear", "/usr/bin/tear", uri, (char *)NULL);
}
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 */
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 */
}
/* Child process */
setsid();
+ close_stdio();
}
execl("/bin/sh", "/bin/sh", "-c", command, (char *)NULL);
}