+#ifdef FREMANTLE
+ /* Put together the path to the MicroB browserd lockfile */
+ if (!(homedir = getenv("HOME")))
+ homedir = DEFAULT_HOMEDIR;
+ len = strlen(homedir) + strlen(MICROB_PROFILE_DIR) + 1;
+ if (!(microb_profile_dir = calloc(len, sizeof(char)))) {
+ printf("calloc() failed\n");
+ exit(1);
+ }
+ snprintf(microb_profile_dir, len, "%s%s",
+ homedir, MICROB_PROFILE_DIR);
+ len = strlen(homedir) + strlen(MICROB_PROFILE_DIR) +
+ strlen("/") + strlen(MICROB_LOCKFILE) + 1;
+ if (!(microb_lockfile = calloc(len, sizeof(char)))) {
+ printf("calloc() failed\n");
+ exit(1);
+ }
+ snprintf(microb_lockfile, len, "%s%s/%s",
+ homedir, MICROB_PROFILE_DIR, MICROB_LOCKFILE);
+
+ /* Watch for the creation of a MicroB browserd lockfile
+ NB: The watch has to be set up here, before the browser
+ is launched, to make sure there's no race between browserd
+ starting and us creating the watch */
+ if ((fd = inotify_init()) == -1) {
+ perror("inotify_init");
+ exit(1);
+ }
+ if ((inot_wd = inotify_add_watch(fd, microb_profile_dir,
+ IN_CREATE)) == -1) {
+ perror("inotify_add_watch");
+ exit(1);
+ }
+ free(microb_profile_dir);
+
+ /* Set up the D-Bus eavesdropping we'll use to watch for MicroB
+ acquiring the com.nokia.osso_browser D-Bus name. Again, this needs
+ to happen before the browser is launched, so that there's no race
+ between establishing the watch and browser startup.
+
+ Ideas for how to do this monitoring derived from the dbus-monitor
+ code (tools/dbus-monitor.c in the D-Bus codebase). */
+ dbus_error_init(&dbus_error);
+
+ raw_connection = dbus_bus_get_private(DBUS_BUS_SESSION, &dbus_error);
+ if (!raw_connection) {
+ fprintf(stderr,
+ "Failed to open connection to session bus: %s\n",
+ dbus_error.message);
+ dbus_error_free(&dbus_error);
+ exit(1);
+ }
+
+ dbus_bus_add_match(raw_connection,
+ "type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='com.nokia.osso_browser'",
+ &dbus_error);
+ if (dbus_error_is_set(&dbus_error)) {
+ fprintf(stderr,
+ "Failed to set up watch for browser UI start: %s\n",
+ dbus_error.message);
+ dbus_error_free(&dbus_error);
+ exit(1);
+ }
+ filter_func = check_microb_started;
+ if (!dbus_connection_add_filter(raw_connection,
+ filter_func, NULL, NULL)) {
+ fprintf(stderr, "Failed to set up watch filter!\n");
+ exit(1);
+ }
+