Hi,

While trying to do part 2 of the assignment for COMP535 on my home
computer, I found out that grouter segfaults on 64-bit machines. The
problem is that pthread_t is typedef'd to unsigned long int which is
64 bits on 64-bit platforms, but grouter stores its thread ids in
32-bit ints. The attached patch fixes it for me; grouter still
segfaults while exiting (there's a problem with raise(SIGUSR1) in
cli.c) but at least it doesn't stop me from completing the assignment.

The patch is against latest devel branch.

Thanks,

--
Samuel Cormier-Iijima <sciyo...@gmail.com>
http://sciyoshi.com/
Index: backend/include/packetcore.h
===================================================================
--- backend/include/packetcore.h	(revision 80)
+++ backend/include/packetcore.h	(working copy)
@@ -12,6 +12,7 @@
 #include <slack/std.h>
 #include <slack/map.h>
 #include <slack/list.h>
+#include <pthread.h>
 
 #include "message.h"
 #include "grouter.h"
@@ -55,7 +56,7 @@
 void modifyQueueDiscipline(pktcore_t *pcore, char *qname, char *qdisc);
 int delPktCoreQueue(pktcore_t *pcore, char *qname);
 
-int PktCoreSchedulerInit(pktcore_t *pcore);
+pthread_t PktCoreSchedulerInit(pktcore_t *pcore);
 int PktCoreWorkerInit(pktcore_t *pcore);
 void *packetProcessor(void *pc);
 
Index: backend/include/grouter.h
===================================================================
--- backend/include/grouter.h	(revision 80)
+++ backend/include/grouter.h	(working copy)
@@ -22,8 +22,8 @@
  */
 #include <limits.h>
 #include <sys/time.h>
+#include <pthread.h>
 
-
 /*
  * global definitions.... this is stuff that could not be
  * put into specialized header files....
@@ -84,10 +84,10 @@
 	int cli_flag;
 	char *config_file;
 	char *config_dir;
-	int ghandler;
-	int clihandler;
-	int scheduler;
-	int worker;
+	pthread_t ghandler;
+	pthread_t clihandler;
+	pthread_t scheduler;
+	pthread_t worker;
 	int schedcycle;
 	char schedpolicy[MAX_NAME_LEN];
 } router_config;
@@ -112,5 +112,5 @@
 
 // function prototypes for code in router.c
 void redefineSignalHandler(int sigid, void (*my_func)());
-void wait4thread(int threadid);
+void wait4thread(pthread_t threadid);
 #endif
Index: backend/src/grouter/SConscript
===================================================================
--- backend/src/grouter/SConscript	(revision 80)
+++ backend/src/grouter/SConscript	(working copy)
@@ -4,6 +4,7 @@
 gini_include = gini_src + '/include'
 
 env = Environment(CPPPATH=gini_include)
+env.Append(CFLAGS='-g')
 env.Append(CFLAGS='-DHAVE_PTHREAD_RWLOCK=1')
 env.Append(CFLAGS='-DHAVE_GETOPT_LONG')
 
Index: backend/src/grouter/cli.c
===================================================================
--- backend/src/grouter/cli.c	(revision 80)
+++ backend/src/grouter/cli.c	(working copy)
@@ -880,7 +880,7 @@
 			else
 				verbose(1, "[setCmd]:: ERROR!! level should be in [0..6] \n");
 		} else
-			printf("\nVerbose level: %d \n", prog_verbosity_level());
+			printf("\nVerbose level: %ld \n", prog_verbosity_level());
 	} else if (!strcmp(next_tok, "raw-times"))
 	{
 		if ((next_tok = strtok(NULL, " \n")) != NULL)
@@ -996,7 +996,7 @@
 	else if (!strcmp(next_tok, "sched-cycle"))
 		printf("\nSchedule cycle length: %d (microseconds) \n", rconfig.schedcycle);
 	else if (!strcmp(next_tok, "verbose"))
-		printf("\nVerbose level: %d \n", prog_verbosity_level());
+		printf("\nVerbose level: %ld \n", prog_verbosity_level());
 	else if (!strcmp(next_tok, "raw-times"))
 		printf("\nRaw time mode: %d  \n", getTimeMode());
 	else if (!strcmp(next_tok, "update-delay"))
Index: backend/src/grouter/packetcore.c
===================================================================
--- backend/src/grouter/packetcore.c	(revision 80)
+++ backend/src/grouter/packetcore.c	(working copy)
@@ -288,9 +288,10 @@
 // as the scheduler. Only the dequeue is hooked up. The enqueue part is
 // in the classifier. The dequeue will put the scheduler in wait when it
 // runs out of jobs in the queue. The enqueue will wake up a sleeping scheduler.
-int PktCoreSchedulerInit(pktcore_t *pcore)
+pthread_t PktCoreSchedulerInit(pktcore_t *pcore)
 {
-	int threadstat, threadid;
+	int threadstat;
+	pthread_t threadid;
 
 	threadstat = pthread_create((pthread_t *)&threadid, NULL, (void *)roundRobinScheduler, (void *)pcore);
 	if (threadstat != 0)
Index: backend/src/grouter/SConstruct
===================================================================
--- backend/src/grouter/SConstruct	(revision 80)
+++ backend/src/grouter/SConstruct	(working copy)
@@ -8,6 +8,7 @@
 gini_include = gini_src + '/include'
 
 env = Environment(CPPPATH=gini_include)
+env.Append(CFLAGS='-g')
 env.Append(CFLAGS='-DHAVE_PTHREAD_RWLOCK=1')
 env.Append(CFLAGS='-DHAVE_GETOPT_LONG')
 
Index: backend/src/grouter/grouter.c
===================================================================
--- backend/src/grouter/grouter.c	(revision 80)
+++ backend/src/grouter/grouter.c	(working copy)
@@ -101,7 +101,7 @@
 }
 
 
-void wait4thread(int threadid)
+void wait4thread(pthread_t threadid)
 {
 	int *jstatus;
 	if (threadid > 0)
_______________________________________________
gini mailing list
gini@cs.mcgill.ca
http://mailman.cs.mcgill.ca/mailman/listinfo/gini

Reply via email to