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 27, 2024
1 parent 32be264 commit 4dec588
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 20 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
40 changes: 40 additions & 0 deletions 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 @@ -57,6 +61,7 @@ timestamp_now(char *s, size_t sz)
strftime(s, sz, "%FT%TZ", gmtime(&now));
}

#ifdef BUILDING_ON_LINUX
static char *
get_cmdline(pid_t pid)
{
Expand Down Expand Up @@ -129,6 +134,41 @@ get_cmdline(pid_t pid)

return ret;
}
#else
static char *
get_cmdline(pid_t pid)
{
int mib[4];
size_t len;
char *cmdline;

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, &len, NULL, 0) == -1) {
perror("sysctl");
exit(EXIT_FAILURE);
}

cmdline = malloc(len);
if (cmdline == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}

// Now, get the actual command line
if (sysctl(mib, 4, cmdline, &len, NULL, 0) == -1) {
perror("sysctl");
exit(EXIT_FAILURE);
}

printf("Command line for PID %d: %s\n", pid, cmdline);
return cmdline;
}
#endif

void
record_process_start(pid_t pid, char *poutname)
Expand Down
Loading

0 comments on commit 4dec588

Please sign in to comment.