From 48f31d2b71c30e580523e3a4848098464cbe2203 Mon Sep 17 00:00:00 2001 From: Donaldo Date: Tue, 10 Mar 2026 13:44:52 +0100 Subject: [PATCH 1/2] fix(macos): add build support for macOS (util.h + no -static) - config.h: use HAVE_UTIL_H on __APPLE__ instead of HAVE_PTY_H ( does not exist on macOS, provides openpty/forkpty) - atch.h: add #ifdef HAVE_UTIL_H guard to include - makefile: STATIC_FLAG is empty on Darwin, -static on Linux (Apple toolchain does not support fully static binaries) Fixes: https://github.com/mobydeck/atch/issues/ --- atch.h | 4 ++++ config.h | 4 ++++ makefile | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) 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 $< > $@ From e0fe425fff7fa57f4498389433e0a63906b00e33 Mon Sep 17 00:00:00 2001 From: Donaldo Date: Tue, 10 Mar 2026 13:56:33 +0100 Subject: [PATCH 2/2] fix(master): scope buf and fd variables to non-TIOCSCTTY branch Variables were declared at block scope but only used in the #else branch, causing -Wunused-variable and -Wunused-but-set-variable warnings on platforms where TIOCSCTTY is defined (e.g. macOS). Move declarations into the #else block where they are actually used. Co-Authored-By: Claude Sonnet 4.6 --- master.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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);