Skip to content

Commit

Permalink
[WIP] backing up patches :)
Browse files Browse the repository at this point in the history
Signed-off-by: Fotios Valasiadis <[email protected]>
  • Loading branch information
fvalasiad committed Aug 28, 2024
1 parent 65d2a81 commit 174269d
Show file tree
Hide file tree
Showing 3 changed files with 325 additions and 26 deletions.
10 changes: 5 additions & 5 deletions examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ all:
examples: $(EXAMPLES)

compile_single_file: f1.c
$(EXE) -o $@.out $(CC) -c $^
$(EXE) -o $@.out $(CC) -c f1.c

compile_link_file: f1.c
$(EXE) -o $@.out $(CC) $^
$(EXE) -o $@.out $(CC) f1.c

compile_file_include: f2.c
$(EXE) -o $@.out $(CC) -c $^
$(EXE) -o $@.out $(CC) -c f2.c

compile_file_sysinclude: f3.c
$(EXE) -o $@.out $(CC) -c $^
$(EXE) -o $@.out $(CC) -c f3.c

compile_two_files: f4.c f5.c
$(EXE) -o $@.out $(CC) $^
$(EXE) -o $@.out $(CC) f4.c f5.c


clean:
Expand Down
38 changes: 37 additions & 1 deletion src/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ SPDX-License-Identifier: LGPL-2.1-or-later
#include <fcntl.h>
#include <errno.h>

#ifdef BUILDING_ON_FREEBSD
#include <sys/sysctl.h>
#endif

FILE *fout;

void
Expand Down Expand Up @@ -60,6 +64,7 @@ timestamp_now(char *s, size_t sz)
static char *
get_cmdline(pid_t pid)
{
#ifdef BUILDING_ON_LINUX
char cmd_fname[32];

sprintf(cmd_fname, "/proc/%ld/cmdline", (long) pid);
Expand All @@ -83,6 +88,35 @@ get_cmdline(pid_t pid)
return NULL;
}

#else // FreeBSD
int mib[4];
ssize_t n;
char *data;

mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_ARGS;
mib[3] = pid;

// First, get the size of the command line
if (sysctl(mib, 4, NULL, (size_t *) &n, NULL, 0) == -1) {
perror("sysctl");
exit(EXIT_FAILURE);
}

data = malloc(n);
if (data == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}

// Now, get the actual command line
if (sysctl(mib, 4, data, (size_t *) &n, NULL, 0) == -1) {
perror("sysctl");
exit(EXIT_FAILURE);
}
#endif

ssize_t sz;
bool has_spaces;
int i;
Expand All @@ -99,7 +133,9 @@ get_cmdline(pid_t pid)
has_spaces = false;
}
}

if (sz == 0) {
return NULL;
}
char *ret = malloc(sz);

if (ret == NULL) {
Expand Down
Loading

0 comments on commit 174269d

Please sign in to comment.