Diagnose sys_exec_info_script failures

* src/system.c (sys_exec_info_script): Diagnose failures in
getline, fclose.  Don’t worry about freeing memory
as caller will immediately exit anyway.
This commit is contained in:
Paul Eggert
2024-11-01 09:39:33 -07:00
parent 9afbe6961c
commit fae968bd2d

View File

@@ -830,25 +830,33 @@ sys_exec_info_script (const char **archive_name, int volume_number)
{ {
/* Master */ /* Master */
int rc;
int status; int status;
char *buf = NULL; char *buf = NULL;
size_t size = 0; size_t size = 0;
FILE *fp;
xclose (p[PWRITE]); xclose (p[PWRITE]);
fp = fdopen (p[PREAD], "r"); FILE *fp = fdopen (p[PREAD], "r");
if (!fp) if (!fp)
{ {
signal (SIGPIPE, saved_handler); signal (SIGPIPE, saved_handler);
call_arg_error ("fdopen", info_script_option); call_arg_error ("fdopen", info_script_option);
return -1; return -1;
} }
rc = getline (&buf, &size, fp); ssize_t rc = getline (&buf, &size, fp);
fclose (fp); if (rc < 0)
{
if (rc > 0 && buf[rc-1] == '\n') signal (SIGPIPE, saved_handler);
buf[--rc] = 0; read_error (info_script_option);
return -1;
}
*archive_name = buf;
buf[rc - 1] = '\0';
if (fclose (fp) < 0)
{
signal (SIGPIPE, saved_handler);
close_error (info_script_option);
return -1;
}
while (waitpid (pid, &status, 0) < 0) while (waitpid (pid, &status, 0) < 0)
if (errno != EINTR) if (errno != EINTR)
@@ -859,18 +867,7 @@ sys_exec_info_script (const char **archive_name, int volume_number)
} }
signal (SIGPIPE, saved_handler); signal (SIGPIPE, saved_handler);
return WIFEXITED (status) ? WEXITSTATUS (status) : -1;
if (WIFEXITED (status))
{
if (WEXITSTATUS (status) == 0 && rc > 0)
*archive_name = buf;
else
free (buf);
return WEXITSTATUS (status);
}
free (buf);
return -1;
} }
/* Child */ /* Child */