Skip to content

Commit

Permalink
Portability improvements
Browse files Browse the repository at this point in the history
* Add or fix support for building on Solaris, illumos,
  Linux/musl, NetBSD, OpenBSD, IBM AIX, and Haiku.
* Use pkg-config when available to determine CFLAGS and
  libraries.
* Cleanup Makefile.
* Cleanup excess trailing whitespace characters.
* Indent nested preprocessor directives with GNU Cppi.
* Tested build under Oracle Solaris, OpenIndiana illumos,
  Linux/musl, Linux/glibc, IBM AIX, Haiku, FreeBSD, OpenBSD,
  NetBSD, and Apple macOS.
* Compilation tested and working with PCC, GCC, Clang, IBM XL C,
  IBM Open XL C, Oracle Studio C, NVIDIA HPC SDK C, Portland
  Group C, and DMD ImportC.

Signed-off-by: Jeffrey H. Johnson <trnsz@pobox.com>
  • Loading branch information
johnsonjh committed Aug 9, 2024
1 parent 2c1c27e commit 5fc3404
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 193 deletions.
71 changes: 71 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Makefile for the supdup server and client.

SHELL = /bin/sh
PREFIX ?= /usr/local

CC ?= cc
RM ?= rm -f

OS_NAME ?= $(shell uname 2> /dev/null)
CFLAGS += $(shell pkg-config --cflags ncurses 2> /dev/null)
NCURSES_LIBS ?= $(shell pkg-config --libs ncurses 2> /dev/null || printf '%s' "-lncurses")

# AIX (needs linking libcurses *after* libncurses)
ifeq ($(OS_NAME), AIX)
EXTRA_LDFLAGS = -lcurses
endif

# Mac OS X
ifeq ($(OS_NAME), Darwin)
LDFLAGS += -L/opt/local/lib
endif

# Solaris and illumos
ifeq ($(OS_NAME), SunOS)
CFLAGS += -I/usr/include/ncurses
EXTRA_LDFLAGS = -lnsl -lsocket
endif

# Haiku
ifeq ($(OS_NAME), Haiku)
EXTRA_LDFLAGS = -lnetwork
endif

# NetBSD
ifeq ($(OS_NAME), NetBSD)
CFLAGS += -I/usr/pkg/include -I/usr/pkg/include/ncurses
LDFLAGS += -L/usr/pkg/lib
endif

# The server (supdupd) isn't ready for prime time.
.PHONY: all
all: supdup

SUPDUP_OBJS = supdup.o charmap.o tcp.o chaos.o
supdup: $(SUPDUP_OBJS)
$(CC) $(LDFLAGS) -o $@ $(SUPDUP_OBJS) $(NCURSES_LIBS) $(EXTRA_LDFLAGS)

SUPDUPD_OBJS = supdupd.o
supdupd: $(SUPDUPD_OBJS)
$(CC) $(LDFLAGS) -o $@ $(SUPDUPD_OBJS)

.PHONY: install
install: supdup
install -m 0755 supdup $(PREFIX)/bin
test -x supdupd && install -m 0755 supdupd $(PREFIX)/bin

.PHONY: clean
clean:
$(RM) *.o
$(RM) supdup supdupd

.PHONY: distclean
distclean: clean
$(RM) *~ *.bak core *.core

# Dependencies
chaos.o: supdup.h
charmap.o: charmap.h
supdup.o: charmap.h
supdupd.o: supdup.h
tcp.o: supdup.h
36 changes: 0 additions & 36 deletions Makefile

This file was deleted.

39 changes: 20 additions & 19 deletions chaos.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@

#if USE_CHAOS_STREAM_SOCKET

#include <stdio.h>
#include <netdb.h>
#include <unistd.h>
#include <string.h>
#include <sys/un.h>
#include <sys/errno.h>
# include <stdio.h>
# include <netdb.h>
# include <unistd.h>
# include <string.h>
# include <sys/un.h>
# include <errno.h>
# include <sys/socket.h>

// Where are the chaos sockets? Cf. https://github.com/bictorv/chaosnet-bridge
#ifndef CHAOS_SOCKET_DIRECTORY
#define CHAOS_SOCKET_DIRECTORY "/tmp"
#endif
# if !defined(CHAOS_SOCKET_DIRECTORY)
# define CHAOS_SOCKET_DIRECTORY "/tmp"
# endif
// What DNS domain should be used to translate Chaos addresses to names?
#ifndef CHAOS_ADDRESS_DOMAIN
#define CHAOS_ADDRESS_DOMAIN "ch-addr.net"
#endif
# if !defined(CHAOS_ADDRESS_DOMAIN)
# define CHAOS_ADDRESS_DOMAIN "ch-addr.net"
# endif
// What DNS server should be used to fetch Chaos class data?
#ifndef CHAOS_DNS_SERVER
# if !defined(CHAOS_DNS_SERVER)
// #define CHAOS_DNS_SERVER "130.238.19.25"
#define CHAOS_DNS_SERVER "dns.chaosnet.net"
#endif
# define CHAOS_DNS_SERVER "dns.chaosnet.net"
# endif

static int
connect_to_named_socket(int socktype, char *path)
{
int sock, slen;
struct sockaddr_un server;

if ((sock = socket(AF_UNIX, socktype, 0)) < 0) {
perror("socket(AF_UNIX)");
return -1;
Expand Down Expand Up @@ -61,7 +62,7 @@ static ssize_t write_all(int fd, void *buf, size_t n)
return m;
x += m;
n -= m;
}
}
return x - (char *)buf;
}

Expand All @@ -77,12 +78,12 @@ static ssize_t read_all(int fd, void *buf, size_t n)
return m;
x += m;
n -= m;
}
}
return x - (char *)buf;
}

static int
connection(int net, const char *host, const char *contact)
connection(int net, const char *host, const char *contact)
{
char buf[1000]; /*Bill Gates says this ought to be enough.*/
char *bp, cbuf[2];
Expand Down
4 changes: 2 additions & 2 deletions charmap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef CHARMAP_H
#define CHARMAP_H
#if !defined(CHARMAP_H)
# define CHARMAP_H

typedef struct {
char *name;
Expand Down
16 changes: 8 additions & 8 deletions supdup-login.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
#include <errno.h>
#include <syslog.h>

#define SCPYN(a, b) strncpy(a, b, sizeof(a))
#define SCPYN(a, b) strncpy(a, b, sizeof(a))

#define NMAX sizeof(utmp.ut_name)

#define FALSE 0
#define TRUE -1
#define FALSE 0
#define TRUE -1

char QUOTAWARN[] = "/usr/ucb/quota"; /* warn user about quotas */
char CANTRUN[] = "login: Can't run ";
Expand Down Expand Up @@ -218,7 +218,7 @@ main(argc, argv)
namep = crypt(pp, pwd->pw_passwd);
setpriority(PRIO_PROCESS, 0, 0);
/* loseit */
#ifdef PARANOIA
#if defined(PARANOIA)
/* If not secure check that password is long enough
and don't allow no-password logins */
if (!ttysecure) {
Expand Down Expand Up @@ -638,7 +638,7 @@ getstr(buf, cnt, err)
char *speeds[] =
{ "0", "50", "75", "110", "134", "150", "200", "300",
"600", "1200", "1800", "2400", "4800", "9600", "19200", "38400" };
#define NSPEEDS (sizeof (speeds) / sizeof (speeds[0]))
#define NSPEEDS (sizeof (speeds) / sizeof (speeds[0]))

doremoteterm(term, tp)
char *term;
Expand All @@ -658,19 +658,19 @@ doremoteterm(term, tp)
tp->sg_flags = ECHO|CRMOD|ANYP|XTABS;
}

#ifdef 0
#if 0
/* Use syslog instead */
logerr(fmt, a1, a2, a3)
char *fmt, *a1, *a2, *a3;
{
#ifdef LOGERR
# if defined(LOGERR)
FILE *cons = fopen("/dev/console", "w");

if (cons != NULL) {
fprintf(cons, fmt, a1, a2, a3);
fprintf(cons, "\n\r");
fclose(cons);
}
#endif
# endif
}
#endif /* 0 */
Loading

0 comments on commit 5fc3404

Please sign in to comment.