diff options
Diffstat (limited to 'common/init.c')
-rw-r--r-- | common/init.c | 93 |
1 files changed, 90 insertions, 3 deletions
diff --git a/common/init.c b/common/init.c index d8e0be7bf..d818856dd 100644 --- a/common/init.c +++ b/common/init.c @@ -33,16 +33,23 @@ #include "util.h" +#ifdef HAVE_W32CE_SYSTEM +#include <assuan.h> +static void parse_std_file_handles (int *argcp, char ***argvp); +#endif /*HAVE_W32CE_SYSTEM*/ + /* This function is to be used early at program startup to make sure that some subsystems are initialized. This is in particular important for W32 to initialize the sockets so that our socket emulation code used directly as well as in libassuan may be used. It should best be called before any I/O is done so that setup - required for logging is ready. CAUTION: This might be called while - running suid(root). */ + required for logging is ready. ARGCP and ARGVP are the addresses + of the parameters given to main. This function may modify them. + + CAUTION: This might be called while running suid(root). */ void -init_common_subsystems (void) +init_common_subsystems (int *argcp, char ***argvp) { /* Try to auto set the character set. */ set_native_charset (NULL); @@ -66,5 +73,85 @@ init_common_subsystems (void) /* Initialize the Estream library. */ es_init (); + + /* Special hack for Windows CE: We extract some options from arg + to setup the standard handles. */ +#ifdef HAVE_W32CE_SYSTEM + parse_std_file_handles (argcp, argvp); +#else + (void)argcp; + (void)argvp; +#endif } + + +/* WindowsCE uses a very strange way of handling the standard streams. + There is a function SetStdioPath to associate a standard stream + with a file or a device but what we really want is to use pipes as + standard streams. Despite that we implement pipes using a device, + we would have some limitations on the number of open pipes due to + the 3 character limit of device file name. Thus we don't take this + path. Another option would be to install a file system driver with + support for pipes; this would allow us to get rid of the device + name length limitation. However, with GnuPG we can get away be + redefining the standard streams and passing the handles to be used + on the command line. This has also the advantage that it makes + creating a process much easier and does not require the + SetStdioPath set and restore game. The caller needs to pass the + rendezvous ids using up to three options: + + -&S0=<handle> -&S1=<handle> -&S2=<handle> + + They are all optional but they must be the first arguments on the + command line. Parsing stops as soon as an invalid option is found. + These rendezvous ids are then used to finish the pipe creation.*/ +#ifdef HAVE_W32CE_SYSTEM +static void +parse_std_file_handles (int *argcp, char ***argvp) +{ + int argc = *argcp; + char **argv = *argvp; + const char *s; + assuan_fd_t fd; + int i; + int fixup = 0; + + if (!argc) + return; + + for (argc--, argv++; argc; argc--, argv++) + { + s = *argv; + if (*s == '-' && s[1] == '&' && s[2] == 'S' + && (s[3] == '0' || s[3] == '1' || s[3] == '2') + && s[4] == '=' + && (strchr ("-01234567890", s[5]) || !strcmp (s+5, "null"))) + { + if (s[5] == 'n') + fd = ASSUAN_INVALID_FD; + else + fd = _assuan_w32ce_finish_pipe (atoi (s+5), s[3] != '0'); + _es_set_std_fd (s[3] - '0', (int)fd); + fixup++; + } + else + break; + } + + if (fixup) + { + argc = *argcp; + argc -= fixup; + *argcp = argc; + + argv = *argvp; + for (i=1; i < argc; i++) + argv[i] = argv[i + fixup]; + for (; i < argc + fixup; i++) + argv[i] = NULL; + } + + +} +#endif /*HAVE_W32CE_SYSTEM*/ |