diff options
| author | Congcong Kuo <congcong.kuo@gmail.com> | 2025-07-21 11:02:40 +0800 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-10-19 21:29:39 +0200 |
| commit | 3af52f845fe2ceb448416ac7b9f48925673c594e (patch) | |
| tree | c8623599d15363a8e760adf1ad9dd01477ceabd7 /nix/nix-daemon | |
| parent | cbda925613b2962db8c6dbb2ea3dda7e3b433611 (diff) | |
daemon: Bump to C++20 and use ‘std::format’ instead of ‘boost::format’.
* nix/boost: This directory and all files inside it are removed.
* nix/libstore/build.cc (Goal::trace): Use ‘std::string’ instead of ‘const format &’.
(DerivationGoal::startBuilder, ...): Use ‘std::format’ or ‘std::vformat’ instead of ‘boost::format’.
* nix/libstore/builtins.cc (builtinDownload): Same.
* nix/libstore/derivations.cc (DerivationOutput::parseHashInfo, ...): Same.
* nix/libstore/gc.cc (LocalStore::openGCLock, ...): Same.
* nix/libstore/globals.cc (Settings::_get): Same.
* nix/libstore/local-store.cc: (checkStoreNotSymlink, ...): Same.
* nix/libstore/misc.cc (dfsVisit, showBytes): Same
* nix/libstore/optimise-store.cc (makeWritable, ...): Same.
* nix/libstore/pathlocks.cc (openLockFile, ...): Same.
* nix/libstore/references.cc (search, scanForReferences): Same.
* nix/libstore/sqlite.hh (throwSQLiteError): Use ‘std::string’ instead of ‘const format &’.
* nix/libstore/sqlite.cc (throwSQLiteError): Use ‘std::string’ instead of ‘const format &’.
* nix/libstore/store-api.cc (assertStorePath, ...): Use ‘std::format’ instead of ‘boost::format’.
* nix/libutil/affinity.cc (setAffinityTo): Same.
* nix/libutil/archive.cc (dumpContents, ...): Same.
* nix/libutil/hash.cc (parseHash, parseHash32, parseHash16or32, hashFile): Same.
* nix/libutil/hash.hh (parseHash, parseHash32, parseHash16or32, isHash): Same.
* nix/libutil/serialise.cc : Add ‘<cassert>’ header file.
* nix/libutil/spawn.cc (addPhaseAfter, ...): Use ‘std::format’ instead of ‘boost::format’.
* nix/libutil/types.hh (FormatOrString): Removed.
(BaseError, BaseError::addPrefix, SysError, MakeError):
Use ‘std::string or std::string_view’ instead of ‘FormatOrString’.
* nix/libutil/util.hh (Nest::open, printMsg_, warnOnce, expect): Same.
* nix/libutil/util.cc (BaseError::BaseError, ...): Same.
(writeToStderr, _interrupted): Use std::uncaught_exceptions() instead of std::uncaught_exception()
* nix/nix-daemon/nix-daemon.cc (performOp, ...): Same.
* nix/nix-daemon/guix-daemon.cc (string_to_bool, ...): Same.
* nix/local.mk: Remove ‘libformat.a’ from ‘noinst_LIBRARIES’,
remove ‘libformat_a_SOURCES’ and ‘libformat_headers’,
remove ‘libformat_a_CPPFLAGS’ from ‘libutil_a_CPPFLAGS’ and ‘guix_daemon_LDADD’,
update ‘AM_CXXFLAGS’ to ‘-std=c++20’.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'nix/nix-daemon')
| -rw-r--r-- | nix/nix-daemon/guix-daemon.cc | 47 | ||||
| -rw-r--r-- | nix/nix-daemon/nix-daemon.cc | 25 |
2 files changed, 36 insertions, 36 deletions
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc index 30727d55593..af09839932f 100644 --- a/nix/nix-daemon/guix-daemon.cc +++ b/nix/nix-daemon/guix-daemon.cc | |||
| @@ -37,6 +37,7 @@ | |||
| 37 | #include <strings.h> | 37 | #include <strings.h> |
| 38 | #include <exception> | 38 | #include <exception> |
| 39 | #include <iostream> | 39 | #include <iostream> |
| 40 | #include <format> | ||
| 40 | 41 | ||
| 41 | #include <libintl.h> | 42 | #include <libintl.h> |
| 42 | #include <locale.h> | 43 | #include <locale.h> |
| @@ -187,7 +188,7 @@ string_to_bool (const char *arg, bool dflt = true) | |||
| 187 | else if (strcasecmp (arg, "no") == 0) | 188 | else if (strcasecmp (arg, "no") == 0) |
| 188 | return false; | 189 | return false; |
| 189 | else | 190 | else |
| 190 | throw nix::Error (format ("'%1%': invalid Boolean value") % arg); | 191 | throw nix::Error(std::format("'{}': invalid Boolean value", arg)); |
| 191 | } | 192 | } |
| 192 | 193 | ||
| 193 | /* Parse a single option. */ | 194 | /* Parse a single option. */ |
| @@ -201,10 +202,8 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
| 201 | break; | 202 | break; |
| 202 | case GUIX_OPT_CHROOT_DIR: | 203 | case GUIX_OPT_CHROOT_DIR: |
| 203 | { | 204 | { |
| 204 | std::string chroot_dirs; | 205 | std::string chroot_dirs {settings.get("build-extra-chroot-dirs", "")}; |
| 205 | 206 | ||
| 206 | chroot_dirs = settings.get ("build-extra-chroot-dirs", | ||
| 207 | (std::string) ""); | ||
| 208 | if (chroot_dirs == "") | 207 | if (chroot_dirs == "") |
| 209 | chroot_dirs = arg; | 208 | chroot_dirs = arg; |
| 210 | else | 209 | else |
| @@ -337,7 +336,8 @@ open_unix_domain_socket (const char *file) | |||
| 337 | struct sockaddr_un addr; | 336 | struct sockaddr_un addr; |
| 338 | addr.sun_family = AF_UNIX; | 337 | addr.sun_family = AF_UNIX; |
| 339 | if (fileRel.size () >= sizeof (addr.sun_path)) | 338 | if (fileRel.size () >= sizeof (addr.sun_path)) |
| 340 | throw Error (format (_("socket file name '%1%' is too long")) % fileRel); | 339 | throw Error (std::vformat( (_("socket file name '%1%' is too long")), |
| 340 | std::make_format_args(fileRel))); | ||
| 341 | strcpy (addr.sun_path, fileRel.c_str ()); | 341 | strcpy (addr.sun_path, fileRel.c_str ()); |
| 342 | 342 | ||
| 343 | unlink (file); | 343 | unlink (file); |
| @@ -349,13 +349,15 @@ open_unix_domain_socket (const char *file) | |||
| 349 | int res = bind (fdSocket, (struct sockaddr *) &addr, sizeof addr); | 349 | int res = bind (fdSocket, (struct sockaddr *) &addr, sizeof addr); |
| 350 | umask (oldMode); | 350 | umask (oldMode); |
| 351 | if (res == -1) | 351 | if (res == -1) |
| 352 | throw SysError (format (_("cannot bind to socket '%1%'")) % file); | 352 | throw SysError (std::vformat( (_("cannot bind to socket '{}'")), |
| 353 | std::make_format_args(file))); | ||
| 353 | 354 | ||
| 354 | if (chdir ("/") == -1) /* back to the root */ | 355 | if (chdir ("/") == -1) /* back to the root */ |
| 355 | throw SysError (_("cannot change current directory")); | 356 | throw SysError (_("cannot change current directory")); |
| 356 | 357 | ||
| 357 | if (listen (fdSocket, 5) == -1) | 358 | if (listen (fdSocket, 5) == -1) |
| 358 | throw SysError (format (_("cannot listen on socket '%1%'")) % file); | 359 | throw SysError (std::vformat( (_("cannot listen on socket '{}'")), |
| 360 | std::make_format_args(file))); | ||
| 359 | 361 | ||
| 360 | return fdSocket.borrow (); | 362 | return fdSocket.borrow (); |
| 361 | } | 363 | } |
| @@ -373,7 +375,7 @@ open_inet_socket (const struct sockaddr *address, socklen_t length) | |||
| 373 | throw SysError (_("cannot bind TCP socket")); | 375 | throw SysError (_("cannot bind TCP socket")); |
| 374 | 376 | ||
| 375 | if (listen (fd, 5) == -1) | 377 | if (listen (fd, 5) == -1) |
| 376 | throw SysError (format (_("cannot listen on TCP socket"))); | 378 | throw SysError (_("cannot listen on TCP socket")); |
| 377 | 379 | ||
| 378 | return fd.borrow (); | 380 | return fd.borrow (); |
| 379 | } | 381 | } |
| @@ -423,11 +425,9 @@ listening_sockets (const std::list<std::string> &options) | |||
| 423 | &hints, &res); | 425 | &hints, &res); |
| 424 | 426 | ||
| 425 | if (err != 0) | 427 | if (err != 0) |
| 426 | throw Error(format ("failed to look up '%1%': %2%") | 428 | throw Error(std::format("failed to look up '{}': {}", option, gai_strerror(err))); |
| 427 | % option % gai_strerror (err)); | ||
| 428 | 429 | ||
| 429 | printMsg (lvlDebug, format ("listening on '%1%', port '%2%'") | 430 | printMsg(lvlDebug, std::format("listening on '{}', port '{}'", host, port)); |
| 430 | % host % port); | ||
| 431 | 431 | ||
| 432 | /* XXX: Pick the first result, RES. */ | 432 | /* XXX: Pick the first result, RES. */ |
| 433 | result.push_back (open_inet_socket (res->ai_addr, | 433 | result.push_back (open_inet_socket (res->ai_addr, |
| @@ -530,17 +530,19 @@ main (int argc, char *argv[]) | |||
| 530 | /* We were not "socket-activated" so open the sockets specified by | 530 | /* We were not "socket-activated" so open the sockets specified by |
| 531 | LISTEN_OPTIONS. */ | 531 | LISTEN_OPTIONS. */ |
| 532 | sockets = listening_sockets (listen_options); | 532 | sockets = listening_sockets (listen_options); |
| 533 | else | 533 | else { |
| 534 | printMsg (lvlInfo, | 534 | auto size = sockets.size(); |
| 535 | format (ngettext ("socket-activated with %1% socket", | 535 | printMsg (lvlInfo, |
| 536 | "socket-activated with %1% sockets", | 536 | std::vformat((ngettext ("socket-activated with %1% socket", |
| 537 | sockets.size ())) | 537 | "socket-activated with %1% sockets", |
| 538 | % sockets.size ()); | 538 | size)), |
| 539 | std::make_format_args(size))); | ||
| 540 | } | ||
| 539 | 541 | ||
| 540 | /* Effect all the changes made via 'settings.set'. */ | 542 | /* Effect all the changes made via 'settings.set'. */ |
| 541 | settings.update (); | 543 | settings.update (); |
| 542 | printMsg(lvlDebug, | 544 | printMsg(lvlDebug, |
| 543 | format ("build log compression: %1%") % settings.logCompression); | 545 | std::format("build log compression: {}", int(settings.logCompression))); |
| 544 | 546 | ||
| 545 | if (geteuid () == 0 && settings.buildUsersGroup.empty ()) | 547 | if (geteuid () == 0 && settings.buildUsersGroup.empty ()) |
| 546 | fprintf (stderr, _("warning: daemon is running as root, so \ | 548 | fprintf (stderr, _("warning: daemon is running as root, so \ |
| @@ -553,7 +555,7 @@ using `--build-users-group' is highly recommended\n")); | |||
| 553 | chroot_dirs = settings.get ("build-extra-chroot-dirs", | 555 | chroot_dirs = settings.get ("build-extra-chroot-dirs", |
| 554 | (std::string) ""); | 556 | (std::string) ""); |
| 555 | printMsg (lvlDebug, | 557 | printMsg (lvlDebug, |
| 556 | format ("extra chroot directories: '%1%'") % chroot_dirs); | 558 | std::format("extra chroot directories: '{}'", chroot_dirs)); |
| 557 | } | 559 | } |
| 558 | 560 | ||
| 559 | if (useDiscover) | 561 | if (useDiscover) |
| @@ -568,9 +570,8 @@ using `--build-users-group' is highly recommended\n")); | |||
| 568 | }); | 570 | }); |
| 569 | } | 571 | } |
| 570 | 572 | ||
| 571 | printMsg (lvlDebug, | 573 | printMsg(lvlDebug, |
| 572 | format ("automatic deduplication set to %1%") | 574 | std::format("automatic deduplication set to {}", settings.autoOptimiseStore)); |
| 573 | % settings.autoOptimiseStore); | ||
| 574 | 575 | ||
| 575 | run (sockets); | 576 | run (sockets); |
| 576 | } | 577 | } |
diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc index f2ffe8fa6f8..3890adb2c74 100644 --- a/nix/nix-daemon/nix-daemon.cc +++ b/nix/nix-daemon/nix-daemon.cc | |||
| @@ -10,8 +10,10 @@ | |||
| 10 | #include "builtins.hh" | 10 | #include "builtins.hh" |
| 11 | 11 | ||
| 12 | #include <algorithm> | 12 | #include <algorithm> |
| 13 | #include <format> | ||
| 13 | 14 | ||
| 14 | #include <cstring> | 15 | #include <cstring> |
| 16 | #include <cassert> | ||
| 15 | #include <unistd.h> | 17 | #include <unistd.h> |
| 16 | #include <signal.h> | 18 | #include <signal.h> |
| 17 | #include <sys/types.h> | 19 | #include <sys/types.h> |
| @@ -640,7 +642,7 @@ static void performOp(bool trusted, unsigned int clientVersion, | |||
| 640 | if (pw != NULL) | 642 | if (pw != NULL) |
| 641 | store->createUser(value, pw->pw_uid); | 643 | store->createUser(value, pw->pw_uid); |
| 642 | else | 644 | else |
| 643 | printMsg(lvlInfo, format("user name %1% not found") % value); | 645 | printMsg(lvlInfo, std::format("user name {} not found", value)); |
| 644 | } | 646 | } |
| 645 | else | 647 | else |
| 646 | settings.set(trusted ? name : "untrusted-" + name, value); | 648 | settings.set(trusted ? name : "untrusted-" + name, value); |
| @@ -772,7 +774,7 @@ static void performOp(bool trusted, unsigned int clientVersion, | |||
| 772 | } | 774 | } |
| 773 | 775 | ||
| 774 | default: | 776 | default: |
| 775 | throw Error(format("invalid operation %1%") % op); | 777 | throw Error(std::format("invalid operation {}", op)); |
| 776 | } | 778 | } |
| 777 | } | 779 | } |
| 778 | 780 | ||
| @@ -834,7 +836,7 @@ static void processConnection(bool trusted, uid_t userId) | |||
| 834 | if (pw != NULL && pw->pw_name != NULL) | 836 | if (pw != NULL && pw->pw_name != NULL) |
| 835 | store->createUser(pw->pw_name, userId); | 837 | store->createUser(pw->pw_name, userId); |
| 836 | else | 838 | else |
| 837 | printMsg(lvlInfo, format("user with UID %1% not found") % userId); | 839 | printMsg(lvlInfo, std::format("user with UID {} not found", userId)); |
| 838 | } | 840 | } |
| 839 | 841 | ||
| 840 | stopWork(); | 842 | stopWork(); |
| @@ -882,7 +884,7 @@ static void processConnection(bool trusted, uid_t userId) | |||
| 882 | 884 | ||
| 883 | canSendStderr = false; | 885 | canSendStderr = false; |
| 884 | _isInterrupted = false; | 886 | _isInterrupted = false; |
| 885 | printMsg(lvlDebug, format("%1% operations") % opCount); | 887 | printMsg(lvlDebug, std::format("{} operations", opCount)); |
| 886 | } | 888 | } |
| 887 | 889 | ||
| 888 | 890 | ||
| @@ -971,9 +973,8 @@ static void acceptConnection(int fdSocket) | |||
| 971 | struct passwd * pw = getpwuid(cred.uid); | 973 | struct passwd * pw = getpwuid(cred.uid); |
| 972 | string user = pw ? pw->pw_name : std::to_string(cred.uid); | 974 | string user = pw ? pw->pw_name : std::to_string(cred.uid); |
| 973 | 975 | ||
| 974 | printMsg(lvlInfo, | 976 | printMsg(lvlInfo, std::format("accepted connection from pid {}, user {}", |
| 975 | format((string) "accepted connection from pid %1%, user %2%") | 977 | clientPid, user)); |
| 976 | % clientPid % user); | ||
| 977 | #endif | 978 | #endif |
| 978 | } else { | 979 | } else { |
| 979 | char address_str[128]; | 980 | char address_str[128]; |
| @@ -992,9 +993,7 @@ static void acceptConnection(int fdSocket) | |||
| 992 | } | 993 | } |
| 993 | 994 | ||
| 994 | if (result != NULL) { | 995 | if (result != NULL) { |
| 995 | printMsg(lvlInfo, | 996 | printMsg(lvlInfo, std::format("accepted connection from {}", address_str)); |
| 996 | format("accepted connection from %1%") | ||
| 997 | % address_str); | ||
| 998 | } | 997 | } |
| 999 | } | 998 | } |
| 1000 | 999 | ||
| @@ -1004,7 +1003,7 @@ static void acceptConnection(int fdSocket) | |||
| 1004 | 1003 | ||
| 1005 | /* Background the daemon. */ | 1004 | /* Background the daemon. */ |
| 1006 | if (setsid() == -1) | 1005 | if (setsid() == -1) |
| 1007 | throw SysError(format("creating a new session")); | 1006 | throw SysError("creating a new session"); |
| 1008 | 1007 | ||
| 1009 | /* Restore normal handling of SIGCHLD. */ | 1008 | /* Restore normal handling of SIGCHLD. */ |
| 1010 | setSigChldAction(false); | 1009 | setSigChldAction(false); |
| @@ -1033,7 +1032,7 @@ static void acceptConnection(int fdSocket) | |||
| 1033 | } catch (Interrupted & e) { | 1032 | } catch (Interrupted & e) { |
| 1034 | throw; | 1033 | throw; |
| 1035 | } catch (Error & e) { | 1034 | } catch (Error & e) { |
| 1036 | printMsg(lvlError, format("error processing connection: %1%") % e.msg()); | 1035 | printMsg(lvlError, std::format("error processing connection: {}", e.msg())); |
| 1037 | } | 1036 | } |
| 1038 | } | 1037 | } |
| 1039 | 1038 | ||
| @@ -1072,7 +1071,7 @@ static void daemonLoop(const std::vector<int>& sockets) | |||
| 1072 | int err = errno; | 1071 | int err = errno; |
| 1073 | if (err == EINTR) | 1072 | if (err == EINTR) |
| 1074 | continue; | 1073 | continue; |
| 1075 | throw SysError(format("select error: %1%") % strerror(err)); | 1074 | throw SysError(std::format("select error: {}", strerror(err))); |
| 1076 | } | 1075 | } |
| 1077 | 1076 | ||
| 1078 | for (unsigned int i = 0; i < sockets.size(); i++) { | 1077 | for (unsigned int i = 0; i < sockets.size(); i++) { |
