Fossil SCM
Add the fossil_pledge() utility routine, that is a no-op unless compiled with FOSSIL_HAVE_PLEDGE.
Commit
7b81a9993b4c8192b75940c093bfe7ba3d3c51abd92af750828ea9b7619ae154
Parent
39b4368682acf2e…
3 files changed
+2
+12
+16
+2
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -471,10 +471,12 @@ | ||
| 471 | 471 | int verboseFlag = command==CHANGES && find_option("verbose", "v", 0); |
| 472 | 472 | const char *zIgnoreFlag = find_option("ignore", 0, 1); |
| 473 | 473 | unsigned scanFlags = 0; |
| 474 | 474 | unsigned flags = 0; |
| 475 | 475 | int vid, i; |
| 476 | + | |
| 477 | + fossil_pledge("stdio rpath wpath cpath id flock tty", ""); | |
| 476 | 478 | |
| 477 | 479 | /* Load affirmative flag options. */ |
| 478 | 480 | for( i=0; i<count(flagDefs); ++i ){ |
| 479 | 481 | if( (command==CHANGES || !(flagDefs[i].mask & C_CLASSIFY)) |
| 480 | 482 | && find_option(flagDefs[i].option, 0, 0) ){ |
| 481 | 483 |
| --- 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 @@ | ||
| 253 | 253 | |
| 254 | 254 | /* |
| 255 | 255 | ** Number of elements in an array |
| 256 | 256 | */ |
| 257 | 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 | + | |
| 258 | 270 | |
| 259 | 271 | #endif /* _RC_COMPILE_ */ |
| 260 | 272 |
| --- 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 @@ | ||
| 483 | 483 | } |
| 484 | 484 | setrlimit(RLIMIT_STACK, &x); |
| 485 | 485 | #endif /* defined(RLIMIT_STACK) */ |
| 486 | 486 | #endif /* defined(__unix__) */ |
| 487 | 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__) */ | |
| 488 | 504 |
| --- 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 |