#ifndef HISTOGRAM_AUTOSTART_H #define HISTOGRAM_AUTOSTART_H #ifndef BOOT_DIRECTORY #define BOOT_DIRECTORY "/var/lib/webosbrew/init.d" #endif #ifndef BOOT_SCRIPT #define BOOT_SCRIPT \ "/media/developer/apps/usr/palm/services/org.webosbrew.histogramhyperion.service/boot.sh" #endif #define BOOT_HOOK BOOT_DIRECTORY "/60-histogramhyperion" /* Exact pre-0.6.1 hook; only this known own file may be migrated. */ static const char legacy_boot_script[] = "#!/bin/sh\n# Histogram Hyperion own boot hook v1\n(\n attempt=0\n while [ -x " "/var/lib/webosbrew/init.d/60-histogramhyperion ] && [ \"$attempt\" -lt 120 ]; do\n " "result=$(timeout 12 luna-send -n 1 luna://org.webosbrew.histogramhyperion.service/start '{}' " "2>&1)\n case \"$result\" in\n *'\"running\":true'*) exit 0 ;;\n esac\n " "attempt=$((attempt + 1))\n sleep 5\n done\n echo 'Histogram Hyperion boot start " "cancelled or timed out'\n) >/var/lib/webosbrew/histogramhyperion-boot.log 2>&1 0 && access(BOOT_HOOK, X_OK) == 0; } static bool set_boot(bool enabled) { int kind = boot_hook_kind(); if (kind < 0) return false; if (!enabled) return kind == 0 || unlink(BOOT_HOOK) == 0; if (access(BOOT_SCRIPT, X_OK) != 0) return false; if (kind == 2) return true; if (mkdir(BOOT_DIRECTORY, 0755) != 0 && errno != EEXIST) return false; /* Never overwrite another process's temporary file or a foreign hook. */ if (symlink(BOOT_SCRIPT, BOOT_HOOK ".tmp") != 0) return false; bool ok = rename(BOOT_HOOK ".tmp", BOOT_HOOK) == 0; if (!ok) unlink(BOOT_HOOK ".tmp"); return ok; } #endif