Alien-uv
view release on metacpan or search on metacpan
libuv/src/unix/aix.c view on Meta::CPAN
if (p == NULL)
return 0;
if (uv__path_is_a_directory((char*)filename) == 0) {
sprintf(cmd, "/aha/fs/modDir.monFactory");
} else {
sprintf(cmd, "/aha/fs/modFile.monFactory");
}
strncat(cmd, filename, (p - filename));
rc = uv__makedir_p(cmd);
if (rc == -1 && errno != EEXIST){
return UV__ERR(errno);
}
return rc;
}
/*
* Checks if /aha is mounted, then proceeds to set up the monitoring
* objects for the specified file.
* Returns 0 on success, or an error code < 0 on failure
*/
static int uv__setup_ahafs(const char* filename, int *fd) {
int rc = 0;
char mon_file_write_string[RDWR_BUF_SIZE];
char mon_file[PATH_MAX];
int file_is_directory = 0; /* -1 == NO, 0 == YES */
/* Create monitor file name for object */
file_is_directory = uv__path_is_a_directory((char*)filename);
if (file_is_directory == 0)
sprintf(mon_file, "/aha/fs/modDir.monFactory");
else
sprintf(mon_file, "/aha/fs/modFile.monFactory");
if ((strlen(mon_file) + strlen(filename) + 5) > PATH_MAX)
return UV_ENAMETOOLONG;
/* Make the necessary subdirectories for the monitor file */
rc = uv__make_subdirs_p(filename);
if (rc == -1 && errno != EEXIST)
return rc;
strcat(mon_file, filename);
strcat(mon_file, ".mon");
*fd = 0; errno = 0;
/* Open the monitor file, creating it if necessary */
*fd = open(mon_file, O_CREAT|O_RDWR);
if (*fd < 0)
return UV__ERR(errno);
/* Write out the monitoring specifications.
* In this case, we are monitoring for a state change event type
* CHANGED=YES
* We will be waiting in select call, rather than a read:
* WAIT_TYPE=WAIT_IN_SELECT
* We only want minimal information for files:
* INFO_LVL=1
* For directories, we want more information to track what file
* caused the change
* INFO_LVL=2
*/
if (file_is_directory == 0)
sprintf(mon_file_write_string, "CHANGED=YES;WAIT_TYPE=WAIT_IN_SELECT;INFO_LVL=2");
else
sprintf(mon_file_write_string, "CHANGED=YES;WAIT_TYPE=WAIT_IN_SELECT;INFO_LVL=1");
rc = write(*fd, mon_file_write_string, strlen(mon_file_write_string)+1);
if (rc < 0 && errno != EBUSY)
return UV__ERR(errno);
return 0;
}
/*
* Skips a specified number of lines in the buffer passed in.
* Walks the buffer pointed to by p and attempts to skip n lines.
* Returns the total number of lines skipped
*/
static int uv__skip_lines(char **p, int n) {
int lines = 0;
while(n > 0) {
*p = strchr(*p, '\n');
if (!p)
return lines;
(*p)++;
n--;
lines++;
}
return lines;
}
/*
* Parse the event occurrence data to figure out what event just occurred
* and take proper action.
*
* The buf is a pointer to the buffer containing the event occurrence data
* Returns 0 on success, -1 if unrecoverable error in parsing
*
*/
static int uv__parse_data(char *buf, int *events, uv_fs_event_t* handle) {
int evp_rc, i;
char *p;
char filename[PATH_MAX]; /* To be used when handling directories */
p = buf;
*events = 0;
/* Clean the filename buffer*/
for(i = 0; i < PATH_MAX; i++) {
filename[i] = 0;
libuv/src/unix/aix.c view on Meta::CPAN
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
}
int uv_fs_event_stop(uv_fs_event_t* handle) {
#ifdef HAVE_SYS_AHAFS_EVPRODS_H
if (!uv__is_active(handle))
return 0;
uv__io_close(handle->loop, &handle->event_watcher);
uv__handle_stop(handle);
if (uv__path_is_a_directory(handle->path) == 0) {
uv__free(handle->dir_filename);
handle->dir_filename = NULL;
}
uv__free(handle->path);
handle->path = NULL;
uv__close(handle->event_watcher.fd);
handle->event_watcher.fd = -1;
return 0;
#else
return UV_ENOSYS;
#endif
}
void uv__fs_event_close(uv_fs_event_t* handle) {
#ifdef HAVE_SYS_AHAFS_EVPRODS_H
uv_fs_event_stop(handle);
#else
UNREACHABLE();
#endif
}
char** uv_setup_args(int argc, char** argv) {
char** new_argv;
size_t size;
char* s;
int i;
if (argc <= 0)
return argv;
/* Save the original pointer to argv.
* AIX uses argv to read the process name.
* (Not the memory pointed to by argv[0..n] as on Linux.)
*/
process_argv = argv;
process_argc = argc;
/* Calculate how much memory we need for the argv strings. */
size = 0;
( run in 1.045 second using v1.01-cache-2.11-cpan-fa01517f264 )