Beispiel #1
0
void Execut_window::checkLockStatus(void)//抽屉关闭返回0
{
    if(SCI_send(3))
    {
        QMessageBox qMbox;
        qMbox.setText(QString("请关闭抽屉"));
        qMbox.setStandardButtons(QMessageBox::Ok);
        int ret = qMbox.exec();
        if(ret == QMessageBox::Ok)
        {
            if(SCI_send(3))
            {
                checkLockStatus();
            }
        }
    }

}
Beispiel #2
0
int
writeLockFile(RunTimeOpts * rtOpts)
{

    int lockPid = 0;

    DBGV("Checking lock file: %s\n", rtOpts->lockFile);

    if ( (G_lockFilePointer=fopen(rtOpts->lockFile, "w+")) == NULL) {
        PERROR("Could not open lock file %s for writing", rtOpts->lockFile);
        return(0);
    }
    if (lockFile(fileno(G_lockFilePointer)) < 0) {
        if ( checkLockStatus(fileno(G_lockFilePointer),
                             DEFAULT_LOCKMODE, &lockPid) == 0) {
            ERROR("Another "PTPD_PROGNAME" instance is running: %s locked by PID %d\n",
                  rtOpts->lockFile, lockPid);
        } else {
            PERROR("Could not acquire lock on %s:", rtOpts->lockFile);
        }
        goto failure;
    }
    if(ftruncate(fileno(G_lockFilePointer), 0) == -1) {
        PERROR("Could not truncate %s: %s",
               rtOpts->lockFile, strerror(errno));
        goto failure;
    }
    if ( fprintf(G_lockFilePointer, "%ld\n", (long)getpid()) == -1) {
        PERROR("Could not write to lock file %s: %s",
               rtOpts->lockFile, strerror(errno));
        goto failure;
    }
    INFO("Successfully acquired lock on %s\n", rtOpts->lockFile);
    fflush(G_lockFilePointer);
    return(1);
failure:
    fclose(G_lockFilePointer);
    return(0);

}
void intervalWork(VersionUpdateConfig *config) {

	if(debug) {
		fprintf(stdout, "start intervalWork\n");
	}
	//clean old responsefile
	remove(config->reponseFilePath->ptr);

	buffer *lastModifiedTime = NULL;

	int paramLen = config->URLDomain->used + config->tmpVersionFilePath->used + config->reponseFilePath->used;
	buffer *param = buffer_init_size(20 + paramLen);
	stringAppend(param, " ", 1);
	stringAppend(param, config->URLDomain->ptr, config->URLDomain->used);
	stringAppend(param, " -O ", 4);
	stringAppend(param, config->tmpVersionFilePath->ptr, config->tmpVersionFilePath->used);
	stringAppend(param, " > ", 3);
	stringAppend(param, config->reponseFilePath->ptr, config->reponseFilePath->used);
	stringAppend(param, " 2>&1 ", 6);

	while(1) {
		char *responseCnt = readResponse(config->reponseFilePath->ptr);
		int httpStatus = getHttpStatus(responseCnt);
		if(debug) {
			fprintf(stdout, "httpStatus:%d\n", httpStatus);
		}
		// ignore the lock checke for the first version file request
		if(0 != httpStatus && 404 != httpStatus) {
			int bLocked = checkLockStatus(config->lockRequestURL->ptr);
			if(bLocked){
				sleep(config->intervalSecond);
				continue;
			}
		}
		if(304 != httpStatus) {
			getLastModified(responseCnt, &lastModifiedTime);
		}
		debug_buffer(lastModifiedTime, "lastModifiedTime");
		
		//thread interval exec
		buffer *cmdBuf = buffer_init_size(LAST_MODIFIED_LEN + WGET_CMD_LEN + HEADER_LEN + param->used);
		stringAppend(cmdBuf, WGET_CMD, WGET_CMD_LEN);
		if(NULL != lastModifiedTime) {
			stringAppend(cmdBuf, HEADER, HEADER_LEN);
			stringAppend(cmdBuf, lastModifiedTime->ptr, lastModifiedTime->used);
			stringAppend(cmdBuf, "\"", 1);
		}
		stringAppend(cmdBuf, param->ptr, param->used);
		debug_buffer(cmdBuf, "cmdBuf");

		if(-1 == system(cmdBuf->ptr)) {
			fprintf(stderr, "system (wget...) error:%s\n", cmdBuf->ptr);
			exit(4);
		}

		free(responseCnt);
		buffer_free(cmdBuf);

		checkAndGzip(config->tmpVersionFilePath, config->versionFilePath,
					config->expectVersionFilePath, config->reponseFilePath);

		sleep(config->intervalSecond);
	}
}