Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/memprof/ChangeLog,v
retrieving revision 1.68
diff -u -p -u -r1.68 ChangeLog
--- ChangeLog	8 Aug 2002 01:32:55 -0000	1.68
+++ ChangeLog	8 Aug 2002 11:40:45 -0000
@@ -1,3 +1,23 @@
+2002-08-08  Michael Meeks  <michael@ximian.com>
+
+	* process.c (process_get_cmdline): 
+	use g_file_get_contents instead of getline
+
+	* tree.c,
+	* main.c,
+	* server.c: int casts on pid_t, uid_t
+
+	* main.c (WAIT_ANY): define if not defined.
+
+	* memintercept.c: switch to gthread for Solaris.
+	(new_process): setup sigpipe if we have to. 
+	MSG_NOSIGNAL - rename to SEND_FLAGS and cope if we
+	don't have it.
+	(__clone, __vfork, __fork): switch to pid_t ret type.
+
+	* main.c (show_error): use g_strdup_printf not
+	vasprintf.
+
 Tue Aug  6 21:14:00 2002  Owen Taylor  <otaylor@redhat.com>
 
 	* memintercept.c (debug): Add a mini-printf implementation, use
Index: main.c
===================================================================
RCS file: /cvs/gnome/memprof/main.c,v
retrieving revision 1.22
diff -u -p -u -r1.22 main.c
--- main.c	8 Aug 2002 01:32:55 -0000	1.22
+++ main.c	8 Aug 2002 11:40:46 -0000
@@ -45,6 +45,10 @@
 #include "profile.h"
 #include "server.h"
 
+#ifndef WAIT_ANY
+#  define WAIT_ANY -1
+#endif
+
 struct _ProcessWindow {
 	MPProcess *process;
 	Profile *profile;
@@ -704,7 +708,8 @@ status_changed_cb (MPProcess *process, P
 	} else {
 		char *status  = process_get_status_text (process);
 		char *cmdline = process_get_cmdline (process);
-		char *title = g_strdup_printf ("%s - %s (%d) - %s", _("MemProf"), cmdline, process->pid, status);
+		char *title = g_strdup_printf ("%s - %s (%d) - %s", _("MemProf"),
+					       cmdline, (int) process->pid, status);
 		gtk_window_set_title (GTK_WINDOW (pwin->main_window), title);
 		g_free (title);
 		g_free (status);
@@ -1394,7 +1399,7 @@ show_error (GtkWidget *parent_window,
 	GtkWidget *dialog;
 
 	va_start (args, format);
-	vasprintf (&message, format, args);
+	message = g_strdup_vprintf (format, args);
 	va_end (args);
 
 	dialog = gtk_message_dialog_new (parent_window ? GTK_WINDOW (parent_window) : NULL,
@@ -1403,7 +1408,7 @@ show_error (GtkWidget *parent_window,
 					   GTK_MESSAGE_ERROR :
 					   GTK_MESSAGE_WARNING,
 					 GTK_BUTTONS_OK, message);
-	free (message);
+	g_free (message);
 
 	gtk_window_set_title (GTK_WINDOW (dialog),
 			      (error == ERROR_FATAL) ?
Index: memintercept.c
===================================================================
RCS file: /cvs/gnome/memprof/memintercept.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 memintercept.c
--- memintercept.c	8 Aug 2002 01:32:55 -0000	1.15
+++ memintercept.c	8 Aug 2002 11:40:46 -0000
@@ -31,9 +31,10 @@
 #include <fcntl.h>
 #include <string.h>
 #include <stdarg.h>
+#include <signal.h>
 #include "memintercept.h"
 
-#include <pthread.h>
+#include <glib/gthread.h>
 
 #include <sys/socket.h>
 #include <sys/types.h>
@@ -44,12 +45,12 @@ static int initialized = 0;
 static int (*old_execve) (const char *filename,
 			  char *const argv[],
 			  char *const envp[]);
-static int (*old_fork) (void);
-static int (*old_vfork) (void);
-static int (*old_clone) (int (*fn) (void *arg),
-			 void *child_stack,
-			 int flags,
-			 void *arg);
+static pid_t (*old_fork)   (void);
+static pid_t (*old_vfork)  (void);
+static pid_t (*old_clone)  (int (*fn) (void *arg),
+			    void *child_stack,
+			    int flags,
+			    void *arg);
 static void *(*old_malloc) (size_t size);
 static void *(*old_calloc) (size_t nmemb, size_t size);
 static void *(*old_memalign) (size_t boundary, size_t size);
@@ -59,7 +60,7 @@ static void (*old__exit) (int status);
 
 #define MAX_THREADS 128
 
-static pthread_mutex_t malloc_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+static GStaticRecMutex malloc_mutex = G_STATIC_REC_MUTEX_INIT;
 static int tracing = 1;
 
 static int pids[MAX_THREADS];
@@ -74,8 +75,20 @@ int starter_last = 0;
 
 #undef ENABLE_DEBUG
 
-#define MI_LOCK() pthread_mutex_lock (&malloc_mutex);
-#define MI_UNLOCK() pthread_mutex_unlock (&malloc_mutex);
+#define MI_LOCK() g_static_rec_mutex_lock (&malloc_mutex);
+#define MI_UNLOCK() g_static_rec_mutex_unlock (&malloc_mutex);
+
+#ifdef MSG_NOSIGNAL
+/* We use this to get an EPIPE instead of a pipe signal on send */
+#  define SEND_FLAGS    MSG_NOSIGNAL
+#  define SETUP_SIGPIPE 
+#else
+/* We turn off sigpipe, invasive but no other way to do it, and
+ * every real person disables sigpipe anyway it seems.
+ */
+#  define SEND_FLAGS 0
+#  define SETUP_SIGPIPE signal (SIGPIPE, SIG_IGN);
+#endif
 
 static void
 abort_unitialized (const char *call)
@@ -235,8 +248,7 @@ write_all (int fd, void *buf, int total)
 	int written = 0;
 
 	while (written < total) {
-		/* Use send() to avoid EPIPE errors */
-		count = send (fd, buf + written, total - written, MSG_NOSIGNAL);
+		count = send (fd, buf + written, total - written, SEND_FLAGS);
 		if (count < 0) {
 			if (errno != EINTR)
 				goto error;
@@ -275,6 +287,8 @@ new_process (pid_t old_pid, MIOperation 
 	if (addrlen > sizeof (addr))
 		addrlen = sizeof(addr);
 
+	SETUP_SIGPIPE
+
 	outfd = socket (PF_UNIX, SOCK_STREAM, 0);
 	if (outfd < 0) {
 			write (2, "FRUG", 4);
@@ -593,7 +607,7 @@ free (void *ptr)
 	__libc_free (ptr);
 }
 
-int
+pid_t
 __fork (void)
 {
 	if (!initialized)
@@ -613,7 +627,7 @@ __fork (void)
 		return (*old_fork) ();
 }
 
-int
+pid_t
 __vfork (void)
 {
 	if (!initialized)
@@ -663,7 +677,8 @@ typedef struct 
 	pid_t pid;
 } CloneData;
 
-int clone_thunk (void *arg)
+int
+clone_thunk (void *arg)
 {
 	CloneData *data = arg;
 	int (*fn)(void *) = data->fn;
@@ -675,10 +690,11 @@ int clone_thunk (void *arg)
 	return (*fn) (sub_arg);
 }
 
-int __clone (int (*fn) (void *arg),
-	     void *child_stack,
-	     int   flags,
-	     void *arg)
+pid_t
+__clone (int (*fn) (void *arg),
+	 void *child_stack,
+	 int   flags,
+	 void *arg)
 {
 	volatile CloneData data;
 	int pid;
Index: process.c
===================================================================
RCS file: /cvs/gnome/memprof/process.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 process.c
--- process.c	15 Jul 2002 23:39:00 -0000	1.21
+++ process.c	8 Aug 2002 11:40:47 -0000
@@ -837,28 +837,21 @@ process_get_status_text (MPProcess *proc
 char *
 process_get_cmdline (MPProcess *process)
 {
+	gsize n;
 	char *fname;
 	char *result;
-	char *tmp = NULL;
-	int n = 0;
-	FILE *in = NULL;
 
 	if (process->status == MP_PROCESS_DEFUNCT)
 		return g_strdup ("");
 	
-	fname = g_strdup_printf ("/proc/%d/cmdline", process->pid);
-	in = fopen (fname, "r");
-	if (!in) {
-		g_warning ("Can't open %s\n", fname);
-		return g_strdup ("");
-	}
-	g_free (fname);
+	fname = g_strdup_printf ("/proc/%d/cmdline", (int) process->pid);
 
-	getline (&tmp, &n, in);
-	result = g_strdup (tmp);
-	free (tmp);
+	if (!g_file_get_contents (fname, &result, &n, NULL)) {
+		g_warning ("Can't open '%s'\n", fname);
+		result = g_strdup_printf ("%d", (int) process->pid);
+	}
 
-	fclose (in);
+	g_free (fname);
 
 	return result;
 }
Index: server.c
===================================================================
RCS file: /cvs/gnome/memprof/server.c,v
retrieving revision 1.9
diff -u -p -u -r1.9 server.c
--- server.c	15 Jul 2002 23:39:00 -0000	1.9
+++ server.c	8 Aug 2002 11:40:47 -0000
@@ -23,6 +23,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <string.h>
 #include <unistd.h>
 #include <sys/un.h>
 #include <sys/stat.h>
@@ -267,7 +268,7 @@ cleanup_socket (void)
 	 * this to fail
 	 */
 	{
-		char *tmpdir = tmpdir = g_strdup_printf ("%s/memprof.%d", g_get_tmp_dir(), getuid());
+		char *tmpdir = tmpdir = g_strdup_printf ("%s/memprof.%d", g_get_tmp_dir(), (int) getuid());
 		if (rmdir (tmpdir) != 0) {
 			if (errno != ENOTEMPTY)
 				g_warning ("Unlinking %s failed with error: %s\n", tmpdir, g_strerror (errno));
@@ -337,7 +338,7 @@ create_control_socket (MPServer *server)
 	mode_t old_mask = umask (077);
 
 #ifdef USE_SOCKET_DIRECTORY
-	char *tmpdir = g_strdup_printf ("%s/memprof.%d", g_get_tmp_dir(), getuid());
+	char *tmpdir = g_strdup_printf ("%s/memprof.%d", g_get_tmp_dir(), (int) getuid());
 	struct stat st_buf;
 #endif
 	
@@ -379,7 +380,7 @@ create_control_socket (MPServer *server)
 	} else
 		fatal ("memprof: error calling stat() on %s: %s\n", tmpdir, g_strerror (errno));
 
-	server->socket_path = g_strdup_printf ("%s/server.%d", tmpdir, getpid());
+	server->socket_path = g_strdup_printf ("%s/server.%d", tmpdir, (int) getpid());
 	if (g_file_exists (server->socket_path)) {
 		g_warning ("Stale memprof socket %s, removing\n", server->socket_path);
 		unlink (server->socket_path);
Index: tree.c
===================================================================
RCS file: /cvs/gnome/memprof/tree.c,v
retrieving revision 1.6
diff -u -p -u -r1.6 tree.c
--- tree.c	15 Jul 2002 23:39:00 -0000	1.6
+++ tree.c	8 Aug 2002 11:40:47 -0000
@@ -189,7 +189,7 @@ update_node (GtkCTreeNode *node)
 	ProcessWindow *pwin = gtk_ctree_node_get_row_data (GTK_CTREE (tree_ctree), node);
 	MPProcess *process = process_window_get_process (pwin);
 
-	sprintf(buffer, "%d", process->pid);
+	sprintf(buffer, "%d", (int) process->pid);
 	gtk_ctree_node_set_text (GTK_CTREE (tree_ctree), node, 0, buffer);
 
 	cmdline = process_get_cmdline (process);
