Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=a430570c25c35d9b0f7bf4610ddbe29155617e74
commit a430570c25c35d9b0f7bf4610ddbe29155617e74 Author: James Buren <[email protected]> Date: Sat Aug 11 17:00:48 2012 -0500 redirect stderr and stdout to the same log file diff --git a/fwsetup.h b/fwsetup.h index 0755d1f..15a4032 100644 --- a/fwsetup.h +++ b/fwsetup.h @@ -7,12 +7,14 @@ #include <string.h> #include <unistd.h> #include <locale.h> +#include <fcntl.h> #include <assert.h> #include <wchar.h> #define _(S) S #define memzero(P,N) memset(P,0,N) #define assert_not_reached() assert(0) +#define LOGFILE "fwsetup.log" #define WINDOWTITLE_TEXT _("Frugalware Linux Installer") #define NEXTBUTTON_TEXT _("Next") #define PREVIOUSBUTTON_TEXT _("Previous") diff --git a/utility.c b/utility.c index bd995a5..22e9c33 100644 --- a/utility.c +++ b/utility.c @@ -1,10 +1,48 @@ #include "fwsetup.h" +static FILE *redirect_std_stream(FILE *oldfp,int oldfd) +{ + assert(oldfp != 0); + assert(oldfd != -1); + + int newfd = fileno(oldfp); + FILE *newfp = 0; + + fclose(oldfp); + + close(newfd); + + dup2(oldfd,newfd); + + newfp = fdopen(newfd,"wb"); + + setbuf(newfp,0); + + return newfp; +} + extern void eprintf(const char *s,...) { assert(s != 0); va_list args; + static bool prepared = false; + + if(!prepared) + { + int fd = open(LOGFILE,O_CREAT|O_TRUNC|O_WRONLY,0644); + + if(fd == -1) + return; + + stderr = redirect_std_stream(stderr,fd); + +#ifndef NEWT + stdout = redirect_std_stream(stdout,fd); +#endif + + prepared = true; + } va_start(args,s); _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
