summaryrefslogtreecommitdiff
path: root/nix/nix-daemon
diff options
context:
space:
mode:
Diffstat (limited to 'nix/nix-daemon')
-rw-r--r--nix/nix-daemon/guix-daemon.cc47
-rw-r--r--nix/nix-daemon/nix-daemon.cc25
2 files changed, 36 insertions, 36 deletions
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
index 30727d5559..af09839932 100644
--- a/nix/nix-daemon/guix-daemon.cc
+++ b/nix/nix-daemon/guix-daemon.cc
@@ -37,6 +37,7 @@
#include <strings.h>
#include <exception>
#include <iostream>
+#include <format>
#include <libintl.h>
#include <locale.h>
@@ -187,7 +188,7 @@ string_to_bool (const char *arg, bool dflt = true)
else if (strcasecmp (arg, "no") == 0)
return false;
else
- throw nix::Error (format ("'%1%': invalid Boolean value") % arg);
+ throw nix::Error(std::format("'{}': invalid Boolean value", arg));
}
/* Parse a single option. */
@@ -201,10 +202,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
break;
case GUIX_OPT_CHROOT_DIR:
{
- std::string chroot_dirs;
+ std::string chroot_dirs {settings.get("build-extra-chroot-dirs", "")};
- chroot_dirs = settings.get ("build-extra-chroot-dirs",
- (std::string) "");
if (chroot_dirs == "")
chroot_dirs = arg;
else
@@ -337,7 +336,8 @@ open_unix_domain_socket (const char *file)
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
if (fileRel.size () >= sizeof (addr.sun_path))
- throw Error (format (_("socket file name '%1%' is too long")) % fileRel);
+ throw Error (std::vformat( (_("socket file name '%1%' is too long")),
+ std::make_format_args(fileRel)));
strcpy (addr.sun_path, fileRel.c_str ());
unlink (file);
@@ -349,13 +349,15 @@ open_unix_domain_socket (const char *file)
int res = bind (fdSocket, (struct sockaddr *) &addr, sizeof addr);
umask (oldMode);
if (res == -1)
- throw SysError (format (_("cannot bind to socket '%1%'")) % file);
+ throw SysError (std::vformat( (_("cannot bind to socket '{}'")),
+ std::make_format_args(file)));
if (chdir ("/") == -1) /* back to the root */
throw SysError (_("cannot change current directory"));
if (listen (fdSocket, 5) == -1)
- throw SysError (format (_("cannot listen on socket '%1%'")) % file);
+ throw SysError (std::vformat( (_("cannot listen on socket '{}'")),
+ std::make_format_args(file)));
return fdSocket.borrow ();
}
@@ -373,7 +375,7 @@ open_inet_socket (const struct sockaddr *address, socklen_t length)
throw SysError (_("cannot bind TCP socket"));
if (listen (fd, 5) == -1)
- throw SysError (format (_("cannot listen on TCP socket")));
+ throw SysError (_("cannot listen on TCP socket"));
return fd.borrow ();
}
@@ -423,11 +425,9 @@ listening_sockets (const std::list<std::string> &options)
&hints, &res);
if (err != 0)
- throw Error(format ("failed to look up '%1%': %2%")
- % option % gai_strerror (err));
+ throw Error(std::format("failed to look up '{}': {}", option, gai_strerror(err)));
- printMsg (lvlDebug, format ("listening on '%1%', port '%2%'")
- % host % port);
+ printMsg(lvlDebug, std::format("listening on '{}', port '{}'", host, port));
/* XXX: Pick the first result, RES. */
result.push_back (open_inet_socket (res->ai_addr,
@@ -530,17 +530,19 @@ main (int argc, char *argv[])
/* We were not "socket-activated" so open the sockets specified by
LISTEN_OPTIONS. */
sockets = listening_sockets (listen_options);
- else
- printMsg (lvlInfo,
- format (ngettext ("socket-activated with %1% socket",
- "socket-activated with %1% sockets",
- sockets.size ()))
- % sockets.size ());
+ else {
+ auto size = sockets.size();
+ printMsg (lvlInfo,
+ std::vformat((ngettext ("socket-activated with %1% socket",
+ "socket-activated with %1% sockets",
+ size)),
+ std::make_format_args(size)));
+ }
/* Effect all the changes made via 'settings.set'. */
settings.update ();
printMsg(lvlDebug,
- format ("build log compression: %1%") % settings.logCompression);
+ std::format("build log compression: {}", int(settings.logCompression)));
if (geteuid () == 0 && settings.buildUsersGroup.empty ())
fprintf (stderr, _("warning: daemon is running as root, so \
@@ -553,7 +555,7 @@ using `--build-users-group' is highly recommended\n"));
chroot_dirs = settings.get ("build-extra-chroot-dirs",
(std::string) "");
printMsg (lvlDebug,
- format ("extra chroot directories: '%1%'") % chroot_dirs);
+ std::format("extra chroot directories: '{}'", chroot_dirs));
}
if (useDiscover)
@@ -568,9 +570,8 @@ using `--build-users-group' is highly recommended\n"));
});
}
- printMsg (lvlDebug,
- format ("automatic deduplication set to %1%")
- % settings.autoOptimiseStore);
+ printMsg(lvlDebug,
+ std::format("automatic deduplication set to {}", settings.autoOptimiseStore));
run (sockets);
}
diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc
index f2ffe8fa6f..3890adb2c7 100644
--- a/nix/nix-daemon/nix-daemon.cc
+++ b/nix/nix-daemon/nix-daemon.cc
@@ -10,8 +10,10 @@
#include "builtins.hh"
#include <algorithm>
+#include <format>
#include <cstring>
+#include <cassert>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
@@ -640,7 +642,7 @@ static void performOp(bool trusted, unsigned int clientVersion,
if (pw != NULL)
store->createUser(value, pw->pw_uid);
else
- printMsg(lvlInfo, format("user name %1% not found") % value);
+ printMsg(lvlInfo, std::format("user name {} not found", value));
}
else
settings.set(trusted ? name : "untrusted-" + name, value);
@@ -772,7 +774,7 @@ static void performOp(bool trusted, unsigned int clientVersion,
}
default:
- throw Error(format("invalid operation %1%") % op);
+ throw Error(std::format("invalid operation {}", op));
}
}
@@ -834,7 +836,7 @@ static void processConnection(bool trusted, uid_t userId)
if (pw != NULL && pw->pw_name != NULL)
store->createUser(pw->pw_name, userId);
else
- printMsg(lvlInfo, format("user with UID %1% not found") % userId);
+ printMsg(lvlInfo, std::format("user with UID {} not found", userId));
}
stopWork();
@@ -882,7 +884,7 @@ static void processConnection(bool trusted, uid_t userId)
canSendStderr = false;
_isInterrupted = false;
- printMsg(lvlDebug, format("%1% operations") % opCount);
+ printMsg(lvlDebug, std::format("{} operations", opCount));
}
@@ -971,9 +973,8 @@ static void acceptConnection(int fdSocket)
struct passwd * pw = getpwuid(cred.uid);
string user = pw ? pw->pw_name : std::to_string(cred.uid);
- printMsg(lvlInfo,
- format((string) "accepted connection from pid %1%, user %2%")
- % clientPid % user);
+ printMsg(lvlInfo, std::format("accepted connection from pid {}, user {}",
+ clientPid, user));
#endif
} else {
char address_str[128];
@@ -992,9 +993,7 @@ static void acceptConnection(int fdSocket)
}
if (result != NULL) {
- printMsg(lvlInfo,
- format("accepted connection from %1%")
- % address_str);
+ printMsg(lvlInfo, std::format("accepted connection from {}", address_str));
}
}
@@ -1004,7 +1003,7 @@ static void acceptConnection(int fdSocket)
/* Background the daemon. */
if (setsid() == -1)
- throw SysError(format("creating a new session"));
+ throw SysError("creating a new session");
/* Restore normal handling of SIGCHLD. */
setSigChldAction(false);
@@ -1033,7 +1032,7 @@ static void acceptConnection(int fdSocket)
} catch (Interrupted & e) {
throw;
} catch (Error & e) {
- printMsg(lvlError, format("error processing connection: %1%") % e.msg());
+ printMsg(lvlError, std::format("error processing connection: {}", e.msg()));
}
}
@@ -1072,7 +1071,7 @@ static void daemonLoop(const std::vector<int>& sockets)
int err = errno;
if (err == EINTR)
continue;
- throw SysError(format("select error: %1%") % strerror(err));
+ throw SysError(std::format("select error: {}", strerror(err)));
}
for (unsigned int i = 0; i < sockets.size(); i++) {