diff --git a/src/builder/b-sai.c b/src/builder/b-sai.c
index e7206c6..e0daf92 100644
--- a/src/builder/b-sai.c
+++ b/src/builder/b-sai.c
@@ -43,6 +43,7 @@
#if defined(__APPLE__)
#include <sys/stat.h> /* for mkdir() */
+#include <mach-o/dyld.h>
#endif
#if defined(WIN32)
@@ -364,8 +365,6 @@ app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
if (saib_deletion_init(argv0))
return 1;
- if (saib_deletion_init(argv0))
- return 1;
/*
@@ -488,8 +487,26 @@ saib_app_run(int argc, const char **argv)
struct stat sb;
const char *p;
+ static char execpath[PATH_MAX];
+
argv0 = argv[0];
+#if defined(__APPLE__)
+ {
+ uint32_t size = sizeof(execpath);
+ if (_NSGetExecutablePath(execpath, &size) == 0)
+ argv0 = execpath;
+ }
+#elif defined(__linux__)
+ {
+ ssize_t n = readlink("/proc/self/exe", execpath, sizeof(execpath) - 1);
+ if (n > 0) {
+ execpath[n] = '\0';
+ argv0 = execpath;
+ }
+ }
+#endif
+
if ((p = lws_cmdline_option(argc, argv, "--home")))
/*
* This is the deletion worker process being spawned, it only
diff --git a/src/server/s-power.c b/src/server/s-power.c
index a8f3e35..ef0b643 100644
--- a/src/server/s-power.c
+++ b/src/server/s-power.c
@@ -392,6 +392,7 @@ sais_power_tx(struct vhd *vhd, struct pss *pss, uint8_t *buf, size_t bl)
return 0;
}
+ *p = '\0';
n = 0;
lws_start_foreach_dll(struct lws_dll2 *, px, vhd->pending_plats.head) {
sais_plat_t *pl = lws_container_of(px, sais_plat_t, list);