diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2025-06-26 12:12:29 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-10-16 15:14:37 +0200 |
| commit | d1910384d3581dcbc564353a098089d1a52c08d6 (patch) | |
| tree | 9a34ab5d84323b2bb8d166d62d17901871181eed /nix/libutil/spawn.cc | |
| parent | c7b8f3ec1a25a31bc08e74910a5632c766da4971 (diff) | |
daemon: Export as little as needed from libutil/spawn.cc.
* nix/libutil/spawn.cc (reset_writeToStderrAction, restoreAffinityAction)
(setsidAction, earlyIOSetupAction, dropAmbientCapabilitiesAction)
(chrootAction, chdirAction, closeMostFDsAction, setPersonalityAction)
(oomSacrificeAction, setIDsAction, setNoNewPrivsAction)
(addSeccompFilterAction, restoreSIGPIPEAction, setupSuccessAction)
(usernsInitSyncAction, usernsSetIDsAction, initLoopbackAction)
(setHostAndDomainAction, makeFilesystemsPrivateAction)
(makeChrootSeparateFilesystemAction, bindMount)
(mountIntoChroot, mountIntoChrootAction, mountProcAction)
(mountDevshmAction, mountDevptsAction, pivotRootAction)
(idMapToIdentityMap, lockMountsAction, runChildSetupEntry): Add ‘static’
qualifier.
* nix/libutil/spawn.hh: Remove the corresponding ‘extern’ declarations.
Change-Id: I3156d72d866f22fa31aa9a843f116771763ccb61
Diffstat (limited to 'nix/libutil/spawn.cc')
| -rw-r--r-- | nix/libutil/spawn.cc | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/nix/libutil/spawn.cc b/nix/libutil/spawn.cc index d3f4e5bf19a..7855275494f 100644 --- a/nix/libutil/spawn.cc +++ b/nix/libutil/spawn.cc | |||
| @@ -144,19 +144,19 @@ void replacePhase(Phases & phases, string replaceLabel, Action newAction) | |||
| 144 | 144 | ||
| 145 | /* A curated selection of predefined actions */ | 145 | /* A curated selection of predefined actions */ |
| 146 | 146 | ||
| 147 | void reset_writeToStderrAction(SpawnContext & ctx) | 147 | static void reset_writeToStderrAction(SpawnContext & ctx) |
| 148 | { | 148 | { |
| 149 | _writeToStderr = 0; | 149 | _writeToStderr = 0; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | 152 | ||
| 153 | void restoreAffinityAction(SpawnContext & ctx) | 153 | static void restoreAffinityAction(SpawnContext & ctx) |
| 154 | { | 154 | { |
| 155 | restoreAffinity(); | 155 | restoreAffinity(); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | 158 | ||
| 159 | void setsidAction(SpawnContext & ctx) | 159 | static void setsidAction(SpawnContext & ctx) |
| 160 | { | 160 | { |
| 161 | /* Puts the current process in a separate session, which implies a | 161 | /* Puts the current process in a separate session, which implies a |
| 162 | separate process group, so it doesn't receive group-directed signals | 162 | separate process group, so it doesn't receive group-directed signals |
| @@ -168,7 +168,7 @@ void setsidAction(SpawnContext & ctx) | |||
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | 170 | ||
| 171 | void earlyIOSetupAction(SpawnContext & ctx) | 171 | static void earlyIOSetupAction(SpawnContext & ctx) |
| 172 | { | 172 | { |
| 173 | for(auto i = ctx.earlyCloseFDs.begin(); i != ctx.earlyCloseFDs.end(); i++) | 173 | for(auto i = ctx.earlyCloseFDs.begin(); i != ctx.earlyCloseFDs.end(); i++) |
| 174 | if(close(*i) == -1) | 174 | if(close(*i) == -1) |
| @@ -198,7 +198,7 @@ void earlyIOSetupAction(SpawnContext & ctx) | |||
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | 200 | ||
| 201 | void dropAmbientCapabilitiesAction(SpawnContext & ctx) | 201 | static void dropAmbientCapabilitiesAction(SpawnContext & ctx) |
| 202 | { | 202 | { |
| 203 | /* Drop ambient capabilities such as CAP_CHOWN that might have been granted | 203 | /* Drop ambient capabilities such as CAP_CHOWN that might have been granted |
| 204 | when starting guix-daemon. */ | 204 | when starting guix-daemon. */ |
| @@ -211,7 +211,7 @@ void dropAmbientCapabilitiesAction(SpawnContext & ctx) | |||
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | 213 | ||
| 214 | void chrootAction(SpawnContext & ctx) | 214 | static void chrootAction(SpawnContext & ctx) |
| 215 | { | 215 | { |
| 216 | if(ctx.doChroot) | 216 | if(ctx.doChroot) |
| 217 | #if HAVE_CHROOT | 217 | #if HAVE_CHROOT |
| @@ -223,7 +223,7 @@ void chrootAction(SpawnContext & ctx) | |||
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | 225 | ||
| 226 | void chdirAction(SpawnContext & ctx) | 226 | static void chdirAction(SpawnContext & ctx) |
| 227 | { | 227 | { |
| 228 | if(ctx.setcwd) | 228 | if(ctx.setcwd) |
| 229 | if(chdir(ctx.cwd.c_str()) == -1) | 229 | if(chdir(ctx.cwd.c_str()) == -1) |
| @@ -231,7 +231,7 @@ void chdirAction(SpawnContext & ctx) | |||
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | 233 | ||
| 234 | void closeMostFDsAction(SpawnContext & ctx) | 234 | static void closeMostFDsAction(SpawnContext & ctx) |
| 235 | { | 235 | { |
| 236 | if(ctx.closeMostFDs) closeMostFDs(ctx.preserveFDs); | 236 | if(ctx.closeMostFDs) closeMostFDs(ctx.preserveFDs); |
| 237 | for(auto i = ctx.preserveFDs.begin(); i != ctx.preserveFDs.end(); i++) | 237 | for(auto i = ctx.preserveFDs.begin(); i != ctx.preserveFDs.end(); i++) |
| @@ -239,7 +239,7 @@ void closeMostFDsAction(SpawnContext & ctx) | |||
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | 241 | ||
| 242 | void setPersonalityAction(SpawnContext & ctx) | 242 | static void setPersonalityAction(SpawnContext & ctx) |
| 243 | { | 243 | { |
| 244 | if(ctx.setPersona) | 244 | if(ctx.setPersona) |
| 245 | #ifdef __linux__ | 245 | #ifdef __linux__ |
| @@ -251,7 +251,7 @@ void setPersonalityAction(SpawnContext & ctx) | |||
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | 253 | ||
| 254 | void oomSacrificeAction(SpawnContext & ctx) | 254 | static void oomSacrificeAction(SpawnContext & ctx) |
| 255 | { | 255 | { |
| 256 | #ifdef __linux__ | 256 | #ifdef __linux__ |
| 257 | if(ctx.oomSacrifice) | 257 | if(ctx.oomSacrifice) |
| @@ -265,7 +265,7 @@ void oomSacrificeAction(SpawnContext & ctx) | |||
| 265 | } | 265 | } |
| 266 | 266 | ||
| 267 | 267 | ||
| 268 | void setIDsAction(SpawnContext & ctx) | 268 | static void setIDsAction(SpawnContext & ctx) |
| 269 | { | 269 | { |
| 270 | if(ctx.setSupplementaryGroups) | 270 | if(ctx.setSupplementaryGroups) |
| 271 | if(setgroups(ctx.supplementaryGroups.size(), | 271 | if(setgroups(ctx.supplementaryGroups.size(), |
| @@ -285,7 +285,7 @@ void setIDsAction(SpawnContext & ctx) | |||
| 285 | throw SysError("setuid failed"); | 285 | throw SysError("setuid failed"); |
| 286 | } | 286 | } |
| 287 | 287 | ||
| 288 | void setNoNewPrivsAction(SpawnContext & ctx) | 288 | static void setNoNewPrivsAction(SpawnContext & ctx) |
| 289 | { | 289 | { |
| 290 | if(ctx.setNoNewPrivs) | 290 | if(ctx.setNoNewPrivs) |
| 291 | #if __linux__ && defined(PR_SET_NO_NEW_PRIVS) | 291 | #if __linux__ && defined(PR_SET_NO_NEW_PRIVS) |
| @@ -296,7 +296,7 @@ void setNoNewPrivsAction(SpawnContext & ctx) | |||
| 296 | #endif | 296 | #endif |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | void addSeccompFilterAction(SpawnContext & ctx) | 299 | static void addSeccompFilterAction(SpawnContext & ctx) |
| 300 | { | 300 | { |
| 301 | if(ctx.addSeccompFilter) { | 301 | if(ctx.addSeccompFilter) { |
| 302 | #if __linux__ && defined(PR_SET_SECCOMP) && defined(SECCOMP_MODE_FILTER) | 302 | #if __linux__ && defined(PR_SET_SECCOMP) && defined(SECCOMP_MODE_FILTER) |
| @@ -316,7 +316,7 @@ void addSeccompFilterAction(SpawnContext & ctx) | |||
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | 318 | ||
| 319 | void restoreSIGPIPEAction(SpawnContext & ctx) | 319 | static void restoreSIGPIPEAction(SpawnContext & ctx) |
| 320 | { | 320 | { |
| 321 | /* Restore default handling of SIGPIPE, otherwise some programs will | 321 | /* Restore default handling of SIGPIPE, otherwise some programs will |
| 322 | randomly say "Broken pipe". */ | 322 | randomly say "Broken pipe". */ |
| @@ -328,14 +328,14 @@ void restoreSIGPIPEAction(SpawnContext & ctx) | |||
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | 330 | ||
| 331 | void setupSuccessAction(SpawnContext & ctx) | 331 | static void setupSuccessAction(SpawnContext & ctx) |
| 332 | { | 332 | { |
| 333 | if(ctx.signalSetupSuccess) | 333 | if(ctx.signalSetupSuccess) |
| 334 | writeFull(STDERR_FILENO, "\n"); | 334 | writeFull(STDERR_FILENO, "\n"); |
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | 337 | ||
| 338 | void execAction(SpawnContext & ctx) | 338 | void execAction(SpawnContext & ctx) // kept public for use in 'build.cc' |
| 339 | { | 339 | { |
| 340 | Strings envStrs; | 340 | Strings envStrs; |
| 341 | std::vector<char *> envPtrs; | 341 | std::vector<char *> envPtrs; |
| @@ -378,7 +378,7 @@ Phases getBasicSpawnPhases() | |||
| 378 | } | 378 | } |
| 379 | 379 | ||
| 380 | 380 | ||
| 381 | void usernsInitSyncAction(SpawnContext & sctx) | 381 | static void usernsInitSyncAction(SpawnContext & sctx) |
| 382 | { | 382 | { |
| 383 | #if CLONE_ENABLED | 383 | #if CLONE_ENABLED |
| 384 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 384 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -397,7 +397,7 @@ void usernsInitSyncAction(SpawnContext & sctx) | |||
| 397 | } | 397 | } |
| 398 | 398 | ||
| 399 | 399 | ||
| 400 | void usernsSetIDsAction(SpawnContext & sctx) | 400 | static void usernsSetIDsAction(SpawnContext & sctx) |
| 401 | { | 401 | { |
| 402 | #if CLONE_ENABLED | 402 | #if CLONE_ENABLED |
| 403 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 403 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -420,7 +420,7 @@ void usernsSetIDsAction(SpawnContext & sctx) | |||
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | 422 | ||
| 423 | void initLoopbackAction(SpawnContext & sctx) | 423 | static void initLoopbackAction(SpawnContext & sctx) |
| 424 | { | 424 | { |
| 425 | #if CLONE_ENABLED | 425 | #if CLONE_ENABLED |
| 426 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 426 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -440,7 +440,7 @@ void initLoopbackAction(SpawnContext & sctx) | |||
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | 442 | ||
| 443 | void setHostAndDomainAction(SpawnContext & sctx) | 443 | static void setHostAndDomainAction(SpawnContext & sctx) |
| 444 | { | 444 | { |
| 445 | #if CLONE_ENABLED | 445 | #if CLONE_ENABLED |
| 446 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 446 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -456,7 +456,7 @@ void setHostAndDomainAction(SpawnContext & sctx) | |||
| 456 | } | 456 | } |
| 457 | 457 | ||
| 458 | 458 | ||
| 459 | void makeFilesystemsPrivateAction(SpawnContext & sctx) | 459 | static void makeFilesystemsPrivateAction(SpawnContext & sctx) |
| 460 | { | 460 | { |
| 461 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H && defined(MS_REC) && defined(MS_PRIVATE) | 461 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H && defined(MS_REC) && defined(MS_PRIVATE) |
| 462 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 462 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -468,7 +468,7 @@ void makeFilesystemsPrivateAction(SpawnContext & sctx) | |||
| 468 | } | 468 | } |
| 469 | 469 | ||
| 470 | 470 | ||
| 471 | void makeChrootSeparateFilesystemAction(SpawnContext & sctx) | 471 | static void makeChrootSeparateFilesystemAction(SpawnContext & sctx) |
| 472 | { | 472 | { |
| 473 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H && defined(MS_BIND) | 473 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H && defined(MS_BIND) |
| 474 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 474 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -521,7 +521,7 @@ static int statfsToMountFlags(int f_flags) | |||
| 521 | } | 521 | } |
| 522 | 522 | ||
| 523 | 523 | ||
| 524 | void bindMount(Path source, Path target, bool readOnly) | 524 | static void bindMount(Path source, Path target, bool readOnly) |
| 525 | { | 525 | { |
| 526 | #if HAVE_SYS_MOUNT_H && defined(MS_BIND) | 526 | #if HAVE_SYS_MOUNT_H && defined(MS_BIND) |
| 527 | struct stat st; | 527 | struct stat st; |
| @@ -595,9 +595,9 @@ void bindMount(Path source, Path target, bool readOnly) | |||
| 595 | } | 595 | } |
| 596 | 596 | ||
| 597 | 597 | ||
| 598 | void mountIntoChroot(std::map<Path, Path> filesInChroot, | 598 | static void mountIntoChroot(std::map<Path, Path> filesInChroot, |
| 599 | set<Path> readOnlyFiles, | 599 | set<Path> readOnlyFiles, |
| 600 | Path chrootRootDir) | 600 | Path chrootRootDir) |
| 601 | { | 601 | { |
| 602 | #if HAVE_SYS_MOUNT_H && defined(MS_BIND) | 602 | #if HAVE_SYS_MOUNT_H && defined(MS_BIND) |
| 603 | for(auto i = filesInChroot.begin(); i != filesInChroot.end(); i++) { | 603 | for(auto i = filesInChroot.begin(); i != filesInChroot.end(); i++) { |
| @@ -612,7 +612,7 @@ void mountIntoChroot(std::map<Path, Path> filesInChroot, | |||
| 612 | } | 612 | } |
| 613 | 613 | ||
| 614 | 614 | ||
| 615 | void mountIntoChrootAction(SpawnContext & sctx) | 615 | static void mountIntoChrootAction(SpawnContext & sctx) |
| 616 | { | 616 | { |
| 617 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H && defined(MS_BIND) | 617 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H && defined(MS_BIND) |
| 618 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 618 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -623,7 +623,7 @@ void mountIntoChrootAction(SpawnContext & sctx) | |||
| 623 | } | 623 | } |
| 624 | 624 | ||
| 625 | 625 | ||
| 626 | void mountProcAction(SpawnContext & sctx) | 626 | static void mountProcAction(SpawnContext & sctx) |
| 627 | { | 627 | { |
| 628 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H | 628 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H |
| 629 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 629 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -637,7 +637,7 @@ void mountProcAction(SpawnContext & sctx) | |||
| 637 | } | 637 | } |
| 638 | 638 | ||
| 639 | 639 | ||
| 640 | void mountDevshmAction(SpawnContext & sctx) | 640 | static void mountDevshmAction(SpawnContext & sctx) |
| 641 | { | 641 | { |
| 642 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H | 642 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H |
| 643 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 643 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -651,7 +651,7 @@ void mountDevshmAction(SpawnContext & sctx) | |||
| 651 | } | 651 | } |
| 652 | 652 | ||
| 653 | 653 | ||
| 654 | void mountDevptsAction(SpawnContext & sctx) | 654 | static void mountDevptsAction(SpawnContext & sctx) |
| 655 | { | 655 | { |
| 656 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H | 656 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H |
| 657 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 657 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -673,7 +673,7 @@ void mountDevptsAction(SpawnContext & sctx) | |||
| 673 | } | 673 | } |
| 674 | 674 | ||
| 675 | 675 | ||
| 676 | void pivotRootAction(SpawnContext & sctx) | 676 | static void pivotRootAction(SpawnContext & sctx) |
| 677 | { | 677 | { |
| 678 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H | 678 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H |
| 679 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 679 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -700,7 +700,7 @@ void pivotRootAction(SpawnContext & sctx) | |||
| 700 | } | 700 | } |
| 701 | 701 | ||
| 702 | 702 | ||
| 703 | string idMapToIdentityMap(const string & map) | 703 | static string idMapToIdentityMap(const string & map) |
| 704 | { | 704 | { |
| 705 | std::vector<string> mapLines = | 705 | std::vector<string> mapLines = |
| 706 | tokenizeString<std::vector<string> >(map, "\n"); | 706 | tokenizeString<std::vector<string> >(map, "\n"); |
| @@ -720,7 +720,7 @@ string idMapToIdentityMap(const string & map) | |||
| 720 | * processes in it after unshare is called. So fork a child and have it do | 720 | * processes in it after unshare is called. So fork a child and have it do |
| 721 | * the initialization. */ | 721 | * the initialization. */ |
| 722 | void unshareAndInitUserns(int flags, const string & uidMap, | 722 | void unshareAndInitUserns(int flags, const string & uidMap, |
| 723 | const string & gidMap, bool allowSetgroups) | 723 | const string & gidMap, bool allowSetgroups) |
| 724 | { | 724 | { |
| 725 | #if CLONE_ENABLED | 725 | #if CLONE_ENABLED |
| 726 | pid_t pid_ = getpid(); | 726 | pid_t pid_ = getpid(); |
| @@ -767,7 +767,7 @@ void unshareAndInitUserns(int flags, const string & uidMap, | |||
| 767 | } | 767 | } |
| 768 | 768 | ||
| 769 | 769 | ||
| 770 | void lockMountsAction(SpawnContext & sctx) | 770 | static void lockMountsAction(SpawnContext & sctx) |
| 771 | { | 771 | { |
| 772 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H | 772 | #if CLONE_ENABLED && HAVE_SYS_MOUNT_H |
| 773 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; | 773 | CloneSpawnContext & ctx = (CloneSpawnContext &) sctx; |
| @@ -868,7 +868,7 @@ void runChildSetup(SpawnContext & ctx) | |||
| 868 | } | 868 | } |
| 869 | 869 | ||
| 870 | 870 | ||
| 871 | int runChildSetupEntry(void *data) | 871 | static int runChildSetupEntry(void *data) |
| 872 | { | 872 | { |
| 873 | runChildSetup(* (SpawnContext *)data); | 873 | runChildSetup(* (SpawnContext *)data); |
| 874 | return 1; | 874 | return 1; |
