summaryrefslogtreecommitdiff
path: root/pkg/launcher
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2018-02-14 02:38:47 +0100
committerKali Kaneko <kali@leap.se>2018-02-15 16:36:58 +0100
commit5abd127f3780ca2078962ace489bd4c32b5d545d (patch)
tree4e3f81c695fe848906c89b4fd34c20a4e9c39e02 /pkg/launcher
parent76878da40906af750aed62d63bd1e928bfa45163 (diff)
[pkg] packaging fixes for anonvpn bundle
Diffstat (limited to 'pkg/launcher')
-rw-r--r--pkg/launcher/Makefile2
-rw-r--r--pkg/launcher/bitmask-launcher.c33
2 files changed, 30 insertions, 5 deletions
diff --git a/pkg/launcher/Makefile b/pkg/launcher/Makefile
index 8dd1013d..8948e6b4 100644
--- a/pkg/launcher/Makefile
+++ b/pkg/launcher/Makefile
@@ -1,5 +1,5 @@
CC = gcc
-CFLAGS = -g -Wall
+CFLAGS = -g -Wall -fPIE
STRIP = strip
default: bitmask
diff --git a/pkg/launcher/bitmask-launcher.c b/pkg/launcher/bitmask-launcher.c
index cf5c2a18..b9bda1c2 100644
--- a/pkg/launcher/bitmask-launcher.c
+++ b/pkg/launcher/bitmask-launcher.c
@@ -4,20 +4,45 @@
* part of the bitmask bundle.
* execute main entrypoint in a child folder inside the bundle.
*
- * (c) LEAP Encryption Access Project, 2016.
+ * (c) LEAP Encryption Access Project, 2016-2018.
* License: GPL.
*
*/
#include <unistd.h>
#include <stdlib.h>
+#include <libgen.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
-char* const bitmask_path = "lib";
-char* const entrypoint = "bitmask";
+#define MAXBUFFSIZE 1024
+
+char* const lib = "/lib";
+char* const entrypoint = "app";
+char* const linkname = "/proc/self/exe";
int main(int argc, char *argv[])
{
+ char buf[MAXBUFFSIZE];
+ char pth[MAXBUFFSIZE];
+ char *dirc, *dname;
+ const size_t bufsize = MAXBUFFSIZE + 1;
+
argv[0] = entrypoint;
- chdir(bitmask_path);
+ buf[0] = 0;
+ pth[0] = 0;
+
+ readlink(linkname, buf, bufsize - 1);
+
+ dirc = strdup(buf);
+ dname = dirname(dirc);
+ strncat(pth, dname, strlen(dname));
+ strncat(pth, lib, strlen(lib));
+
+ if (chdir(pth) < 0)
+ {
+ fprintf(stderr, "error: %s\n", strerror(errno));
+ }
execv(entrypoint, argv);
}