int uv_os_uname(uv_utsname_t* buffer) { struct utsname buf; int r; if (buffer == NULL) return UV_EINVAL; if (uname(&buf) == -1) { r = UV__ERR(errno); goto error; } r = uv__strscpy(buffer->sysname, buf.sysname, sizeof(buffer->sysname)); if (r == UV_E2BIG) goto error; #ifdef _AIX r = snprintf(buffer->release, sizeof(buffer->release), "%s.%s", buf.version, buf.release); if (r >= sizeof(buffer->release)) { r = UV_E2BIG; goto error; } #else r = uv__strscpy(buffer->release, buf.release, sizeof(buffer->release)); if (r == UV_E2BIG) goto error; #endif r = uv__strscpy(buffer->version, buf.version, sizeof(buffer->version)); if (r == UV_E2BIG) goto error; #if defined(_AIX) || defined(__PASE__) r = uv__strscpy(buffer->machine, "ppc64", sizeof(buffer->machine)); #else r = uv__strscpy(buffer->machine, buf.machine, sizeof(buffer->machine)); #endif if (r == UV_E2BIG) goto error; return 0; error: buffer->sysname[0] = '\0'; buffer->release[0] = '\0'; buffer->version[0] = '\0'; buffer->machine[0] = '\0'; return r; }
int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { uv_cpu_info_t* cpu_info; perfstat_cpu_total_t ps_total; perfstat_cpu_t* ps_cpus; perfstat_id_t cpu_id; int result, ncpus, idx = 0; result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1); if (result == -1) { return UV_ENOSYS; } ncpus = result = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0); if (result == -1) { return UV_ENOSYS; } ps_cpus = (perfstat_cpu_t*) uv__malloc(ncpus * sizeof(perfstat_cpu_t)); if (!ps_cpus) { return UV_ENOMEM; } /* TODO(bnoordhuis) Check uv__strscpy() return value. */ uv__strscpy(cpu_id.name, FIRST_CPU, sizeof(cpu_id.name)); result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus); if (result == -1) { uv__free(ps_cpus); return UV_ENOSYS; } *cpu_infos = (uv_cpu_info_t*) uv__malloc(ncpus * sizeof(uv_cpu_info_t)); if (!*cpu_infos) { uv__free(ps_cpus); return UV_ENOMEM; } *count = ncpus; cpu_info = *cpu_infos; while (idx < ncpus) { cpu_info->speed = (int)(ps_total.processorHZ / 1000000); cpu_info->model = uv__strdup(ps_total.description); cpu_info->cpu_times.user = ps_cpus[idx].user; cpu_info->cpu_times.sys = ps_cpus[idx].sys; cpu_info->cpu_times.idle = ps_cpus[idx].idle; cpu_info->cpu_times.irq = ps_cpus[idx].wait; cpu_info->cpu_times.nice = 0; cpu_info++; idx++; } uv__free(ps_cpus); return 0; }
/* This is the internal callback */ static void uv__ahafs_event(uv_loop_t* loop, uv__io_t* event_watch, unsigned int fflags) { char result_data[RDWR_BUF_SIZE]; int bytes, rc = 0; uv_fs_event_t* handle; int events = 0; char fname[PATH_MAX]; char *p; handle = container_of(event_watch, uv_fs_event_t, event_watcher); /* At this point, we assume that polling has been done on the * file descriptor, so we can just read the AHAFS event occurrence * data and parse its results without having to block anything */ bytes = pread(event_watch->fd, result_data, RDWR_BUF_SIZE, 0); assert((bytes >= 0) && "uv__ahafs_event - Error reading monitor file"); /* In file / directory move cases, AIX Event infrastructure * produces a second event with no data. * Ignore it and return gracefully. */ if(bytes == 0) return; /* Parse the data */ if(bytes > 0) rc = uv__parse_data(result_data, &events, handle); /* Unrecoverable error */ if (rc == -1) return; /* For directory changes, the name of the files that triggered the change * are never absolute pathnames */ if (uv__path_is_a_directory(handle->path) == 0) { p = handle->dir_filename; } else { p = strrchr(handle->path, '/'); if (p == NULL) p = handle->path; else p++; } /* TODO(bnoordhuis) Check uv__strscpy() return value. */ uv__strscpy(fname, p, sizeof(fname)); handle->cb(handle, fname, events, 0); }
/* * Recursive call to mkdir() to create intermediate folders, if any * Returns code from mkdir call */ static int uv__makedir_p(const char *dir) { char tmp[256]; char *p = NULL; size_t len; int err; /* TODO(bnoordhuis) Check uv__strscpy() return value. */ uv__strscpy(tmp, dir, sizeof(tmp)); len = strlen(tmp); if (tmp[len - 1] == '/') tmp[len - 1] = 0; for (p = tmp + 1; *p; p++) { if (*p == '/') { *p = 0; err = mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); if (err != 0 && errno != EEXIST) return err; *p = '/'; } } return mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); }
int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb, const char* filename, unsigned int flags) { #ifdef HAVE_SYS_AHAFS_EVPRODS_H int fd, rc, str_offset = 0; char cwd[PATH_MAX]; char absolute_path[PATH_MAX]; char readlink_cwd[PATH_MAX]; struct timeval zt; fd_set pollfd; /* Figure out whether filename is absolute or not */ if (filename[0] == '\0') { /* Missing a pathname */ return UV_ENOENT; } else if (filename[0] == '/') { /* We have absolute pathname */ /* TODO(bnoordhuis) Check uv__strscpy() return value. */ uv__strscpy(absolute_path, filename, sizeof(absolute_path)); } else { /* We have a relative pathname, compose the absolute pathname */ snprintf(cwd, sizeof(cwd), "/proc/%lu/cwd", (unsigned long) getpid()); rc = readlink(cwd, readlink_cwd, sizeof(readlink_cwd) - 1); if (rc < 0) return rc; /* readlink does not null terminate our string */ readlink_cwd[rc] = '\0'; if (filename[0] == '.' && filename[1] == '/') str_offset = 2; snprintf(absolute_path, sizeof(absolute_path), "%s%s", readlink_cwd, filename + str_offset); } if (uv__is_ahafs_mounted() < 0) /* /aha checks failed */ return UV_ENOSYS; /* Setup ahafs */ rc = uv__setup_ahafs((const char *)absolute_path, &fd); if (rc != 0) return rc; /* Setup/Initialize all the libuv routines */ uv__handle_start(handle); uv__io_init(&handle->event_watcher, uv__ahafs_event, fd); handle->path = uv__strdup(filename); handle->cb = cb; handle->dir_filename = NULL; uv__io_start(handle->loop, &handle->event_watcher, POLLIN); /* AHAFS wants someone to poll for it to start mointoring. * so kick-start it so that we don't miss an event in the * eventuality of an event that occurs in the current loop. */ do { memset(&zt, 0, sizeof(zt)); FD_ZERO(&pollfd); FD_SET(fd, &pollfd); rc = select(fd + 1, &pollfd, NULL, NULL, &zt); } while (rc == -1 && errno == EINTR); return 0; #else return UV_ENOSYS; #endif }