Skip to content
Closed
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
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ jobs:
- ubuntu:jammy
- ubuntu:focal
- ubuntu:bionic
- ubuntu:xenial
cross_compile: [""]
variant: [""]
include:
- container: "ubuntu:xenial"
arch: x86-64
compiler: cc

- container: "ubuntu:xenial"
arch: x86-64
compiler: clang

# Debian 32-bit builds
- container: "debian:testing"
arch: i386
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ CFLAGS := $(CFLAGS) -Wextra -Wno-unused-parameter -Wno-unused-result -Wno-missin
# Few clang version still have warnings so fail only on GCC
GCC_CFLAGS := -Werror
GCC_CFLAGS += -Wformat-signedness -Wnull-dereference -Wduplicated-cond -Wduplicated-branches -Wvla-larger-than=1
GCC_CFLAGS += -Walloc-zero -Wstringop-truncation -Wdouble-promotion -Wshadow -Wunsafe-loop-optimizations
GCC_CFLAGS += -Walloc-zero -Wdouble-promotion -Wshadow -Wunsafe-loop-optimizations
GCC_CFLAGS += -Wpointer-arith -Wcast-align -Wwrite-strings -Wlogical-op -Wstrict-overflow=4 -Wundef -Wjump-misses-init
#GCC_CFLAGS += -Wstringop-truncation # not on Ubuntu bionic, gcc 7.5 doesn't support it
CLANG_CFLAGS := -Wnull-dereference -Wdouble-promotion -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-overflow=4 -Wundef
# TODO:
# GCC_CFLAGS += -Wcast-qual
# CLANG_CFLAGS += -Wcast-qual -Wcast-align
ifeq ($(CC),cc)
ifneq (,$(findstring gcc,$(CC)))
CFLAGS += $(GCC_CFLAGS)
else ifeq ($(CC),clang)
else ifneq (,$(findstring clang,$(CC)))
CFLAGS += $(CLANG_CFLAGS)
else
$(info No compiler flags for: $(CC))
Expand Down
45 changes: 24 additions & 21 deletions conmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct conmux {

struct conmux_lookup {
char *host;
int port;
char *port;
};

struct conmux_response {
Expand Down Expand Up @@ -193,7 +193,7 @@ static int registry_lookup(const char *service, struct conmux_lookup *result)
*p++ = '\0';

result->host = strdup(resp.result);
result->port = strtol(p, NULL, 10);
result->port = strdup(p);

ret = strcmp(resp.status, "OK") ? -1 : 0;

Expand Down Expand Up @@ -226,17 +226,16 @@ static int conmux_data(int fd, void *data)

void *conmux_open(struct device *dev)
{
struct addrinfo hints = {0}, *addrs, *addr;
struct conmux_response resp = {};
struct conmux_lookup lookup;
struct sockaddr_in saddr;
struct conmux *conmux;
struct hostent *hent;
const char *service = dev->control_dev;
const char *user;
ssize_t n;
char req[256];
int ret;
int fd;
int fd = -1;

user = getenv("USER");
if (!user)
Expand All @@ -246,27 +245,31 @@ void *conmux_open(struct device *dev)
if (ret)
exit(1);

fprintf(stderr, "conmux device at %s:%d\n", lookup.host, lookup.port);
fprintf(stderr, "conmux device at %s:%s\n", lookup.host, lookup.port);

fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
err(1, "failed to create registry socket");
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;

memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(lookup.port);
ret = getaddrinfo(lookup.host, lookup.port, &hints, &addrs);
if (ret != 0)
errx(1, "failed resolve \"%s\": %s", lookup.host, gai_strerror(ret));

hent = gethostbyname(lookup.host);
if (!hent) {
errno = h_errno;
err(1, "failed resolve \"%s\"", lookup.host);
}
for (addr = addrs; addr; addr = addr->ai_next) {
fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (fd < 0)
err(1, "failed to create registry socket");

saddr.sin_addr = *(struct in_addr *)hent->h_addr_list[0];
ret = connect(fd, addr->ai_addr, addr->ai_addrlen);
if (ret < 0) {
warn("failed to connect to conmux instance");
close(fd);
fd = -1;
}
}

ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
if (ret < 0)
err(1, "failed to connect to conmux instance");
if (fd == -1)
errx(1, "failed to connect to conmux instance");

ret = snprintf(req, sizeof(req), "CONNECT id=cdba:%s to=console\n", user);
if (ret >= (int)sizeof(req))
Expand Down