Mailing List Archive

Cancel operation does not return error code
Hi,

if your using gpgme with interactive password entry on the command line and
the user cancels the operation, shouldn't there be an error returned?

Following code

err = gpgme_op_encrypt(ctx, NULL, GPGME_ENCRYPT_SYMMETRIC, in, out);

fprintf(stdout, "DEBUG ERROR Code = \%d \%s \%s\n" , gpgme_err_code(err),
gpgme_strsource(err) , gpgme_strerror(err));

If user cancel on the passwort screen, the following error code is returned

ERROR Code = 0 Unspecified source Success



If I look at the docu and search through the net, there is always said that
GPG_ERR_CANCELED should be returned.

https://www.gnupg.org/documentation/manuals/gpgme/Error-Codes.html



Why this is important?

The output stream already created the output file and if the users cancel
the operation I need an indicator to do a cleanup afterwards.



Thx

Regards

Sven
Cancel operation does not return error code [ In reply to ]
Hi,

if your using gpgme with interactive password entry on the command line and the user cancels the operation, shouldn't there be an error returned?

Following code

err = gpgme_op_encrypt(ctx, NULL, GPGME_ENCRYPT_SYMMETRIC, in, out);
fprintf(stdout, "DEBUG ERROR Code = \%d \%s \%s\n" , gpgme_err_code(err), gpgme_strsource(err) , gpgme_strerror(err));

If user cancel on the passwort screen, the following error code is returned

ERROR Code = 0 Unspecified source Success

If I look at the docu and search through the net, there is always said that GPG_ERR_CANCELED should be returned.
https://www.gnupg.org/documentation/manuals/gpgme/Error-Codes.html

Why this is important?
The output stream already created the output file and if the users cancel the operation I need an indicator to do a cleanup afterwards.

Thx
Regards
Sven

_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-users
Re: Cancel operation does not return error code [ In reply to ]
On Donnerstag, 10. M?rz 2022 14:30:29 CET Schultschik, Sven via Gnupg-users
wrote:
> if your using gpgme with interactive password entry on the command line and
> the user cancels the operation, shouldn't there be an error returned?
>
> Following code
>
> err = gpgme_op_encrypt(ctx, NULL, GPGME_ENCRYPT_SYMMETRIC, in, out);
>
> fprintf(stdout, "DEBUG ERROR Code = \%d \%s \%s\n" , gpgme_err_code(err),
> gpgme_strsource(err) , gpgme_strerror(err));
>
> If user cancel on the passwort screen, the following error code is returned
>
> ERROR Code = 0 Unspecified source Success

When I run t-encrypt-sym (in gpgme/tests/gpg) and cancel the passphrase dialog
provided by pinentry-qt, then t-encrypt-sym prints
../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation cancelled

When I force usage of pinentry-tty and cancel the passphrase entry with
Ctrl+D, then I get the same result:
=====
$ ./t-encrypt-sym
Enter passphrase

Passphrase:
../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation cancelled
=====

So, in general, gpgme_op_encrypt seems to return the correct error code. What
I'm wondering is how do you cancel "interactive password entry on the command
line" resp. how do you do "interactive password entry on the command line"?

Regards,
Ingo
AW: Cancel operation does not return error code [ In reply to ]
The method gpgme_op_encrypt provides the interactive possibility itself.

If you don't set a passphrase with gpgme_set_passphrase_cb before calling gpgme_op_encrypt, it asks itself for a passphrase.

See screenshot.

There are more issues with this interactive view.

1. Cancel does not send an error
2. If you wait for the timeout of the passphrase form, it returns Error 0 Success as well
3. Ctrl+C does not cancel the gpgme passphrase entry. See screenshot 2

Ctrl+C I tried to fix by catching the ctrl+c signal an cancel gpgme itself

void signal_callback_handler(int signum)
{
gpgme_error_t err = gpgme_cancel(_ctx);
_ctx = gpgme_wait(_ctx, &err, false);
}

signal(SIGINT, signal_callback_handler);

regards
Sven

-----Urspr?ngliche Nachricht-----
Von: Gnupg-users <gnupg-users-bounces@gnupg.org> Im Auftrag von Ingo Kl?cker
Gesendet: Donnerstag, 10. M?rz 2022 22:16
An: gnupg-users@gnupg.org
Betreff: Re: Cancel operation does not return error code

On Donnerstag, 10. M?rz 2022 14:30:29 CET Schultschik, Sven via Gnupg-users
wrote:
> if your using gpgme with interactive password entry on the command
> line and the user cancels the operation, shouldn't there be an error returned?
>
> Following code
>
> err = gpgme_op_encrypt(ctx, NULL, GPGME_ENCRYPT_SYMMETRIC, in, out);
>
> fprintf(stdout, "DEBUG ERROR Code = \%d \%s \%s\n" ,
> gpgme_err_code(err),
> gpgme_strsource(err) , gpgme_strerror(err));
>
> If user cancel on the passwort screen, the following error code is
> returned
>
> ERROR Code = 0 Unspecified source Success

When I run t-encrypt-sym (in gpgme/tests/gpg) and cancel the passphrase dialog provided by pinentry-qt, then t-encrypt-sym prints
../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation cancelled

When I force usage of pinentry-tty and cancel the passphrase entry with
Ctrl+D, then I get the same result:
=====
$ ./t-encrypt-sym
Enter passphrase

Passphrase:
../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation cancelled =====

So, in general, gpgme_op_encrypt seems to return the correct error code. What I'm wondering is how do you cancel "interactive password entry on the command line" resp. how do you do "interactive password entry on the command line"?

Regards,
Ingo
Re: Cancel operation does not return error code [ In reply to ]
[.It would be great, if you wouldn't top-post even if this isn't easy with
Outlook or Office 365 or whatever email client you are using.]

On Freitag, 11. M?rz 2022 10:29:41 CET Schultschik, Sven via Gnupg-users
wrote:
> The method gpgme_op_encrypt provides the interactive possibility itself.
>
> If you don't set a passphrase with gpgme_set_passphrase_cb before calling
> gpgme_op_encrypt, it asks itself for a passphrase.
>
> See screenshot.

Okay. You are using pinentry-curses.

> There are more issues with this interactive view.
>
> 1. Cancel does not send an error

I cannot reproduce this. For me it works correctly.
```
$ export GNUPGHOME=$(mktemp --directory)
$ cat >${GNUPGHOME}/gpg-agent.conf <<EOF
pinentry-program /usr/bin/pinentry-curses
EOF
$ ./t-encrypt-sym
[Tab][Tab][Enter]
../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation cancelled
```

> 2. If you wait for the timeout of the passphrase form, it returns Error 0
> Success as well

Let's try.
```
$ cat >>${GNUPGHOME}/gpg-agent.conf <<EOF
pinentry-timeout 5
EOF
$ gpgconf --kill all
$ ./t-encrypt-sym
[wait 5 seconds ...]
../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation cancelled
```

> 3. Ctrl+C does not cancel the gpgme passphrase entry. See
> screenshot 2

Pressing Ctrl+C while t-encrypt-sym is running and pinentry-curses is asking
for the password quits pinentry-curses and t-encrypt-sym without further
output. That's common behavior for command line programs.

My conclusion is that gpgme_op_encrypt() is working as expected as my
experiments with the official test t-encrypt-sym proves. I suspect that there
is something wrong with your program. Please have a look at the official test
t-encrypt-sym (in tests/gpg of gpgme's source code) and check what you are
doing differently.

I'm using gpgme 1.17.1.

Regards,
Ingo

> -----Urspr?ngliche Nachricht-----
> Von: Gnupg-users <gnupg-users-bounces@gnupg.org> Im Auftrag von Ingo Kl?cker
> Gesendet: Donnerstag, 10. M?rz 2022 22:16
> An: gnupg-users@gnupg.org
> Betreff: Re: Cancel operation does not return error code
>
> On Donnerstag, 10. M?rz 2022 14:30:29 CET Schultschik, Sven via Gnupg-users
>
> wrote:
> > if your using gpgme with interactive password entry on the command
> > line and the user cancels the operation, shouldn't there be an error
> > returned?
> >
> > Following code
> >
> > err = gpgme_op_encrypt(ctx, NULL, GPGME_ENCRYPT_SYMMETRIC, in, out);
> >
> > fprintf(stdout, "DEBUG ERROR Code = \%d \%s \%s\n" ,
> > gpgme_err_code(err),
> > gpgme_strsource(err) , gpgme_strerror(err));
> >
> > If user cancel on the passwort screen, the following error code is
> > returned
> >
> > ERROR Code = 0 Unspecified source Success
>
> When I run t-encrypt-sym (in gpgme/tests/gpg) and cancel the passphrase
> dialog provided by pinentry-qt, then t-encrypt-sym prints
> ../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation
> cancelled
>
> When I force usage of pinentry-tty and cancel the passphrase entry with
> Ctrl+D, then I get the same result:
> =====
> $ ./t-encrypt-sym
> Enter passphrase
>
> Passphrase:
> ../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation
> cancelled =====
>
> So, in general, gpgme_op_encrypt seems to return the correct error code.
> What I'm wondering is how do you cancel "interactive password entry on the
> command line" resp. how do you do "interactive password entry on the
> command line"?
>
> Regards,
> Ingo
AW: Cancel operation does not return error code [ In reply to ]
[.Sorry, i need to use outlook even if I don't like it, but I will try to
make things better if I know whats wrong. Outlook doesn't even format text
answers correctly :( I made it by hand ... ]

> -----Urspr?ngliche Nachricht-----
> Von: Gnupg-users <gnupg-users-bounces@gnupg.org> Im Auftrag von Ingo
Kl?cker
> Gesendet: Freitag, 11. M?rz 2022 11:18
> An: gnupg-users@gnupg.org
> Betreff: Re: Cancel operation does not return error code
>
> [.It would be great, if you wouldn't top-post even if this isn't easy with
Outlook or Office 365 or whatever email client you are using.]
>
> On Freitag, 11. M?rz 2022 10:29:41 CET Schultschik, Sven via Gnupg-users
> wrote:
> > The method gpgme_op_encrypt provides the interactive possibility itself.
> >
> > If you don't set a passphrase with gpgme_set_passphrase_cb before
> > calling gpgme_op_encrypt, it asks itself for a passphrase.
> >
> > See screenshot.
>
> Okay. You are using pinentry-curses.
>
> > There are more issues with this interactive view.
> >
> > 1. Cancel does not send an error
>
> I cannot reproduce this. For me it works correctly.
> ```
> $ export GNUPGHOME=$(mktemp --directory) $ cat
>${GNUPGHOME}/gpg-agent.conf <<EOF pinentry-program /usr/bin/pinentry-curses
EOF $ ./t-encrypt-sym [Tab][Tab][Enter]
>../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation
cancelled ```
>
> > 2. If you wait for the timeout of the passphrase form, it returns
> > Error 0 Success as well
>
> Let's try.
> ```
> $ cat >>${GNUPGHOME}/gpg-agent.conf <<EOF pinentry-timeout 5 EOF $ gpgconf
--kill all $ ./t-encrypt-sym [wait 5 seconds ...]
>../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation
cancelled ```
>
> > 3. Ctrl+C does not cancel the gpgme passphrase entry. See screenshot 2
>
> Pressing Ctrl+C while t-encrypt-sym is running and pinentry-curses is
asking for the password quits pinentry-curses and t-encrypt-sym without
further output. That's common behavior for command line programs.
>
> My conclusion is that gpgme_op_encrypt() is working as expected as my
experiments with the official test t-encrypt-sym proves. I suspect that
there is something wrong with your program. Please have a look at the
official test t-encrypt-sym (in tests/gpg > of gpgme's source code) and
check what you are doing differently.

I pretty much copied the tests/gpg/t-encrypt-sym.c
Only difference is to use streams instead of mem

int encryptBackup(string infile, bool cliintpw, string webpw)
{ gpgme_check_version(NULL);

gpgme_error_t err;
gpgme_encrypt_result_t result;

init_gpgme();

err = gpgme_new(&_ctx);
fail_if_err(err, NULL, NULL);
gpgme_set_armor(_ctx, 1);

FILE *instream;
instream = fopen(infile.c_str(), "r");
if (instream == NULL)
{
throw runtime_error("Backup archive not found " + infile + "\n");
}
gpgme_data_t in = NULL;
err = gpgme_data_new_from_stream(&in, instream);
fail_if_err(err, in, NULL, instream);

FILE *outstream;
_encryptedArchiveFullFilePath = infile.append(".gpg");
outstream = fopen(_encryptedArchiveFullFilePath.c_str(), "w");
gpgme_data_t out = NULL;
err = gpgme_data_new_from_stream(&out, outstream);
fail_if_err(err, in, out, instream, outstream,
_encryptedArchiveFullFilePath);

fprintf(stdout, "DEBUG Start encryption\n");
err = gpgme_op_encrypt(_ctx, NULL, GPGME_ENCRYPT_SYMMETRIC, in,
out);
fprintf(stdout, "DEBUG ERROR Code = \%d \%s \%s\n" ,
gpgme_err_code(err), gpgme_strsource(err) , gpgme_strerror(err));
fprintf(stdout, "DEBUG End encryption\n");

fprintf(stdout, "DEBUG Outpath = \%s\n",
_encryptedArchiveFullFilePath.c_str());
fail_if_err(err, in, out, instream, outstream,
_encryptedArchiveFullFilePath);

result = gpgme_op_encrypt_result(_ctx);

if (result->invalid_recipients)
{
string err(result->invalid_recipients->fpr);
throw runtime_error("Invalid recipient encountered: " + err + "\n");
}

fclose(instream);
fclose(outstream);
gpgme_data_release(in);
gpgme_data_release(out);
gpgme_release(_ctx);

return 0;
}


> I'm using gpgme 1.17.1.

I'm on Debian 11 with 1.14.0-1
Could it be a bug in the "old" version?

Regards
Sven
> Regards,
> Ingo

> > -----Urspr?ngliche Nachricht-----
> > Von: Gnupg-users <gnupg-users-bounces@gnupg.org> Im Auftrag von Ingo
> > Kl?cker
> > Gesendet: Donnerstag, 10. M?rz 2022 22:16
> > An: gnupg-users@gnupg.org
> > Betreff: Re: Cancel operation does not return error code
> >
> > On Donnerstag, 10. M?rz 2022 14:30:29 CET Schultschik, Sven via
> > Gnupg-users
> >
> > wrote:
> > > if your using gpgme with interactive password entry on the command
> > > line and the user cancels the operation, shouldn't there be an error
> > > returned?
> > >
> > > Following code
> > >
> > > err = gpgme_op_encrypt(ctx, NULL, GPGME_ENCRYPT_SYMMETRIC, in, out);
> > >
> > > fprintf(stdout, "DEBUG ERROR Code = \%d \%s \%s\n" ,
> > > gpgme_err_code(err),
> > > gpgme_strsource(err) , gpgme_strerror(err));
> > >
> > > If user cancel on the passwort screen, the following error code is
> > > returned
> > >
> > > ERROR Code = 0 Unspecified source Success
> >
> > When I run t-encrypt-sym (in gpgme/tests/gpg) and cancel the
> > passphrase dialog provided by pinentry-qt, then t-encrypt-sym prints
> > ../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation
> > cancelled
> >
> > When I force usage of pinentry-tty and cancel the passphrase entry
> > with
> > Ctrl+D, then I get the same result:
> > =====
> > $ ./t-encrypt-sym
> > Enter passphrase
> >
> > Passphrase:
> > ../../../../src/gpgme/tests/gpg/t-encrypt-sym.c:67: GPGME: Operation
> > cancelled =====
> >
> > So, in general, gpgme_op_encrypt seems to return the correct error code.
> > What I'm wondering is how do you cancel "interactive password entry on
> > the command line" resp. how do you do "interactive password entry on
> > the command line"?
> >
> > Regards,
> > Ingo
AW: Cancel operation does not return error code [ In reply to ]
> -----Urspr?ngliche Nachricht-----
> Von: Gnupg-users <gnupg-users-bounces@gnupg.org> Im Auftrag von Ingo Kl?cker
> Gesendet: Freitag, 11. M?rz 2022 11:18
> An: gnupg-users@gnupg.org
> Betreff: Re: Cancel operation does not return error code
>
> [.It would be great, if you wouldn't top-post even if this isn't easy with Outlook or Office 365 or whatever email client you are using.]
>
> > 3. Ctrl+C does not cancel the gpgme passphrase entry. See screenshot 2
>
> Pressing Ctrl+C while t-encrypt-sym is running and pinentry-curses is asking for the password quits pinentry-curses and t-encrypt-sym without further output. That's common behavior for command line programs.

The problem is not that it quits without any further ouput. The problem is, that the command line is broken after a ctrl+c and the pinentry-curse is somehow still alife. You can't type or it is not visible. If you hit enter you get back to the pinentry saying that you don't inserted any passwort.

Is there a proper way or example how to cancel all operations on a ctrl-c signal?

>
> My conclusion is that gpgme_op_encrypt() is working as expected as my experiments with the official test t-encrypt-sym proves. I suspect that there is something wrong with your program. Please have a look at the official test t-encrypt-sym (in tests/gpg > of gpgme's source code) and check what you are doing differently.
>
> I'm using gpgme 1.17.1.

I tested now in a docker container with Arch:latest and gpgme 1.17 and the Canceloperation err returned as expected. It really seems to be a bug in the 1.14.

Regards Sven

_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-users
Re: Cancel operation does not return error code [ In reply to ]
On Freitag, 11. M?rz 2022 17:05:44 CET Schultschik, Sven via Gnupg-users
wrote:
> > -----Urspr?ngliche Nachricht-----
> > Von: Gnupg-users <gnupg-users-bounces@gnupg.org> Im Auftrag von Ingo
> > Kl?cker Gesendet: Freitag, 11. M?rz 2022 11:18
> > An: gnupg-users@gnupg.org
> > Betreff: Re: Cancel operation does not return error code
> >
> > [.It would be great, if you wouldn't top-post even if this isn't easy with
> > Outlook or Office 365 or whatever email client you are using.]>
> > > 3. Ctrl+C does not cancel the gpgme passphrase entry. See screenshot 2
> >
> > Pressing Ctrl+C while t-encrypt-sym is running and pinentry-curses is
> > asking for the password quits pinentry-curses and t-encrypt-sym without
> > further output. That's common behavior for command line programs.
>
> The problem is not that it quits without any further ouput. The problem is,
> that the command line is broken after a ctrl+c and the pinentry-curse is
> somehow still alife. You can't type or it is not visible. If you hit enter
> you get back to the pinentry saying that you don't inserted any passwort.

Hmm, I didn't observe this problem with t-encrypt-sym. Maybe using pinentry-
tty is an option. It's not as fancy as the curses one, but hopefully it
doesn't mess up the terminal on Ctrl+C.

> Is there a proper way or example how to cancel all operations on a ctrl-c
> signal?

There is gpgme_cancel and gpgme_cancel_async:
https://www.gnupg.org/documentation/manuals/gpgme/Cancellation.html
But I don't know how to use them to cancel all operations on Ctrl+C.

> > My conclusion is that gpgme_op_encrypt() is working as expected as my
> > experiments with the official test t-encrypt-sym proves. I suspect that
> > there is something wrong with your program. Please have a look at the
> > official test t-encrypt-sym (in tests/gpg > of gpgme's source code) and
> > check what you are doing differently.
> >
> > I'm using gpgme 1.17.1.
>
> I tested now in a docker container with Arch:latest and gpgme 1.17 and the
> Canceloperation err returned as expected. It really seems to be a bug in
> the 1.14.

Yes. Could have been fixed by the following commit:
https://dev.gnupg.org/rM35ca460019ea29ae646d08c954d4d4bf2dc1e8e1

Regards,
Ingo
AW: Cancel operation does not return error code [ In reply to ]
> -----Urspr?ngliche Nachricht-----
> Von: Gnupg-users <gnupg-users-bounces@gnupg.org> Im Auftrag von Ingo
Kl?cker
> Gesendet: Freitag, 11. M?rz 2022 22:22
> An: gnupg-users@gnupg.org
> Betreff: Re: Cancel operation does not return error code
>
> On Freitag, 11. M?rz 2022 17:05:44 CET Schultschik, Sven via Gnupg-users
> wrote:
> > > -----Urspr?ngliche Nachricht-----
> > > Von: Gnupg-users <gnupg-users-bounces@gnupg.org> Im Auftrag von Ingo
> > > Kl?cker Gesendet: Freitag, 11. M?rz 2022 11:18
> > > An: gnupg-users@gnupg.org
> > > Betreff: Re: Cancel operation does not return error code
> > >
> > > [.It would be great, if you wouldn't top-post even if this isn't easy
> > > with Outlook or Office 365 or whatever email client you are using.]>
> > > > 3. Ctrl+C does not cancel the gpgme passphrase entry. See
> > > > screenshot 2
> > >
> > > Pressing Ctrl+C while t-encrypt-sym is running and pinentry-curses
> > > is asking for the password quits pinentry-curses and t-encrypt-sym
> > > without further output. That's common behavior for command line
programs.
> >
> > The problem is not that it quits without any further ouput. The
> > problem is, that the command line is broken after a ctrl+c and the
> > pinentry-curse is somehow still alife. You can't type or it is not
> > visible. If you hit enter you get back to the pinentry saying that you
don't inserted any passwort.
>
> Hmm, I didn't observe this problem with t-encrypt-sym. Maybe using
pinentry- tty is an option. It's not as fancy as the curses one, but
hopefully it doesn't mess up the terminal on Ctrl+C.

I didn't saw that there is a possible choose between different pinentry
terminal modes. I thought there is only modes ASK or LOOPBACK to choose of
https://www.gnupg.org/documentation/manuals/gpgme/Pinentry-Mode.html#Pinentr
y-Mode

>
> > Is there a proper way or example how to cancel all operations on a
> > ctrl-c signal?
>
> There is gpgme_cancel and gpgme_cancel_async:
>
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.gnupg.
org%2Fdocumentation%2Fmanuals%2Fgpgme%2FCancellation.html&amp;data=04%7C01%7
Csven.schultschik%40siemens.com%
7C9be151e1b53748551dc108da03a5b0af%7C38ae3bcd95794fd4addab42e1495d55a%7C1%7C
0%7C637826308011207949%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV
2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=B%2FwuWdAQ%2FyWZa5AAP
7MTFxR7xbwdo%2Fl6iiREatwfIOE%3D&amp;reserved=0
> But I don't know how to use them to cancel all operations on Ctrl+C.

I'm using the Cancel methods on ctrl+c but the terminal is anyway messed up.
Would it be worth a bug report?
I tried both gpgme_cancel and gpgme_cancel_async with same result.

/**
* Clean Up after ctrl-c
*
* @since 1.2.0
*
* @param signum
*/
void signal_callback_handler(int signum)
{
fprintf(stdout, "Interrupt signal caught\n");

if (_ctx) {
fprintf(stdout, "DEBUG cancel async");
gpgme_error_t err = gpgme_cancel_async(_ctx);
fail_if_err(err);
_ctx = gpgme_wait(_ctx, &err, false);
fail_if_err(err);
}
// Terminate program
exit(signum);
}
Re: AW: Cancel operation does not return error code [ In reply to ]
> I'm using the Cancel methods on ctrl+c but the terminal is anyway messed up.
> Would it be worth a bug report?

No. The pinentry is background process and there is no portable way to
save and restore the screen. Thus your application may want to do
something like this after a gpgme operation:

if ((s = gpgme_get_ctx_flag (ctx, "redraw")) && *s)
fputs ("Screen redraw suggested\n", stdout);


Salam-Shalom,

Werner



p.s.
Please trim your quotes to make them easier for everyone to read.

--
Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz.
AW: AW: Cancel operation does not return error code [ In reply to ]
> > I'm using the Cancel methods on ctrl+c but the terminal is anyway messed up.
> > Would it be worth a bug report?
>
> No. The pinentry is background process and there is no portable way to save and restore the screen. Thus your application may want to do something like this after a gpgme operation:
>
> if ((s = gpgme_get_ctx_flag (ctx, "redraw")) && *s)
> fputs ("Screen redraw suggested\n", stdout);
>

I implemented as suggested. And yes this makes it possible to type again, but the pinentry still running in the background and if you hit enter two times it comes back and the terminal acts weird. See screenshots

gpgme_error_t err = gpgme_cancel(_ctx);
const char* s;
if (( s = gpgme_get_ctx_flag (_ctx, "redraw")) && *s)
if (!system("reset"))
log(LOG_ERR, "Could not reset terminal. Reset Terminal suggested");
fail_if_err(err);
_ctx = gpgme_wait(_ctx, &err, false);
fail_if_err(err);
gpgme_release(_ctx);

There must be a possibility to proper kill the pinentry

Regards

Sven
Re: AW: AW: Cancel operation does not return error code [ In reply to ]
On Wed, 16 Mar 2022 16:22, Schultschik, Sven said:

> There must be a possibility to proper kill the pinentry

gpg-agent closes the pinentry or kills it on timeout. You need to
properly restore your tty in case the used curses version does not act
correctly or the pinentry died.


Salam-Shalom,

Werner

--
Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz.