On Sun, Aug 14, 2016 at 12:30:46AM +0200, Joerg Jung wrote:
> Hi,
>
> please find below a diff for sic to enable pledge() to be used on
> OpenBSD. This diff was originally submitted by Ali H. Fardan via
> ports_AT_openbsd.org. While here, I enabled the usage of strlcpy()
> from libc on OpenBSD.
>
> Honestly, I'm not sure about how such portability goo should be
> handled the suckless way, but since I see similar #ifdef __linux__
> instances in slock, I guess the proposed way is okay?
>
> Thanks,
> Regards,
> Joerg
>
>
> diff --git a/sic.c b/sic.c
> index ce6d216..b22ea06 100644
> --- a/sic.c
> +++ b/sic.c
> _AT_@ -182,6 +182,8 @@ main(int argc, char *argv[]) {
> setbuf(stdout, NULL);
> setbuf(srv, NULL);
> setbuf(stdin, NULL);
> + if (pledge("stdio", NULL) == -1)
> + eprint("error: pledge:");
> for(;;) { /* main loop */
> FD_ZERO(&rd);
> FD_SET(0, &rd);
> diff --git a/util.c b/util.c
> index 8afa58f..88ea06e 100644
> --- a/util.c
> +++ b/util.c
> _AT_@ -40,12 +40,16 @@ dial(char *host, char *port) {
> return srv;
> }
>
> +#ifndef __OpenBSD__
> +#define pledge(promises, paths) 0
> +
> #define strlcpy _strlcpy
> static void
> strlcpy(char *to, const char *from, int l) {
> memccpy(to, from, '\0', l);
> to[l-1] = '\0';
> }
> +#endif
>
> static char *
> eat(char *s, int (*p)(int), int r) {
>
Hi,
In general we should try to avoid ifdefs asmuch as possible. But I would not
mind the pledge in the form:
#ifdef __OpenBSD__
if (pledge("stdio", NULL) == -1)
eprint("error: pledge:");
#endif
Also in my opinion we should just import the OpenBSD strlcpy() version or
rename the current one, it has not the same behaviour as strlcpy and is
confusing.
Attached is my proposed patch.
--
Kind regards,
Hiltjo
Received on Sun Aug 14 2016 - 11:11:49 CEST