Fossil SCM

Add the fossil_pledge() utility routine, that is a no-op unless compiled with FOSSIL_HAVE_PLEDGE.

drh 2018-01-15 16:18 trunk
Commit 7b81a9993b4c8192b75940c093bfe7ba3d3c51abd92af750828ea9b7619ae154
--- src/checkin.c
+++ src/checkin.c
@@ -471,10 +471,12 @@
471471
int verboseFlag = command==CHANGES && find_option("verbose", "v", 0);
472472
const char *zIgnoreFlag = find_option("ignore", 0, 1);
473473
unsigned scanFlags = 0;
474474
unsigned flags = 0;
475475
int vid, i;
476
+
477
+ fossil_pledge("stdio rpath wpath cpath id flock tty", "");
476478
477479
/* Load affirmative flag options. */
478480
for( i=0; i<count(flagDefs); ++i ){
479481
if( (command==CHANGES || !(flagDefs[i].mask & C_CLASSIFY))
480482
&& find_option(flagDefs[i].option, 0, 0) ){
481483
--- src/checkin.c
+++ src/checkin.c
@@ -471,10 +471,12 @@
471 int verboseFlag = command==CHANGES && find_option("verbose", "v", 0);
472 const char *zIgnoreFlag = find_option("ignore", 0, 1);
473 unsigned scanFlags = 0;
474 unsigned flags = 0;
475 int vid, i;
 
 
476
477 /* Load affirmative flag options. */
478 for( i=0; i<count(flagDefs); ++i ){
479 if( (command==CHANGES || !(flagDefs[i].mask & C_CLASSIFY))
480 && find_option(flagDefs[i].option, 0, 0) ){
481
--- src/checkin.c
+++ src/checkin.c
@@ -471,10 +471,12 @@
471 int verboseFlag = command==CHANGES && find_option("verbose", "v", 0);
472 const char *zIgnoreFlag = find_option("ignore", 0, 1);
473 unsigned scanFlags = 0;
474 unsigned flags = 0;
475 int vid, i;
476
477 fossil_pledge("stdio rpath wpath cpath id flock tty", "");
478
479 /* Load affirmative flag options. */
480 for( i=0; i<count(flagDefs); ++i ){
481 if( (command==CHANGES || !(flagDefs[i].mask & C_CLASSIFY))
482 && find_option(flagDefs[i].option, 0, 0) ){
483
+12
--- src/config.h
+++ src/config.h
@@ -253,7 +253,19 @@
253253
254254
/*
255255
** Number of elements in an array
256256
*/
257257
#define count(X) (sizeof(X)/sizeof(X[0]))
258
+
259
+/*
260
+** The pledge() interface is currently only available on OpenBSD 5.9
261
+** and later. Make calls to fossil_pledge() no-ops on all platforms
262
+** that omit the FOSSIL_HAVE_PLEDGE configuration parameter.
263
+*/
264
+#if defined(FOSSIL_HAVE_PLEDGE)
265
+# define fossil_pledge(A,B) fossil_pledge_impl(A,B)
266
+#else
267
+# define fossil_pledge(A,B)
268
+#endif
269
+
258270
259271
#endif /* _RC_COMPILE_ */
260272
--- src/config.h
+++ src/config.h
@@ -253,7 +253,19 @@
253
254 /*
255 ** Number of elements in an array
256 */
257 #define count(X) (sizeof(X)/sizeof(X[0]))
 
 
 
 
 
 
 
 
 
 
 
 
258
259 #endif /* _RC_COMPILE_ */
260
--- src/config.h
+++ src/config.h
@@ -253,7 +253,19 @@
253
254 /*
255 ** Number of elements in an array
256 */
257 #define count(X) (sizeof(X)/sizeof(X[0]))
258
259 /*
260 ** The pledge() interface is currently only available on OpenBSD 5.9
261 ** and later. Make calls to fossil_pledge() no-ops on all platforms
262 ** that omit the FOSSIL_HAVE_PLEDGE configuration parameter.
263 */
264 #if defined(FOSSIL_HAVE_PLEDGE)
265 # define fossil_pledge(A,B) fossil_pledge_impl(A,B)
266 #else
267 # define fossil_pledge(A,B)
268 #endif
269
270
271 #endif /* _RC_COMPILE_ */
272
+16
--- src/util.c
+++ src/util.c
@@ -483,5 +483,21 @@
483483
}
484484
setrlimit(RLIMIT_STACK, &x);
485485
#endif /* defined(RLIMIT_STACK) */
486486
#endif /* defined(__unix__) */
487487
}
488
+
489
+#if defined(FOSSIL_HAVE_PLEDGE)
490
+/*
491
+** Interface to pledge() on OpenBSD 5.9 and later.
492
+**
493
+** There is a macro in config.h that make translates calls to
494
+** "fossil_pledge(A,B)" into calls to this routine on OpenBSD.
495
+** On all other platforms, this routine does not exist.
496
+*/
497
+void fossil_pledge_impl(const char *promises, const char *execpromises){
498
+ if( pledge(promises, execpromises) ){
499
+ fossil_fatal("pledge(\"%s\",\"%s\") fails with errno=%d",
500
+ promises, execpromises, (int)errno);
501
+ }
502
+}
503
+#endif /* defined(__OpenBSD__) */
488504
--- src/util.c
+++ src/util.c
@@ -483,5 +483,21 @@
483 }
484 setrlimit(RLIMIT_STACK, &x);
485 #endif /* defined(RLIMIT_STACK) */
486 #endif /* defined(__unix__) */
487 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
--- src/util.c
+++ src/util.c
@@ -483,5 +483,21 @@
483 }
484 setrlimit(RLIMIT_STACK, &x);
485 #endif /* defined(RLIMIT_STACK) */
486 #endif /* defined(__unix__) */
487 }
488
489 #if defined(FOSSIL_HAVE_PLEDGE)
490 /*
491 ** Interface to pledge() on OpenBSD 5.9 and later.
492 **
493 ** There is a macro in config.h that make translates calls to
494 ** "fossil_pledge(A,B)" into calls to this routine on OpenBSD.
495 ** On all other platforms, this routine does not exist.
496 */
497 void fossil_pledge_impl(const char *promises, const char *execpromises){
498 if( pledge(promises, execpromises) ){
499 fossil_fatal("pledge(\"%s\",\"%s\") fails with errno=%d",
500 promises, execpromises, (int)errno);
501 }
502 }
503 #endif /* defined(__OpenBSD__) */
504

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button