Relax ttyname_r error checks
* src/engine-assuan.c (llass_new): Don't treat ttyname_r error as fatal. * src/engine-g13.c (g13_new): Likewise. * src/engine-gpg.c (gpg_new): Likewise. * src/engine-gpgsm.c (gpgsm_new): Likewise. * src/engine-uiserver.c (uiserver_new): Likewise. -- Even though isatty() returns 1, ttyname_r() may fail in many ways, e.g., when /dev/pts is not accessible under chroot. Since all our uses of ttyname_r() require that the function works, we can treat the failure as if isatty() fails. Signed-off-by: Daiki Ueno <ueno@gnu.org>
This commit is contained in:
parent
97f1f3e883
commit
028a0ef333
@ -282,12 +282,10 @@ llass_new (void **engine, const char *file_name, const char *home_dir)
|
|||||||
char *dft_ttytype = NULL;
|
char *dft_ttytype = NULL;
|
||||||
|
|
||||||
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
if (rc)
|
|
||||||
{
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
err = gpg_error_from_errno (rc);
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
goto leave;
|
if (!rc)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||||
{
|
{
|
||||||
|
@ -286,12 +286,10 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
if (rc)
|
|
||||||
{
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
err = gpg_error_from_errno (rc);
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
goto leave;
|
if (!rc)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||||
{
|
{
|
||||||
|
@ -513,6 +513,8 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
|
|||||||
rc = add_arg (gpg, dft_display);
|
rc = add_arg (gpg, dft_display);
|
||||||
|
|
||||||
free (dft_display);
|
free (dft_display);
|
||||||
|
if (rc)
|
||||||
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isatty (1))
|
if (isatty (1))
|
||||||
@ -520,9 +522,10 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
err = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
if (err)
|
|
||||||
rc = gpg_error_from_errno (err);
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
else
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
|
if (!err)
|
||||||
{
|
{
|
||||||
if (*dft_ttyname)
|
if (*dft_ttyname)
|
||||||
{
|
{
|
||||||
@ -547,9 +550,9 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
|
|||||||
|
|
||||||
free (dft_ttytype);
|
free (dft_ttytype);
|
||||||
}
|
}
|
||||||
|
if (rc)
|
||||||
|
goto leave;
|
||||||
}
|
}
|
||||||
if (rc)
|
|
||||||
goto leave;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
|
@ -408,12 +408,10 @@ gpgsm_new (void **engine, const char *file_name, const char *home_dir)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
if (rc)
|
|
||||||
{
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
err = gpg_error_from_errno (rc);
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
goto leave;
|
if (!rc)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||||
{
|
{
|
||||||
|
@ -326,12 +326,10 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir)
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
rc = ttyname_r (1, dft_ttyname, sizeof (dft_ttyname));
|
||||||
if (rc)
|
|
||||||
{
|
/* Even though isatty() returns 1, ttyname_r() may fail in many
|
||||||
err = gpg_error_from_errno (rc);
|
ways, e.g., when /dev/pts is not accessible under chroot. */
|
||||||
goto leave;
|
if (!rc)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user