Plugin API: add malloc()
authorEduardo Silva <edsiper@gmail.com>
Tue, 29 Sep 2009 02:18:33 +0000 (22:18 -0400)
committerEduardo Silva <edsiper@gmail.com>
Tue, 29 Sep 2009 02:18:33 +0000 (22:18 -0400)
src/include/plugin.h
src/plugin.c
src/plugins/cheetah/cheetah.c

index dbb2ed1..899a56d 100644 (file)
@@ -59,8 +59,8 @@ struct plugin {
 struct plugin_api {
         struct server_config *config;
         struct sched_list_node **sched_list;
-
-        void (*malloc)(void *);
+        /* Functions */
+        void *(*malloc)(int *);
 };
 
 typedef char mk_plugin_data_t[];
index b00d096..099dbb0 100644 (file)
@@ -144,6 +144,7 @@ void mk_plugin_init()
         api = mk_mem_malloc_z(sizeof(struct plugin_api));
         api->config = config;
         api->sched_list = &sched_list;
+        api->malloc = (void *) mk_mem_malloc;
 
         path = mk_mem_malloc_z(1024);
         snprintf(path, 1024, "%s/%s", config->serverconf, MK_PLUGIN_LOAD);
index d5adac9..462ed24 100644 (file)
@@ -70,13 +70,14 @@ struct plugin_api *papi;
 void mk_cheetah_print_worker_memory_usage(pid_t pid)
 {
         int last, init, n, c = 0;
+        int s = 1024;
         char *buf;
         char *value;
         pid_t ppid;
         FILE *f;
         
         ppid = getpid();
-        buf = malloc(1024);
+        buf = papi->malloc(s);
         sprintf(buf, MK_CHEETAH_PROC_TASK, ppid, pid);
 
         f = fopen(buf, "r");
@@ -85,7 +86,7 @@ void mk_cheetah_print_worker_memory_usage(pid_t pid)
                 return;
         }
 
-        buf = fgets(buf, 1024, f);
+        buf = fgets(buf, s, f);
         if(!buf){
                 printf("Cannot format details\n");
                 return;