ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/disk_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/disk_stats.c (file contents):
Revision 1.58 by ats, Sun Apr 4 23:26:23 2004 UTC vs.
Revision 1.60 by ats, Mon Apr 5 00:07:37 2004 UTC

# Line 31 | Line 31
31   #include <time.h>
32   #include "statgrab.h"
33   #include "vector.h"
34 + #include "tools.h"
35  
36   #ifdef SOLARIS
37   #include <sys/mnttab.h>
# Line 42 | Line 43
43   #if defined(LINUX) || defined(CYGWIN)
44   #include <mntent.h>
45   #include <sys/vfs.h>
45 #include "tools.h"
46   #endif
47  
48   #ifdef LINUX
# Line 76 | Line 76
76                          "ntfs"}
77   #endif
78  
79 static char *copy_string(char **dest, const char *src) {
80        char *new;
81
82        new = realloc(*dest, strlen(src) + 1);
83        if (new == NULL) {
84                return NULL;
85        }
86
87        strcpy(new, src);
88        *dest = new;
89        return new;
90 }
91
79   static void disk_stat_init(disk_stat_t *d) {
80          d->device_name = NULL;
81          d->fs_type = NULL;
# Line 178 | Line 165 | disk_stat_t *get_disk_stats(int *entries){
165                          disk_ptr=disk_stats+num_disks;
166  
167   #ifdef ALLBSD
168 <                        if (copy_string(&disk_ptr->device_name, mp->f_mntfromname) == NULL) {
168 >                        if (update_string(&disk_ptr->device_name, mp->f_mntfromname) == NULL) {
169                                  return NULL;
170                          }
171 <                        if (copy_string(&disk_ptr->fs_type, mp->f_fstypename) == NULL) {
171 >                        if (update_string(&disk_ptr->fs_type, mp->f_fstypename) == NULL) {
172                                  return NULL;
173                          }
174 <                        if (copy_string(&disk_ptr->mnt_point, mp->f_mntonname) == NULL) {
174 >                        if (update_string(&disk_ptr->mnt_point, mp->f_mntonname) == NULL) {
175                                  return NULL;
176                          }
177  
# Line 198 | Line 185 | disk_stat_t *get_disk_stats(int *entries){
185                          disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes;
186   #endif
187   #if defined(LINUX) || defined(CYGWIN)
188 <                        if (copy_string(&disk_ptr->device_name, mp->mnt_fsname) == NULL) {
188 >                        if (update_string(&disk_ptr->device_name, mp->mnt_fsname) == NULL) {
189                                  return NULL;
190                          }
191                                  
192 <                        if (copy_string(&disk_ptr->fs_type, mp->mnt_type) == NULL) {    
192 >                        if (update_string(&disk_ptr->fs_type, mp->mnt_type) == NULL) {  
193                                  return NULL;
194                          }
195  
196 <                        if (copy_string(&disk_ptr->mnt_point, mp->mnt_dir) == NULL) {
196 >                        if (update_string(&disk_ptr->mnt_point, mp->mnt_dir) == NULL) {
197                                  return NULL;
198                          }
199                          disk_ptr->size = (long long)fs.f_bsize * (long long)fs.f_blocks;
# Line 224 | Line 211 | disk_stat_t *get_disk_stats(int *entries){
211                           * Downside is its a bit hungry for a lot of mounts, as MNT_MAX_SIZE would prob
212                           * be upwards of a k each
213                           */
214 <                        if (copy_string(&disk_ptr->device_name, mp.mnt_special) == NULL) {
214 >                        if (update_string(&disk_ptr->device_name, mp.mnt_special) == NULL) {
215                                  return NULL;
216                          }
217  
218 <                        if (copy_string(&disk_ptr->fs_type, mp.mnt_fstype) == NULL) {
218 >                        if (update_string(&disk_ptr->fs_type, mp.mnt_fstype) == NULL) {
219                                  return NULL;
220                          }
221          
222 <                        if (copy_string(&disk_ptr->mnt_point, mp.mnt_mountp) == NULL) {
222 >                        if (update_string(&disk_ptr->mnt_point, mp.mnt_mountp) == NULL) {
223                                  return NULL;
224                          }
225                          
# Line 393 | Line 380 | diskio_stat_t *get_diskio_stats(int *entries){
380          }
381  
382          for (i = 0; i < num_disks; i++) {
383 +                const char *name;
384                  u_int64_t rbytes, wbytes;
385  
386   #ifdef NETBSD
# Line 419 | Line 407 | diskio_stat_t *get_diskio_stats(int *entries){
407                  
408                  diskio_stats_ptr->read_bytes = rbytes;
409                  diskio_stats_ptr->write_bytes = wbytes;
422                if (diskio_stats_ptr->disk_name != NULL) {
423                        free(diskio_stats_ptr->disk_name);
424                }
410   #ifdef NETBSD
411 <                diskio_stats_ptr->disk_name = strdup(stats[i].dk_name);
411 >                name = stats[i].dk_name;
412   #else
413 <                diskio_stats_ptr->disk_name = strdup(dk_name[i]);
413 >                name = dk_name[i];
414   #endif
415 +                if (update_string(&diskio_stats_ptr->disk_name, name) == NULL) {
416 +                        return NULL;
417 +                }
418                  diskio_stats_ptr->systime = time(NULL);
419          
420                  num_diskio++;  
# Line 488 | Line 476 | diskio_stat_t *get_diskio_stats(int *entries){
476                  diskio_stats_ptr->write_bytes=dev_ptr->bytes_written;
477   #endif
478                  if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name);
479 <                asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number);
479 >                if (asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number) == -1) {
480 >                        return NULL;
481 >                }
482                  diskio_stats_ptr->systime=time(NULL);
483  
484                  num_diskio++;
# Line 517 | Line 507 | diskio_stat_t *get_diskio_stats(int *entries){
507                          diskio_stats_ptr=diskio_stats+num_diskio;
508                          
509                          diskio_stats_ptr->read_bytes=kios.nread;
520                        
510                          diskio_stats_ptr->write_bytes=kios.nwritten;
511 <
512 <                        if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name);
513 <
514 <                        diskio_stats_ptr->disk_name=strdup((char *) get_svr_from_bsd(ksp->ks_name));
511 >                        if (update_string(&diskio_stats_ptr->disk_name,
512 >                                          get_svr_from_bsd(ksp->ks_name)) == NULL) {
513 >                                return NULL;
514 >                        }
515                          diskio_stats_ptr->systime=time(NULL);
516 +
517                          num_diskio++;
518                  }
519          }
# Line 578 | Line 568 | diskio_stat_t *get_diskio_stats(int *entries){
568                          goto out;
569                  }
570  
571 <                if (diskio_stats[n].disk_name != NULL)
572 <                        free(diskio_stats[n].disk_name);
573 <                diskio_stats[n].disk_name = strdup(name);
571 >                if (update_string(&diskio_stats[n].disk_name, name) == NULL) {
572 >                        goto out;
573 >                }
574                  diskio_stats[n].read_bytes = rsect * 512;
575                  diskio_stats[n].write_bytes = wsect * 512;
576                  diskio_stats[n].systime = now;
# Line 696 | Line 686 | diskio_stat_t *get_diskio_stats_diff(int *entries){
686                  src = &diskio_stats[i];
687                  dest = &diff[i];
688  
689 <                if (dest->disk_name != NULL) {
690 <                        free(dest->disk_name);
689 >                if (update_string(&dest->disk_name, src->disk_name) == NULL) {
690 >                        return NULL;
691                  }
702                dest->disk_name = strdup(src->disk_name);
692                  dest->read_bytes = src->read_bytes;
693                  dest->write_bytes = src->write_bytes;
694                  dest->systime = src->systime;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines