2
* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4
* This file is free software; as a special exception the author gives
5
* unlimited permission to copy and/or distribute it, with or without
6
* modifications, as long as this notice is preserved.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
10
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22
#include <sys/types.h>
32
#ifdef HAVE_DOSISH_SYSTEM
33
int main( int argc, char **argv )
35
fprintf(stderr, "Sorry, not yet available for DOSish systems\n");
40
static int serverpid = -1;
45
fprintf(stderr, "usage: shmtest gpg-command-line\n");
52
return default_strusage(level);
59
#ifdef HAVE_LC_MESSAGES
60
setlocale( LC_MESSAGES, "" );
62
setlocale( LC_ALL, "" );
64
bindtextdomain( PACKAGE, G10_LOCALEDIR );
65
textdomain( PACKAGE );
71
do_get_string( int mode, const char *keyword, byte *area, size_t areasize )
77
n = area[0] << 8 | area[1];
78
/* fixme: do some sanity checks here */
80
p = tty_get( keyword );
82
p = tty_get_hidden( keyword );
84
yes = tty_get_answer_is_yes( keyword );
87
memcpy( area+n+2, p, len );
97
area[3] = 1; /* we should better use a semaphore */
98
kill( serverpid, SIGUSR1 );
104
main(int argc, char **argv)
107
size_t areasize = 4096;
115
log_set_name("shmtest");
117
#ifndef USE_SHM_COPROCESSING
118
log_info("SHM_COPRPOCESSING is not available\n");
123
for(n=0,i=1; i < argc; i++ )
124
n += strlen(argv[i]) + 1;
125
p = m_alloc( 100 + n );
126
strcpy( p, "../g10/gpg --status-fd 1 --run-as-shm-coprocess 0");
127
for(i=1; i < argc; i++ ) {
132
fp = popen( p, "r" );
135
log_error("popen failed: %s\n", strerror(errno));
137
while ( fgets (buf, sizeof (buf) - 1, fp ) != NULL ) {
138
size_t len = strlen(buf);
139
if( len >= 9 && !memcmp( buf, "[GNUPG:] ", 9 ) ) {
141
int is_info = 0, is_get = 0;
143
for( p = strtok(buf+9, " \n"); p ; p = strtok(NULL, " \n")) {
145
if( word==1 && !strcmp(p,"SHM_INFO") ) {
149
log_error("duplicate SHM_INFO ignored\n" );
151
else if( is_info && (p2 = strchr(p, '=' )) ) {
154
val = atoi(p2); /* should be atou() for some values */
155
if( !strcmp(p, "pv" ) ) {
157
log_fatal("invalid protocol version %d\n", val );
160
else if( !strcmp(p, "pid" ) )
162
else if( !strcmp(p, "shmid" ) )
165
else if( word == 1 && !strcmp(p,"SHM_GET") )
167
else if( word == 1 && !strcmp(p,"SHM_GET_BOOL") )
169
else if( word == 1 && !strcmp(p,"SHM_GET_HIDDEN") )
171
else if( word == 2 && is_get ) {
172
do_get_string( is_get, p, area, areasize );
176
log_info("Status: %s\n", p);
180
log_fatal("SHM info without protocol version\n");
181
if( serverpid == -1 )
182
log_fatal("SHM info without server's pid\n");
184
log_fatal("SHM info without id\n");
185
log_info("Shared memory info: server=%d shm_id=%d\n",
187
area = shmat( shm_id, 0, 0 );
188
if( area == (void*)-1 )
189
log_fatal("attach to shared memory failed: %s\n",
199
log_error("pclose failed\n");