Skip to content

Commit

Permalink
Pid read buffer size is defined using define rather than const
Browse files Browse the repository at this point in the history
  • Loading branch information
skosachiov authored and radosroka committed Nov 18, 2024
1 parent 6d787ad commit b8644cd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/library/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "process.h"
#include "file.h"

#define BUF_SIZE 8192 // Buffer for reading pid status, mainly for group list

#define BUFSZ 12 // Largest unsigned int is 10 characters long
/*
* This is an optimized integer to string conversion. It only
Expand Down Expand Up @@ -339,8 +341,7 @@ uid_t get_program_uid_from_pid(pid_t pid)

attr_sets_entry_t *get_gid_set_from_pid(pid_t pid)
{
const int buf_size = 8192;
char buf[buf_size];
char buf[BUF_SIZE];
int gid = -1;
FILE *f;
attr_sets_entry_t *set = init_standalone_set(INT);
Expand All @@ -350,7 +351,7 @@ attr_sets_entry_t *get_gid_set_from_pid(pid_t pid)
f = fopen(path, "rt");
if (f) {
__fsetlocking(f, FSETLOCKING_BYCALLER);
while (fgets(buf, buf_size, f)) {
while (fgets(buf, BUF_SIZE, f)) {
if (memcmp(buf, "Gid:", 4) == 0) {
sscanf(buf, "Gid: %d ", &gid);
append_int_attr_set(set, gid);
Expand All @@ -360,7 +361,7 @@ attr_sets_entry_t *get_gid_set_from_pid(pid_t pid)

char *data;
int offset;
while (fgets(buf, buf_size, f)) {
while (fgets(buf, BUF_SIZE, f)) {
if (memcmp(buf, "Groups:", 7) == 0) {
data = buf + 7;
while (sscanf(data," %d%n", &gid,
Expand Down

0 comments on commit b8644cd

Please sign in to comment.