Exemple #1
0
 string open_tag(const string &tag, const string &cls, int id = -1) {
     std::stringstream s;
     s << "<" << tag << " class='" << cls << "' id='";
     if (id == -1) {
         s << context_stack.back() << "-";
         s << unique_id();
     } else {
         s << id;
     }
     s << "'>";
     context_stack.push_back(unique_id());
     return s.str();
 }
Exemple #2
0
    string var(const string &x) {
        int id;
        if (scope.contains(x)) {
            id = scope.get(x);
        } else {
            id = unique_id();
            scope.push(x, id);
        }

        std::stringstream s;
        s << "<b class='Variable Matched' id='" << id << "-" << unique_id() << "'>";
        s << x;
        s << "</b>";
        return s.str();
    }
Exemple #3
0
void StMObAllocateMach(LVAL menu)
{
  HMENU theMenu;
  int menuID;

  menuID = unique_id();
  theMenu = CreatePopupMenu();
  if (! theMenu) xlfail("menu allocation failed");
  set_menu_address(theMenu, menu);
  set_slot_value(menu, s_id, cvfixnum((FIXTYPE) menuID));
}
Exemple #4
0
DTerr Resource::import (const FilePath &pathname, std::string args)
{
	_file_path = pathname;
	_args = args;
	
	_time_loaded = Time::seconds();

	// Spew to the log
    LOG_MESSAGE << "Loading " << _file_path.full_path() << " (UID = " << unique_id() << ")";
	
    return DT3_ERR_NONE;
}
Exemple #5
0
vfs_fd_handle vfs_fd_create(struct vfs_inode *node) {
  struct vfs_fd *fd;

  if (!(fd = calloc(sizeof(*fd), 1)))
    stderror("calloc");
  fd->fh = unique_id();
  fd->node = node;
  fd->prev = NULL;
  fd->next = vfs_fd_list;
  if (vfs_fd_list)
    vfs_fd_list->prev = fd;
  vfs_fd_list = fd;
  vfs_node_ref(fd->node);
  return fd->fh;
}
int
CamerasChild::NumberOfCapabilities(CaptureEngine aCapEngine,
                                   const char* deviceUniqueIdUTF8)
{
  LOG((__PRETTY_FUNCTION__));
  LOG(("NumberOfCapabilities for %s", deviceUniqueIdUTF8));
  nsCString unique_id(deviceUniqueIdUTF8);
  nsCOMPtr<nsIRunnable> runnable =
    media::NewRunnableFrom([this, aCapEngine, unique_id]() -> nsresult {
      if (this->SendNumberOfCapabilities(aCapEngine, unique_id)) {
        return NS_OK;
      }
      return NS_ERROR_FAILURE;
    });
  LockAndDispatch<> dispatcher(this, __func__, runnable, 0, mReplyInteger);
  LOG(("Capture capability count: %d", dispatcher.ReturnValue()));
  return dispatcher.ReturnValue();
}
int
CamerasChild::GetCaptureCapability(CaptureEngine aCapEngine,
                                   const char* unique_idUTF8,
                                   const unsigned int capability_number,
                                   webrtc::CaptureCapability& capability)
{
  LOG(("GetCaptureCapability: %s %d", unique_idUTF8, capability_number));
  nsCString unique_id(unique_idUTF8);
  nsCOMPtr<nsIRunnable> runnable =
    media::NewRunnableFrom([this, aCapEngine, unique_id, capability_number]() -> nsresult {
      if (this->SendGetCaptureCapability(aCapEngine, unique_id, capability_number)) {
        return NS_OK;
      }
      return NS_ERROR_FAILURE;
    });
  LockAndDispatch<> dispatcher(this, __func__, runnable);
  if (dispatcher.Success()) {
    capability = mReplyCapability;
  }
  return dispatcher.ReturnValue();
}
Exemple #8
0
void CddaDevice::AudioCDTagsLoaded(const QString& artist, const QString& album,
                                   const MusicBrainzClient::ResultList& results) {
  MusicBrainzClient *musicbrainz_client = qobject_cast<MusicBrainzClient*>(sender());
  musicbrainz_client->deleteLater();
  SongList songs;
  int track_number = 1;
  if (results.size() == 0)
    return;
  model_->Reset();
  foreach (const MusicBrainzClient::Result& ret, results) {
    Song song;
    song.set_artist(artist);
    song.set_album(album);
    song.set_title(ret.title_);
    song.set_length_nanosec(ret.duration_msec_ * kNsecPerMsec);
    song.set_track(track_number);
    song.set_year(ret.year_);
    song.set_id(track_number);
    // We need to set url: that's how playlist will find the correct item to update
    song.set_url(QUrl(QString("cdda://%1/%2").arg(unique_id()).arg(track_number++)));
    songs << song;
  }
Exemple #9
0
ReturnOop IsolateObj::duplicate(JVM_SINGLE_ARG_TRAPS) const {
  UsingFastOops fast_oops;
  IsolateObj::Fast dup = 
      Universe::new_instance(Universe::isolate_class() JVM_CHECK_0);

  dup().set_unique_id( unique_id() );
  dup().set_use_verifier( use_verifier() );
  dup().set_api_access_init( api_access_init() );
#if ENABLE_MULTIPLE_PROFILES_SUPPORT
  dup().set_profile_id( profile_id() );
#endif // ENABLE_MULTIPLE_PROFILES_SUPPORT

  OopDesc* p;
  // Do not use JVM_ZCHECK because result can be NULL
  p = Universe::deep_copy(main_class() JVM_CHECK_0);
  dup().set_main_class(p);
  p = Universe::deep_copy(main_args() JVM_CHECK_0);
  dup().set_main_args(p);
  p = Universe::deep_copy(app_classpath() JVM_CHECK_0);
  dup().set_app_classpath(p);

  return dup.obj();
}
Exemple #10
0
bool WmdmDevice::StartCopy(QList<Song::FileType>* supported_types) {
  // Ensure only one "organise files" can be active at any one time
  db_busy_.lock();

  // This initialises COM and gets a connection to the device
  thread_.reset(new WmdmThread);
  if (!thread_->manager())
    return false;

  // Find a place to put the files.  We default to the root folder for now, but
  // could look for a "Music" folder in the future?
  WmdmLister* wmdm_lister = static_cast<WmdmLister*>(lister());
  QString canonical_name = wmdm_lister->DeviceCanonicalName(unique_id());
  IWMDMStorage* destination = thread_->GetRootStorage(canonical_name);

  // Get the control interface
  destination->QueryInterface(IID_IWMDMStorageControl3, (void**)&storage_control_);

  // Get the storage3 interface for CreateEmptyMetadataObject later
  destination->QueryInterface(IID_IWMDMStorage3, (void**)&storage_);

  destination->Release();

  // Did the caller want a list of supported filetypes?
  if (supported_types) {
    IWMDMDevice* device = thread_->GetDeviceByCanonicalName(canonical_name);
    if (!GetSupportedFiletypes(supported_types, device)) {
      device->Release();
      FinishCopy(false);
      return false;
    }
    device->Release();
  }

  return true;
}
Exemple #11
0
void vfs_mount(const struct volume_metadata *md, const char *path) {
  const char *argv[] = {
      "cloudfs", path,
      "-f", "-s",
      "-o", "hard_remove",
      NULL };

  notice("Volume mounting on %s", path);

  misc_maybe_fork();

  object_load();

  vfs_fsid = unique_id();

  if (fuse_main(sizearr(argv) - 1, (char**) argv, &vfs_oper, NULL) != 0)
    warning("FUSE failed");

  notice("Volume disconnecting");

  vfs_fd_clear();
  vfs_node_clear();
  object_unload();
}
void Udisks2Lister::Init() {
  udisks2_interface_.reset(new OrgFreedesktopDBusObjectManagerInterface(
      udisks2_service_, "/org/freedesktop/UDisks2",
      QDBusConnection::systemBus()));

  QDBusPendingReply<ManagedObjectList> reply =
      udisks2_interface_->GetManagedObjects();
  reply.waitForFinished();

  if (!reply.isValid()) {
    qLog(Warning) << "Error enumerating udisks2 devices:"
                  << reply.error().name() << reply.error().message();
    udisks2_interface_.reset();
    return;
  }

  for (const QDBusObjectPath& path : reply.value().keys()) {
    auto partition_data = ReadPartitionData(path);

    if (!partition_data.dbus_path.isEmpty()) {
      QWriteLocker locker(&device_data_lock_);
      device_data_[partition_data.unique_id()] = partition_data;
    }
  }

  for (const auto& id : device_data_.keys()) {
    emit DeviceAdded(id);
  }

  connect(udisks2_interface_.get(),
          SIGNAL(InterfacesAdded(QDBusObjectPath, InterfacesAndProperties)),
          SLOT(DBusInterfaceAdded(QDBusObjectPath, InterfacesAndProperties)));
  connect(udisks2_interface_.get(),
          SIGNAL(InterfacesRemoved(QDBusObjectPath, QStringList)),
          SLOT(DBusInterfaceRemoved(QDBusObjectPath, QStringList)));
}
Exemple #13
0
int
CamerasChild::AllocateCaptureDevice(CaptureEngine aCapEngine,
                                    const char* unique_idUTF8,
                                    const unsigned int unique_idUTF8Length,
                                    int& capture_id,
                                    const nsACString& aOrigin)
{
  LOG((__PRETTY_FUNCTION__));
  nsCString unique_id(unique_idUTF8);
  nsCString origin(aOrigin);
  nsCOMPtr<nsIRunnable> runnable =
    media::NewRunnableFrom([this, aCapEngine, unique_id, origin]() -> nsresult {
      if (this->SendAllocateCaptureDevice(aCapEngine, unique_id, origin)) {
        return NS_OK;
      }
      return NS_ERROR_FAILURE;
    });
  LockAndDispatch<> dispatcher(this, __func__, runnable);
  if (dispatcher.Success()) {
    LOG(("Capture Device allocated: %d", mReplyInteger));
    capture_id = mReplyInteger;
  }
  return dispatcher.ReturnValue();
}
Exemple #14
0
//-------------------------------------------------------------------------
OL_Data::OL_Data( const Token &t,
                  int DataType,
                  ActionType mode ):BaseData(t,mode)
{


    char *dbgStr;
    dbgStr = getenv("OL_DEBUG");
    dbgLevel = ( dbgStr ? atoi ( dbgStr ) : 0 );

    /* first generate grep all the mode info */
    istat = mode & IGNORE_ON;
    removeSpaces = mode & REMOVE_SPACES;

    f_name = strdup( t.file() );
    line_num = t.line();

    if ( istat && !Dispatch::OutsideIgnoreScope() ) {
        data_avail = 0;
        return;
    }

    const AttributeRec *attRec;
    if ( !(attRec = t.LookupAttr( DataType )) ) {

        if ( mode & GENERATE_ID ) {
            const char *str = unique_id();

            ValueBuffer.writeStr( str );
            data_avail = 1;
            data_complete = 1;
        }
        else {

            /*
             * The default rule kicks in, i.e use #CONTENT
             */

            addSubTask( new Content( t, mode) );
        }

        return;
    }

    tokContent.Parse( ( char *)attRec->getAttrValueString() );


    const OL_Expression *eptr = tokContent.exprlist;
    assert(eptr != NULL);

    switch ( eptr->type() ) {

    case REFERENCE:
    {
        BaseData *sub_data = new AttributeData(t, eptr->name(), mode );
        if ( sub_data ) {
            if (  data_avail= sub_data->DataWillBeAvailable() ) {
                ValueBuffer.write( sub_data->content(),
                                   sub_data->content_size() );
                data_complete = 1;
            }
            delete sub_data;
        }
    }

    break;

    case CONTENT:
        addSubTask( new Content(t, mode) );
        break;

    case CONCAT:
        addSubTask( new Concat( t,
                                (ExprList *)eptr->data_list(),
                                mode) );
        break;

    case FIRSTOF:
        addSubTask( new FirstOf( t,
                                 (ExprList *)eptr->data_list(),
                                 mode) );
        break;

    case GENERIC_ID:
        addSubTask( new GenericId( t,
                                   eptr->name(),
                                   mode) );
        break;

    case LITERAL:
        data_avail = 1;
        data_complete = 1;
        ValueBuffer.writeStr( ( const char *)eptr->data_list() );
        break;

    default:
        abort();
    }

}
Exemple #15
0
/// default constructor
Unit::Unit()
:uuid(unique_id()){

}
bool AggressiveDCEPass::AggressiveDCE(Function* func) {
  // Mark function parameters as live.
  AddToWorklist(&func->DefInst());
  func->ForEachParam(
      [this](const Instruction* param) {
        AddToWorklist(const_cast<Instruction*>(param));
      },
      false);

  // Compute map from block to controlling conditional branch
  std::list<BasicBlock*> structuredOrder;
  cfg()->ComputeStructuredOrder(func, &*func->begin(), &structuredOrder);
  ComputeBlock2HeaderMaps(structuredOrder);
  bool modified = false;
  // Add instructions with external side effects to worklist. Also add branches
  // EXCEPT those immediately contained in an "if" selection construct or a loop
  // or continue construct.
  // TODO(greg-lunarg): Handle Frexp, Modf more optimally
  call_in_func_ = false;
  func_is_entry_point_ = false;
  private_stores_.clear();
  // Stacks to keep track of when we are inside an if- or loop-construct.
  // When immediately inside an if- or loop-construct, we do not initially
  // mark branches live. All other branches must be marked live.
  std::stack<bool> assume_branches_live;
  std::stack<uint32_t> currentMergeBlockId;
  // Push sentinel values on stack for when outside of any control flow.
  assume_branches_live.push(true);
  currentMergeBlockId.push(0);
  for (auto bi = structuredOrder.begin(); bi != structuredOrder.end(); ++bi) {
    // If exiting if or loop, update stacks
    if ((*bi)->id() == currentMergeBlockId.top()) {
      assume_branches_live.pop();
      currentMergeBlockId.pop();
    }
    for (auto ii = (*bi)->begin(); ii != (*bi)->end(); ++ii) {
      SpvOp op = ii->opcode();
      switch (op) {
        case SpvOpStore: {
          uint32_t varId;
          (void)GetPtr(&*ii, &varId);
          // Mark stores as live if their variable is not function scope
          // and is not private scope. Remember private stores for possible
          // later inclusion.  We cannot call IsLocalVar at this point because
          // private_like_local_ has not been set yet.
          if (IsVarOfStorage(varId, SpvStorageClassPrivate) ||
              IsVarOfStorage(varId, SpvStorageClassWorkgroup))
            private_stores_.push_back(&*ii);
          else if (!IsVarOfStorage(varId, SpvStorageClassFunction))
            AddToWorklist(&*ii);
        } break;
        case SpvOpCopyMemory:
        case SpvOpCopyMemorySized: {
          uint32_t varId;
          (void)GetPtr(ii->GetSingleWordInOperand(kCopyMemoryTargetAddrInIdx),
                       &varId);
          if (IsVarOfStorage(varId, SpvStorageClassPrivate) ||
              IsVarOfStorage(varId, SpvStorageClassWorkgroup))
            private_stores_.push_back(&*ii);
          else if (!IsVarOfStorage(varId, SpvStorageClassFunction))
            AddToWorklist(&*ii);
        } break;
        case SpvOpLoopMerge: {
          assume_branches_live.push(false);
          currentMergeBlockId.push(
              ii->GetSingleWordInOperand(kLoopMergeMergeBlockIdInIdx));
        } break;
        case SpvOpSelectionMerge: {
          assume_branches_live.push(false);
          currentMergeBlockId.push(
              ii->GetSingleWordInOperand(kSelectionMergeMergeBlockIdInIdx));
        } break;
        case SpvOpSwitch:
        case SpvOpBranch:
        case SpvOpBranchConditional:
        case SpvOpUnreachable: {
          if (assume_branches_live.top()) {
            AddToWorklist(&*ii);
          }
        } break;
        default: {
          // Function calls, atomics, function params, function returns, etc.
          // TODO(greg-lunarg): function calls live only if write to non-local
          if (!ii->IsOpcodeSafeToDelete()) {
            AddToWorklist(&*ii);
          }
          // Remember function calls
          if (op == SpvOpFunctionCall) call_in_func_ = true;
        } break;
      }
    }
  }
  // See if current function is an entry point
  for (auto& ei : get_module()->entry_points()) {
    if (ei.GetSingleWordInOperand(kEntryPointFunctionIdInIdx) ==
        func->result_id()) {
      func_is_entry_point_ = true;
      break;
    }
  }
  // If the current function is an entry point and has no function calls,
  // we can optimize private variables as locals
  private_like_local_ = func_is_entry_point_ && !call_in_func_;
  // If privates are not like local, add their stores to worklist
  if (!private_like_local_)
    for (auto& ps : private_stores_) AddToWorklist(ps);
  // Perform closure on live instruction set.
  while (!worklist_.empty()) {
    Instruction* liveInst = worklist_.front();
    // Add all operand instructions if not already live
    liveInst->ForEachInId([&liveInst, this](const uint32_t* iid) {
      Instruction* inInst = get_def_use_mgr()->GetDef(*iid);
      // Do not add label if an operand of a branch. This is not needed
      // as part of live code discovery and can create false live code,
      // for example, the branch to a header of a loop.
      if (inInst->opcode() == SpvOpLabel && liveInst->IsBranch()) return;
      AddToWorklist(inInst);
    });
    if (liveInst->type_id() != 0) {
      AddToWorklist(get_def_use_mgr()->GetDef(liveInst->type_id()));
    }
    // If in a structured if or loop construct, add the controlling
    // conditional branch and its merge.
    BasicBlock* blk = context()->get_instr_block(liveInst);
    Instruction* branchInst = block2headerBranch_[blk];
    if (branchInst != nullptr) {
      AddToWorklist(branchInst);
      Instruction* mergeInst = branch2merge_[branchInst];
      AddToWorklist(mergeInst);
    }
    // If the block is a header, add the next outermost controlling
    // conditional branch and its merge.
    Instruction* nextBranchInst = header2nextHeaderBranch_[blk];
    if (nextBranchInst != nullptr) {
      AddToWorklist(nextBranchInst);
      Instruction* mergeInst = branch2merge_[nextBranchInst];
      AddToWorklist(mergeInst);
    }
    // If local load, add all variable's stores if variable not already live
    if (liveInst->opcode() == SpvOpLoad || liveInst->IsAtomicWithLoad()) {
      uint32_t varId;
      (void)GetPtr(liveInst, &varId);
      if (varId != 0) {
        ProcessLoad(varId);
      }
      // Process memory copies like loads
    } else if (liveInst->opcode() == SpvOpCopyMemory ||
               liveInst->opcode() == SpvOpCopyMemorySized) {
      uint32_t varId;
      (void)GetPtr(liveInst->GetSingleWordInOperand(kCopyMemorySourceAddrInIdx),
                   &varId);
      if (varId != 0) {
        ProcessLoad(varId);
      }
      // If merge, add other branches that are part of its control structure
    } else if (liveInst->opcode() == SpvOpLoopMerge ||
               liveInst->opcode() == SpvOpSelectionMerge) {
      AddBreaksAndContinuesToWorklist(liveInst);
      // If function call, treat as if it loads from all pointer arguments
    } else if (liveInst->opcode() == SpvOpFunctionCall) {
      liveInst->ForEachInId([this](const uint32_t* iid) {
        // Skip non-ptr args
        if (!IsPtr(*iid)) return;
        uint32_t varId;
        (void)GetPtr(*iid, &varId);
        ProcessLoad(varId);
      });
      // If function parameter, treat as if it's result id is loaded from
    } else if (liveInst->opcode() == SpvOpFunctionParameter) {
      ProcessLoad(liveInst->result_id());
      // We treat an OpImageTexelPointer as a load of the pointer, and
      // that value is manipulated to get the result.
    } else if (liveInst->opcode() == SpvOpImageTexelPointer) {
      uint32_t varId;
      (void)GetPtr(liveInst, &varId);
      if (varId != 0) {
        ProcessLoad(varId);
      }
    }
    worklist_.pop();
  }

  // Kill dead instructions and remember dead blocks
  for (auto bi = structuredOrder.begin(); bi != structuredOrder.end();) {
    uint32_t mergeBlockId = 0;
    (*bi)->ForEachInst([this, &modified, &mergeBlockId](Instruction* inst) {
      if (!IsDead(inst)) return;
      if (inst->opcode() == SpvOpLabel) return;
      // If dead instruction is selection merge, remember merge block
      // for new branch at end of block
      if (inst->opcode() == SpvOpSelectionMerge ||
          inst->opcode() == SpvOpLoopMerge)
        mergeBlockId = inst->GetSingleWordInOperand(0);
      to_kill_.push_back(inst);
      modified = true;
    });
    // If a structured if or loop was deleted, add a branch to its merge
    // block, and traverse to the merge block and continue processing there.
    // We know the block still exists because the label is not deleted.
    if (mergeBlockId != 0) {
      AddBranch(mergeBlockId, *bi);
      for (++bi; (*bi)->id() != mergeBlockId; ++bi) {
      }

      auto merge_terminator = (*bi)->terminator();
      if (merge_terminator->opcode() == SpvOpUnreachable) {
        // The merge was unreachable. This is undefined behaviour so just
        // return (or return an undef). Then mark the new return as live.
        auto func_ret_type_inst = get_def_use_mgr()->GetDef(func->type_id());
        if (func_ret_type_inst->opcode() == SpvOpTypeVoid) {
          merge_terminator->SetOpcode(SpvOpReturn);
        } else {
          // Find an undef for the return value and make sure it gets kept by
          // the pass.
          auto undef_id = Type2Undef(func->type_id());
          auto undef = get_def_use_mgr()->GetDef(undef_id);
          live_insts_.Set(undef->unique_id());
          merge_terminator->SetOpcode(SpvOpReturnValue);
          merge_terminator->SetInOperands({{SPV_OPERAND_TYPE_ID, {undef_id}}});
          get_def_use_mgr()->AnalyzeInstUse(merge_terminator);
        }
        live_insts_.Set(merge_terminator->unique_id());
      }
    } else {
      ++bi;
    }
  }

  return modified;
}
Exemple #17
0
int vfs_node_lookup(const char *path, struct vfs_inode **out_node,
                    bool new_file) {
  struct vfs_inode *res_node, *f_node;
  struct vfs_inode_ptr empty_ptr, *pend;
  char *mpath, **path_list, **pptr;
  uint64_t parent_inode;
  bool found;
  int ret;

  if (!(res_node = calloc(sizeof(*res_node), 1)))
    stderror("calloc");
  vfs_node_ref(res_node);

  if (!(mpath = strdup(path)))
    stderror("strdup");
  if (!(path_list = vfs_path_split(mpath)))
    error("Error splitting path");

  pend = (new_file ? &empty_ptr : NULL);

  ret = 0;
  parent_inode = 0;
  if (!path_list[0]) {
    if (new_file) {
      ret = -EEXIST;
    } else {
      strcpy(res_node->data.name, "/");
      res_node->data.flag |= VFS_INODE_FLAG_VALID;
      res_node->data.mode = S_IFDIR | 0755;
      res_node->data.nlink = 2;
      res_node->data.ctime = res_node->data.mtime =
                             res_node->data.atime = time(NULL);
      res_node->is_root = true;
    }
  } else {
    for (pptr = path_list; *pptr; pptr++) {
      struct vfs_inode *dir_list, *found_node;
      bool last_file = (pptr[1] ? false : true);

      if ((ret = vfs_dir_read(parent_inode, &dir_list, pend)) != 0) {
        warning("File system missing data at inode %016" PRIx64,
                parent_inode);
        break;
      }

      found = false;
      for (found_node = dir_list; found_node; found_node = found_node->next) {
        if (!strcmp(found_node->data.name, *pptr)) {
          if (last_file) {
            memcpy(&res_node->data, &found_node->data, sizeof(res_node->data));
            memcpy(&res_node->ptr, &found_node->ptr, sizeof(res_node->ptr));
          }
          parent_inode = found_node->data.ino;
          if (last_file || S_ISDIR(found_node->data.mode))
            found = true;
          else
            ret = -ENOTDIR;
          break;
        }
      }

      vfs_dir_read_free(dir_list);

      if (new_file && last_file) {
        if (found) {
          ret = -EEXIST;
        } else if (strlen(*pptr) > VFS_PATH_MAX - 1) {
          ret = -ENAMETOOLONG;
        } else {
          memcpy(&res_node->ptr, &empty_ptr, sizeof(res_node->ptr));
          strcpy(res_node->data.name, *pptr);
          res_node->data.ino = unique_id();
          res_node->data.flag |= VFS_INODE_FLAG_VALID;
          res_node->data.ctime = res_node->data.mtime =
                                 res_node->data.atime = time(NULL);
        }
        break;
      }
      if (!found) {
        if (!ret)
          ret = -ENOENT;
        break;
      }
    }
  }

  vfs_path_split_free(path_list);
  free(mpath);

  if (ret || !out_node) {
    free(res_node);
    return ret;
  }

  for (f_node = vfs_node_open_list; f_node; f_node = f_node->next) {
    if ((f_node->data.flag & VFS_INODE_FLAG_VALID) &&
        res_node->data.ino == f_node->data.ino) {
      free(res_node);
      vfs_node_ref(f_node);
      f_node->data.atime = time(NULL);
      *out_node = f_node;
      return ret;
    }
  }

  res_node->data.atime = time(NULL);
  res_node->next = vfs_node_open_list;
  if (vfs_node_open_list)
    vfs_node_open_list->prev = res_node;
  vfs_node_open_list = res_node;
  *out_node = res_node;
  return ret;
}
Exemple #18
0
static bool value( void )
{
  DEVELOPER_DEBUG( "value() %s\n", cursor );
  if ( ! ( unique_id() || number() || stringvalue() ) ) return false;
  return true;
}
Exemple #19
0
static unsigned long spawn_erlang_epmd(ei_cnode *ec,
				       char *alive,
				       Erl_IpAddr adr,
				       int flags, 
				       char *erl_or_epmd, 
				       char *args[], 
				       int port,
				       int is_erlang)
{
#if defined(VXWORKS)
    FUNCPTR erlfunc;
#else /* Windows */
    STARTUPINFO sinfo; 
    SECURITY_ATTRIBUTES sa;
    PROCESS_INFORMATION pinfo;
#endif
    char *cmdbuf;
    int cmdlen;
    char *ptr;
    int i;
    int num_args;
    char *name_format;
    struct in_addr myaddr;
    struct in_addr *hisaddr = (struct in_addr *)adr;
    char iaddrbuf[IP_ADDR_CHARS + 1];
    int ret;

    if(is_erlang){
	get_addr(ei_thishostname(ec), &myaddr);
#if defined(VXWORKS)
     	inet_ntoa_b(myaddr, iaddrbuf);
#else /* Windows */
	if((ptr = inet_ntoa(myaddr)) == NULL)
	    return 0;
	else
	    strcpy(iaddrbuf,ptr);
#endif
    }
    if ((flags & ERL_START_REMOTE) || 
	(is_erlang && (hisaddr->s_addr != myaddr.s_addr))) {
	return 0;
    } else {
	num_args = enquote_args(args, &args);
	for(cmdlen = i = 0; args[i] != NULL; ++i)
	    cmdlen += strlen(args[i]) + 1;
#if !defined(VXWORKS)
	/* On VxWorks, we dont actually run a command,
	   we call start_erl() */
	if(!erl_or_epmd) 
#endif
	    erl_or_epmd = (is_erlang) ? DEF_ERL_COMMAND :
	    DEF_EPMD_COMMAND;
	if(is_erlang){
	    name_format = (flags & ERL_START_LONG) ? ERL_NAME_FMT :
		ERL_SNAME_FMT;
	    cmdlen += 
		strlen(erl_or_epmd) + (*erl_or_epmd != '\0') +
		strlen(name_format) + 1 + strlen(alive) +
		strlen(ERL_REPLY_FMT) + 1 + strlen(iaddrbuf) +  
	            2 * FORMATTED_INT_LEN +
		1;
	    ptr = cmdbuf = malloc(cmdlen);
	    if(*erl_or_epmd != '\0')
		ptr += sprintf(ptr,"%s ",erl_or_epmd);
	    ptr += sprintf(ptr, name_format,
			   alive);
	    ptr += sprintf(ptr, " " ERL_REPLY_FMT,
		       iaddrbuf, port, unique_id());
	} else { /* epmd */
	    cmdlen += strlen(erl_or_epmd) + (*erl_or_epmd != '\0') + 1;
	    ptr = cmdbuf = malloc(cmdlen);
	    if(*erl_or_epmd != '\0')
		ptr += sprintf(ptr,"%s ",erl_or_epmd);
	    else
		*(ptr++) = '\0';
	}
	for(i= 0; args[i] != NULL; ++i){
	    *(ptr++) = ' ';
	    strcpy(ptr,args[i]);
	    ptr += strlen(args[i]);
	}
	free_args(args);
	if (flags & ERL_START_VERBOSE) {
	    fprintf(stderr,"erl_call: commands are %s\n",cmdbuf);
	}
	/* OK, one single command line... */
#if defined(VXWORKS)
	erlfunc = lookup_function((is_erlang) ? ERLANG_SYM :
				  EPMD_SYM);
	if(erlfunc == NULL){
	    if (flags & ERL_START_VERBOSE) {
		fprintf(stderr,"erl_call: failed to find symbol %s\n",
			(is_erlang) ? ERLANG_SYM : EPMD_SYM);
	    }
	    ret = 0;
	} else {
	/* Just call it, it spawns itself... */
	    ret = (unsigned long) 
		(*erlfunc)((int) cmdbuf,0,0,0,0,0,0,0,0,0);
	    if(ret == (unsigned long) ERROR)
		ret = 0;
	}
#else /* Windows */
	/* Hmmm, hidden or unhidden window??? */
	memset(&sinfo,0,sizeof(sinfo));
	sinfo.cb = sizeof(STARTUPINFO); 
	sinfo.dwFlags = STARTF_USESHOWWINDOW /*| 
	    STARTF_USESTDHANDLES*/;
	sinfo.wShowWindow = SW_HIDE; /* Hidden! */
	sinfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
	sinfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	sinfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
	sa.nLength = sizeof(sa);
	sa.lpSecurityDescriptor = NULL;
	sa.bInheritHandle = /*TRUE*/ FALSE;
	if(!CreateProcess(
			  NULL,
			  cmdbuf,
			  &sa,
			  NULL,
			  /*TRUE*/ FALSE,
			  0 | CREATE_NEW_CONSOLE,
			  NULL,
			  NULL,
			  &sinfo,
			  &pinfo))
	    ret = 0;
	else
	    ret = (unsigned long) pinfo.hProcess;
#endif
	free(cmdbuf);
	return ret;
    }
    /* NOTREACHED */
}
Exemple #20
0
/* Start an Erlang node. return value 0 indicates that node was
 * started successfully, negative values indicate error. 
 * 
 * node -  the name of the remote node to start (alivename@hostname).
 * flags - turn on or off certain options. See erl_start.h for a list.
 * erl -  is the name of the erl script to call. If NULL, the default
 * name "erl" will be used.
 * args - a NULL-terminated list of strings containing
 * additional arguments to be sent to the remote Erlang node. These
 * strings are simply appended to the end of the command line, so any
 * quoting of special characters, etc must be done by the caller.
 * There may be some conflicts between some of these arguments and the
 * default arguments hard-coded into this function, so be careful. 
 */
int erl_start_sys(ei_cnode *ec, char *alive, Erl_IpAddr adr, int flags,
		  char *erl, char *args[])
{
  struct timeval timeout;
  struct sockaddr_in addr;
  SocklenType namelen;
  int port;
  int sockd = 0;
  int one = 1;
#if defined(VXWORKS) || defined(__WIN32__)
  unsigned long pid = 0;
#else
  int pid = 0;
#endif
  int r = 0;

  if (((sockd = socket(AF_INET, SOCK_STREAM, 0)) < 0) ||
      (setsockopt(sockd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one)) < 0)) {
    r = ERL_SYS_ERROR;
    goto done;
  }
  
  memset(&addr,0,sizeof(addr));
  addr.sin_family = AF_INET;              
  addr.sin_addr.s_addr = htonl(INADDR_ANY); 
  addr.sin_port = 0;

  if (bind(sockd,(struct sockaddr *)&addr,sizeof(addr))<0) {
      return ERL_SYS_ERROR;
  }
  namelen = sizeof(addr);
  if (getsockname(sockd,(struct sockaddr *)&addr,&namelen)<0) {
      return ERL_SYS_ERROR;
  }
  port = ntohs(addr.sin_port);

  listen(sockd,5);

#if defined(VXWORKS) || defined(__WIN32__)
  if((pid = spawn_erlang_epmd(ec,alive,adr,flags,erl,args,port,1)) 
      == 0)
     return ERL_SYS_ERROR;
  timeout.tv_usec = 0;
  timeout.tv_sec = 10; /* ignoring ERL_START_TIME */
  if((r = wait_for_erlang(sockd,unique_id(),&timeout)) 
     == ERL_TIMEOUT) {
#if defined(VXWORKS)
      taskDelete((int) pid);
      if(taskIdVerify((int) pid) != ERROR)
	  taskDeleteForce((int) pid);
#else /* Windows */
      /* Well, this is not a nice way to do it, and it does not 
	 always kill the emulator, but the alternatives are few.*/
      TerminateProcess((HANDLE) pid,1);
#endif /* defined(VXWORKS) */
  }
#else /* Unix */
  switch ((pid = fork())) {
  case -1:
    r = ERL_SYS_ERROR;
    break;

  case 0:
    /* child - start the erlang node */
    exec_erlang(ec, alive, adr, flags, erl, args, port);

    /* error if reached - parent reports back to caller after timeout
       so we just exit here */
    exit(1);
    break;

  default:

    /* parent - waits for response from Erlang node */
    /* child pid used here as magic number */
    timeout.tv_usec = 0;
    timeout.tv_sec = 10; /* ignoring ERL_START_TIME */
    if ((r = wait_for_erlang(sockd,pid,&timeout)) == ERL_TIMEOUT) {
      /* kill child if no response */
      kill(pid,SIGINT);
      sleep(1);
      if (waitpid(pid,NULL,WNOHANG) != pid) {
	/* no luck - try harder */
	kill(pid,SIGKILL);
	sleep(1);
	waitpid(pid,NULL,WNOHANG);
      }
    }

  }
#endif /* defined(VXWORKS) || defined(__WIN32__) */

done:
#if defined(__WIN32__)
  if (sockd) closesocket(sockd);
#else
  if (sockd) close(sockd);
#endif
  return r;
} /* erl_start_sys() */
Exemple #21
0
    static void dump_ex (typename basic_state_machine<CharT>::iterator &iter_,
        ostream &stream_)
    {
        const std::size_t states_ = iter_->states;

        for (std::size_t i_ = 0; i_ < states_; ++i_)
        {
            state (stream_);
            stream_ << i_ << std::endl;

            if (iter_->end_state)
            {
                end_state (stream_);
                stream_ << iter_->id;
                unique_id (stream_);
                stream_ << iter_->unique_id;
                dfa (stream_);
                stream_ << iter_->goto_dfa;
                stream_ << std::endl;
            }

            if (iter_->bol_index != npos)
            {
                bol (stream_);
                stream_ << iter_->bol_index << std::endl;
            }

            if (iter_->eol_index != npos)
            {
                eol (stream_);
                stream_ << iter_->eol_index << std::endl;
            }

            const std::size_t transitions_ = iter_->transitions;

            if (transitions_ == 0)
            {
                ++iter_;
            }

            for (std::size_t t_ = 0; t_ < transitions_; ++t_)
            {
                std::size_t goto_state_ = iter_->goto_state;

                if (iter_->token.any ())
                {
                    any (stream_);
                }
                else
                {
                    open_bracket (stream_);

                    if (iter_->token._negated)
                    {
                        negated (stream_);
                    }

                    string charset_;
                    CharT c_ = 0;

                    escape_control_chars (iter_->token._charset,
                        charset_);
                    c_ = *charset_.c_str ();

                    if (!iter_->token._negated &&
                        (c_ == '^' || c_ == ']'))
                    {
                        stream_ << '\\';
                    }

                    stream_ << charset_;
                    close_bracket (stream_);
                }

                stream_ << goto_state_ << std::endl;
                ++iter_;
            }

            stream_ << std::endl;
        }
    }
Exemple #22
0
Boolean 
info_lib::define_info_base( char* base_name, char* base_desc, 
                            char* spec_file_path
                          )
{
//MESSAGE(cerr, "define_info_base()");
//debug(cerr, base_name);
//debug(cerr, base_desc);
//debug(cerr, spec_file_path);

   char new_db_path[PATHSIZ]; 
   char f_name[PATHSIZ]; 
   char base_uid[UIDSIZ]; 

   strcpy(new_db_path, form("%s/%s", info_lib_path, base_name));

   strcpy(base_uid, unique_id());

   g_mode_8_3 = 1;

   info_base* base = get_info_base(base_name) ;

/* no checking here. DDK assures unique base name case
   if ( base == 0 ) {
*/
      
//////////////////////////
// check info base path
//////////////////////////
      if ( check_and_create_dir(new_db_path) == false ) {
         throw(stringException(form("bad base bath %s", new_db_path)));
      }

//////////////////////////
// remove any old files 
//////////////////////////

      strcpy(f_name, form("%s.%s", base_name, DATA_FILE_SUFFIX));
      if ( exist_file(f_name, new_db_path) == true )
         del_file(f_name, new_db_path);

      strcpy(f_name, form("%s.%s", base_name, INDEX_FILE_SUFFIX));
      if ( exist_file(f_name, new_db_path) == true )
         del_file(f_name, new_db_path);

      strcpy(f_name, form("%s.%s", base_name, SCHEMA_FILE_SUFFIX));
      if ( exist_file(f_name, new_db_path) == true )
         del_file(f_name, new_db_path);


      f_obj_dict -> init_a_base(spec_file_path, new_db_path, base_name);

      const char* lang;
      if ((lang = getenv("LC_ALL")) == NULL)
	if ((lang = getenv("LC_CTYPE")) == NULL)
	  if ((lang = getenv("LANG")) == NULL)
	    lang = "C";

#ifdef DtinfoClient
      _DtXlateDb db    = NULL;
      char* std_locale = NULL;

      if (_DtLcxOpenAllDbs(&db) == 0)
      {
	char platform[_DtPLATFORM_MAX_LEN + 1];
	int execver, compver;

	if (_DtXlateGetXlateEnv(db, platform, &execver, &compver) == 0)
	{
	  _DtLcxXlateOpToStd(db, platform, compver, DtLCX_OPER_SETLOCALE,
					lang, &std_locale, NULL, NULL, NULL);
	}
	_DtLcxCloseDb(&db);
	db = NULL;
      }
#endif

      base = new info_base(*f_obj_dict, set_nm_list, list_nm_list,
                           new_db_path, base_name, base_desc, base_uid,
#ifdef DtinfoClient
			   std_locale ? std_locale : lang,
#else
			   lang,
#endif
                           mm_version(MAJOR, MINOR)
                          );

      info_base_list.insert_as_tail(new dlist_void_ptr_cell(base));

/*************************************/
// add the base name and description
// to the names file
/*************************************/
      char* lib_nm = form("%s/%s", info_lib_path, MAP_FILE_8_3);

      fstream nm_out(lib_nm, ios::app, open_file_prot());

      if ( !nm_out ) {
         MESSAGE(cerr, form("can't open %s/%s for append", 
                            info_lib_path, MAP_FILE_8_3)
                );
         throw(streamException(nm_out.rdstate()));
      }

      if ( bytes(nm_out) == 0 ) {
         char* lib_entry = form("%s\t%s\n", info_lib_name, unique_id());

         if ( !(nm_out << lib_entry) ) {
            MESSAGE(cerr, 
	       form("write %s.%s failed", info_lib_path, MAP_FILE_8_3));
            throw(streamException(nm_out.rdstate()));
         }
      }

      char* base_entry = form("%s\t%s\t%s\t%s\t%d\t%d\n", 
                              base_name, base_desc, base_uid,
#ifdef DtinfoClient
			      std_locale ? std_locale: lang,
#else
			      lang,
#endif
			      MAJOR, MINOR
                             );
#ifdef DtinfoClient
      if (std_locale)
	free(std_locale);
#endif

      if ( !(nm_out << base_entry) ) {
         MESSAGE(cerr, form("write %s.%s failed", info_lib_path, MAP_FILE_8_3));
         throw(streamException(nm_out.rdstate()));
      }

      nm_out.close();

      if ( nm_out.fail() ) {
         MESSAGE(cerr, form("close %s.%s failed", info_lib_path, MAP_FILE_8_3));
         throw(streamException(nm_out.rdstate()));
      }

   //}


//MESSAGE(cerr, "define() done");
   return true;
}