示例#1
0
Containers::Array<char, Directory::MapDeleter> Directory::map(const std::string& filename, std::size_t size) {
    /* Open the file for writing. Create if it doesn't exist, truncate it if it
       does. */
    const int fd = open(filename.data(), O_RDWR|O_CREAT|O_TRUNC, mode_t(0600));
    if(fd == -1) {
        Error() << "Utility::Directory::map(): can't open the file";
        return nullptr;
    }

    /* Resize the file to requested size by seeking one byte before */
    if(lseek(fd, size - 1, SEEK_SET) == -1) {
        close(fd);
        Error() << "Utility::Directory::map(): can't seek to resize the file";
        return nullptr;
    }

    /* And then writing a zero byte on that position */
    if(::write(fd, "", 1) != 1) {
        close(fd);
        Error() << "Utility::Directory::map(): can't write to resize the file";
        return nullptr;
    }

    /* Map the file */
    char* data = reinterpret_cast<char*>(mmap(nullptr, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0));
    if(data == MAP_FAILED) {
        close(fd);
        Error() << "Utility::Directory::map(): can't map the file";
        return nullptr;
    }

    return Containers::Array<char, MapDeleter>{data, size, MapDeleter{fd}};
}
void FileMetadataWidgetTest::slotChooseFiles()
{
    KUrl::List urlList = KFileDialog::getOpenUrls();
    KFileItemList list;
    foreach(const KUrl& url, urlList)
        list << KFileItem( url, QString(), mode_t() );

    m_metadataWidget->setItems( list );
}
示例#3
0
void
SigGen::update(DefaultGUIModel::update_flags_t flag)
{
  switch (flag)
    {
  case INIT:
    setParameter("Freq (Hz)", QString::number(freq));
    setParameter("ZAP max Freq (Hz)", QString::number(freq2));
    setParameter("ZAP duration (s)", QString::number(ZAPduration));
    setParameter("Delay", QString::number(delay));
    setParameter("Width", QString::number(width));
    setParameter("Amplitude", QString::number(amp));
    setState("Time (s)", systime);
    updateMode(0);
    waveShape->setCurrentItem(mode);
    break;
  case MODIFY:
    delay = getParameter("Delay").toDouble();
    freq = getParameter("Freq (Hz)").toDouble();
    freq2 = getParameter("ZAP max Freq (Hz)").toDouble();
    ZAPduration = getParameter("ZAP duration (s)").toDouble();
    width = getParameter("Width").toDouble();
    amp = getParameter("Amplitude").toDouble();
    mode = mode_t(waveShape->currentItem());
    initStimulus();
    break;
  case PERIOD:
    dt = RT::System::getInstance()->getPeriod() * 1e-9; // time in seconds
    initStimulus();
  case PAUSE:
    output(0) = 0.0;
    zapWave.setIndex(0);
    break;
  case UNPAUSE:
    systime = 0;
    count = 0;
    break;
  default:
    break;
    }
}
示例#4
0
int startDaemon()
{
    pid_t pid;

    pid = fork();

	///NOTE: version in trunk checks for CHILD, not 0...
    if( pid  < 0 )
	exit( EXIT_FAILURE );

    if( pid > 0 )
	exit( EXIT_SUCCESS );

    ///NOTE: version in trunk checks for ERROR not 0...
    if( setsid() < 0 )
        exit( EXIT_FAILURE  );

	/// change to root in file system
    if( ( chdir( "/" ) ) < 0 ) 
        exit( EXIT_FAILURE  );

    umask( 0 );

    for( int i = sysconf( _SC_OPEN_MAX ); i > 0; i-- )
        close( i );

    /// check if the directory for pid file exist
    ifstream fin;
    string path = "/tmp/wonder";
    fin.open( path.c_str() , ios_base::in );

    if( !fin.is_open() )
    {
        /// create /tmp/wonder directory if it does not exist yet
        /// the sticky: anyone is able to create files, but
        /// not able to delete anyone elses files but their own
        int error = mkdir( path.c_str(), mode_t(S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX));
        if( error != 0 )
            return 1;   
    }

    /// open file stream to write the pid in
    string name;
    ostringstream spid;

    /// get pid of parent process
    spid << getpid();

    if( twonderConf->user == NULL )
        pathPidfile = path + "/twonder." + spid.str() + ".pid";
    else
        pathPidfile = path + "/twonder." + ( string ) twonderConf->user + ".pid";

    ofstream pidFile( pathPidfile.c_str() );
    pidFile << spid.str();
    pidFile.close();

    /// write stdin to /dev/null
    freopen("/dev/null", "r", stdin );

    /// write stdout and stderr to the log file     
    freopen( "/var/log/wonder.log", "w", stdout );
    freopen( "/var/log/wonder.log", "w", stderr );

    return 0;
}