+ /* 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);
+