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.50 by pajs, Wed Apr 7 15:46:34 2004 UTC vs.
Revision 1.59 by ats, Sat Nov 6 14:55:53 2004 UTC

# Line 30 | Line 30
30   #include <stdlib.h>
31   #include <unistd.h>
32   #include <sys/types.h>
33 #include <regex.h>
33   #ifdef ALLBSD
34   #include <fcntl.h>
35   #endif
# Line 43 | Line 42
42   #include <sys/param.h>
43   #include <sys/sysctl.h>
44   #endif
45 + #ifdef HPUX
46 + #include <sys/param.h>
47 + #include <sys/pstat.h>
48 + #endif
49  
50   #include "tools.h"
51   #include "statgrab.h"
# Line 266 | Line 269 | static int build_mapping(){
269  
270   #endif
271  
272 <
270 <
272 > #if defined(LINUX) || defined(CYGWIN)
273   char *sg_f_read_line(FILE *f, const char *string){
274          /* Max line length. 8k should be more than enough */
275          static char line[8192];
# Line 278 | Line 280 | char *sg_f_read_line(FILE *f, const char *string){
280                  }
281          }
282  
283 +        sg_set_error(SG_ERROR_PARSE, NULL);
284          return NULL;
285   }
286  
# Line 291 | Line 294 | char *sg_get_string_match(char *line, regmatch_t *matc
294          return match_string;
295   }
296  
297 + long long sg_get_ll_match(char *line, regmatch_t *match){
298 +        char *ptr;
299 +        long long num;
300  
301 +        ptr=line+match->rm_so;
302 +        num=atoll(ptr);
303  
304 +        return num;
305 + }
306 + #endif
307 +
308   #ifndef HAVE_ATOLL
309   static long long atoll(const char *s) {
310          long long value = 0;
# Line 431 | Line 443 | int sg_update_string(char **dest, const char *src) {
443          return 0;
444   }
445  
434 long long sg_get_ll_match(char *line, regmatch_t *match){
435        char *ptr;
436        long long num;
437
438        ptr=line+match->rm_so;
439        num=atoll(ptr);
440
441        return num;
442 }
443
446   #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
447   kvm_t *sg_get_kvm() {
448          static kvm_t *kvmd = NULL;
# Line 450 | Line 452 | kvm_t *sg_get_kvm() {
452          }
453  
454          kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL);
455 +        if(kvmd == NULL) {
456 +                sg_set_error(SG_ERROR_KVM_OPENFILES, NULL);
457 +        }
458          return kvmd;
459   }
460  
# Line 462 | Line 467 | kvm_t *sg_get_kvm2() {
467          }
468  
469          kvmd2 = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL);
470 +        if(kvmd2 == NULL) {
471 +                sg_set_error(SG_ERROR_KVM_OPENFILES, NULL);
472 +        }
473          return kvmd2;
474   }
475   #endif
# Line 477 | Line 485 | struct uvmexp *sg_get_uvmexp() {
485          mib[1] = VM_UVMEXP;
486  
487          if (sysctl(mib, 2, &uvm, &size, NULL, 0) < 0) {
488 +                sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_VM.VM_UVMEXP");
489                  return NULL;
490          }
491  
# Line 484 | Line 493 | struct uvmexp *sg_get_uvmexp() {
493   }
494   #endif
495  
496 + #ifdef HPUX
497 + struct pst_static *sg_get_pstat_static() {
498 +        static int got = 0;
499 +        static struct pst_static pst;
500 +
501 +        if (!got) {
502 +                if (pstat_getstatic(&pst, sizeof pst, 1, 0) == -1) {
503 +                        sg_set_error_with_errno(SG_ERROR_PSTAT,
504 +                                                "pstat_static");
505 +                        return NULL;
506 +                }
507 +                got = 1;
508 +        }
509 +        return &pst;
510 + }
511 + #endif
512 +
513   int sg_init(){
514 +        sg_set_error(SG_ERROR_NONE, NULL);
515 +
516   #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
517          if (sg_get_kvm() == NULL) {
518                  return -1;
# Line 506 | Line 534 | int sg_init(){
534   }
535  
536   int sg_drop_privileges() {
537 <        if (setegid(getgid()) != 0) return -1;
538 <        if (seteuid(getuid()) != 0) return -1;
537 > #ifdef HAVE_SETEGID
538 >        if (setegid(getgid()) != 0) {
539 > #elif defined(HAVE_SETRESGID)
540 >        if (setresgid(getgid(), getgid(), getgid()) != 0) {
541 > #else
542 >        {
543 > #endif
544 >                sg_set_error_with_errno(SG_ERROR_SETEGID, NULL);
545 >                return -1;
546 >        }
547 > #ifdef HAVE_SETEUID
548 >        if (seteuid(getuid()) != 0) {
549 > #elif defined(HAVE_SETRESUID)
550 >        if (setresuid(getuid(), getuid(), getuid()) != 0) {
551 > #else
552 >        {
553 > #endif
554 >                sg_set_error_with_errno(SG_ERROR_SETEUID, NULL);
555 >                return -1;
556 >        }
557          return 0;
558   }
559  
# Line 515 | Line 561 | void *sg_realloc(void *ptr, size_t size) {
561          void *tmp = NULL;
562          tmp = realloc(ptr, size);
563          if(tmp == NULL) {
564 <                sg_set_error(SG_ERROR_MALLOC, NULL);
564 >                sg_set_error_with_errno(SG_ERROR_MALLOC, NULL);
565          }
566          return tmp;
567   }
522

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines