Browse code

Redirect stdin/stdout/stderr

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@52 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2003/09/24 14:54:53
Showing 2 changed files
... ...
@@ -114,6 +114,9 @@ Changes
114 114
 0.60d	26/8/03	Removed superflous buffer and unneeded strerror call
115 115
 		ETIMEDOUT isn't an error, but should give a warning
116 116
 0.60e	09/9/03	Added -P and -q flags by "Nicholas M. Kirsch" <nick@kirsch.org>
117
+0.60f	17/9/03	Changed fprintf to fputs where possible
118
+		Redirect stdin from /dev/null, stdout&stderr to
119
+		/dev/console
117 120
 
118 121
 BUG REPORTS
119 122
 
... ...
@@ -119,9 +119,12 @@
119 119
  *			ETIMEDOUT isn't an error, but should give a warning
120 120
  *	0.60e	09/9/03	Added -P and -q flags by "Nicholas M. Kirsch"
121 121
  *			<nick@kirsch.org>
122
+ *	0.60f	24/9/03	Changed fprintf to fputs where possible
123
+ *			Redirect stdin from /dev/null, stdout&stderr to
124
+ *			/dev/console
122 125
  */
123 126
 
124
-#define	CM_VERSION	"0.60e"
127
+#define	CM_VERSION	"0.60f"
125 128
 
126 129
 /*#define	CONFDIR	"/usr/local/etc"*/
127 130
 
... ...
@@ -154,7 +157,8 @@
154 154
 #include <sys/time.h>
155 155
 #include <netinet/in.h>
156 156
 #include <signal.h>
157
-#include <regex.h>	// njh@bandsman.co.uk
157
+#include <regex.h>
158
+#include <fcntl.h>
158 159
 
159 160
 #define _GNU_SOURCE
160 161
 #include "getopt.h"
... ...
@@ -517,12 +521,19 @@ main(int argc, char **argv)
517 517
 		unlink(port + 6);
518 518
 
519 519
 	if(smfi_register(smfilter) == MI_FAILURE) {
520
-		fprintf(stderr, "smfi_register failure\n");
520
+		fputs("smfi_register failure\n", stderr);
521 521
 		return EX_UNAVAILABLE;
522 522
 	}
523 523
 
524 524
 	signal(SIGPIPE, SIG_IGN);
525 525
 
526
+	close(0);
527
+	close(1);
528
+	close(2);
529
+	open("/dev/null", O_RDONLY);
530
+	open("/dev/console", O_WRONLY);
531
+	open("/dev/console", O_WRONLY);
532
+
526 533
 	return smfi_main();
527 534
 }
528 535
 
... ...
@@ -583,7 +594,10 @@ clamfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
583 583
 
584 584
 	if(use_syslog)
585 585
 		syslog(LOG_NOTICE, "clamfi_connect: connection from %s [%s]", hostname, remoteIP);
586
-	printf("clamfi_connect: connection from %s [%s]\n", hostname, remoteIP);
586
+#ifdef	CL_DEBUG
587
+	if(debug_level >= 4)
588
+		printf("clamfi_connect: connection from %s [%s]\n", hostname, remoteIP);
589
+#endif
587 590
 
588 591
 	if(!oflag)
589 592
 		if(strcmp(remoteIP, "127.0.0.1") == 0) {
... ...
@@ -690,7 +704,7 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
690 690
 #endif
691 691
 				char message[64];
692 692
 
693
-#ifdef TARGET_OS_SOLARIS        /* no strerror_r */
693
+#ifdef TARGET_OS_SOLARIS	/* no strerror_r */
694 694
 				snprintf(message, sizeof(message), "pthread_cond_timedwait: %s", strerror(rc));
695 695
 #else
696 696
 				strerror_r(rc, buf, sizeof(buf));
... ...
@@ -809,11 +823,12 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
809 809
 		close(privdata->dataSocket);
810 810
 		close(privdata->cmdSocket);
811 811
 		free(privdata);
812
-		fprintf(stderr, "Expected port information from clamd, got '%s'\n",
813
-			buf);
814 812
 		if(use_syslog)
815 813
 			syslog(LOG_ERR, "Expected port information from clamd, got '%s'",
816 814
 				buf);
815
+		else
816
+			fprintf(stderr, "Expected port information from clamd, got '%s'\n",
817
+				buf);
817 818
 		return SMFIS_TEMPFAIL;
818 819
 	}
819 820
 
... ...
@@ -839,7 +854,7 @@ clamfi_envfrom(SMFICTX *ctx, char **argv)
839 839
 
840 840
 		/* 0.4 - use better error message */
841 841
 		if(use_syslog) {
842
-#ifdef TARGET_OS_SOLARIS        /* no strerror_r */
842
+#ifdef TARGET_OS_SOLARIS	/* no strerror_r */
843 843
 			syslog(LOG_ERR, "Failed to connect to port %d given by clamd: %s", port, strerror(rc));
844 844
 #else
845 845
 			strerror_r(rc, buf, sizeof(buf));