void fsevents_monitor::fsevents_callback(ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]) { fsevents_monitor *fse_monitor = static_cast<fsevents_monitor *> (clientCallBackInfo); if (!fse_monitor) { throw libfsw_exception(_("The callback info cannot be cast to fsevents_monitor.")); } vector<event> events; time_t curr_time; time(&curr_time); for (size_t i = 0; i < numEvents; ++i) { events.push_back({((char **) eventPaths)[i], curr_time, decode_flags(eventFlags[i])}); } if (events.size() > 0) { fse_monitor->notify_events(events); } }
void kqueue_monitor::process_events(const vector<struct kevent>& changes, const vector<struct kevent>& event_list, int event_num) { time_t curr_time; time(&curr_time); vector<event> events; for (auto i = 0; i < event_num; ++i) { struct kevent e = event_list[i]; if (e.flags & EV_ERROR) { perror(_("Event with EV_ERROR")); continue; } // If a NOTE_DELETE is found or a NOTE_LINK is found on a directory, then // the descriptor should be closed and the node rescanned: removing a // subtree in *BSD usually result in NOTE_REMOVED | NOTE_LINK being logged // for each subdirectory, but sometimes NOTE_WRITE | NOTE_LINK is only // observed. For this reason we mark those descriptors as to be deleted // anyway. // // If a NOTE_RENAME or NOTE_REVOKE flag is found, the file // descriptor should probably be closed and the file should be rescanned. // If a NOTE_WRITE flag is found and the descriptor is a directory, then // the directory needs to be rescanned because at least one file has // either been created or deleted. if ((e.fflags & NOTE_DELETE)) { load->descriptors_to_remove.insert(e.ident); } else if ((e.fflags & NOTE_RENAME) || (e.fflags & NOTE_REVOKE) || ((e.fflags & NOTE_WRITE) && S_ISDIR(load->file_modes[e.ident]))) { load->descriptors_to_rescan.insert(e.ident); } // Invoke the callback passing every path for which an event has been // received with a non empty filter flag. if (e.fflags) { events.push_back({load->file_names_by_descriptor[e.ident], curr_time, decode_flags(e.fflags)}); } } if (events.size()) { notify_events(events); } }
extern CAMLprim value kc_open(value path, value options) { CAMLparam2(path, options); KCDB* db = kcdbnew(); if (! kcdbopen(db, String_val(path), decode_flags(options, OPEN_FLAGS))) { const char *error = kcdbemsg(db); kcdbdel(db); RAISE(error); } value caml_db = alloc_small(1, Abstract_tag); KCDB_val(caml_db) = db; CAMLreturn(caml_db); }
int DefaultServer::openFile(ServerContext& s, const char *path, void **handle, const char *flags, int mode) { int posix_flags = decode_flags(flags); // block I/O on client requires sometimes reading in order to write by blocks if (posix_flags & O_WRONLY #ifdef __linux__ && !(posix_flags & O_DIRECT) #endif ) { posix_flags &= ~O_WRONLY; posix_flags |= O_RDWR; } int fd = -1; //_DEBUG("create flag set/mode: 0%o / 0%o", posix_flags & O_CREAT, mode); if ((posix_flags & O_CREAT) == O_CREAT) { posix_flags |= O_TRUNC; } if ((posix_flags & O_APPEND) == O_APPEND) { // turn off append due to pwrite O_APPEND bug posix_flags |= O_RDWR; posix_flags &= ~O_APPEND; } _STDERR("DEFAULT_SERVER open_file flags = %s (%o)", flags, posix_flags); if ((fd = ::open(path, posix_flags, mode)) < 0) { if (fd == 0) { fd = ::dup(fd); ::close(0); } *handle = NULL; return -errno; } *handle = ((char *) (0)) + fd; return 0; }
NORETURN __cilkrts_c_sync_except (__cilkrts_worker *w, __cilkrts_stack_frame *sf) { __cxa_eh_globals *state = __cxa_get_globals(); _Unwind_Exception *exc = (_Unwind_Exception *)sf->except_data; CILK_ASSERT((sf->flags & (CILK_FRAME_UNSYNCHED|CILK_FRAME_EXCEPTING)) == (CILK_FRAME_UNSYNCHED|CILK_FRAME_EXCEPTING)); sf->flags &= ~CILK_FRAME_EXCEPTING; #if DEBUG_EXCEPTIONS fflush(stdout); char decoded[9]; decode_flags(sf->flags, decoded); if (exc) fprintf(stderr, "__cilkrts_sync_except W%u %p/%s %p->%p [%u %p]\n", w->self, sf, decoded, exc, to_cxx(exc)->nextException, state->uncaughtExceptions, state->caughtExceptions); else fprintf(stderr, "__cilkrts_sync_except W%d %p/%s none [%u %p]\n", w->self, sf, decoded, state->uncaughtExceptions, state->caughtExceptions); #endif /* Here the identity of an rethrown exception is always known. If exc is NULL this call is only to preserve parent state. */ save_exception_info(w, state, exc, false, "sync_except"); #if 0 { full_frame *ff = w->l->frame_ff; CILK_ASSERT(NULL == ff->pending_exception); ff->pending_exception = w->l->pending_exception; w->l->pending_exception = NULL; } #endif CILK_ASSERT(!std::uncaught_exception()); __cilkrts_c_sync(w, sf); }
int MemoryServer::openFile(ServerContext& s, const char *path, void **handle, const char *flags, int mode) { int posix_flags = decode_flags(flags); bool is_create = (strchr(flags, 'c') != NULL) ? true : false; if (is_create && readOnly(s)) { return -EPERM; } memory_node_t *node = MemoryNode::find(static_cast<memory_node_t *>(s.getData(name())), path, is_create); (void) posix_flags; (void) s; (void) mode; if (node == NULL) { return -ENOENT; } if ((node->stat.fs_mode & S_IFDIR) && !is_create) { return -EISDIR; } if (is_create) { memory_node_t *child = new memory_node_t; ASSERT(child); child->delete_mode = false; child->read_mode = is_create || (strchr(flags, 'r') != NULL) ? true : false; child->write_mode = is_create || (strchr(flags, 'w') != NULL) ? true : false; child->name = base_name(path); child->stat.fs_ino = ++m_inode;; child->stat.fs_size = 0; child->stat.fs_blocks = 1; child->stat.fs_atime = child->stat.fs_mtime = child->stat.fs_ctime = time(0); child->stat.fs_mode = S_IFREG | mode; child->stat.fs_nlink = 0; child->stat.fs_uid = 65534; child->stat.fs_gid = 65534; child->stat.fs_blksize = 4096; node->kids[child->name] = child; node->stat.fs_nlink++; child->parent = node; m_fs_stat.f_used_blocks++; m_fs_stat.f_used_inodes++; node = child; } else { node->delete_mode = false; node->read_mode = (strchr(flags, 'r') != NULL) ? true : false; node->write_mode = (strchr(flags, 'w') != NULL) ? true : false; } *handle = node; return 0; }
CILK_ABI_THROWS_VOID __cilkrts_return_exception(__cilkrts_stack_frame *sf) { __cilkrts_worker *w = sf->worker; _Unwind_Exception *exc = (_Unwind_Exception *)sf->except_data; CILK_ASSERT(sf->flags & CILK_FRAME_DETACHED); sf->flags &= ~CILK_FRAME_DETACHED; /* * If we are in replay mode, and a steal occurred during the recording * phase, stall till a steal actually occurs. */ replay_wait_for_steal_if_parent_was_stolen(w); /* If this is to be an abnormal return, save the active exception. */ if (!__cilkrts_pop_tail(w)) { /* Write a record to the replay log for an attempt to return to a stolen parent. This must be done before the exception handler invokes __cilkrts_leave_frame which will bump the pedigree so the replay_wait_for_steal_if_parent_was_stolen() above will match on replay */ replay_record_orphaned(w); /* Now that the record/replay stuff is done, update the pedigree */ update_pedigree_on_leave_frame(w, sf); /* Inline pop_frame; this may not be needed. */ w->current_stack_frame = sf->call_parent; sf->call_parent = 0; __cxa_eh_globals *state = __cxa_get_globals(); #if DEBUG_EXCEPTIONS fflush(stdout); char decoded[9]; decode_flags(sf->flags, decoded); fprintf(stderr, "__cilkrts_save_except W%u sf %p/%s exc %p [%u %p] suspend\n", w->self, sf, decoded, exc, state->uncaughtExceptions, state->caughtExceptions); #endif /* Like __cilkrts_save_exception_state except for setting the rethrow flag. */ save_exception_info(w, state, exc, exc == NULL, "save_except"); { full_frame *ff = w->l->frame_ff; CILK_ASSERT(NULL == ff->pending_exception); ff->pending_exception = w->l->pending_exception; w->l->pending_exception = NULL; } __cilkrts_exception_from_spawn(w, sf); /* does not return */ } /* This code path is taken when the parent is attached. It is on the same stack and part of the same full frame. The caller is cleaning up the Cilk frame during unwind and will reraise the exception */ /* Now that the record/replay stuff is done, update the pedigree */ update_pedigree_on_leave_frame(w, sf); #if DEBUG_EXCEPTIONS /* DEBUG ONLY */ { __cxa_eh_globals *state = __cxa_get_globals(); fflush(stdout); char decoded[9]; decode_flags(sf->flags, decoded); fprintf(stderr, "__cilkrts_save_except W%d %p/%s %p->%p [%u %p] escape\n", w->self, sf, decoded, exc, exc ? to_cxx(exc)->nextException : 0, state->uncaughtExceptions, state->caughtExceptions); /* XXX This is triggering in the user thread which gets an exception from somewhere but does not get the corresponding runtime exception state. XXX There might be two or more uncaught exceptions. Test could be (uncaught != 0) == (exc != 0). First, design tests to see if that case is otherwise handled correctly. And what if there's an uncaught exception that does not belong to this function? I.e. this is a return from spawn in a destructor. */ if (exc) CILK_ASSERT((int)state->uncaughtExceptions > 0); /*CILK_ASSERT(state->uncaughtExceptions == (exc != 0));*/ } #endif /* The parent is attached so this exception can be propagated normally. */ return; }
/* * --------------------------------------------------------------------------- * * Return an lbuf pointing to the object name and possibly the db# and flags */ UTF8 *unparse_object(dbref player, dbref target, bool obey_myopic, bool bAddColor) { UTF8 *buf = alloc_lbuf("unparse_object"); if (NOPERM <= target && target < 0) { mux_strncpy(buf, aszSpecialDBRefNames[-target], LBUF_SIZE-1); } else if (!Good_obj(target)) { mux_sprintf(buf, LBUF_SIZE, T("*ILLEGAL*(#%d)"), target); } else { bool exam; if (obey_myopic) { exam = MyopicExam(player, target); } else { exam = Examinable(player, target); } // Leave and extra 100 bytes for the dbref and flags at the end and // color at the beginning if necessary.. // mux_field fldName = StripTabsAndTruncate( Moniker(target), buf, LBUF_SIZE-100, LBUF_SIZE-100); UTF8 *bp = buf + fldName.m_byte; #if defined(FIRANMUX) if ( fldName.m_column == fldName.m_byte && bAddColor) { // There is no color in the name, so look for @color, or highlight. // UTF8 *buf2 = alloc_lbuf("unparse_object.color"); UTF8 *bp2 = buf2; UTF8 *pLetters = AcquireColorLetters(player, target); if (NULL != pLetters) { safe_str(LettersToBinary(pLetters), buf2, &bp2); free_lbuf(pLetters); pLetters = NULL; } else { safe_str((UTF8 *)COLOR_INTENSE, buf2, &bp2); } *bp = '\0'; safe_str(buf, buf2, &bp2); safe_str((UTF8 *)COLOR_RESET, buf2, &bp2); // Swap buffers. // free_lbuf(buf); buf = buf2; bp = bp2; } #else UNUSED_PARAMETER(bAddColor); #endif // FIRANMUX if ( exam || (Flags(target) & (CHOWN_OK | JUMP_OK | LINK_OK | DESTROY_OK)) || (Flags2(target) & ABODE)) { // Show everything. // UTF8 *fp = decode_flags(player, &(db[target].fs)); safe_str(T("(#"), buf, &bp); safe_ltoa(target, buf, &bp); safe_str(fp, buf, &bp); safe_chr(')', buf, &bp); free_sbuf(fp); } *bp = '\0'; } return buf; }
static ERL_NIF_TERM emmap_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { int flags; int prot; bool direct, lock; unsigned long int len; unsigned long int offset; char buf[1024]; #ifndef NDEBUG if ( sizeof(long int) != sizeof(size_t) ) { abort(); } #endif if (argc == 4 && enif_get_string(env, argv[0], buf, 1024, ERL_NIF_LATIN1) && enif_get_ulong(env, argv[1], &offset) && enif_get_ulong(env, argv[2], &len) && decode_flags(env, argv[3], &prot, &flags, &direct, &lock)) { int mode = (((prot & PROT_WRITE)==PROT_WRITE) ? O_RDWR : O_RDONLY); int fd = open(buf, mode); if (fd < 0) { return make_error_tuple(env, errno); } void * res = mmap(0, (size_t) len, prot, flags, fd, (size_t) offset); if (res == MAP_FAILED) { return make_error_tuple(env, errno); } close(fd); mhandle* handle = (mhandle*)enif_alloc_resource_compat(env, MMAP_RESOURCE, sizeof(mhandle)); if (lock) handle->rwlock = enif_rwlock_create((char*)"mmap"); else handle->rwlock = 0; handle->prot = prot; handle->mem = res; handle->len = len; handle->closed = false; handle->direct = direct; handle->position = 0; ERL_NIF_TERM resource = enif_make_resource(env, handle); enif_release_resource_compat(env, handle); return enif_make_tuple2(env, enif_make_atom(env, "ok"), resource); } else { return enif_make_badarg(env); } }