32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <sys/ioctl.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
45 #include <sys/protosw.h>
46 #include <libperfstat.h>
49 #include <sys/procfs.h>
53 #include <sys/pollset.h>
55 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
56 #include <sys/ahafs_evProds.h>
59 #include <sys/mntctl.h>
60 #include <sys/vmount.h>
63 #include <sys/vnode.h>
65 #define RDWR_BUF_SIZE 4096
66 #define EQ(a,b) (strcmp(a,b) == 0)
86 loop->backend_fd = pollset_create(-1);
88 if (
loop->backend_fd == -1)
96 if (
loop->fs_fd != -1) {
101 if (
loop->backend_fd != -1) {
102 pollset_destroy(
loop->backend_fd);
103 loop->backend_fd = -1;
122 if (pollset_ctl(
loop->backend_fd, &
pc, 1))
126 if (pollset_ctl(
loop->backend_fd, &
pc, 1))
134 struct pollfd events[1024];
152 if (
loop->nfds == 0) {
167 pc.events =
w->pevents;
171 if (
w->events == 0) {
173 if (pollset_ctl(
loop->backend_fd, &
pc, 1)) {
175 assert(0 &&
"Failed to add file descriptor (pc.fd) to pollset");
180 rc = pollset_query(
loop->backend_fd, &pqry);
183 assert(0 &&
"Failed to query pollset for file descriptor");
186 assert(0 &&
"Pollset does not contain file descriptor");
194 if (
w->events != 0 || add_failed) {
202 if (pollset_ctl(
loop->backend_fd, &
pc, 1)) {
203 assert(0 &&
"Failed to delete file descriptor (pc.fd) from pollset");
207 if (pollset_ctl(
loop->backend_fd, &
pc, 1)) {
208 assert(0 &&
"Failed to add file descriptor (pc.fd) to pollset");
213 w->events =
w->pevents;
235 nfds = pollset_poll(
loop->backend_fd,
247 if (reset_timeout != 0) {
261 if (errno !=
EINTR) {
265 if (reset_timeout != 0) {
284 loop->watchers[
loop->nwatchers] = (
void*) events;
307 pollset_ctl(
loop->backend_fd, &
pc, 1);
314 if (
w == &
loop->signal_io_watcher) {
318 w->cb(
loop,
w, pe->revents);
324 if (reset_timeout != 0) {
329 if (have_signals != 0) {
331 loop->signal_io_watcher.cb(
loop, &
loop->signal_io_watcher, POLLIN);
337 if (have_signals != 0)
358 diff =
loop->time - base;
368 perfstat_memory_total_t mem_total;
369 int result = perfstat_memory_total(
NULL, &mem_total,
sizeof(mem_total), 1);
373 return mem_total.real_free * 4096;
378 perfstat_memory_total_t mem_total;
379 int result = perfstat_memory_total(
NULL, &mem_total,
sizeof(mem_total), 1);
383 return mem_total.real_total * 4096;
393 perfstat_cpu_total_t ps_total;
394 int result = perfstat_cpu_total(
NULL, &ps_total,
sizeof(ps_total), 1);
396 avg[0] = 0.; avg[1] = 0.; avg[2] = 0.;
399 avg[0] = ps_total.loadavg[0] / (double)(1 << SBITS);
400 avg[1] = ps_total.loadavg[1] / (double)(1 << SBITS);
401 avg[2] = ps_total.loadavg[2] / (double)(1 << SBITS);
405 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
406 static char* uv__rawname(
const char* cp,
char (*
dst)[FILENAME_MAX+1]) {
409 dp = rindex(cp,
'/');
413 snprintf(*
dst,
sizeof(*
dst),
"%.*s/r%s", (
int) (dp - cp), cp, dp + 1);
425 static int uv__path_is_a_directory(
char*
filename) {
431 if (statbuf.st_type == VDIR)
442 static int uv__is_ahafs_mounted(
void){
443 char rawbuf[FILENAME_MAX+1];
446 int size_multiplier = 10;
447 size_t siz =
sizeof(
struct vmount)*size_multiplier;
449 const char *
dev =
"/aha";
457 rv = mntctl(MCTL_QUERY, siz, (
char*)
p);
467 rv = mntctl(MCTL_QUERY, siz, (
char*)
p);
473 for(vmt =
p,
i = 0;
i < rv;
i++) {
474 obj = vmt2dataptr(vmt, VMT_OBJECT);
475 stub = vmt2dataptr(vmt, VMT_STUB);
477 if (
EQ(obj,
dev) ||
EQ(uv__rawname(obj, &rawbuf),
dev) ||
EQ(stub,
dev)) {
481 vmt = (
struct vmount *) ((
char *) vmt + vmt->vmt_length);
492 static int uv__makedir_p(
const char *dir) {
503 for (
p =
tmp + 1; *
p;
p++) {
506 err =
mkdir(
tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
512 return mkdir(
tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
520 static int uv__make_subdirs_p(
const char *
filename) {
531 if (uv__path_is_a_directory((
char*)
filename) == 0) {
538 rc = uv__makedir_p(
cmd);
540 if (rc == -1 && errno !=
EEXIST){
553 static int uv__setup_ahafs(
const char*
filename,
int *
fd) {
556 char mon_file[PATH_MAX];
557 int file_is_directory = 0;
560 file_is_directory = uv__path_is_a_directory((
char*)
filename);
562 if (file_is_directory == 0)
563 sprintf(mon_file,
"/aha/fs/modDir.monFactory");
565 sprintf(mon_file,
"/aha/fs/modFile.monFactory");
567 if ((strlen(mon_file) + strlen(
filename) + 5) > PATH_MAX)
568 return UV_ENAMETOOLONG;
572 if (rc == -1 && errno !=
EEXIST)
576 strcat(mon_file,
".mon");
597 if (file_is_directory == 0)
598 sprintf(mon_file_write_string,
"CHANGED=YES;WAIT_TYPE=WAIT_IN_SELECT;INFO_LVL=2");
600 sprintf(mon_file_write_string,
"CHANGED=YES;WAIT_TYPE=WAIT_IN_SELECT;INFO_LVL=1");
602 rc =
write(*
fd, mon_file_write_string, strlen(mon_file_write_string)+1);
603 if (rc < 0 && errno !=
EBUSY)
614 static int uv__skip_lines(
char **
p,
int n) {
618 *
p = strchr(*
p,
'\n');
647 for(
i = 0;
i < PATH_MAX;
i++) {
653 if (strncmp(
buf,
"BUF_WRAP", strlen(
"BUF_WRAP")) == 0) {
654 assert(0 &&
"Buffer wrap detected, Some event occurrences lost!");
665 if (uv__skip_lines(&
p, 9) != 9)
668 if (sscanf(
p,
"RC_FROM_EVPROD=%d\nEND_EVENT_DATA", &evp_rc) == 1) {
669 if (uv__path_is_a_directory(
handle->path) == 0) {
670 if (evp_rc == AHAFS_MODDIR_UNMOUNT || evp_rc == AHAFS_MODDIR_REMOVE_SELF) {
679 if (uv__skip_lines(&
p, 1) != 1)
683 if (sscanf(
p,
"BEGIN_EVPROD_INFO\n%sEND_EVPROD_INFO",
filename) == 1) {
689 if (evp_rc == AHAFS_MODFILE_RENAME)
708 char fname[PATH_MAX];
719 assert((
bytes >= 0) &&
"uv__ahafs_event - Error reading monitor file");
730 rc = uv__parse_data(result_data, &events,
handle);
739 if (uv__path_is_a_directory(
handle->path) == 0) {
742 p = strrchr(
handle->path,
'/');
758 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
770 unsigned int flags) {
771 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
772 int fd, rc, str_offset = 0;
774 char absolute_path[PATH_MAX];
775 char readlink_cwd[PATH_MAX];
791 snprintf(
cwd,
sizeof(
cwd),
"/proc/%lu/cwd", (
unsigned long) getpid());
792 rc =
readlink(
cwd, readlink_cwd,
sizeof(readlink_cwd) - 1);
796 readlink_cwd[rc] =
'\0';
801 snprintf(absolute_path,
sizeof(absolute_path),
"%s%s", readlink_cwd,
805 if (uv__is_ahafs_mounted() < 0)
809 rc = uv__setup_ahafs((
const char *)absolute_path, &
fd);
826 memset(&zt, 0,
sizeof(zt));
830 }
while (rc == -1 && errno ==
EINTR);
839 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
846 if (uv__path_is_a_directory(
handle->path) == 0) {
854 handle->event_watcher.fd = -1;
864 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
890 size =
sizeof(exepath);
900 for (
i = 0;
i < argc;
i++)
904 size += (argc + 1) *
sizeof(
char*);
907 if (new_argv ==
NULL)
912 s = (
char*) &new_argv[argc + 1];
913 for (
i = 0;
i < argc;
i++) {
936 if (new_title ==
NULL)
999 snprintf(pp,
sizeof(pp),
"/proc/%lu/psinfo", (
unsigned long) getpid());
1007 if (
read(
fd, &psinfo,
sizeof(psinfo)) ==
sizeof(psinfo)) {
1008 *rss = (
size_t)psinfo.pr_rssize * 1024;
1018 struct utmp *utmp_buf;
1023 utmpname(UTMP_FILE);
1027 while ((utmp_buf = getutent()) !=
NULL) {
1028 if (utmp_buf->ut_user[0] && utmp_buf->ut_type == USER_PROCESS)
1030 if (utmp_buf->ut_type == BOOT_TIME)
1031 boot_time = utmp_buf->ut_time;
1046 perfstat_cpu_total_t ps_total;
1047 perfstat_cpu_t* ps_cpus;
1048 perfstat_id_t cpu_id;
1051 result = perfstat_cpu_total(
NULL, &ps_total,
sizeof(ps_total), 1);
1056 ncpus = result = perfstat_cpu(
NULL,
NULL,
sizeof(perfstat_cpu_t), 0);
1061 ps_cpus = (perfstat_cpu_t*)
uv__malloc(
ncpus *
sizeof(perfstat_cpu_t));
1067 uv__strscpy(cpu_id.name, FIRST_CPU,
sizeof(cpu_id.name));
1068 result = perfstat_cpu(&cpu_id, ps_cpus,
sizeof(perfstat_cpu_t),
ncpus);
1082 cpu_info = *cpu_infos;
1084 cpu_info->
speed = (
int)(ps_total.processorHZ / 1000000);
1104 struct ifreq *ifr, *
p, flg;
1105 struct in6_ifreq if6;
1106 struct sockaddr_dl* sa_addr;
1130 if (ifc.ifc_req ==
NULL) {
1140 #define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p))
1144 while ((
char*)ifr < (
char*)ifc.ifc_req + ifc.ifc_len) {
1146 ifr = (
struct ifreq*)
1147 ((
char*)ifr +
sizeof(ifr->ifr_name) +
ADDR_SIZE(ifr->ifr_addr));
1149 if (!(
p->ifr_addr.sa_family ==
AF_INET6 ||
1153 memcpy(flg.ifr_name,
p->ifr_name,
sizeof(flg.ifr_name));
1159 if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
1170 if (!(*addresses)) {
1174 address = *addresses;
1177 while ((
char*)ifr < (
char*)ifc.ifc_req + ifc.ifc_len) {
1179 ifr = (
struct ifreq*)
1180 ((
char*)ifr +
sizeof(ifr->ifr_name) +
ADDR_SIZE(ifr->ifr_addr));
1182 if (!(
p->ifr_addr.sa_family ==
AF_INET6 ||
1186 inet6 = (
p->ifr_addr.sa_family ==
AF_INET6);
1188 memcpy(flg.ifr_name,
p->ifr_name,
sizeof(flg.ifr_name));
1192 if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
1205 memset(&if6, 0,
sizeof(if6));
1206 r =
uv__strscpy(if6.ifr_name,
p->ifr_name,
sizeof(if6.ifr_name));
1210 memcpy(&if6.ifr_Addr, &
p->ifr_addr,
sizeof(if6.ifr_Addr));
1211 if (
ioctl(sock6fd, SIOCGIFNETMASK6, &if6) == -1)
1224 address->
is_internal = flg.ifr_flags & IFF_LOOPBACK ? 1 : 0;
1231 while ((
char*)ifr < (
char*)ifc.ifc_req + ifc.ifc_len) {
1233 ifr = (
struct ifreq*)
1234 ((
char*)ifr +
sizeof(ifr->ifr_name) +
ADDR_SIZE(ifr->ifr_addr));
1236 if (
p->ifr_addr.sa_family != AF_LINK)
1239 address = *addresses;
1241 if (strcmp(address->
name,
p->ifr_name) == 0) {
1242 sa_addr = (
struct sockaddr_dl*) &
p->ifr_addr;
1295 if ((
int) events[
i].fd ==
fd)
1302 if(
loop->backend_fd >= 0)
1303 pollset_ctl(
loop->backend_fd, &
pc, 1);
uint64_t uv_get_total_memory(void)
void uv__fs_event_close(uv_fs_event_t *handle)
void uv_loadavg(double avg[3])
int uv_fs_event_stop(uv_fs_event_t *handle)
void uv__platform_invalidate_fd(uv_loop_t *loop, int fd)
uint64_t uv_get_free_memory(void)
int uv_interface_addresses(uv_interface_address_t **addresses, int *count)
void uv__io_poll(uv_loop_t *loop, int timeout)
static char ** process_argv
int uv__io_check_fd(uv_loop_t *loop, int fd)
void uv__process_title_cleanup(void)
uv_once_t process_title_mutex_once
void init_process_title_mutex_once(void)
int uv__platform_loop_init(uv_loop_t *loop)
char ** uv_setup_args(int argc, char **argv)
int uv_fs_event_start(uv_fs_event_t *handle, uv_fs_event_cb cb, const char *filename, unsigned int flags)
int uv_uptime(double *uptime)
void uv_free_interface_addresses(uv_interface_address_t *addresses, int count)
static char * process_title_ptr
int uv__io_fork(uv_loop_t *loop)
int uv_fs_event_init(uv_loop_t *loop, uv_fs_event_t *handle)
int uv_cpu_info(uv_cpu_info_t **cpu_infos, int *count)
uint64_t uv_get_constrained_memory(void)
void uv__platform_loop_delete(uv_loop_t *loop)
int uv_set_process_title(const char *title)
int uv_get_process_title(char *buffer, size_t size)
int uv_resident_set_memory(size_t *rss)
uv_mutex_t process_title_mutex
static mcore_handle handle
RzList * entries(RzBinFile *bf)
static RzBinSourceLineInfo * lines(RzBinFile *bf)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd socket
static static sync static getppid static getegid const char static filename char static len readlink
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
static static sync static getppid static getegid const char static filename ioctl
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname pread
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig mkdir
static static fork const void static count static fd const char const char static newpath char char char static envp time
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask dev
static static fork const void static count static fd const char const char static newpath char char argv
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz select
static const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage struct sysinfo static info unsigned static __unused struct utsname static buf const char static size const char static name static pid unsigned static persona static fsgid const void static flags const struct iovec static count static fd const void static len static munlockall struct sched_param static p static sched_yield static policy const struct timespec struct timespec static rem uid_t uid_t uid_t static suid struct pollfd unsigned nfds
assert(limit<=UINT32_MAX/2)
#define QUEUE_DATA(ptr, type, field)
#define container_of(ptr, type, member)
static struct sockaddr static addrlen static backlog const void static flags void flags
_W64 unsigned int uintptr_t
ssize_t uv__strscpy(char *d, const char *s, size_t n)
struct uv_cpu_times_s cpu_times
struct sockaddr_in6 netmask6
struct sockaddr_in6 address6
struct sockaddr_in netmask4
union uv_interface_address_s::@399 netmask
union uv_interface_address_s::@398 address
struct sockaddr_in address4
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
void uv__io_close(uv_loop_t *loop, uv__io_t *w)
int uv__search_path(const char *prog, char *buf, size_t *buflen)
void uv__io_init(uv__io_t *w, uv__io_cb cb, int fd)
#define SAVE_ERRNO(block)
pthread_mutex_t uv_mutex_t
char * uv__strdup(const char *s)
void * uv__malloc(size_t size)
void * uv__calloc(size_t count, size_t size)
void uv__metrics_update_idle_time(uv_loop_t *loop)
void uv__metrics_set_provider_entry_time(uv_loop_t *loop)
#define uv__handle_init(loop_, h, type_)
#define uv__handle_stop(h)
#define uv__get_internal_fields(loop)
#define uv__handle_start(h)
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
void(* uv_fs_event_cb)(uv_fs_event_t *handle, const char *filename, int events, int status)
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
UV_EXTERN int uv_mutex_init(uv_mutex_t *handle)
static const z80_opcode fd[]
int read(izstream &zs, T *x, Items items)