Skip to content

Commit

Permalink
reproc: Stop using PATH_MAX
Browse files Browse the repository at this point in the history
PATH_MAX isn't always defined where it should be (see #75). Since
in the only scenario where we use it we just need some fixed size
to increment the buffer size with, let's just define our own constant
and remove the usage of PATH_MAX altogether.
  • Loading branch information
DaanDeMeyer committed Feb 14, 2022
1 parent 0adc53c commit 3eabeb3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions reproc/src/process.posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "pipe.h"
#include "strv.h"

#define CWD_BUF_SIZE_INCREMENT 4096

const pid_t PROCESS_INVALID = -1;

static int signal_mask(int how, const sigset_t *newmask, sigset_t *oldmask)
Expand Down Expand Up @@ -51,7 +53,7 @@ static char *path_prepend_cwd(const char *path)
ASSERT(path);

size_t path_size = strlen(path);
size_t cwd_size = PATH_MAX;
size_t cwd_size = CWD_BUF_SIZE_INCREMENT;

// We always allocate sufficient space for `path` but do not include this
// space in `cwd_size` so we can be sure that when `getcwd` succeeds there is
Expand All @@ -70,7 +72,7 @@ static char *path_prepend_cwd(const char *path)
return NULL;
}

cwd_size += PATH_MAX;
cwd_size += CWD_BUF_SIZE_INCREMENT;

char *result = realloc(cwd, cwd_size + path_size + 1);
if (result == NULL) {
Expand Down

0 comments on commit 3eabeb3

Please sign in to comment.