Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Boehm-Demers-Weiser Garbage Collector. #647

Merged
merged 5 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN dpkg --add-architecture ${TARGETARCH:-arm64} && apt update \
valgrind \
build-essential \
libedit-dev \
libgc-dev \
libicu-dev \
libkrb5-dev \
liblz4-dev \
Expand Down Expand Up @@ -63,11 +64,12 @@ LABEL org.opencontainers.image.source https://github.com/dimitri/pgcopydb
RUN dpkg --add-architecture ${TARGETARCH:-arm64} && apt update \
&& apt install -qqy --no-install-suggests --no-install-recommends \
sudo \
passwd \
passwd \
ca-certificates \
libgc1 \
dimitri marked this conversation as resolved.
Show resolved Hide resolved
libpq5 \
libsqlite3-0 \
lsof \
libsqlite3-0 \
lsof \
tmux \
watch \
psmisc \
Expand Down
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Uploaders:
Build-Depends:
debhelper-compat (= 13),
libedit-dev,
libgc-dev,
libkrb5-dev,
liblz4-dev,
libncurses-dev,
Expand Down
65 changes: 36 additions & 29 deletions src/bin/lib/subcommands.c/runprogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#include "pqexpbuffer.h"

/*
* Now setup internal constants
*/
#define BUFSIZE 1024
#define ARGS_INCREMENT 12

Expand Down Expand Up @@ -51,7 +54,7 @@ typedef struct
char *stdErr;
} Program;

Program run_program(const char *program, ...);
Program *run_program(const char *program, ...);
void initialize_program(Program *prog, char **args, bool setsid);
void execute_subprogram(Program *prog);
void execute_program(Program *prog);
Expand All @@ -77,51 +80,55 @@ static void waitprogram(Program *prog, pid_t childPid);
* the run and then return a Program struct instance with the result of running
* the program.
*/
Program
Program *
dimitri marked this conversation as resolved.
Show resolved Hide resolved
run_program(const char *program, ...)
{
int nb_args = 0;
va_list args;
const char *param;
Program prog = { 0 };

prog.program = strdup(program);
prog.returnCode = -1;
prog.error = 0;
prog.setsid = false;
prog.capture = true;
prog.tty = false;
prog.processBuffer = NULL;
prog.stdOutFd = -1;
prog.stdErrFd = -1;
prog.stdOut = NULL;
prog.stdErr = NULL;

prog.args = (char **) malloc(ARGS_INCREMENT * sizeof(char *));
prog.args[nb_args++] = prog.program;
Program *prog = (Program *) malloc(sizeof(Program));

if (prog == NULL)
{
return NULL;
dimitri marked this conversation as resolved.
Show resolved Hide resolved
}

prog->program = strdup(program);
prog->returnCode = -1;
prog->error = 0;
prog->setsid = false;
prog->capture = true;
prog->tty = false;
prog->processBuffer = NULL;
prog->stdOutFd = -1;
prog->stdErrFd = -1;
prog->stdOut = NULL;
prog->stdErr = NULL;

prog->args = (char **) malloc(ARGS_INCREMENT * sizeof(char *));
prog->args[nb_args++] = prog->program;

va_start(args, program);
while ((param = va_arg(args, const char *)) != NULL)
{
if (nb_args % ARGS_INCREMENT == 0)
{
char **newargs = (char **) malloc((ARGS_INCREMENT *
(nb_args / ARGS_INCREMENT + 1)) *
sizeof(char *));
for (int i = 0; i < nb_args; i++)
int newcount = (ARGS_INCREMENT * (nb_args / ARGS_INCREMENT + 1));
size_t newsize = newcount * sizeof(char *);

prog->args = (char **) realloc(prog->args, newsize);

if (prog->args == NULL)
{
newargs[i] = prog.args[i];
return NULL;
}
free(prog.args);

prog.args = newargs;
}
prog.args[nb_args++] = strdup(param);
prog->args[nb_args++] = strdup(param);
}
va_end(args);
prog.args[nb_args] = NULL;
prog->args[nb_args] = NULL;

execute_subprogram(&prog);
execute_subprogram(prog);

return prog;
}
Expand Down
1 change: 1 addition & 0 deletions src/bin/pgcopydb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ LIBS += $(shell $(PG_CONFIG) --libs)
LIBS += -lpq
LIBS += -lncurses
LIBS += -lsqlite3
LIBS += -lgc

all: $(PGCOPYDB) ;

Expand Down
Loading
Loading