There is no error when the /proc/#/environ file does not contain any
NAME=value items.
Backport from master (v2.41) branch.
Fixes: https://github.com/util-linux/util-linux/issues/3270
Signed-off-by: Karel Zak <kzak@redhat.com>
ssize_t rc = 0;
struct ul_env_list *ls = NULL;
+ errno = 0;
if ((rc = read_all_alloc(fd, &buf)) < 1)
return NULL;
buf[rc] = '\0';
uid_t uid = 0;
gid_t gid = 0;
int keepcaps = 0;
- struct ul_env_list *envls;
#ifdef HAVE_LIBSELINUX
bool selinux = 0;
#endif
/* Pass environment variables of the target process to the spawned process */
if (env_fd >= 0) {
- if ((envls = env_from_fd(env_fd)) == NULL)
+ struct ul_env_list *ls;
+
+ ls = env_from_fd(env_fd);
+ if (!ls && errno)
err(EXIT_FAILURE, _("failed to get environment variables"));
clearenv();
- if (env_list_setenv(envls) < 0)
+ if (ls && env_list_setenv(ls) < 0)
err(EXIT_FAILURE, _("failed to set environment variables"));
- env_list_free(envls);
+ env_list_free(ls);
close(env_fd);
}