Skip to content

Commit

Permalink
O_CLOEXEC
Browse files Browse the repository at this point in the history
  • Loading branch information
rootTHC committed Oct 18, 2024
1 parent fd7752b commit 95e463d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/gs-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ typedef struct cap_rights cap_rights_t;

#define XFREE(ptr) do{if(ptr) free(ptr); ptr = NULL;}while(0)

//#define xfprintf(fpp, a...) do {if ((fpp != NULL) && (*fpp != NULL)) { fprintf(*fpp, a); fflush(*fpp); } } while (0)
#define xfprintf(fp, a...) do {if (fp != NULL) { fprintf(fp, a); fflush(fp); } } while (0)

#ifdef DEBUG
Expand Down
2 changes: 1 addition & 1 deletion lib/gsocket-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ GS_library_init(FILE *err_fp, FILE *dout_fp, gs_cb_log_t func_log)
int
GS_CTX_init(GS_CTX *ctx, fd_set *rfd, fd_set *wfd, fd_set *r, fd_set *w, struct timeval *tv_now)
{
GS_library_init(stderr, stderr, NULL);
GS_library_init(NULL, NULL, NULL);

memset(ctx, 0, sizeof *ctx);

Expand Down
1 change: 0 additions & 1 deletion tools/4_gs-netcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ cbe_peer_timeout(void *ptr)
// checks. Server's ping are not answered by client (which is ok)
if (p->gs->ts_net_io + GS_SEC_TO_USEC(gopt.app_keepalive_sec) < GS_TV_TO_USEC(&gopt.tv_now))
{
// DEBUGF_Y("STOP HERE: why do we not see stat4e? n_sox=%d\n", p->gs->net.n_sox);
DEBUGF_M("[%d] Sending APP PING (fd=%d)\n", p->id, p->gs->fd);
cmd_ping(p);
}
Expand Down
5 changes: 3 additions & 2 deletions tools/gsnc-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,11 @@ SWD_reexec(void) {
}

// Close ALL fds:
for (int i = 0; i < MIN(getdtablesize(), FD_SETSIZE); i++)
close(i);
gopt.err_fp = NULL;
gopt.log_fp = NULL;
int max = MIN(getdtablesize(), FD_SETSIZE);
for (int i = 0; i < max; i++)
close(i);

if (gopt.prg_exename) {
execv(gopt.prg_exename, swd.argv);
Expand Down
6 changes: 5 additions & 1 deletion tools/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,9 @@ open_logfile(const char *fn) {
gopt.log_fp = fopen(fn, "a");
if (gopt.log_fp == NULL)
ERREXIT("fopen(%s): %s\n", fn, strerror(errno));

int fd = fileno(gopt.log_fp);
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
gopt.err_fp = gopt.log_fp;
}

Expand Down Expand Up @@ -1293,7 +1296,8 @@ setup_cmd_child(int except_fd)
{
/* Close all (but 1 end of socketpair) fd's */
int i;
for (i = 3; i < MIN(getdtablesize(), FD_SETSIZE); i++)
int max = MIN(getdtablesize(), FD_SETSIZE);
for (i = 3; i < max; i++)
{
if (i == except_fd)
continue;
Expand Down

0 comments on commit 95e463d

Please sign in to comment.