From 30e754610f1acfcba1644520a8070f87c3decede Mon Sep 17 00:00:00 2001 From: netblue30 Date: Fri, 10 Dec 2021 09:29:47 -0500 Subject: profstats fix (#4733) --- src/profstats/Makefile.in | 2 +- src/profstats/main.c | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src/profstats') diff --git a/src/profstats/Makefile.in b/src/profstats/Makefile.in index e025f5939..fa1b4f200 100644 --- a/src/profstats/Makefile.in +++ b/src/profstats/Makefile.in @@ -3,7 +3,7 @@ all: profstats include ../common.mk -%.o : %.c $(H_FILE_LIST) +%.o : %.c $(H_FILE_LIST) ../include/common.h $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(INCLUDE) -c $< -o $@ profstats: $(OBJS) diff --git a/src/profstats/main.c b/src/profstats/main.c index a472ce259..bc5047bfe 100644 --- a/src/profstats/main.c +++ b/src/profstats/main.c @@ -17,10 +17,8 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include -#include -#include + +#include "../include/common.h" #define MAXBUF 2048 // stats @@ -99,8 +97,9 @@ static void usage(void) { printf("\n"); } -void process_file(const char *fname) { +static void process_file(char *fname) { assert(fname); + char *tmpfname = NULL; if (arg_debug) printf("processing #%s#\n", fname); @@ -109,9 +108,19 @@ void process_file(const char *fname) { FILE *fp = fopen(fname, "r"); if (!fp) { - fprintf(stderr, "Warning: cannot open %s, while processing %s\n", fname, profile); - level--; - return; + // the file was not found in the current directory + // look for it in /etc/firejail directory + if (asprintf(&tmpfname, "%s/%s", SYSCONFDIR, fname) == -1) + errExit("asprintf"); + + fp = fopen(tmpfname, "r"); + if (!fp) { + fprintf(stderr, "Warning: cannot open %s or %s, while processing %s\n", fname, tmpfname, profile); + free(tmpfname); + level--; + return; + } + fname = tmpfname; } int have_include_local = 0; @@ -204,6 +213,8 @@ void process_file(const char *fname) { if (!have_include_local) printf("No include .local found in %s\n", fname); level--; + if (tmpfname) + free(tmpfname); } int main(int argc, char **argv) { -- cgit v1.2.3-54-g00ecf