diff options
Diffstat (limited to 'g10')
-rw-r--r-- | g10/ChangeLog | 6 | ||||
-rw-r--r-- | g10/keyedit.c | 5 | ||||
-rw-r--r-- | g10/status.c | 37 |
3 files changed, 44 insertions, 4 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog index 7d4595ea2..d3cba7a74 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,9 @@ +2000-10-13 Werner Koch <[email protected]> + + * keyedit.c (keyedit_menu): Allow batchmode with a command_fd. + * status.c (my_read): New. + (do_get_from_fd): use it. + 2000-10-12 Werner Koch <[email protected]> * keygen.c (keygen_add_std_prefs): Add Rijndael to the prefs. diff --git a/g10/keyedit.c b/g10/keyedit.c index 79f7c6350..30302fa74 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -625,8 +625,9 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands, int toggle; int have_commands = !!commands; - - if( opt.batch && !have_commands ) { + if ( opt.command_fd != -1 ) + ; + else if( opt.batch && !have_commands ) { log_error(_("can't do that in batchmode\n")); goto leave; } diff --git a/g10/status.c b/g10/status.c index ba30c01e3..116d146de 100644 --- a/g10/status.c +++ b/g10/status.c @@ -24,6 +24,7 @@ #include <string.h> #include <errno.h> #include <unistd.h> +#include <signal.h> #ifdef USE_SHM_COPROCESSING #ifdef USE_CAPABILITIES #include <sys/capability.h> @@ -46,6 +47,10 @@ #include "i18n.h" #include "cipher.h" /* for progress functions */ +#define CONTROL_D ('D' - 'A' + 1) + + + static int fd = -1; #ifdef USE_SHM_COPROCESSING static int shm_id = -1; @@ -340,6 +345,28 @@ do_shm_get( const char *keyword, int hidden, int bool ) #endif /* USE_SHM_COPROCESSING */ +static int +myread(int fd, void *buf, size_t count) +{ + int rc; + do { + rc = read( fd, buf, count ); + } while ( rc == -1 && errno == EINTR ); + if ( !rc && count ) { + static int eof_emmited=0; + if ( eof_emmited < 3 ) { + *(char*)buf = CONTROL_D; + rc = 1; + eof_emmited++; + } + else { /* Ctrl-D not caught - do something reasonable */ + raise (SIGHUP); /* no more input data */ + } + } + return rc; +} + + /**************** * Request a string from the client over the command-fd @@ -365,8 +392,14 @@ do_get_from_fd( const char *keyword, int hidden, int bool ) i=0; } /* Hmmm: why not use our read_line function here */ - if( read( opt.command_fd, string+i, 1) != 1 || string[i] == '\n' ) - break; + if( myread( opt.command_fd, string+i, 1) != 1 || string[i] == '\n' ) + break; + else if ( string[i] == CONTROL_D ) { + /* found ETX - cancel the line and return a sole ETX */ + string[0] = CONTROL_D; + i=1; + break; + } } string[i] = 0; |