Skip to content
Open
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
4 changes: 4 additions & 0 deletions atch.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <pty.h>
#endif

#ifdef HAVE_UTIL_H
#include <util.h>
#endif

#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
#endif
Expand Down
4 changes: 4 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#define HAVE_LIBUTIL 1
#ifdef __APPLE__
#define HAVE_UTIL_H 1
#else
#define HAVE_PTY_H 1
#endif

#define HAVE_SYS_IOCTL_H 1
#define HAVE_SYS_RESOURCE_H 1
Expand Down
9 changes: 8 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ CFLAGS = -g -O2 -W -Wall -I. -DPACKAGE_VERSION=\"$(VERSION)\"
LDFLAGS =
LIBS = -lutil

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
STATIC_FLAG =
else
STATIC_FLAG = -static
endif

OBJ = attach.o master.o atch.o
SRC = attach.c master.c atch.c

Expand All @@ -14,7 +21,7 @@ archs = amd64 arm64
arch ?= $(shell arch)

atch: $(OBJ)
$(CC) -o $(BUILDDIR)/$@ -static $(LDFLAGS) $(OBJ) $(LIBS)
$(CC) -o $(BUILDDIR)/$@ $(STATIC_FLAG) $(LDFLAGS) $(OBJ) $(LIBS)

atch.1.md: README.md scripts/readme2man.sh
bash scripts/readme2man.sh $< > $@
Expand Down
12 changes: 5 additions & 7 deletions master.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,18 +853,16 @@ forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp)
if (pid < 0)
return -1;
else if (pid == 0) {
char *buf;
int fd;

setsid();
#ifdef TIOCSCTTY
buf = NULL;
if (ioctl(slave, TIOCSCTTY, NULL) < 0)
_exit(1);
#else
buf = ptsname(master);
fd = open(buf, O_RDWR);
close(fd);
{
char *buf = ptsname(master);
int fd = open(buf, O_RDWR);
close(fd);
}
#endif
dup2(slave, 0);
dup2(slave, 1);
Expand Down