Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
hurufu committed May 11, 2024
1 parent d6879ef commit a444a6f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
9 changes: 5 additions & 4 deletions .gdbinit
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#source gdb.scm
set env CK_FORK=no
file ./demo
set follow-exec-mode new
set print repeats 0
break main
file /bin/s6-tcpclient
#break main
#break fsm_frontend_foreign
break fsm_wireformat
break starter
#break fsm_wireformat
#break starter
#break sus_select
#break sus_read
#break sus_write
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LDFLAGS += $(call if_coverage,--coverage)
# Project configuration ########################################################
RL_C := wireprotocol.c header.c body.c attrs.c frame.c
RL_O := $(RL_C:.c=.o)
CFILES := main.c log.c utils.c serialization.c ucspi.c
CFILES := main.c log.c utils.c serialization.c ucspi.c npthfix.c
OFILES := $(RL_O) $(CFILES:.c=.o)
UT_C := ut.c serialization.c log.c utils.c contextring.c
UT_O := $(UT_C:.c=.o) header.o body.o frame.o attrs.o
Expand Down
20 changes: 9 additions & 11 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
#include <sys/resource.h>
#include <npth.h>

typedef void* (* const npth_entry_t)(void*);

struct ThreadBag {
npth_t handle;
const char* const name;
void* (* const entry)(void*);
npth_entry_t entry;
void* const arg;
};

int npth_sigwait(const sigset_t *set, int *sig) {
npth_unprotect();
const int res = sigwait(set, sig);
npth_protect();
return res;
}
#define npth_define(Entry, ...) \
{ .entry = (npth_entry_t)Entry, .name = #Entry, .arg = &(struct Entry ## _args){ __VA_ARGS__ } }

static void adjust_rlimit(void) {
// This will force syscalls that allocate file descriptors to fail if it
Expand All @@ -37,23 +35,23 @@ int main(const int ac, const char* av[static const ac]) {
adjust_rlimit();
int fd_fo_main = STDOUT_FILENO, fd_fi_main = STDIN_FILENO;
ucsp_info_and_adjust_fds(&fd_fo_main, &fd_fi_main);
LOGDX("%d %d", fd_fo_main, fd_fi_main);
struct ThreadBag thr[] = {
{ .entry = fsm_wireformat, .name = "wireprotocol", .arg = &(struct fsm_wireformat_args){fd_fi_main}}
npth_define(fsm_wireformat, .infd = fd_fi_main)
};
npth_init();
npth_sigev_init();
npth_sigev_add(SIGINT);
npth_sigev_add(SIGPWR);
npth_sigev_fini();
for (size_t i = 0; i < lengthof(thr); i++) {
xnpth_create(&thr[i].handle, NULL, thr[i].entry, thr[i].arg);
xnpth_setname_np(thr[i].handle, thr[i].name);
}
for (;;) {
int sig;
LOGDX("Waiting for a signal...");
xnpth_sigwait(npth_sigev_sigmask(), &sig);
switch (sig) {
case SIGINT:
case SIGPWR:
LOGD("got %s", strsignal(sig));
break;
default:
Expand Down

0 comments on commit a444a6f

Please sign in to comment.