Skip to content

Commit

Permalink
workaround to avoid a bug in gpgme
Browse files Browse the repository at this point in the history
  • Loading branch information
jbar committed Nov 5, 2014
1 parent dd79c4a commit e07fd56
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@

/* CONFIGURE: required (at least) version of gpgme
*/
#define GPGME_VERSION_MIN "1.3.1"
#define GPGME_VERSION_MIN "1.2.0"

/* CONFIGURE: If this is defined, some of the built-in error pages will
** have more explicit information about exactly what the problem is.
Expand Down
3 changes: 2 additions & 1 deletion src/manual.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ The default to try first hostname (/etc/hostname).
The config-file option name for this flag is "ehost".
.TP
.B -l
Specifies a file for logging.
Specifies a file for logging HTTP requests.
If no -l argument is specified, @software@ logs via syslog().
If "-l -" is specified, @software@ output HTTP requests on STDOUT.
If "-l /dev/null" is specified, @software@ doesn't log at all.
The config-file option name for this flag is "logfile".
.TP
Expand Down
59 changes: 42 additions & 17 deletions src/thttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,28 @@ main( int argc, char** argv )

if ( ! debug )
{
/* We're not going to use stdin or stdout from here on, so close
** them to save file descriptors.
*/
int fdnull;
/* We're not going to use stdin, so close it to save a file descriptor.*/
(void) fclose( stdin );
if ( logfp != stdout )

if ( logfp != stdout ) {
(void) fclose( stdout );
/* We're not going to use stdout, but gpgpme will crash or behave strangely
** if we use it freely, so we need to make sure it point to /dev/null.
*/
fdnull=open("/dev/null", O_WRONLY);
if (fdnull == -1 ) {
syslog( LOG_CRIT, "open %.80s - %m","/dev/null");
exit( 1 );
}
else if (fdnull != STDOUT_FILENO) {
if (dup2(fdnull,STDOUT_FILENO) == -1) {
syslog( LOG_CRIT, "dup2 - %m");
exit( 1 );
}
close(fdnull);
}
}

switch ( fork() )
{
Expand All @@ -592,15 +608,7 @@ main( int argc, char** argv )
exit( 0 );
}
#ifdef HAVE_SETSID
(void) setsid();
#endif /* HAVE_SETSID */
}
else
{
/* Even if we don't daemonize, we still want to disown our parent
** process.
*/
#ifdef HAVE_SETSID
/* disown our parent process */
(void) setsid();
#endif /* HAVE_SETSID */
}
Expand Down Expand Up @@ -912,9 +920,26 @@ main( int argc, char** argv )
fdwatch_add_fd( hs->listen_fds[i], (void*) 0, FDW_READ );

/* We will now only use syslog if some errors happen, so close stderr */
warnx("started successfully ! (pid [%d], messages are now sent to syslog only)",getpid());
if ( ! debug )
if ( debug )
warnx("started successfully ! (pid [%d], foreground/debug mode, usable env. var.: GPGME_DEBUG )",getpid());
else {
int fdnull;
warnx("started successfully ! (pid [%d], messages are now sent to syslog only)",getpid());
fclose( stderr );
// Alas, gpgpme seems using STDIN, STDOUT and STDERR and will crash or behave strangely if we use them freely, so we need to make sure STDERR -> /dev/null
fdnull=open("/dev/null", O_WRONLY);
if (fdnull == -1 ) {
syslog( LOG_CRIT, "open %.80s - %m","/dev/null");
exit( 1 );
}
else if (fdnull != STDERR_FILENO) {
if (dup2(fdnull,STDERR_FILENO) == -1) {
syslog( LOG_CRIT, "dup2 - %m");
exit( 1 );
}
close(fdnull);
}
}

/* Main loop. */
(void) gettimeofday( &tv, (struct timezone*) 0 );
Expand Down Expand Up @@ -1123,7 +1148,7 @@ parse_args( int argc, char** argv )
static void
usage( void )
{
(void) fprintf( stderr,
(void) fprintf( stderr,
"Usage: %s [options]\n"
"Options:\n"
" -u USER user to switch to (if started as root) - default: "DEFAULT_USER"\n"
Expand Down Expand Up @@ -1154,7 +1179,7 @@ usage( void )
" -E HOST external host name or IP adress - default: default hostname\n"
" -fpr KeyID fingerprint of the "SOFTWARE_NAME"'s OpenPGP key - no default, MANDATORY\n"
" -V show version and exit\n"
" -D stay in foreground\n"
" -D stay in foreground (usefull to debug or monitor)\n"
, argv0, user, DEFAULT_PORT
#if DEFAULT_CONNLIMIT > 0
, DEFAULT_CONNLIMIT
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#endif /* OPENUDC */
#endif /* SOFTWARE_NAME */

#define SOFTWARE_VERSION "0.3.5 30Oct2014"
#define SOFTWARE_VERSION "0.3.6 05Nov2014"
#define SOFTWARE_ADDRESS "http://openudc.org/"

#endif /* _VERSION_H_ */

0 comments on commit e07fd56

Please sign in to comment.