33 |
|
#include <stdlib.h> |
34 |
|
#include <sys/types.h> |
35 |
|
#include <dirent.h> |
36 |
– |
#include <string.h> |
36 |
|
#endif |
37 |
+ |
#include <string.h> |
38 |
|
|
39 |
|
#ifdef SOLARIS |
40 |
|
#include <procfs.h> |
78 |
|
#include <unistd.h> |
79 |
|
#define PROCESS_BATCH 30 |
80 |
|
#endif |
81 |
+ |
#ifdef WIN32 |
82 |
+ |
#include <windows.h> |
83 |
+ |
#include <psapi.h> |
84 |
+ |
#endif |
85 |
|
|
86 |
|
static void proc_state_init(sg_process_stats *s) { |
87 |
|
s->process_name = NULL; |
420 |
|
proctitle = NULL; |
421 |
|
|
422 |
|
do { |
423 |
< |
if(size >= buflen) { |
423 |
> |
if((long) size >= buflen) { |
424 |
|
buflen *= 2; |
425 |
|
size = buflen; |
426 |
|
proctitletmp = sg_realloc(proctitle, buflen); |
442 |
|
size = 0; |
443 |
|
break; |
444 |
|
} |
445 |
< |
} while(size >= buflen); |
445 |
> |
} while((long) size >= buflen); |
446 |
|
|
447 |
|
if(size > 0) { |
448 |
|
proc_state_ptr->proctitle = sg_malloc(size+1); |
689 |
|
return NULL; |
690 |
|
} |
691 |
|
|
692 |
< |
do { |
692 |
> |
while (1) { |
693 |
|
num = pstat_getproc(pstat_procinfo, sizeof pstat_procinfo[0], |
694 |
|
PROCESS_BATCH, procidx); |
695 |
+ |
if (num == -1) { |
696 |
+ |
sg_set_error_with_errno(SG_ERROR_PSTAT, |
697 |
+ |
"pstat_getproc"); |
698 |
+ |
return NULL; |
699 |
+ |
} else if (num == 0) { |
700 |
+ |
break; |
701 |
+ |
} |
702 |
|
|
703 |
|
for (i = 0; i < num; i++) { |
704 |
|
struct pst_status *pi = &pstat_procinfo[i]; |
751 |
|
|
752 |
|
proc_state_size++; |
753 |
|
} |
754 |
< |
procidx = pstat_procinfo[n - 1].pst_idx + 1; |
755 |
< |
} while (num > 0); |
754 |
> |
procidx = pstat_procinfo[num - 1].pst_idx + 1; |
755 |
> |
} |
756 |
|
#endif |
757 |
|
|
758 |
|
#ifdef CYGWIN |
759 |
|
sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin"); |
760 |
|
return NULL; |
761 |
|
#endif |
762 |
+ |
#ifdef WIN32 |
763 |
+ |
/* FIXME The data needed for this is probably do able with the |
764 |
+ |
* "performance registry". Although using this appears to be a black |
765 |
+ |
* art and closely guarded secret. |
766 |
+ |
* This is not directly used in ihost, so not considered a priority */ |
767 |
+ |
sg_set_error(SG_ERROR_UNSUPPORTED, "Win32"); |
768 |
+ |
return NULL; |
769 |
+ |
#endif |
770 |
|
|
771 |
|
*entries = proc_state_size; |
772 |
|
return proc_state; |
774 |
|
|
775 |
|
sg_process_count *sg_get_process_count() { |
776 |
|
static sg_process_count process_stat; |
777 |
+ |
#ifndef WIN32 |
778 |
|
sg_process_stats *ps; |
779 |
|
int ps_size, x; |
780 |
+ |
#else |
781 |
+ |
DWORD aProcesses[1024]; |
782 |
+ |
DWORD cbNeeded; |
783 |
+ |
#endif |
784 |
|
|
785 |
|
process_stat.sleeping = 0; |
786 |
|
process_stat.running = 0; |
788 |
|
process_stat.stopped = 0; |
789 |
|
process_stat.total = 0; |
790 |
|
|
791 |
+ |
#ifndef WIN32 |
792 |
|
ps = sg_get_process_stats(&ps_size); |
793 |
|
if (ps == NULL) { |
794 |
|
return NULL; |
817 |
|
} |
818 |
|
|
819 |
|
process_stat.total = ps_size; |
820 |
+ |
#else |
821 |
+ |
if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded)) |
822 |
+ |
return NULL; |
823 |
+ |
process_stat.total = cbNeeded / sizeof(DWORD); |
824 |
+ |
#endif |
825 |
|
|
826 |
|
return &process_stat; |
827 |
|
} |