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.51 by tdb, Wed Apr 7 21:08:40 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 <
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 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 430 | Line 443 | int sg_update_string(char **dest, const char *src) {
443          return 0;
444   }
445  
433 long long sg_get_ll_match(char *line, regmatch_t *match){
434        char *ptr;
435        long long num;
436
437        ptr=line+match->rm_so;
438        num=atoll(ptr);
439
440        return num;
441 }
442
446   #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
447   kvm_t *sg_get_kvm() {
448          static kvm_t *kvmd = NULL;
# Line 482 | 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(SG_ERROR_SYSCTL, "CTL_VM.VM_UVMEXP");
488 >                sg_set_error_with_errno(SG_ERROR_SYSCTL, "CTL_VM.VM_UVMEXP");
489                  return NULL;
490          }
491  
# Line 490 | 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 512 | Line 534 | int sg_init(){
534   }
535  
536   int sg_drop_privileges() {
537 + #ifdef HAVE_SETEGID
538          if (setegid(getgid()) != 0) {
539 <                sg_set_error(SG_ERROR_SETEGID, NULL);
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 <                sg_set_error(SG_ERROR_SETEUID, NULL);
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;
# Line 527 | 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   }
534

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines