From 2990ce9b390ec1e2bfa1c043c406878e8aff86dd Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 21 Dec 2017 11:18:28 +0000 Subject: Big 2.6.3.0 reorganization - Add libposixplz, update headers - Add memmem and friends - Add textmessage to libunixonacid - Update some sysdeps tests --- src/include/skalibs/bytestr.h | 11 ++--- src/include/skalibs/djbunix.h | 9 ++-- src/include/skalibs/environ.h | 7 +-- src/include/skalibs/getpeereid.h | 9 +--- src/include/skalibs/mininetstring.h | 5 +- src/include/skalibs/posixplz.h | 45 +++++++++++++++++ src/include/skalibs/setgroups.h | 12 ++++- src/include/skalibs/skalibs.h | 4 +- src/include/skalibs/skamisc.h | 1 + src/include/skalibs/stddjb.h | 4 +- src/include/skalibs/textmessage.h | 96 +++++++++++++++++++++++++++++++++++++ src/include/skalibs/unixonacid.h | 1 + src/include/skalibs/webipc.h | 2 +- 13 files changed, 171 insertions(+), 35 deletions(-) create mode 100644 src/include/skalibs/posixplz.h create mode 100644 src/include/skalibs/textmessage.h (limited to 'src/include') diff --git a/src/include/skalibs/bytestr.h b/src/include/skalibs/bytestr.h index 1f3942b..3a5c95e 100644 --- a/src/include/skalibs/bytestr.h +++ b/src/include/skalibs/bytestr.h @@ -3,27 +3,21 @@ #ifndef BYTESTR_H #define BYTESTR_H -#include #include /* for Alphas and other archs where char != 8bit */ #define T8(x) ((x) & 0xffU) -#include #include #include +#include #define byte_copy(to, n, from) memmove(to, (from), n) #define byte_copyr(to, n, from) memmove(to, (from), n) #define byte_diff(a, n, b) memcmp(a, (b), n) #define byte_zero(p, n) memset(p, 0, n) #define str_len strlen - -#ifdef SKALIBS_HASSTRNLEN -# define str_nlen strnlen -#else -# define str_nlen(s, max) byte_chr(s, (max), 0) -#endif +#define str_nlen strnlen #define str_diff strcmp #define str_diffn strncmp @@ -36,6 +30,7 @@ extern size_t byte_rchr (char const *, size_t, int) gccattr_pure ; extern size_t byte_in (char const *, size_t, char const *, size_t) gccattr_pure ; #define byte_equal(s, n, t) (!memcmp(s, (t), n)) extern size_t byte_count (char const *, size_t, char) gccattr_pure ; +extern size_t byte_search (char const *, size_t, char const *, size_t) ; #define str_diffb(a, n, b) strncmp(a, (b), n) extern size_t str_chr (char const *, int) gccattr_pure ; diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h index 4dc534e..b095c82 100644 --- a/src/include/skalibs/djbunix.h +++ b/src/include/skalibs/djbunix.h @@ -9,7 +9,8 @@ #include #include #include -#include /* compatibility */ +#include /* will disappear */ +#include #define DJBUNIX_FLAG_NB 0x01U #define DJBUNIX_FLAG_COE 0x02U @@ -56,7 +57,6 @@ extern int pathexec_env (char const *, char const *) ; extern void pathexec_r (char const *const *, char const *const *, size_t, char const *, size_t) ; extern void pathexec_r_name (char const *, char const *const *, char const *const *, size_t, char const *, size_t) ; extern void pathexec_fromenv (char const *const *, char const *const *, size_t) ; -extern void execvep (char const *, char const *const *, char const *const *, char const *) ; extern void pathexec_run (char const *, char const *const *, char const *const *) ; extern void pathexec0_run (char const *const *, char const *const *) ; extern void pathexec (char const *const *) ; @@ -89,11 +89,9 @@ extern unsigned int wait_reap (void) ; extern int waitn (pid_t *, unsigned int) ; extern int waitn_reap (pid_t *, unsigned int) ; -extern pid_t doublefork (void) ; - extern int fd_chdir (int) ; -#define absolutepath(sa, s) sarealpath(sa, s) +#define absolutepath(sa, s) sarealpath(sa, s) /* will disappear */ extern int sarealpath (stralloc *, char const *) ; extern int sarealpath_tmp (stralloc *, char const *, stralloc *) ; extern int sabasename (stralloc *, char const *, size_t) ; @@ -162,7 +160,6 @@ extern int rm_rf_in_tmp (stralloc *, size_t) ; /* caution ! */ extern int rmstar (char const *) ; extern int rmstar_tmp (char const *, stralloc *) ; -extern int touch (char const *) ; extern int filecopy_unsafe (char const *, char const *, unsigned int) ; extern int filecopy_suffix (char const *, char const *, unsigned int, char const *) ; extern int hiercopy (char const *, char const *) ; diff --git a/src/include/skalibs/environ.h b/src/include/skalibs/environ.h index 6bf3041..0d4494b 100644 --- a/src/include/skalibs/environ.h +++ b/src/include/skalibs/environ.h @@ -1,8 +1,5 @@ /* ISC license. */ -#ifndef ENVIRON_H -#define ENVIRON_H +/* This header is being deprecated */ -extern char **environ ; - -#endif +#include diff --git a/src/include/skalibs/getpeereid.h b/src/include/skalibs/getpeereid.h index 4aa2898..0d4494b 100644 --- a/src/include/skalibs/getpeereid.h +++ b/src/include/skalibs/getpeereid.h @@ -1,10 +1,5 @@ /* ISC license. */ -#ifndef GETPEEREID_H -#define GETPEEREID_H +/* This header is being deprecated */ -#include - -extern int getpeereid (int, uid_t *, gid_t *) ; - -#endif +#include diff --git a/src/include/skalibs/mininetstring.h b/src/include/skalibs/mininetstring.h index 1997b18..9e88601 100644 --- a/src/include/skalibs/mininetstring.h +++ b/src/include/skalibs/mininetstring.h @@ -4,9 +4,10 @@ #define MININETSTRING_H #include +#include #include -extern int mininetstring_read (int, stralloc *, uint32_t *) ; -extern int mininetstring_write (int, char const *, uint16_t, uint32_t *) ; +extern int mininetstring_read (int, stralloc *, uint32_t *) gccattr_deprecated ; +extern int mininetstring_write (int, char const *, uint16_t, uint32_t *) gccattr_deprecated ; #endif diff --git a/src/include/skalibs/posixplz.h b/src/include/skalibs/posixplz.h new file mode 100644 index 0000000..72cffee --- /dev/null +++ b/src/include/skalibs/posixplz.h @@ -0,0 +1,45 @@ +/* ISC license. */ + +#ifndef SKALIBS_POSIXPLZ_H +#define SKALIBS_POSIXPLZ_H + +#include +#include + + + /* + Stuff that doesn't have its own POSIX header for some reason. + */ + +extern char **environ ; + + + /* + Stuff that _is_ POSIX, but some OSes still don't have it. + openat() et al. should be here, but they're impossible to + emulate correctly, and I don't want an app using openat() + to think it has safe POSIX semantics when it doesn't :/ + EPROTO et al. should be here, but ugh ifdef forests. + */ + +extern size_t strnlen (char const *, size_t) gccattr_pure ; + + + /* + Non-POSIX functions that some OSes provide and others don't. + setgroups() isn't included because it's its own kind of broken. + */ + +extern void *memmem (void const *, size_t, void const *, size_t) gccattr_pure ; +extern int getpeereid (int, uid_t *, gid_t *) ; + + + /* + Functions that aren't standard at all, but honestly could be. :P + */ + +extern void execvep (char const *, char const *const *, char const *const *, char const *) ; +extern pid_t doublefork (void) ; +extern int touch (char const *) ; + +#endif diff --git a/src/include/skalibs/setgroups.h b/src/include/skalibs/setgroups.h index 98998e0..19421e0 100644 --- a/src/include/skalibs/setgroups.h +++ b/src/include/skalibs/setgroups.h @@ -7,6 +7,13 @@ #ifdef SKALIBS_HASSETGROUPS + /* + setgroups() is defined by a lot of OSes. + However, they don't agree on what it should do: + some change the primary gid, others don't, etc. It's a mess. + Never use setgroups(). Use the functions below instead. + */ + #include extern int setgroups_and_gid (gid_t, size_t, gid_t const *) ; @@ -15,8 +22,11 @@ extern int skalibs_setgroups (size_t, gid_t const *) ; #else + /* No setgroups() at all? not much we can do. */ + #include -#define setgroups(n, tab) (errno = ENOSYS, -1) + +#define setgroups_and_gid(g, n, tab) (errno = ENOSYS, -1) #define setgroups_with_egid(n, tab) (errno = ENOSYS, -1) #define skalibs_setgroups(n, tab) (errno = ENOSYS, -1) diff --git a/src/include/skalibs/skalibs.h b/src/include/skalibs/skalibs.h index e889461..2924e1c 100644 --- a/src/include/skalibs/skalibs.h +++ b/src/include/skalibs/skalibs.h @@ -4,11 +4,11 @@ #define SKALIBS_H /* - This header includes everything in skalibs, - except skalibs/config.h and skalibs/sysdeps.h + This header includes everything in skalibs except skalibs/config.h It's heavy! */ +#include #include #include #include diff --git a/src/include/skalibs/skamisc.h b/src/include/skalibs/skamisc.h index cf33ec2..15f7f02 100644 --- a/src/include/skalibs/skamisc.h +++ b/src/include/skalibs/skamisc.h @@ -12,6 +12,7 @@ extern stralloc satmp ; extern int skagetln (buffer *, stralloc *, char) ; extern int skagetln_nofill (buffer *, stralloc *, char) ; extern int skagetlnsep (buffer *, stralloc *, char const *, size_t) ; +extern int skagetlnmaxsep (buffer *, stralloc *, size_t, char const *, size_t) ; extern int getlnmax (buffer *, char *, size_t, size_t *, char) ; extern int getlnmaxsep (buffer *, char *, size_t, size_t *, char const *, size_t) ; diff --git a/src/include/skalibs/stddjb.h b/src/include/skalibs/stddjb.h index 50e07c5..87f72d0 100644 --- a/src/include/skalibs/stddjb.h +++ b/src/include/skalibs/stddjb.h @@ -29,17 +29,15 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include -#include +#include /* will disappear */ #include #include #include diff --git a/src/include/skalibs/textmessage.h b/src/include/skalibs/textmessage.h new file mode 100644 index 0000000..9904534 --- /dev/null +++ b/src/include/skalibs/textmessage.h @@ -0,0 +1,96 @@ +/* ISC license. */ + +#ifndef SKALIBS_TEXTMESSAGE_H +#define SKALIBS_TEXTMESSAGE_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#define TEXTMESSAGE_MAXREADS 128 + + + /* Sender */ + +typedef struct textmessage_sender_s textmessage_sender_t, *textmessage_sender_t_ref ; +struct textmessage_sender_s +{ + bufalloc out ; +} ; +#define TEXTMESSAGE_SENDER_ZERO { .out = BUFALLOC_ZERO } +extern textmessage_sender_t const textmessage_sender_zero ; +#define TEXTMESSAGE_SENDER_INIT(fd) { .out = BUFALLOC_INIT(&fd_write, (fd)) } + +#define textmessage_sender_init(ts, fd) bufalloc_init(&(ts)->out, &fd_write, fd) +#define textmessage_sender_free(ts) bufalloc_free(&(ts)->out) +#define textmessage_sender_fd(ts) bufalloc_fd(&(ts)->out) +extern int textmessage_sender_getfd (textmessage_sender_t const *) gccattr_pure ; +#define textmessage_sender_isempty(ts) bufalloc_isempty(&(ts)->out) + +extern int textmessage_put (textmessage_sender_t *, char const *, size_t) ; +extern int textmessage_putv (textmessage_sender_t *, struct iovec const *, unsigned int) ; + +extern int textmessage_sender_flush (textmessage_sender_t *) ; +extern int unixmessage_sender_timed_flush (textmessage_sender_t *, tain_t const *, tain_t *) ; +#define textmessage_sender_timed_flush_g(ts, deadline) textmessage_sender_timed_flush(ts, (deadline), &STAMP) + +#define textmessage_send(ts, s, len) (textmessage_put(ts, s, len) && textmessage_sender_flush(ts)) +#define textmessage_sendv(ts, v, n) (textmessage_putv(ts, v, n) && textmessage_sender_flush(ts)) +#define textmessage_timed_send(ts, s, len, deadline, stamp) (textmessage_put(ts, s, len) && texxtmessage_sender_timed_flush(ts, deadline, stamp)) +#define textmessage_timed_sendv(ts, v, n, deadline, stamp) (textmessage_putv(ts, v, n) && texxtmessage_sender_timed_flush(ts, deadline, stamp)) +#define textmessage_timed_send_g(ts, s, len, deadline) textmessage_timed_send(ts, s, len, (deadline), &STAMP) +#define textmessage_timed_sendv_g(ts, v, n, deadline) textmessage_timed_sendv(ts, v, n, (deadline), &STAMP) + + + /* Receiver */ + +typedef struct textmessage_receiver_s textmessage_receiver_t, *textmessage_receiver_t_ref ; +struct textmessage_receiver_s +{ + buffer in ; + stralloc indata ; + uint32_t wanted ; + uint32_t max ; +} ; +#define TEXTMESSAGE_RECEIVER_ZERO { .in = BUFFER_ZERO, .indata = STRALLOC_ZERO, .wanted = 0, .max = 0 } +extern textmessage_receiver_t const textmessage_receiver_zero ; +#define TEXTMESSAGE_RECEIVER_INIT(fd, buf, len, n) { .in = BUFFER_INIT(&buffer_read, (fd), buf, len), .indata = STRALLOC_ZERO, .wanted = 0, .max = n } + +extern int textmessage_receiver_init (textmessage_receiver_t *, int, char *, size_t, uint32_t) ; +extern void textmessage_receiver_free (textmessage_receiver_t *) ; +#define textmessage_receiver_fd(tr) buffer_fd(&(tr)->in) +#define textmessage_receiver_isempty(tr) buffer_isempty(&(tr)->in) +#define textmessage_receiver_isfull(tr) buffer_isfull(&(tr)->in) + +extern int textmessage_receiver_hasmsginbuf (textmessage_receiver_t const *) gccattr_pure ; + +extern int textmessage_receive (textmessage_receiver_t *, struct iovec *) ; +extern int textmessage_timed_receive (textmessage_receiver_t *, struct iovec *, tain_t const *, tain_t *) ; +#define textmessage_timed_receive_g(tr, s, max, deadline) textmessage_timed_receive(tr, s, max, (deadline), &STAMP) + +typedef int textmessage_handler_func_t (struct iovec const *, void *) ; +typedef textmessage_handler_func_t *textmessage_handler_func_t_ref ; + +extern int textmessage_handle (textmessage_receiver_t *, textmessage_handler_func_t_ref, void *) ; +extern int textmessage_timed_handle (textmessage_receiver_t *, textmessage_handler_func_t_ref, void *, tain_t const *, tain_t *) ; +#define textmessage_timed_handle_g(tr, f, p, deadline) unixmessage_timed_handle(tr, f, p, (deadline), &STAMP) + + + + /* Globals */ + +extern textmessage_receiver_t textmessage_receiver_0_ ; +#define textmessage_receiver_0 (&textmessage_receiver_0_) + +extern textmessage_sender_t textmessage_sender_1_ ; +#define textmessage_sender_1 (&textmessage_sender_1_) + +extern textmessage_sender_t textmessage_sender_x_ ; +#define textmessage_sender_x (&textmessage_sender_x_) + +#endif diff --git a/src/include/skalibs/unixonacid.h b/src/include/skalibs/unixonacid.h index 9ec3fe8..43bd695 100644 --- a/src/include/skalibs/unixonacid.h +++ b/src/include/skalibs/unixonacid.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff --git a/src/include/skalibs/webipc.h b/src/include/skalibs/webipc.h index 0ddd084..eba6f6b 100644 --- a/src/include/skalibs/webipc.h +++ b/src/include/skalibs/webipc.h @@ -13,7 +13,7 @@ #define IPCPATH_MAX 107 #include -#include +#include #include #include -- cgit v1.2.3