diff --git a/atch.h b/atch.h index d1a299a..fa25454 100644 --- a/atch.h +++ b/atch.h @@ -28,6 +28,10 @@ #include #endif +#ifdef HAVE_UTIL_H +#include +#endif + #ifdef HAVE_LIBUTIL_H #include #endif diff --git a/config.h b/config.h index 4462716..398c905 100644 --- a/config.h +++ b/config.h @@ -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 diff --git a/makefile b/makefile index 949074c..eb43a61 100644 --- a/makefile +++ b/makefile @@ -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 @@ -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 $< > $@ diff --git a/master.c b/master.c index 05d3a04..16f29e3 100644 --- a/master.c +++ b/master.c @@ -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);