Skip to content

Commit

Permalink
build option: add appimage support
Browse files Browse the repository at this point in the history
  • Loading branch information
smitsohu committed Jan 24, 2022
1 parent d1ac6a1 commit 3e7cb95
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/fbuilder/build_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <sys/wait.h>

#define TRACE_OUTPUT "/tmp/firejail-trace.XXXXXX"
#define STRACE_OUTPUT "/tmp/firejail-strace.XXXXXX"

void build_profile(int argc, char **argv, int index, FILE *fp) {
// next index is the application name
Expand All @@ -41,36 +40,33 @@ void build_profile(int argc, char **argv, int index, FILE *fp) {
if(asprintf(&output,"--trace=%s",trace_output) == -1)
errExit("asprintf");

char *cmdlist[] = {
BINDIR "/firejail",
"--quiet",
"--noprofile",
"--caps.drop=all",
"--seccomp",
output,
"--shell=none",
};

// calculate command length
unsigned len = (int) sizeof(cmdlist) / sizeof(char*) + argc - index + 1;
if (arg_debug)
printf("command len %d + %d + 1\n", (int) (sizeof(cmdlist) / sizeof(char*)), argc - index);
char *cmd[len];
cmd[0] = cmdlist[0]; // explicit assignment to clean scan-build error
unsigned len = 64; // plenty of space for firejail command line
len += argc - index; // program command line
len += 1; // NULL

// build command
unsigned i = 0;
for (i = 0; i < (int) sizeof(cmdlist) / sizeof(char*); i++)
cmd[i] = cmdlist[i];

int i2 = index;
for (; i < (len - 1); i++, i2++)
cmd[i] = argv[i2];
assert(i < len);
cmd[i] = NULL;
char *cmd[len];
unsigned curr_len = 0;
cmd[curr_len++] = BINDIR "/firejail";
cmd[curr_len++] = "--quiet";
cmd[curr_len++] = "--noprofile";
cmd[curr_len++] = "--caps.drop=all";
cmd[curr_len++] = "--seccomp";
cmd[curr_len++] = "--shell=none";
cmd[curr_len++] = output;
if (arg_appimage)
cmd[curr_len++] = "--appimage";

int i;
for (i = index; i < argc; i++)
cmd[curr_len++] = argv[i];

assert(curr_len < len);
cmd[curr_len] = NULL;

if (arg_debug) {
for (i = 0; i < len; i++)
for (i = 0; cmd[i]; i++)
printf("%s%s\n", (i)?"\t":"", cmd[i]);
}

Expand Down
1 change: 1 addition & 0 deletions src/fbuilder/fbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define MAX_BUF 4096
// main.c
extern int arg_debug;
extern int arg_appimage;

// build_profile.c
void build_profile(int argc, char **argv, int index, FILE *fp);
Expand Down
3 changes: 3 additions & 0 deletions src/fbuilder/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
#include "fbuilder.h"
int arg_debug = 0;
int arg_appimage = 0;

static void usage(void) {
printf("Firejail profile builder\n");
Expand Down Expand Up @@ -49,6 +50,8 @@ printf("\n");
}
else if (strcmp(argv[i], "--debug") == 0)
arg_debug = 1;
else if (strcmp(argv[i], "--appimage") == 0)
arg_appimage = 1;
else if (strcmp(argv[i], "--build") == 0)
; // do nothing, this is passed down from firejail
else if (strncmp(argv[i], "--build=", 8) == 0) {
Expand Down

0 comments on commit 3e7cb95

Please sign in to comment.