예제 #1
0
파일: main.cpp 프로젝트: anarscari/led-test
int main(int argc, char **argv){
    char buf[BUFSIZE];
    FILE *fp;
    Led led;
    Cmd *cmd;
    struct sigaction new_action;

    if ((argc > 1) && !strcmp(argv[1], "-d")) {
	pid_t pid = fork();
	if (pid < 0) {
	    fprintf(stderr, "Can not fork\n");
	    return -1;
	}
	if (pid) return 0;
    }

    new_action.sa_handler = sigHandler;
    sigemptyset (&new_action.sa_mask);
    new_action.sa_flags = 0;
    sigaction (SIGINT, &new_action, NULL);
    sigaction (SIGHUP, &new_action, NULL);
    sigaction (SIGTERM, &new_action, NULL);

    cmd = createCmd();

    umask(0);
    mknod(FIFO_FILE, S_IFIFO|0666, 0);
    while (1) {
	struct stat st;
	void *arr[2];
	fp = fopen(FIFO_FILE, "r");
	fgets(buf, BUFSIZE, fp);
	fclose(fp);
	if (buf[BUFSIZE - 1]) {
	    fprintf(stderr, "Recieved string is too long, continue\n");
	    continue;
	}
	buf[strlen(buf) - 1] = 0;
	if (!stat(buf, &st) && S_ISFIFO(st.st_mode)) {
	    pthread_t th;
	    arr[0] = buf;
	    arr[1] = cmd;
	    pthread_create(&th, NULL, threadFn, arr);
	    pthread_detach(th);
	}
    }
    return 0;
}
예제 #2
0
CentralWidget::CentralWidget(QWidget *parent) :
    QWidget(parent)
{
    createVideoPlayer();
    createAudioPlayer();
    createTcpClient();
    createCmd();
#ifdef CONFIG_SPEAKER
    createSpeaker();
#endif

    setLayout(createLayout());

    setupKeyHook();

    readLocalSettings();

    initRemoteSettings();
}
예제 #3
0
파일: luks.cpp 프로젝트: KDE/kpmcore
bool luks::create(Report& report, const QString& deviceNode)
{
    Q_ASSERT(m_innerFs);
    Q_ASSERT(!m_passphrase.isEmpty());

    ExternalCommand createCmd(report, QStringLiteral("cryptsetup"),
                              { QStringLiteral("-s"),
                                QStringLiteral("512"),
                                QStringLiteral("--batch-mode"),
                                QStringLiteral("--force-password"),
                                QStringLiteral("luksFormat"),
                                deviceNode });
    if (!( createCmd.start(-1) &&
                createCmd.write(m_passphrase.toUtf8() + '\n') == m_passphrase.toUtf8().length() + 1 &&
                createCmd.waitFor() && createCmd.exitCode() == 0))
    {
        return false;
    }

    ExternalCommand openCmd(report, QStringLiteral("cryptsetup"),
                              { QStringLiteral("open"),
                                deviceNode,
                                suggestedMapperName(deviceNode) });

    if (!( openCmd.start(-1) &&  openCmd.write(m_passphrase.toUtf8() + '\n') == m_passphrase.toUtf8().length() + 1 && openCmd.waitFor()))
        return false;

    scan(deviceNode);

    if (mapperName().isEmpty())
        return false;

    if (!m_innerFs->create(report, mapperName()))
        return false;

    return true;
}
예제 #4
0
void test() {

    //---------------------------------------------------------------------------
    std::vector<dconsole::BaseCmd::Variant> params;

    { // 
    dconsole::BaseCmd* pcmd = createCmd("helloWorld", "Hello, World!", f_hw);
    pcmd->runCommand(params, dconsole::Instance());
    dconsole::Instance().registerCommand(pcmd);
    }

	{ // 
    dconsole::BaseCmd* pcmd = createCmd("do_somethig", "void ret val test", f_voidretval);
    pcmd->runCommand(params, dconsole::Instance());
    dconsole::Instance().registerCommand(pcmd);
    }

	{ // >
    dconsole::BaseCmd* pcmd = createCmd("ret_int", "int ret val test", f_intretval);
    pcmd->runCommand(params, dconsole::Instance());
    dconsole::Instance().registerCommand(pcmd);
    }

    { // 
    dconsole::BaseCmd* pcmd = createCmd("fasimple", "adder", f);
    pcmd->runCommand(params, dconsole::Instance());
    dconsole::Instance().registerCommand(pcmd);

    pcmd = createCmd("fachar", "adder", f1);
    pcmd ->runCommand(params, dconsole::Instance());
    dconsole::Instance().registerCommand(pcmd );
    }

	{ // 
	params.push_back(dconsole::BaseCmd::Variant("1.86"));
    params.push_back(dconsole::BaseCmd::Variant("5"));
	// rv: MyString; p1: int ; p2:int
	dconsole::BaseCmd* pcmd = createCmd("mystring_intint", "returns MyString", f_string_p1Intp2Int);
	pcmd ->runCommand(params, dconsole::Instance());
	dconsole::Instance().registerCommand(pcmd );

	pcmd = createCmd("constcharptr_intint", "returns const char*", f_constcharptr_p1Intp2Int);
	pcmd ->runCommand(params, dconsole::Instance());
	dconsole::Instance().registerCommand(pcmd );

	pcmd = createCmd("charptr_intint", "returns chasr*", f_charptr_p1Intp2Int);
	pcmd ->runCommand(params, dconsole::Instance());
	dconsole::Instance().registerCommand(pcmd );
	// void (*fp)(int,int)
	pcmd = createCmd("void_intint", "returns void", f_void_intint);
	pcmd ->runCommand(params, dconsole::Instance());
	dconsole::Instance().registerCommand(pcmd );
	}

    { // 
    dconsole::BaseCmd* pcmd = createCmd("AND", "logical AND", f_and);
    dconsole::Instance().registerCommand(pcmd);
        
    pcmd = createCmd("OR", "logical OR", f_or);
    dconsole::Instance().registerCommand(pcmd);
    
    pcmd = createCmd("int_float", "desc1", f_intfloat);
    pcmd->runCommand(params, dconsole::Instance());
    dconsole::Instance().registerCommand(pcmd);
     
    pcmd = createCmd("func_add", "adder", f2);
    pcmd ->runCommand(params, dconsole::Instance());
    dconsole::Instance().registerCommand(pcmd);

    pcmd = createCmd("load_world", "Loads world: first parameter - key, second - asyns/sync load", load_world);
    dconsole::Instance().registerCommand(pcmd );
    }

    { // 
    typedef int (*f_intintint_t)(int i1, int i2, int i3);
    dconsole::BaseCmd* pcmd = createCmd("int3", "desc1", f_intintint);
    pcmd->runCommand(params, dconsole::Instance());
    dconsole::Instance().registerCommand(pcmd);
    }
}