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.46 by tdb, Wed Apr 7 09:44:08 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 45 | Line 45
45   #endif
46  
47   #include "tools.h"
48 + #include "statgrab.h"
49  
50   #ifdef SOLARIS
51   #ifdef HAVE_LIBDEVINFO_H
# Line 171 | Line 172 | static int get_alias(char *alias){
172          char *value;
173          int instance;
174          if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
175 <                return 1;
175 >                return -1;
176          }
177          node = di_drv_first_node(alias, root_node);
178          while (node != DI_NODE_NIL) {
# Line 213 | Line 214 | static int build_mapping(){
214          int found;
215  
216          if ((kc = kstat_open()) == NULL) {
217 <                return 1;
217 >                return -1;
218          }
219  
220          for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
# Line 235 | Line 236 | static int build_mapping(){
236                                  if (x>=BIG_ENOUGH){
237                                          /* We've got bigger than we thought was massive */
238                                          /* If we hit this.. Make big enough bigger */
239 <                                        return 1;
239 >                                        return -1;
240                                  }
241                                  if( !strncmp(driver_list[x], device_name, BIG_ENOUGH)){
242                                          found = 1;
# Line 245 | Line 246 | static int build_mapping(){
246  
247                          if(!found){
248                                  if((get_alias(device_name)) != 0){
249 <                                        return 1;
249 >                                        return -1;
250                                  }
251                                  strncpy(driver_list[x], device_name, BIG_ENOUGH);
252                                  list_entries++;
# Line 403 | Line 404 | size_t sg_strlcat(char *dst, const char *src, size_t s
404          return(dlen + (s - src));       /* count does not include NUL */
405   }
406  
407 < char *sg_update_string(char **dest, const char *src) {
407 > int sg_update_string(char **dest, const char *src) {
408          char *new;
409  
410 +        if (src == NULL) {
411 +                /* We're being told to set it to NULL. */
412 +                free(*dest);
413 +                *dest = NULL;
414 +                return 0;
415 +        }
416 +
417          new = realloc(*dest, strlen(src) + 1);
418          if (new == NULL) {
419 <                return NULL;
419 >                return -1;
420          }
421  
422          strcpy(new, src);
423          *dest = new;
424 <        return new;
424 >        return 0;
425   }
426  
427   long long sg_get_ll_match(char *line, regmatch_t *match){
# Line 454 | Line 462 | kvm_t *sg_get_kvm2() {
462   #if defined(NETBSD) || defined(OPENBSD)
463   struct uvmexp *sg_get_uvmexp() {
464          int mib[2];
465 <        size_t size;
466 <        static struct uvmexp *uvm = NULL;
465 >        size_t size = sizeof(struct uvmexp);
466 >        static struct uvmexp uvm;
467          struct uvmexp *new;
468  
469          mib[0] = CTL_VM;
470          mib[1] = VM_UVMEXP;
471  
472 <        if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) {
472 >        if (sysctl(mib, 2, &uvm, &size, NULL, 0) < 0) {
473                  return NULL;
474          }
475  
476 <        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;
476 >        return &uvm;
477   }
478   #endif
479  
480   int sg_init(){
481   #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
482          if (sg_get_kvm() == NULL) {
483 <                return 1;
483 >                return -1;
484          }
485          if (sg_get_kvm2() == NULL) {
486 <                return 1;
486 >                return -1;
487          }
488   #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;
497 #endif
489   #ifdef SOLARIS
490          /* On solaris 7, this will fail if you are not root. But, everything
491           * will still work, just no disk mappings. So we will ignore the exit
# Line 511 | Line 502 | int sg_drop_privileges() {
502          if (setegid(getgid()) != 0) return -1;
503          if (seteuid(getuid()) != 0) return -1;
504          return 0;
505 + }
506 +
507 + void *sg_realloc(void *ptr, size_t size) {
508 +        void *tmp = NULL;
509 +        tmp = realloc(ptr, size);
510 +        if(tmp == NULL) {
511 +                sg_set_error(SG_ERROR_MALLOC_FAILED, NULL);
512 +        }
513 +        return tmp;
514   }
515  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines