Skip to content

Commit

Permalink
refactor: deduplicate definition of RUN_FIREJAIL_NAME_DIR
Browse files Browse the repository at this point in the history
Reuse the definition from src/include/rundefs.h.

Related commits:

* 07c05e8 ("moved sandbox name to /run/firejail/name/<PID>",
  2016-02-19)
* 57ffc35 ("added sandbox name support in firemon", 2018-03-21)
  • Loading branch information
kmk3 committed Jan 12, 2025
1 parent 187488a commit 4a31419
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/include/rundefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define RUN_FIREJAIL_DIR RUN_FIREJAIL_BASEDIR "/firejail"
#define RUN_FIREJAIL_SANDBOX_DIR RUN_FIREJAIL_DIR "/sandbox"
#define RUN_FIREJAIL_APPIMAGE_DIR RUN_FIREJAIL_DIR "/appimage"
#define RUN_FIREJAIL_NAME_DIR RUN_FIREJAIL_DIR "/name" // also used in src/lib/pid.c - todo: move it in a common place
#define RUN_FIREJAIL_NAME_DIR RUN_FIREJAIL_DIR "/name"
#define RUN_FIREJAIL_LIB_DIR RUN_FIREJAIL_DIR "/lib"
#define RUN_FIREJAIL_X11_DIR RUN_FIREJAIL_DIR "/x11"
#define RUN_FIREJAIL_NETWORK_DIR RUN_FIREJAIL_DIR "/network"
Expand Down
6 changes: 3 additions & 3 deletions src/lib/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <limits.h>
#include <sched.h>
#include "../include/common.h"
#include "../include/rundefs.h"

#include <fcntl.h>
#ifndef O_PATH
Expand Down Expand Up @@ -155,10 +156,9 @@ int name2pid(const char *name, pid_t *pid) {
free(comm);
}

// look for the sandbox name in /run/firejail/name/<PID>
// todo: use RUN_FIREJAIL_NAME_DIR define from src/firejail/firejail.h
// look for the sandbox name
char *fname;
if (asprintf(&fname, "/run/firejail/name/%d", newpid) == -1)
if (asprintf(&fname, "%s/%d", RUN_FIREJAIL_NAME_DIR, newpid) == -1)
errExit("asprintf");
FILE *fp = fopen(fname, "r");
if (fp) {
Expand Down
5 changes: 1 addition & 4 deletions src/lib/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "../include/common.h"
#include "../include/pid.h"
#include "../include/rundefs.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -173,10 +174,6 @@ uid_t pid_get_uid(pid_t pid) {
return rv;
}

// todo: RUN_FIREJAIL_NAME_DIR is borrowed from src/firejail/firejail.h
// move it in a common place
#define RUN_FIREJAIL_NAME_DIR "/run/firejail/name"

static void print_elem(unsigned index, int nowrap) {
// get terminal size
struct winsize sz;
Expand Down

0 comments on commit 4a31419

Please sign in to comment.