"Fossies" - the Fresh Open Source Software Archive 
Member "memcached-1.6.15/openbsd_priv.c" (21 Feb 2022, 921 Bytes) of package /linux/www/memcached-1.6.15.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "openbsd_priv.c" see the
Fossies "Dox" file reference documentation.
1 #include <errno.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include "memcached.h"
7
8 /*
9 * this section of code will drop all (OpenBSD) privileges including
10 * those normally granted to all userland process (basic privileges). The
11 * effect of this is that after running this code, the process will not able
12 * to fork(), exec(), etc. See pledge(2) for more information.
13 */
14 void drop_privileges() {
15 extern char *__progname;
16
17 if (settings.socketpath != NULL) {
18 if (pledge("stdio unix", NULL) == -1) {
19 fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno));
20 exit(EXIT_FAILURE);
21 }
22 } else {
23 if (pledge("stdio inet", NULL) == -1) {
24 fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno));
25 exit(EXIT_FAILURE);
26 }
27 }
28 }
29
30 void setup_privilege_violations_handler(void) {
31 // not needed
32 }