Skip to content

Commit

Permalink
fix(userspace/libsinsp): use comm file instead of status to get p…
Browse files Browse the repository at this point in the history
…roc comm.

Signed-off-by: Federico Di Pierro <[email protected]>

Co-authored-by: <[email protected]>
  • Loading branch information
FedeDP committed Dec 11, 2024
1 parent 230ddfb commit dac36cd
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions userspace/libscap/linux/scap_procs.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,21 +559,23 @@ static int32_t scap_proc_add_from_proc(struct scap_linux_platform* linux_platfor
//
// Gather the command name
//
snprintf(filename, sizeof(filename), "%sstatus", dir_name);
snprintf(filename, sizeof(filename), "%scomm", dir_name);

f = fopen(filename, "r");
if(f == NULL) {
return scap_errprintf(error, errno, "can't open %s", filename);
} else {
ASSERT(sizeof(line) >= SCAP_MAX_PATH_SIZE);

if(fgets(line, SCAP_MAX_PATH_SIZE, f) == NULL) {
fclose(f);
return scap_errprintf(error, errno, "can't read from %s", filename);
filesize = fread(line, 1, SCAP_MAX_ARGS_SIZE, f);
if(filesize > 0) {
// In case `comm` is greater than `SCAP_MAX_ARGS_SIZE` it could be
// truncated so we put a `/0` at the end manually.
line[filesize - 1] = 0;
snprintf(tinfo.comm, SCAP_MAX_PATH_SIZE, "%s", line);
} else {
tinfo.comm[0] = 0;
}

line[SCAP_MAX_PATH_SIZE - 1] = 0;
sscanf(line, "Name:%1024s", tinfo.comm);
fclose(f);
}

Expand Down

0 comments on commit dac36cd

Please sign in to comment.