Add pledge(2) support

hints from semarie@ and sthen@
ok sthen@
This commit is contained in:
giovanni 2016-03-09 14:50:11 +00:00
parent 8eb3e250e6
commit 31d184b04d
5 changed files with 57 additions and 11 deletions

View File

@ -1,8 +1,9 @@
# $OpenBSD: Makefile,v 1.30 2016/03/05 21:30:16 giovanni Exp $
# $OpenBSD: Makefile,v 1.31 2016/03/09 14:50:11 giovanni Exp $
COMMENT= distributed memory object caching system
DISTNAME= memcached-1.4.25
REVISION= 0
CATEGORIES= misc
HOMEPAGE= http://www.memcached.org/
@ -12,6 +13,7 @@ MAINTAINER= Giovanni Bechis <giovanni@openbsd.org>
# BSD
PERMIT_PACKAGE_CDROM= Yes
# uses pledge()
WANTLIB += c event pthread
FLAVOR?=

View File

@ -1,7 +1,7 @@
$OpenBSD: patch-configure,v 1.7 2015/05/05 15:43:03 giovanni Exp $
--- configure.orig Sat Apr 25 22:53:45 2015
+++ configure Mon May 4 13:05:07 2015
@@ -6435,7 +6435,7 @@ $as_echo "#define _GNU_SOURCE 1" >>confdefs.h
$OpenBSD: patch-configure,v 1.8 2016/03/09 14:50:11 giovanni Exp $
--- configure.orig Fri Nov 20 08:02:49 2015
+++ configure Sat Mar 5 22:20:56 2016
@@ -6390,7 +6390,7 @@ $as_echo "#define _GNU_SOURCE 1" >>confdefs.h
elif test "$GCC" = "yes"
then
GCC_VERSION=`$CC -dumpversion`

View File

@ -1,10 +1,10 @@
$OpenBSD: patch-items_c,v 1.10 2015/05/05 15:43:03 giovanni Exp $
$OpenBSD: patch-items_c,v 1.11 2016/03/09 14:50:11 giovanni Exp $
printf format string fix for long long time_t
--- items.c.orig Sat Apr 25 22:47:33 2015
+++ items.c Mon May 4 12:52:52 2015
@@ -459,9 +459,9 @@ char *item_cachedump(const unsigned int slabs_clsid, c
--- items.c.orig Fri Nov 20 02:18:56 2015
+++ items.c Sat Mar 5 22:20:56 2016
@@ -460,9 +460,9 @@ char *item_cachedump(const unsigned int slabs_clsid, c
/* Copy the key since it may not be null-terminated in the struct */
strncpy(key_temp, ITEM_key(it), it->nkey);
key_temp[it->nkey] = 0x00; /* terminate */

View File

@ -0,0 +1,44 @@
$OpenBSD: patch-memcached_c,v 1.10 2016/03/09 14:50:11 giovanni Exp $
--- memcached.c.orig Thu Nov 19 08:19:56 2015
+++ memcached.c Sun Mar 6 22:32:48 2016
@@ -23,6 +23,7 @@
#include <sys/uio.h>
#include <ctype.h>
#include <stdarg.h>
+#include <unistd.h>
/* some POSIX systems need the following definition
* to get mlockall flags out of sys/mman.h. */
@@ -5766,6 +5767,32 @@ int main (int argc, char **argv) {
if (pid_file != NULL) {
save_pid(pid_file);
+ }
+
+ if (settings.socketpath != NULL) {
+ if (pid_file != NULL) {
+ if (pledge("stdio cpath unix", NULL) == -1) {
+ fprintf(stderr, "%s: pledge: %s\n", argv[0], strerror(errno));
+ exit(1);
+ }
+ } else {
+ if (pledge("stdio unix", NULL) == -1) {
+ fprintf(stderr, "%s: pledge: %s\n", argv[0], strerror(errno));
+ exit(1);
+ }
+ }
+ } else {
+ if (pid_file != NULL) {
+ if (pledge("stdio cpath inet", NULL) == -1) {
+ fprintf(stderr, "%s: pledge: %s\n", argv[0], strerror(errno));
+ exit(1);
+ }
+ } else {
+ if (pledge("stdio inet", NULL) == -1) {
+ fprintf(stderr, "%s: pledge: %s\n", argv[0], strerror(errno));
+ exit(1);
+ }
+ }
}
/* Drop privileges no longer needed */

View File

@ -1,9 +1,9 @@
#!/bin/sh
#
# $OpenBSD: memcached.rc,v 1.1 2011/12/25 14:37:28 sebastia Exp $
# $OpenBSD: memcached.rc,v 1.2 2016/03/09 14:50:11 giovanni Exp $
daemon="${TRUEPREFIX}/bin/memcached -d"
daemon_flags="-u _memcached -P /var/run/memcached.pid"
daemon_flags="-u _memcached"
. /etc/rc.d/rc.subr