[mw-devel] MW3 r1159 - trunk/src

welshbyte at sucs.org welshbyte at sucs.org
Fri Jul 23 13:13:18 BST 2010


Author: welshbyte
Date: 2010-07-23 13:13:18 +0100 (Fri, 23 Jul 2010)
New Revision: 1159

Modified:
   trunk/src/files.c
   trunk/src/files.h
   trunk/src/ipc.c
   trunk/src/main.c
Log:
- Change open_fifo() to open_incoming_fifo()
- Add an open_outgoing_fifo() function
- Make get_pipe_name() static
- Give files.c its own MAXPIPELENGTH instead of using MAXTEXTLENGTH
- Remove bb.h include from files.c


Modified: trunk/src/files.c
===================================================================
--- trunk/src/files.c	2010-07-23 11:02:40 UTC (rev 1158)
+++ trunk/src/files.c	2010-07-23 12:13:18 UTC (rev 1159)
@@ -17,16 +17,16 @@
 #include "user.h"
 #include "perms.h"
 #include "files.h"
-#include "util.h"
 #include "who.h"
-#include "bb.h" // Just for MAXTEXTLENGTH, sigh
 
 int incoming_pipe;
 
-char *get_pipe_name(int pid)
+#define MAXPIPELENGTH 2048
+
+static char *get_pipe_name(int pid)
 {
-	static char fullpath[MAXTEXTLENGTH];
-	snprintf(fullpath,MAXTEXTLENGTH-1,MSGDIR"/bbs.%d",pid);
+	static char fullpath[MAXPIPELENGTH];
+	snprintf(fullpath,MAXPIPELENGTH-1,MSGDIR"/bbs.%d",pid);
 	return(fullpath);
 }
 
@@ -39,7 +39,7 @@
 	}
 }
 
-void open_fifo(void)
+void open_incoming_fifo(void)
 {
 	if ((incoming_pipe=open(get_pipe_name(getpid()),O_RDWR))<0)
 	{
@@ -48,6 +48,16 @@
 	}
 }
 
+int open_outgoing_fifo(pid_t dest_pid)
+{
+	int fd = open(get_pipe_name(dest_pid), O_WRONLY|O_APPEND|O_NDELAY);
+	if (fd < 0)
+	{
+		perror("Error opening outgoing pipe");
+	}
+	return fd;
+}
+
 void close_fifo(void)
 {
 	if(incoming_pipe)

Modified: trunk/src/files.h
===================================================================
--- trunk/src/files.h	2010-07-23 11:02:40 UTC (rev 1158)
+++ trunk/src/files.h	2010-07-23 12:13:18 UTC (rev 1159)
@@ -10,8 +10,8 @@
 #define WHOFILE     MSGDIR"/who.bb"
 
 void create_pipe(void);
-char *get_pipe_name(int pid);
-void open_fifo(void);
+void open_incoming_fifo(void);
+int open_outgoing_fifo(pid_t dest_pid);
 void close_fifo(void);
 void Lock_File(int f);
 void Unlock_File(int f);

Modified: trunk/src/ipc.c
===================================================================
--- trunk/src/ipc.c	2010-07-23 11:02:40 UTC (rev 1158)
+++ trunk/src/ipc.c	2010-07-23 12:13:18 UTC (rev 1159)
@@ -31,7 +31,6 @@
 int ipc_send_to_pid(pid_t dest, enum ipc_types msgtype, const char * data) {
 	char	buff[MAXTEXTLENGTH];
 	int	fd;
-	char *	fifo_path;
 	ssize_t	dgram_len;
 	pid_t	mypid;
 	char *	qdata;
@@ -39,9 +38,8 @@
 
 	if (dest < 1) return -1;	// Invalid PID
 	if (! data) data = "";
-	fifo_path = get_pipe_name(dest);
 
-	fd = open(fifo_path, O_WRONLY|O_APPEND|O_NDELAY);
+	fd = open_outgoing_fifo(dest);
 	if (fd < 0) {
 		who_delete(dest);
 		return -1;
@@ -65,7 +63,7 @@
 				ret = -2;
 			}
 		} else {
-			fprintf(stderr, "Failed to utf8_clean the message to, %s (not sent)\n", fifo_path); 
+			fprintf(stderr, "Failed to utf8_cleanup the message\n"); 
 		}
 	}
 	close(fd);

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2010-07-23 11:02:40 UTC (rev 1158)
+++ trunk/src/main.c	2010-07-23 12:13:18 UTC (rev 1159)
@@ -588,7 +588,7 @@
 
 	close_fifo();
 	create_pipe();
-	open_fifo();	
+	open_incoming_fifo();
 
 	/* display all new messages for given user */
 	if (msguser_num>-1 && god_mode())




More information about the mw-devel mailing list