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" |
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 |
|
|
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 |
|
|
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; |
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 |
|
} |
535 |
– |
|