diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2015-01-19 16:20:29 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2015-01-19 16:20:29 +0000 |
commit | 347f8a8a14e3fb736ea6f42c7a0da1a0472f947f (patch) | |
tree | 02733a960b201ec3466f97d53329b85505de1315 /src | |
parent | 16de50671c7ad77f2acb4ca19d8806aad0490f03 (diff) | |
download | skalibs-347f8a8a14e3fb736ea6f42c7a0da1a0472f947f.tar.xz |
- Added unixconnection
- Added sig_name & sig_number (suggestion from Olivier Brunel)
- version bumped to 2.2.1.0, rc
Diffstat (limited to 'src')
-rw-r--r-- | src/include/skalibs/sig.h | 3 | ||||
-rw-r--r-- | src/include/skalibs/unixconnection.h | 25 | ||||
-rw-r--r-- | src/include/skalibs/unixonacid.h | 1 | ||||
-rw-r--r-- | src/libstddjb/sig-internal.h | 15 | ||||
-rw-r--r-- | src/libstddjb/sig_name.c | 11 | ||||
-rw-r--r-- | src/libstddjb/sig_number.c | 12 | ||||
-rw-r--r-- | src/libstddjb/sig_table.c | 83 | ||||
-rw-r--r-- | src/libstddjb/skasigaction.c | 5 | ||||
-rw-r--r-- | src/libunixonacid/unixconnection_free.c | 11 | ||||
-rw-r--r-- | src/libunixonacid/unixconnection_init.c | 10 | ||||
-rw-r--r-- | src/libunixonacid/unixconnection_zero.c | 5 |
11 files changed, 178 insertions, 3 deletions
diff --git a/src/include/skalibs/sig.h b/src/include/skalibs/sig.h index 7972e14..fa46b00 100644 --- a/src/include/skalibs/sig.h +++ b/src/include/skalibs/sig.h @@ -43,4 +43,7 @@ extern void sig_pause (void) ; extern void sig_shield (void) ; extern void sig_unshield (void) ; +extern char const *sig_name (int) ; +extern int sig_number (char const *) ; + #endif diff --git a/src/include/skalibs/unixconnection.h b/src/include/skalibs/unixconnection.h new file mode 100644 index 0000000..50a6ee8 --- /dev/null +++ b/src/include/skalibs/unixconnection.h @@ -0,0 +1,25 @@ + /* ISC license. */ + +#ifndef UNIXCONNECTION_H +#define UNIXCONNECTION_H + +#include <skalibs/unixmessage.h> + +typedef struct unixconnection_s unixconnection_t, *unixconnection_t_ref ; +struct unixconnection_s +{ + unixmessage_sender_t out ; + unixmessage_receiver_t in ; + char mainbuf[UNIXMESSAGE_BUFSIZE] ; + char auxbuf[UNIXMESSAGE_AUXBUFSIZE] ; +} ; +#define UNIXCONNECTION_ZERO { .out = UNIXMESSAGE_SENDER_ZERO, .in = UNIXMESSAGE_RECEIVER_ZERO } ; +extern unixconnection_t const unixconnection_zero ; + +extern void unixconnection_init (unixconnection_t *, int, int) ; +extern void unixconnection_free (unixconnection_t *) ; + +#define unixconnection_flush(io) unixmessage_sender_flush(&(io)->out) +#define unixconnection_receive(io, m) unixmessage_receive(&(io)->in, m) + +#endif diff --git a/src/include/skalibs/unixonacid.h b/src/include/skalibs/unixonacid.h index a150e39..9ec3fe8 100644 --- a/src/include/skalibs/unixonacid.h +++ b/src/include/skalibs/unixonacid.h @@ -6,6 +6,7 @@ #include <skalibs/unix-transactional.h> #include <skalibs/unix-timed.h> #include <skalibs/unixmessage.h> +#include <skalibs/unixconnection.h> #include <skalibs/kolbak.h> #include <skalibs/skaclient.h> diff --git a/src/libstddjb/sig-internal.h b/src/libstddjb/sig-internal.h new file mode 100644 index 0000000..9b540fa --- /dev/null +++ b/src/libstddjb/sig-internal.h @@ -0,0 +1,15 @@ +/* ISC license. */ + +#ifndef SIG_INTERNAL +#define SIG_INTERNAL + +typedef struct sigtable_s sigtable_t, *sigtable_t_ref ; +struct sigtable_s +{ + int number ; + char const *name ; +} ; + +extern sigtable_t const skalibs_sigtable[] ; + +#endif diff --git a/src/libstddjb/sig_name.c b/src/libstddjb/sig_name.c new file mode 100644 index 0000000..dd5a456 --- /dev/null +++ b/src/libstddjb/sig_name.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include <skalibs/sig.h> +#include "sig-internal.h" + +char const *sig_name (int sig) +{ + register sigtable_t const *p = skalibs_sigtable ; + for (; p->number ; p++) if (sig == p->number) break ; + return p->number ? p->name : "???" ; +} diff --git a/src/libstddjb/sig_number.c b/src/libstddjb/sig_number.c new file mode 100644 index 0000000..93d9b59 --- /dev/null +++ b/src/libstddjb/sig_number.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include <skalibs/bytestr.h> +#include <skalibs/sig.h> +#include "sig-internal.h" + +int sig_number (char const *name) +{ + register sigtable_t const *p = skalibs_sigtable ; + for (; p->name ; p++) if (!str_diff(name, p->name)) break ; + return p->number ; +} diff --git a/src/libstddjb/sig_table.c b/src/libstddjb/sig_table.c new file mode 100644 index 0000000..d097cb5 --- /dev/null +++ b/src/libstddjb/sig_table.c @@ -0,0 +1,83 @@ + /* ISC license. */ + +#include <signal.h> +#include "sig-internal.h" + +sigtable_t const skalibs_sigtable[] = +{ + { SIGABRT, "ABRT" }, + { SIGALRM, "ALRM" }, + { SIGBUS, "BUS" }, + { SIGCHLD, "CHLD" }, + { SIGCONT, "CONT" }, + { SIGFPE, "FPE" }, + { SIGHUP, "HUP" }, + { SIGILL, "ILL" }, + { SIGINT, "INT" }, + { SIGKILL, "KILL" }, + { SIGPIPE, "PIPE" }, + { SIGQUIT, "QUIT" }, + { SIGSEGV, "SEGV" }, + { SIGSTOP, "STOP" }, + { SIGTERM, "TERM" }, + { SIGTSTP, "TSTP" }, + { SIGTTIN, "TTIN" }, + { SIGTTOU, "TTOU" }, + { SIGUSR1, "USR1" }, + { SIGUSR2, "USR2" }, +#ifdef SIGPOLL + { SIGPOLL, "POLL" }, +#endif +#ifdef SIGPROF + { SIGPROF, "PROF" }, +#endif +#ifdef SIGSYS + { SIGSYS, "SYS" }, +#endif +#ifdef SIGTRAP + { SIGTRAP, "TRAP" }, +#endif +#ifdef SIGURG + { SIGURG, "URG" }, +#endif +#ifdef SIGVTALRM + { SIGVTALRM, "VTALRM" }, +#endif +#ifdef SIGXCPU + { SIGXCPU, "XCPU" }, +#endif +#ifdef SIGXFSZ + { SIGXFSZ, "XFSZ" }, +#endif +#ifdef SIGIOT + { SIGIOT, "IOT" }, +#endif +#ifdef SIGEMT + { SIGEMT, "EMT" }, +#endif +#ifdef SIGSTKFLT + { SIGSTKFLT, "STKFLT" }, +#endif +#ifdef SIGCLD + { SIGCLD, "CLD" }, +#endif +#ifdef SIGWINCH + { SIGWINCH, "WINCH" }, +#endif +#ifdef SIGIO + { SIGIO, "IO" }, +#endif +#ifdef SIGINFO + { SIGINFO, "INFO" }, +#endif +#ifdef SIGLOST + { SIGLOST, "LOST" }, +#endif +#ifdef SIGPWR + { SIGPWR, "PWR" }, +#endif +#ifdef SIGUNUSED + { SIGUNUSED, "UNUSED" }, +#endif + { 0, 0 } +} ; diff --git a/src/libstddjb/skasigaction.c b/src/libstddjb/skasigaction.c index a673fcb..bb55642 100644 --- a/src/libstddjb/skasigaction.c +++ b/src/libstddjb/skasigaction.c @@ -1,7 +1,6 @@ /* ISC license. */ #include <signal.h> -#include <skalibs/sysdeps.h> #include <skalibs/sig.h> int skasigaction (int sig, struct skasigaction const *new, struct skasigaction *old) @@ -10,11 +9,11 @@ int skasigaction (int sig, struct skasigaction const *new, struct skasigaction * if (((new->flags & SKASA_MASKALL) ? sigfillset(&sanew.sa_mask) : sigemptyset(&sanew.sa_mask)) == -1) return -1 ; sanew.sa_handler = new->handler ; sanew.sa_flags = (new->flags & SKASA_NOCLDSTOP) ? SA_NOCLDSTOP : 0 ; - if (sigaction(sig, &sanew, &saold) == -1) return -1 ; + if (sigaction(sig, &sanew, &saold) < 0) return -1 ; if (old) { register int r = sigismember(&saold.sa_mask, (sig == SIGTERM) ? SIGPIPE : SIGTERM) ; - if (r == -1) return -1 ; + if (r < 0) return -1 ; old->flags = 0 ; if (r) old->flags |= SKASA_MASKALL ; if (saold.sa_flags & SA_NOCLDSTOP) old->flags |= SKASA_NOCLDSTOP ; diff --git a/src/libunixonacid/unixconnection_free.c b/src/libunixonacid/unixconnection_free.c new file mode 100644 index 0000000..52f9027 --- /dev/null +++ b/src/libunixonacid/unixconnection_free.c @@ -0,0 +1,11 @@ + /* ISC license. */ + +#include <skalibs/unixmessage.h> +#include <skalibs/unixconnection.h> + +void unixconnection_free (unixconnection_t *io) +{ + unixmessage_sender_free(&io->out) ; + unixmessage_receiver_free(&io->in) ; + *io = unixconnection_zero ; +} diff --git a/src/libunixonacid/unixconnection_init.c b/src/libunixonacid/unixconnection_init.c new file mode 100644 index 0000000..7831d6a --- /dev/null +++ b/src/libunixonacid/unixconnection_init.c @@ -0,0 +1,10 @@ + /* ISC license. */ + +#include <skalibs/unixmessage.h> +#include <skalibs/unixconnection.h> + +void unixconnection_init (unixconnection_t *io, int fdin, int fdout) +{ + unixmessage_receiver_init(&io->in, fdin, io->mainbuf, UNIXMESSAGE_BUFSIZE, io->auxbuf, UNIXMESSAGE_AUXBUFSIZE) ; + unixmessage_sender_init(&io->out, fdout) ; +} diff --git a/src/libunixonacid/unixconnection_zero.c b/src/libunixonacid/unixconnection_zero.c new file mode 100644 index 0000000..9100cac --- /dev/null +++ b/src/libunixonacid/unixconnection_zero.c @@ -0,0 +1,5 @@ + /* ISC license. */ + +#include <skalibs/unixconnection.h> + +unixconnection_t const unixconnection_zero = UNIXCONNECTION_ZERO ; |