From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 0AC3B5A026D for ; Thu, 16 Feb 2023 06:43:21 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PHP4K6zckz4x8K; Thu, 16 Feb 2023 16:43:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676526193; bh=JVJ8UwB7Mxa0BaIPRCCr+qvmkdY8mPPbvD0U/kKZIj4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S9uHxZUvVgYZz/X4RzWmCSoN7uhCTxQzik7p4u4ZFko35GY9j48UK1BARW7mJFNym GGu0kNOZ0LpRGZgjIHpDMBdkifasqQRpS7vG/chzufAhjGnecwg/tfoujHCUkIYe04 61ijDKO3S81kHsM6BRvRIZh7axroelzAAqU0Z9Ys= Date: Thu, 16 Feb 2023 16:40:39 +1100 From: David Gibson To: Laine Stump Subject: Re: [PATCH v4 9/9] convert all remaining err() followed by exit() to die() Message-ID: References: <20230215082437.110151-1-laine@redhat.com> <20230215082437.110151-10-laine@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="AmmG2KRcnT4PTAIS" Content-Disposition: inline In-Reply-To: <20230215082437.110151-10-laine@redhat.com> Message-ID-Hash: UF7BDQHCVM36FRHNMOKDQ2KEAPCSDEWP X-Message-ID-Hash: UF7BDQHCVM36FRHNMOKDQ2KEAPCSDEWP X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --AmmG2KRcnT4PTAIS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 15, 2023 at 03:24:37AM -0500, Laine Stump wrote: > This actually leaves us with 0 uses of err(), but someone could want > to use it in the future, so we may as well leave it around. >=20 > Signed-off-by: Laine Stump Reviewed-by: David Gibson > --- > isolation.c | 67 ++++++++++++++++++----------------------------------- > log.c | 6 ++--- > netlink.c | 3 +-- > passt.c | 12 ++++------ > pasta.c | 20 ++++++---------- > tap.c | 30 ++++++++---------------- > 6 files changed, 47 insertions(+), 91 deletions(-) >=20 > diff --git a/isolation.c b/isolation.c > index 4e6637d..6bae4d4 100644 > --- a/isolation.c > +++ b/isolation.c > @@ -103,10 +103,8 @@ static void drop_caps_ep_except(uint64_t keep) > struct __user_cap_data_struct data[CAP_WORDS]; > int i; > =20 > - if (syscall(SYS_capget, &hdr, data)) { > - err("Couldn't get current capabilities: %s", strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (syscall(SYS_capget, &hdr, data)) > + die("Couldn't get current capabilities: %s", strerror(errno)); > =20 > for (i =3D 0; i < CAP_WORDS; i++) { > uint32_t mask =3D keep >> (32 * i); > @@ -115,10 +113,8 @@ static void drop_caps_ep_except(uint64_t keep) > data[i].permitted &=3D mask; > } > =20 > - if (syscall(SYS_capset, &hdr, data)) { > - err("Couldn't drop capabilities: %s", strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (syscall(SYS_capset, &hdr, data)) > + die("Couldn't drop capabilities: %s", strerror(errno)); > } > =20 > /** > @@ -154,26 +150,20 @@ static void clamp_caps(void) > * normal operation, so carry on without it. > */ > if (prctl(PR_CAPBSET_DROP, i, 0, 0, 0) && > - errno !=3D EINVAL && errno !=3D EPERM) { > - err("Couldn't drop cap %i from bounding set: %s", > + errno !=3D EINVAL && errno !=3D EPERM) > + die("Couldn't drop cap %i from bounding set: %s", > i, strerror(errno)); > - exit(EXIT_FAILURE); > - } > } > =20 > - if (syscall(SYS_capget, &hdr, data)) { > - err("Couldn't get current capabilities: %s", strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (syscall(SYS_capget, &hdr, data)) > + die("Couldn't get current capabilities: %s", strerror(errno)); > =20 > for (i =3D 0; i < CAP_WORDS; i++) > data[i].inheritable =3D 0; > =20 > - if (syscall(SYS_capset, &hdr, data)) { > - err("Couldn't drop inheritable capabilities: %s", > + if (syscall(SYS_capset, &hdr, data)) > + die("Couldn't drop inheritable capabilities: %s", > strerror(errno)); > - exit(EXIT_FAILURE); > - } > } > =20 > /** > @@ -229,46 +219,35 @@ void isolate_user(uid_t uid, gid_t gid, bool use_us= erns, const char *userns, > /* First set our UID & GID in the original namespace */ > if (setgroups(0, NULL)) { > /* If we don't have CAP_SETGID, this will EPERM */ > - if (errno !=3D EPERM) { > - err("Can't drop supplementary groups: %s", > + if (errno !=3D EPERM) > + die("Can't drop supplementary groups: %s", > strerror(errno)); > - exit(EXIT_FAILURE); > - } > } > =20 > - if (setgid(gid) !=3D 0) { > - err("Can't set GID to %u: %s", gid, strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (setgid(gid) !=3D 0) > + die("Can't set GID to %u: %s", gid, strerror(errno)); > =20 > - if (setuid(uid) !=3D 0) { > - err("Can't set UID to %u: %s", uid, strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (setuid(uid) !=3D 0) > + die("Can't set UID to %u: %s", uid, strerror(errno)); > =20 > if (*userns) { /* If given a userns, join it */ > int ufd; > =20 > ufd =3D open(userns, O_RDONLY | O_CLOEXEC); > - if (ufd < 0) { > - err("Couldn't open user namespace %s: %s", > + if (ufd < 0) > + die("Couldn't open user namespace %s: %s", > userns, strerror(errno)); > - exit(EXIT_FAILURE); > - } > =20 > - if (setns(ufd, CLONE_NEWUSER) !=3D 0) { > - err("Couldn't enter user namespace %s: %s", > + if (setns(ufd, CLONE_NEWUSER) !=3D 0) > + die("Couldn't enter user namespace %s: %s", > userns, strerror(errno)); > - exit(EXIT_FAILURE); > - } > =20 > close(ufd); > =20 > } else if (use_userns) { /* Create and join a new userns */ > - if (unshare(CLONE_NEWUSER) !=3D 0) { > - err("Couldn't create user namespace: %s", strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (unshare(CLONE_NEWUSER) !=3D 0) > + die("Couldn't create user namespace: %s", > + strerror(errno)); > } > =20 > /* Joining a new userns gives us full capabilities; drop the > diff --git a/log.c b/log.c > index 2920aba..785bc36 100644 > --- a/log.c > +++ b/log.c > @@ -193,10 +193,8 @@ void logfile_init(const char *name, const char *path= , size_t size) > =20 > log_file =3D open(path, O_CREAT | O_TRUNC | O_APPEND | O_RDWR | O_CLOEX= EC, > S_IRUSR | S_IWUSR); > - if (log_file =3D=3D -1) { > - err("Couldn't open log file %s: %s", path, strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (log_file =3D=3D -1) > + die("Couldn't open log file %s: %s", path, strerror(errno)); > =20 > log_size =3D size ? size : LOGFILE_SIZE_DEFAULT; > =20 > diff --git a/netlink.c b/netlink.c > index b8fa2a0..8f785ca 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -90,8 +90,7 @@ void nl_sock_init(const struct ctx *c, bool ns) > return; > =20 > fail: > - err("Failed to get netlink socket"); > - exit(EXIT_FAILURE); > + die("Failed to get netlink socket"); > } > =20 > /** > diff --git a/passt.c b/passt.c > index c48c2d5..5b8146e 100644 > --- a/passt.c > +++ b/passt.c > @@ -202,10 +202,8 @@ int main(int argc, char **argv) > name =3D basename(argv0); > if (strstr(name, "pasta")) { > sa.sa_handler =3D pasta_child_handler; > - if (sigaction(SIGCHLD, &sa, NULL) || signal(SIGPIPE, SIG_IGN)) { > - err("Couldn't install signal handlers"); > - exit(EXIT_FAILURE); > - } > + if (sigaction(SIGCHLD, &sa, NULL) || signal(SIGPIPE, SIG_IGN)) > + die("Couldn't install signal handlers"); > =20 > c.mode =3D MODE_PASTA; > log_name =3D "pasta"; > @@ -284,10 +282,8 @@ int main(int argc, char **argv) > } > } > =20 > - if (isolate_prefork(&c)) { > - err("Failed to sandbox process, exiting\n"); > - exit(EXIT_FAILURE); > - } > + if (isolate_prefork(&c)) > + die("Failed to sandbox process, exiting"); > =20 > /* Once the log mask is not LOG_EMERG, we will no longer > * log to stderr if there was a log file specified. > diff --git a/pasta.c b/pasta.c > index d4d3dc8..6c9a412 100644 > --- a/pasta.c > +++ b/pasta.c > @@ -131,19 +131,15 @@ void pasta_open_ns(struct ctx *c, const char *netns) > int nfd =3D -1; > =20 > nfd =3D open(netns, O_RDONLY | O_CLOEXEC); > - if (nfd < 0) { > - err("Couldn't open network namespace %s", netns); > - exit(EXIT_FAILURE); > - } > + if (nfd < 0) > + die("Couldn't open network namespace %s", netns); > =20 > c->pasta_netns_fd =3D nfd; > =20 > NS_CALL(ns_check, c); > =20 > - if (c->pasta_netns_fd < 0) { > - err("Couldn't switch to pasta namespaces"); > - exit(EXIT_FAILURE); > - } > + if (c->pasta_netns_fd < 0) > + die("Couldn't switch to pasta namespaces"); > =20 > if (!c->no_netns_quit) { > char buf[PATH_MAX] =3D { 0 }; > @@ -232,11 +228,9 @@ void pasta_start_ns(struct ctx *c, uid_t uid, gid_t = gid, > arg.exe =3D "/bin/sh"; > =20 > if ((size_t)snprintf(sh_arg0, sizeof(sh_arg0), > - "-%s", arg.exe) >=3D sizeof(sh_arg0)) { > - err("$SHELL is too long (%u bytes)", > - strlen(arg.exe)); > - exit(EXIT_FAILURE); > - } > + "-%s", arg.exe) >=3D sizeof(sh_arg0)) > + die("$SHELL is too long (%u bytes)", strlen(arg.exe)); > + > sh_argv[0] =3D sh_arg0; > arg.argv =3D sh_argv; > } > diff --git a/tap.c b/tap.c > index 716d887..02da84d 100644 > --- a/tap.c > +++ b/tap.c > @@ -1008,10 +1008,8 @@ static void tap_sock_unix_init(struct ctx *c) > }; > int i; > =20 > - if (fd < 0) { > - err("UNIX socket: %s", strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (fd < 0) > + die("UNIX socket: %s", strerror(errno)); > =20 > /* In passt mode, we don't know the guest's MAC until it sends > * us packets. Use the broadcast address so our first packets > @@ -1029,18 +1027,14 @@ static void tap_sock_unix_init(struct ctx *c) > snprintf(path, UNIX_PATH_MAX - 1, UNIX_SOCK_PATH, i); > =20 > ex =3D socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0); > - if (ex < 0) { > - err("UNIX domain socket check: %s", strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (ex < 0) > + die("UNIX domain socket check: %s", strerror(errno)); > =20 > ret =3D connect(ex, (const struct sockaddr *)&addr, sizeof(addr)); > if (!ret || (errno !=3D ENOENT && errno !=3D ECONNREFUSED && > errno !=3D EACCES)) { > - if (*c->sock_path) { > - err("Socket path %s already in use", path); > - exit(EXIT_FAILURE); > - } > + if (*c->sock_path) > + die("Socket path %s already in use", path); > =20 > close(ex); > continue; > @@ -1053,10 +1047,8 @@ static void tap_sock_unix_init(struct ctx *c) > break; > } > =20 > - if (i =3D=3D UNIX_SOCK_MAX) { > - err("UNIX socket bind: %s", strerror(errno)); > - exit(EXIT_FAILURE); > - } > + if (i =3D=3D UNIX_SOCK_MAX) > + die("UNIX socket bind: %s", strerror(errno)); > =20 > info("UNIX domain socket bound at %s\n", addr.sun_path); > =20 > @@ -1159,10 +1151,8 @@ static void tap_sock_tun_init(struct ctx *c) > struct epoll_event ev =3D { 0 }; > =20 > NS_CALL(tap_ns_tun, c); > - if (tun_ns_fd =3D=3D -1) { > - err("Failed to open tun socket in namespace"); > - exit(EXIT_FAILURE); > - } > + if (tun_ns_fd =3D=3D -1) > + die("Failed to open tun socket in namespace"); > =20 > pasta_ns_conf(c); > =20 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --AmmG2KRcnT4PTAIS Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmPtwdAACgkQzQJF27ox 2GfXcQ//ezLJKmDJWf7CO/805jaMjAWRnNB3O8QPRHX1xSKosQuVocZsiVGd2UZy 82HlLJZiHYe0lHFZOAaFhOhmC7udZWRhXvXwXZo5JycTtc8KOL35jbO17DqHYp8t W39J5wT+gwrkCejjNts6OMmIyQuTHCG6IjcHlP6dGpWP2W/GzrOvP3ANEEpr8GCl jtzAcV/sUS+PXWLFWeaLjGPn5nIKTkntbInjJCN3aiiOfHMtZpK9IP46hSxS4Ggl hTpUC09xCTUj4tRkNKFKD3lepI4z8Abajp7eBmR71i0GdmnqYi1U+GKO7ftItAml SwKKCcbhicdH02fKd579PeV0tqaZQGEMKEBUkduFZ3V7G/YVwJFqWRjeimD1t+lL iTSFhiQsG/d5IPot0Vre3ShG/JOklzQzQ2qokEhK7wr1M7v9uUyJXTCFnNdpf3em /FbvcGy00AiuZGHfixmoTb76xcUFj3a+7IU1A39s+o2z2fe2BPR/yvTA3HiqsBaq Z90FQIm+wSWGvhhuMRpQUdti8nlCK5jGw1Gk+vFmfIMCnhzxWCK1ZNUFzuhi+1ps NMm93+xc8qvkN2qRmfrjUUELmdG0s9yeEz4l3ISEghAzifut0oLC6QyBkf1s6nZe NuNcpaw4Zkho0E/X39ymHwM0zWuI4U3BBzcmjr62p/FwXjskgHw= =T7LD -----END PGP SIGNATURE----- --AmmG2KRcnT4PTAIS--