Exemple #1
0
static INT64_T get_result(struct chirp_client *c, time_t stoptime)
{
	char line[CHIRP_LINE_MAX];
	INT64_T result;
	INT64_T fields;

	if(!link_readline(c->link, line, CHIRP_LINE_MAX, stoptime)) {
		c->broken = 1;
		errno = ECONNRESET;
		return -1;
	}

	fields = sscanf(line, "%" SCNd64 , &result);
	if(fields != 1) {
		errno = ECONNRESET;
		c->broken = 1;
		return -1;
	}

	result = convert_result(result);
	if(result >= 0) {
		debug(D_CHIRP, " = %lld", result);
	} else {
		debug(D_CHIRP, " = %lld (%s)", result, strerror(errno));
	}

	return result;
}
Exemple #2
0
DLLEXPORT int
chirp_client_swrite( struct chirp_client *c, int fd, const void *buffer,
					int length, int offset, int stride_length, int stride_skip )
{
	int actual;
	int result;

	char command[CHIRP_LINE_MAX];
	sprintf(command, "swrite %d %d %d %d %d\n", fd, length, offset, 
			stride_length, stride_skip);

#ifdef DEBUG_CHIRP
	printf("chirp sending: %s", command);
#endif
	
	result = fputs(command, c->wstream);
	if(result < 0) chirp_fatal_request("swrite");

	result = fflush(c->wstream);
	if(result < 0) chirp_fatal_request("swrite");

	actual = fwrite(buffer,1,length,c->wstream);
	if(actual != length) chirp_fatal_request("swrite");

	return convert_result(get_result(c->rstream));
}
/*
 * Retrieve result set
 */
int get_result(db_con_t* _h, db_res_t** _r)
{
	if ((!_h) || (!_r)) 
	{
#ifdef DBT_EXTRA_DEBUG
		LOG(L_ERR, "DBT:get_result: Invalid parameter value\n");
#endif
		return -1;
	}

	if (!DBT_CON_RESULT(_h))
	{
		LOG(L_ERR, "DBT:get_result: error getting result\n");
		*_r = 0;
		return -3;
	}

	*_r = new_result();
	if (*_r == 0) 
	{
		LOG(L_ERR, "DBT:get_result: No memory left\n");
		return -2;
	}

	if (convert_result(_h, *_r) < 0) 
	{
		LOG(L_ERR, "DBT:get_result: Error while converting result\n");
		pkg_free(*_r);
		return -4;
	}
	
	return 0;
}
Exemple #4
0
/*
 * Retrieve result set
 */
static int store_result(db_con_t* _h, db_res_t** _r)
{
	if ((!_h) || (!_r)) {
		LOG(L_ERR, "store_result: Invalid parameter value\n");
		return -1;
	}

	*_r = new_result();
	if (*_r == 0) {
		LOG(L_ERR, "store_result: No memory left\n");
		return -2;
	}

	MYRES_RESULT(*_r) = mysql_store_result(CON_CONNECTION(_h));
	if (!MYRES_RESULT(*_r)) {
		if (mysql_field_count(CON_CONNECTION(_h)) == 0) {
			(*_r)->col.n = 0;
			(*_r)->n = 0;
			return 0;
		} else {
			LOG(L_ERR, "store_result: %s\n", mysql_error(CON_CONNECTION(_h)));
			free_result(*_r);
			*_r = 0;
			return -3;
		}
	}

	if (convert_result(_h, *_r) < 0) {
		LOG(L_ERR, "store_result: Error while converting result\n");
		mysql_free_result(MYRES_RESULT(*_r));
		pkg_free((*_r)->data);
		pkg_free(*_r);

		/* This cannot be used because if convert_result fails,
		 * free_result will try to free rows and columns too 
		 * and free will be called two times
		 */
		/* free_result(*_r); */
		return -4;
	}
	
	return 0;
}
static int zbx_module_get_value(AGENT_REQUEST *request, AGENT_RESULT *result)
{
    int ret = SYSINFO_RET_OK;

    PyObject *py_request = NULL;
    PyObject *py_result = NULL;

    if (!check_if_forked()) {
        goto on_error;
    }

    py_request = convert_request(request);
    if (!py_request) {
        goto on_error;
    }

    py_result = call_py_fn(mod_zabbix.result_type, NULL);
    if (!py_request) {
        log(LOG_ERR, "Unable to get value '%s': can not create result object",
                request->key);
        goto on_error;
    }

    if (!call_get_value_fn(py_request, py_result, &ret, request->key)) {
        goto on_error;
    }

    if (!convert_result(py_result, result, request->key)) {
        goto on_error;
    }

on_exit:
    Py_XDECREF(py_result);
    Py_XDECREF(py_request);
    return ret;

on_error:
    set_failure_result(result);
    ret = SYSINFO_RET_FAIL;
    goto on_exit;
}
Exemple #6
0
/*
 * Retrieve result set
 */
int get_result(db_con_t* _h, db_res_t** _r)
{
	*_r = new_result_pg(CON_SQLURL(_h));

	if (!CON_RESULT(_h)) {
		LOG(L_ERR, "get_result(): error");
		free_result(*_r);
		*_r = 0;
		return -3;
	}

        if (convert_result(_h, *_r) < 0) {
		LOG(L_ERR, "get_result(): Error while converting result\n");
		free_result(*_r);
		*_r = 0;

		return -4;
	}

	return 0;
}
Exemple #7
0
/// Writes a generic result file based on an ATF result file and an exit code.
///
/// \param input_name Path to the ATF result file to parse.
/// \param output_name Path to the generic result file to create.
/// \param wait_status Exit code of the test program as returned by wait().
/// \param timed_out Whether the test program timed out or not.
/// \param [out] success Whether the result should be considered a success or
///     not; e.g. passed and skipped are successful, but failed is not.
///
/// \return An error if the conversion fails; OK otherwise.
kyua_error_t
kyua_atf_result_rewrite(const char* input_name, const char* output_name,
                        const int wait_status, const bool timed_out,
                        bool* success)
{
    enum atf_status status; int status_arg; char reason[1024];
    status = ATF_STATUS_BROKEN;  // Initialize to shut up gcc warning.
    const kyua_error_t error = read_atf_result(input_name, &status, &status_arg,
                                               reason, sizeof(reason));
    if (kyua_error_is_set(error)) {
        // Errors while parsing the ATF result file can often be attributed to
        // the result file being bogus.  Therefore, just mark the test case as
        // broken, because it possibly is.
        status = ATF_STATUS_BROKEN;
        kyua_error_format(error, reason, sizeof(reason));
        kyua_error_free(error);
    }

    // Errors converting the loaded result to the final result file are not due
    // to a bad test program: they are because our own code fails (e.g. cannot
    // create the output file).  These need to be returned to the caller.
    return convert_result(status, status_arg, reason, wait_status, timed_out,
                          output_name, success);
}
Exemple #8
0
int get_status_cf(void)
{
	char url[BUFSIZE];
	sprintf(url, "http://codeforces.com/api/contest.status?contestId=%d&from=1&count=1&handle=%s",
			solution->problem_info.origin_id / 10, vjudge_user);

	if (DEBUG) {
		write_log("perform url is %s.\n", url);
	}

	// 设置提交地址
	curl_easy_setopt(curl, CURLOPT_URL, url);

	char filename[BUFSIZE];
	sprintf(filename, "%dstatus.txt", solution->solution_id);

	time_t begin_time = time(NULL);
	int rid = 0;
	int usedtime = 0;
	int memory = 0;
	char result[BUFSIZE];
	while (1) {
		if (time(NULL) - begin_time > vj_max_wait_time) {
			write_log("judge time out.\n");
			return OJ_JE;
		}

		perform_curl(filename);

		json_object *obj = json_object_from_file(filename);
		if (obj == NULL) {
			write_log("load json object from file %s error.\n", filename);
			return OJ_JE;
		}
		json_object *submission;
		if (strcmp(json_get_str(obj, "status"), "OK") != 0) {
			json_object_put(obj);
			return OJ_JE;
		} else {
			submission = json_get_obj(obj, "result[0]");
		}

		if (submission == NULL) {
			write_log("get status error, maybe not submit.\n");
			json_object_put(obj);
			return OJ_JE;
		}

		rid = json_get_int(submission, "id");
		strcpy(result, json_get_str(submission, "verdict"));
		usedtime = json_get_int(submission, "timeConsumedMillis");
		memory = json_get_int(submission, "memoryConsumedBytes");
		memory = memory / 1024 + ((memory % 1024) ? 1: 0);

		write_log("rid = %d\n", rid);
		write_log("usedtime = %d\n", usedtime);
		write_log("memory = %d\n", memory);
		write_log("result = %s\n", result);
		if (is_final_result(result)) {
			solution->remote_rid = rid;
			solution->time = usedtime;
			solution->memory = memory;
			int ret = convert_result(result);
			if (ret == OJ_RE) {
				strcpy(solution->runtimeinfo, result);
			}
			write_log("get solution %d status over"
					": %d.\n", solution->solution_id, ret);
			json_object_put(obj);
			return ret;
		}
	}

	return OJ_JE;
}
Exemple #9
0
int get_status_hduoj(void)
{
	int status, i, j;
	regmatch_t pmatch[5];
	const int nmatch = 5;
	regex_t reg;
	const char *pattern = "<td height=22px>([0-9]*)</td>"
		"<td>[: 0-9-]*</td>"
		"<td><font color=[ a-zA-Z]*>([^/]*)</font></td>"
		"<td><a[ 0-9a-zA-Z\\./\\?\\\"=]*>[0-9]*</a></td>"
		"<td>([0-9]*)MS</td>"
		"<td>([0-9]*)K</td>"
		;
	char url[BUFSIZE];
	sprintf(url, "http://acm.hdu.edu.cn/status.php?first=&pid=%d&user=%s"
			"&lang=0&status=0", solution->problem_info.origin_id,
			vjudge_user);
	if (DEBUG) {
		write_log("perform url is %s.\n", url);
	}

	// 设置提交地址
	curl_easy_setopt(curl, CURLOPT_URL, url);

	char filename[BUFSIZE];
	sprintf(filename, "%dstatus.txt", solution->solution_id);

	time_t begin_time = time(NULL);
	int rid = 0;
	int usedtime = 0;
	int memory = 0;
	char result[BUFSIZE];
	char err[BUFSIZE];
	char match_str[BUFSIZE];
	int ret = regcomp(&reg, pattern, REG_EXTENDED);
	if (ret) {
		regerror(ret, &reg, err, BUFSIZE);
		write_log("compile regex error: %s.\n", err);
		return OJ_JE;
	}
	char *html = (char *)malloc(BUFSIZE * BUFSIZE);
	if (html == NULL) {
		write_log("alloc get_status_hduoj html buf memory error.\n");
		regfree(&reg);
		return OJ_JE;
	}
	while (1) {
		if (time(NULL) - begin_time > vj_max_wait_time) {
			write_log("judge time out.\n");
			free(html);
			return OJ_JE;
		}
		perform_curl(filename);

		load_file(filename, html);
		gbk2utf8(html, strlen(html));
		// modified form bnuoj
		if (strstr(html, "Connect(0) to MySQL Server failed.") != NULL
			|| strstr(html, "<b>One or more following ERROR(s) occurred.") != NULL
			|| strstr(html, "<h2>The requested URL could not be retrieved</h2>") != NULL
			|| strstr(html, "<H1 style=\"COLOR: #1A5CC8\" align=center>Sign In Your Account</H1>") != NULL
			|| strstr(html, "PHP: Maximum execution time of") != NULL
			|| strstr(html, "<DIV>Exercise Is Closed Now!</DIV>") != NULL) {
			write_log("get_status_hduoj remote server error.\n");
			write_log("get solution %d status error.\n", solution->solution_id);
			free(html);
			regfree(&reg);
			return OJ_JE;
		} else {
			status = regexec(&reg, html, nmatch, pmatch, 0);
			if (status == REG_NOMATCH) {
				write_log("no match regex: %s.\n", pattern);
				write_log("get solution %d status error.\n", solution->solution_id);
				free(html);
				regfree(&reg);
				return OJ_JE;
			} else if (status == 0) {
				char buf[BUFSIZE];
				for (i = 0; i < nmatch; ++i) {
					int cnt = 0;
					for (j = pmatch[i].rm_so; j < pmatch[i].rm_eo; ++j) {
						buf[cnt++] = html[j];
					}
					buf[cnt] = '\0';
					switch (i) {
						case 0: strcpy(match_str, buf); break;
						case 1: rid = atoi(buf); break;
						case 2: strcpy(result, buf); break;
						case 3: usedtime = atoi(buf); break;
						case 4: memory = atoi(buf); break;
					}
				}
				write_log("match_str = %s\n", match_str);
				write_log("rid = %d\n", rid);
				write_log("usedtime = %d\n", usedtime);
				write_log("memory = %d\n", memory);
				write_log("result = %s\n", result);
				if (is_final_result(result)) {
					solution->remote_rid = rid;
					solution->time = usedtime;
					solution->memory = memory;
					int ret = convert_result(result);
					if (ret == OJ_RE) {
						strcpy(solution->runtimeinfo, result);
					}
					write_log("get solution %d status over"
							": %d.\n", solution->solution_id, ret);
					free(html);
					regfree(&reg);
					return ret;
				}
			}
		}
	}

	free(html);
	regfree(&reg);

	return OJ_JE;
}