1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-29 02:22:45 +02:00

Fixes for command-fd

This commit is contained in:
Werner Koch 2000-10-13 10:31:16 +00:00
parent dc7cea85ba
commit cfdb80a759
3 changed files with 44 additions and 4 deletions

View File

@ -1,3 +1,9 @@
2000-10-13 Werner Koch <wk@gnupg.org>
* 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 <wk@gnupg.org>
* keygen.c (keygen_add_std_prefs): Add Rijndael to the prefs.

View File

@ -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;
}

View File

@ -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;