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

Comparing projects/libstatgrab/src/libstatgrab/tools.c (file contents):
Revision 1.41 by ats, Mon Apr 5 15:40:15 2004 UTC vs.
Revision 1.45 by ats, Tue Apr 6 17:55:16 2004 UTC

# Line 1 | Line 1
1   /*
2 < * i-scream central monitoring system
2 > * i-scream libstatgrab
3   * http://www.i-scream.org
4   * Copyright (C) 2000-2004 i-scream
5   *
# Line 171 | Line 171 | static int get_alias(char *alias){
171          char *value;
172          int instance;
173          if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
174 <                return 1;
174 >                return -1;
175          }
176          node = di_drv_first_node(alias, root_node);
177          while (node != DI_NODE_NIL) {
# Line 213 | Line 213 | static int build_mapping(){
213          int found;
214  
215          if ((kc = kstat_open()) == NULL) {
216 <                return 1;
216 >                return -1;
217          }
218  
219          for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
# Line 235 | Line 235 | static int build_mapping(){
235                                  if (x>=BIG_ENOUGH){
236                                          /* We've got bigger than we thought was massive */
237                                          /* If we hit this.. Make big enough bigger */
238 <                                        return 1;
238 >                                        return -1;
239                                  }
240                                  if( !strncmp(driver_list[x], device_name, BIG_ENOUGH)){
241                                          found = 1;
# Line 245 | Line 245 | static int build_mapping(){
245  
246                          if(!found){
247                                  if((get_alias(device_name)) != 0){
248 <                                        return 1;
248 >                                        return -1;
249                                  }
250                                  strncpy(driver_list[x], device_name, BIG_ENOUGH);
251                                  list_entries++;
# Line 403 | Line 403 | size_t sg_strlcat(char *dst, const char *src, size_t s
403          return(dlen + (s - src));       /* count does not include NUL */
404   }
405  
406 < char *sg_update_string(char **dest, const char *src) {
406 > int sg_update_string(char **dest, const char *src) {
407          char *new;
408  
409 +        if (src == NULL) {
410 +                /* We're being told to set it to NULL. */
411 +                free(*dest);
412 +                *dest = NULL;
413 +                return 0;
414 +        }
415 +
416          new = realloc(*dest, strlen(src) + 1);
417          if (new == NULL) {
418 <                return NULL;
418 >                return -1;
419          }
420  
421          strcpy(new, src);
422          *dest = new;
423 <        return new;
423 >        return 0;
424   }
425  
426   long long sg_get_ll_match(char *line, regmatch_t *match){
# Line 454 | Line 461 | kvm_t *sg_get_kvm2() {
461   #if defined(NETBSD) || defined(OPENBSD)
462   struct uvmexp *sg_get_uvmexp() {
463          int mib[2];
464 <        size_t size;
465 <        static struct uvmexp *uvm = NULL;
464 >        size_t size = sizeof(struct uvmexp);
465 >        static struct uvmexp uvm;
466          struct uvmexp *new;
467  
468          mib[0] = CTL_VM;
469          mib[1] = VM_UVMEXP;
470  
471 <        if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) {
471 >        if (sysctl(mib, 2, &uvm, &size, NULL, 0) < 0) {
472                  return NULL;
473          }
474  
475 <        new = realloc(uvm, size);
469 <        if (new == NULL) {
470 <                return NULL;
471 <        }
472 <        uvm = new;
473 <
474 <        if (sysctl(mib, 2, uvm, &size, NULL, 0) < 0) {
475 <                return NULL;
476 <        }
477 <
478 <        return uvm;
475 >        return &uvm;
476   }
477   #endif
478  
479   int sg_init(){
480   #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
481          if (sg_get_kvm() == NULL) {
482 <                return 1;
482 >                return -1;
483          }
484          if (sg_get_kvm2() == NULL) {
485 <                return 1;
485 >                return -1;
486          }
490 #endif
491 #if defined(NETBSD) || defined(OPENBSD)
492        /* This should always succeed, but it seems that on some
493         * versions of NetBSD the first call to get_uvmexp will return
494         * a non-filled-in structure; this is a workaround for that.
495         */
496        if (sg_get_uvmexp() == NULL) return 1;
487   #endif
488   #ifdef SOLARIS
489          /* On solaris 7, this will fail if you are not root. But, everything

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines