yamd - patch

Luke Kenneth Casson Leighton lkcl at samba.org
Thu Feb 24 20:42:52 GMT 2000


this patch to yamd allows you to track multiple processes.  unfortunately,
yamd assumes that only one process is ever going to be running, so when
tracking smbd or, say, spoolssd, each fork() overwrites the previous yamd
log file (see?  it opens O_WRONLY | O_CREAT | O_TRUNC).

and of course, you need memory tracking on a per-process basis, not
tracking memory on a per-several-process basis (which is why removing the
O_TRUNC isn't a good enough fix).

luke

--- yamd-0.32/yamd.c	Thu Oct 14 17:44:51 1999
+++ /home/lkcl/yamd-0.32/yamd.c	Wed Feb  9 16:48:58 2000
@@ -28,6 +28,7 @@
 #include <sys/resource.h>
 #include <sys/mman.h>
 #include <sys/wait.h>
+#include <sys/stat.h>
 #include <math.h>
 
 /* Configuration info */
@@ -1840,11 +1841,22 @@
     }
   else
     {
+	int count = 0;
+	struct stat buf;
+	static char real_log_file_name[256];
+
+	do
+	{
+		sprintf(real_log_file_name, "%s.%d", logfile_name, count);
+		count++;
+	}
+	while (stat(real_log_file_name, &buf) == 0);
+
       /* Would other perms. be a good idea? */
-      log_fd = open(logfile_name, O_WRONLY | O_CREAT | O_TRUNC, 0600); 
+      log_fd = open(real_log_file_name, O_WRONLY | O_CREAT | O_TRUNC, 0600); 
       if (log_fd < 0)
 	{
-	  perror(logfile_name);
+	  perror(real_log_file_name);
 	  return;
 	}
     }



More information about the samba-technical mailing list