Create task in macOS alwise return kern error - macos-catalina

This is my code:
task_t child;
kern_return_t kr;
ledger_t ledgers = (ledger_t)0;
boolean_t inheret = FALSE;
ledger_array_t ledger_array = &ledgers;
mach_msg_type_number_t count = 1;
kr = task_create(mach_task_self(), ledger_array, count, inheret, &child);
if ( kr != KERN_SUCCESS)
{
printf("We failed getting the task\n");
mach_error("task created: ", kr);
exit(1);
}
I always get: "task created: (os/kern) failure" (I tried to run this as normal use and as root - always get the error).
What do I do rung?

Related

rd_kafka_offsets_for_times() returns error -186 (Local: Invalid argument or configuration.)

I'm trying to get the offset (high watermark offset) for a partition using rd_kafka_offsets_for_times().
Here is a code snippet:
rd_kafka_topic_partition_t* pt0 = rd_kafka_topic_partition_new(topic, 0);
pt0->offset = 0;
pt0->metadata = 0;
pt0->metadata_size = 0;
pt0->opaque = 0;
pt0->err = 0;
pt0->_private = 0;
rd_kafka_topic_partition_list_t* partition_list = rd_kafka_topic_partition_list_new(1);
partition_list->elems = pt0;
rd_kafka_resp_err_t offsets_err = rd_kafka_offsets_for_times(rk, partition_list, 5000);
if (offsets_err != RD_KAFKA_RESP_ERR_NO_ERROR)
{
printf("ERROR: Failed to get offsets: %d: %s.\n", offsets_err,
rd_kafka_err2str(offsets_err));
}
else
{
printf("Successfully got offset.\n");
}
When I run it, I get this error:
ERROR: Failed to get offsets: -186: Local: Invalid argument or configuration.
How do I correct my code to be able to get the offset for the partition?
Need to use rd_kafka_topic_partition_list_add to add a topic partition to the topic partition list. For example:
rd_kafka_topic_partition_list_t* partition_list = rd_kafka_topic_partition_list_new(1);
rd_kafka_topic_partition_t* pt0 = rd_kafka_topic_partition_list_add(partition_list, topic, 0);
pt0->offset = ~0; // set to max integer value
rd_kafka_resp_err_t offsets_err = rd_kafka_offsets_for_times(rk, partition_list, 10000);
if (offsets_err != RD_KAFKA_RESP_ERR_NO_ERROR)
{
printf("ERROR: Failed to get offsets: %d: %s.\n", offsets_err, rd_kafka_err2str(offsets_err));
}
else
{
printf("Successfully got high watermark offset %d.\n", pt0->offset);
}

pull using libgit2, c++

I try pull from remote master to local master. In remote master only one not synchronized commit.
Error in method git_annotated_commit_lookup():
Git Error -3 : object not found - no match
for id (08f4a8cc00400100f083caccd755000020299210)
In callback fetchhead_ref_cb never exevute code in "if" block.
int fetchhead_ref_cb(const char *name, const char *url,
const git_oid *oid, unsigned int is_merge, void *payload)
{
qDebug() << "fetchhead_ref_cb";
if (is_merge)
{
qDebug() << "Is merge";
git_oid_cpy((git_oid *)payload, oid);
}
return 0;
}
bool pullBranch()
{
int error;
git_remote *remote;
git_oid branchOidToMerge;
/* lookup the remote */
error = git_remote_lookup(&remote, repo, "origin");
if (!checkForError(error, "Remote lookup")) {
git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
options.callbacks.credentials = cred_acquire_cb;
error = git_remote_fetch(remote,
NULL, /* refspecs, NULL to use the configured ones */
&options, /* options, empty for defaults */
"pull"); /* reflog mesage, usually "fetch" or "pull", you can leave it NULL for "fetch" */
if (!checkForError(error, "Remote fetch")) {
git_repository_fetchhead_foreach(repo, fetchhead_ref_cb, &branchOidToMerge);
git_merge_options merge_options = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
git_annotated_commit *commit;
error = git_annotated_commit_lookup(&commit, repo, &branchOidToMerge);
if (!checkForError(error, "Annotated commit lookup")) {
error = git_merge(repo, (const git_annotated_commit **)commit, 1, &merge_options, &checkout_options);
if (!checkForError(error, "Merge")) {
git_annotated_commit_free(commit);
git_repository_state_cleanup(repo);
git_remote_free(remote);
return true;
}
}
}
}
git_remote_free(remote);
return false;
}
Solution for fast-forward merge:
GitPullStatus GitWizard::pullBranch()
{
git_remote *remote;
int error = git_remote_lookup(&remote, repo, "origin");
if (!checkForError(error, "Remote lookup")) {
git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
options.callbacks.credentials = cred_acquire_cb;
error = git_remote_fetch(remote,
NULL, /* refspecs, NULL to use the configured ones */
&options, /* options, empty for defaults */
"pull"); /* reflog mesage, usually "fetch" or "pull", you can leave it NULL for "fetch" */
if (!checkForError(error, "Remote fetch")) {
git_oid branchOidToMerge;
git_repository_fetchhead_foreach(repo, fetchhead_ref_cb, &branchOidToMerge);
git_annotated_commit *their_heads[1];
error = git_annotated_commit_lookup(&their_heads[0], repo, &branchOidToMerge);
checkForError(error, "Annotated commit lookup");
git_merge_analysis_t anout;
git_merge_preference_t pout;
qDebug() << "Try analysis";
error = git_merge_analysis(&anout, &pout, repo, (const git_annotated_commit **) their_heads, 1);
checkForError(error, "Merge analysis");
if (anout & GIT_MERGE_ANALYSIS_UP_TO_DATE) {
qDebug() << "up to date";
git_annotated_commit_free(their_heads[0]);
git_repository_state_cleanup(repo);
git_remote_free(remote);
return GitPullStatus::GIT_UP_TO_DATE;
} else if (anout & GIT_MERGE_ANALYSIS_FASTFORWARD) {
qDebug() << "fast-forwarding";
git_reference *ref;
git_reference *newref;
const char *name = QString("refs/heads/").append(mCurrentBranch).toLocal8Bit().data();
if (git_reference_lookup(&ref, repo, name) == 0)
git_reference_set_target(&newref, ref, &branchOidToMerge, "pull: Fast-forward");
git_reset_from_annotated(repo, their_heads[0], GIT_RESET_HARD, NULL);
git_reference_free(ref);
git_repository_state_cleanup(repo);
}
git_annotated_commit_free(their_heads[0]);
git_repository_state_cleanup(repo);
git_remote_free(remote);
return GitPullStatus::GIT_PULL_OK;
}
}
git_remote_free(remote);
return GitPullStatus::GIT_PULL_ERROR;
}

How to fix Connection execute error using ADO in C++

I'm using ado to connect SQL Server in my C++ project.
So I want to insert/update my database and I wrote some queries (see the code) and I'm trying to execute my connection or command.
But it goes on an error at pConnection->Execute(InsertQuery, NULL, adCmdUnspecified);, it says Microsoft C++ exception: _com_error at memory location and in the debug window there is _hr with value _hr : DB_E_ERRORSINCOMMAND One or more errors occurred during processing of command. TYPE: HRESULT
I also tried to execute Command, but I have the same result as Connection.
Should I change adCmdUnspecified into something or am I go wrong somewhere?
What is the solution? Thank you in advance.
//connections above
VARIANT vNameStringType;
_bstr_t InsertQuery(L"Insert Into TestTB(AccountID, Name) Values(#AccountID, #Name)");
hr = pCommand.CreateInstance(__uuidof(Command));
pCommand->ActiveConnection = pConnection;
pCommand->CommandText = InsertQuery;
pCommand->CommandType = adCmdText;
for (int i = 0; i < size; i++)
{
a[i].name;
a[i].login;
vIntegerType.vt = VT_I4;
vIntegerType.intVal = a[i].login;
vNameStringType.vt = VT_BSTR;
vNameStringType.bstrVal = _bstr_t(a[i].name);
int DataExistCounter = 0;
NameParam = pCommand->CreateParameter(_bstr_t("#Name"), adVarChar, adParamInput, 150, _bstr_t(vNameStringType));
pCommand->Parameters->Append(NameParam);
AccIDParam = pCommand->CreateParameter("#AccountID", adInteger, adParamInput, sizeof(int), vIntegerType);
pCommand->Parameters->Append(AccIDParam);
pRecordset->MoveFirst();
while (!pRecordset->EndOfFile)
{
valFieldNam = pRecordset->Fields->GetItem("Name")->Value;
valFieldAcc = pRecordset->Fields->GetItem("AccountID")->Value;
if (valFieldAcc == a[i].login)
{
DataExistCounter++;
}
pRecordset->MoveNext();
}
if (DataExistCounter > 0)
{
//update
}
else
{
pConnection->Execute(InsertQuery, NULL, adCmdUnspecified);
}
}
pRecordset->Close();
pConnection->Close();
CoUninitialize();

unixODBC SQLExecute() error

Sometimes I get quite strange error message from SQLExecute() during INSERT. Have no idea how I can deal with this, other queries are ok.
Log
[ODBC][67383][1485443238.457802][SQLPrepare.c][196]
Entry:
Statement = 0x101022600
SQL = [INSERT INTO Core_Message(channel_id, date, member_id, reply_id) VALUES(25, '2017-01-26 18:07:18', 4, NULL)
][length = 109 (SQL_NTS)]
[ODBC][67383][1485443238.457893][SQLPrepare.c][377]
Exit:[SQL_SUCCESS]
[ODBC][67383][1485443238.458014][SQLExecute.c][187]
Entry:
Statement = 0x101022600
[ODBC][67383][1485443238.458189][SQLExecute.c][357]
Exit:[SQL_ERROR]
DIAG [HY000] no error information;
Error while preparing parameters
[ODBC][67383][1485443238.458543][SQLFreeHandle.c][381]
Entry:
Handle Type = 3
Input Handle = 0x101022600
[ODBC][67383][1485443238.458670][SQLFreeHandle.c][494]
Exit:[SQL_SUCCESS]
Code
SQLLEN length(0);
if (!isSuccess(SQLPrepare(_statement, (unsigned char *)query.c_str(), SQL_NTS))) {
_status = StatementStatus::Fault;
return false;
}
for (std::size_t i=0; i<reference_vector.size(); i++) {
length = reference_vector.at(i).get().length();
if (!isSuccess(SQLBindParameter(_statement, i + 1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, reference_vector.at(i).get().length(), 0, (char *)reference_vector.at(i).get().c_str(), (SQLLEN)reference_vector.at(i).get().length(), &length))) {
_status = StatementStatus::Fault;
return false;
}
}
if (!isSuccess(SQLExecute(_statement))) {
_status = StatementStatus::Fault;
return false;
}
Tricky block with SQLBindParameter() event don't used in runtime.
Thanks in advance.

Why is this SQlite3 query execution returning "SQLITE BUSY : Database is locked" and what it the likely solution

This code keeps returning "SQLITE BUSY : Database is locked" even though I was not accessing it from another external thread or process and how can I resolve this?
The code uses CppSQLite3 C++ wrapper for SQLite.
int DepartmentAccess::SaveOrDeleteAccess(long long iDeptNameID,long long &iUserID,int &iAccessTypeID)
{
char szString[1000];
char chAccessTypeID[1000];
StringCbPrintfA(szString,sizeof(szString),"%d",iAccessTypeID);
EncryptString(szString,chAccessTypeID);
try
{
char szDatabaseFile[1000];
GetDatabaseA(szDatabaseFile,sizeof(szDatabaseFile));
CppSQLite3DB db;
db.open(szDatabaseFile);
CppSQLite3Statement stmt = db.compileStatement("SELECT AccessID FROM DepartmentAccess WHERE (InsututionID = ? AND DeptNameID = ? AND UserID = ? AND AccessType = ?)");
stmt.bind(1,m_iInsututionID);
stmt.bind(2,iDeptNameID);
stmt.bind(3,iUserID);
stmt.bind(4,chAccessTypeID);
CppSQLite3Query q = stmt.execQuery();
if(!q.fieldIsNull(0))
{
if(!m_iMode)
{
return -2;
}
}
if(!m_iMode)
{
StringCbCopyA(szString,sizeof(szString),"INSERT INTO DepartmentAccess(InsututionID,DeptNameID,UserID,AccessType) VALUES(?,?,?,?)");
}
else
{
StringCbCopyA(szString,sizeof(szString),"DELETE FROM DepartmentAccess WHERE (InsututionID = ? AND DeptNameID = ? AND UserID = ? AND AccessType = ?)");
}
CppSQLite3Statement stmt1 = db.compileStatement(szString);
int iPosition = 1;
stmt1.bind(iPosition++, m_iInsututionID);
stmt1.bind(iPosition++, iDeptNameID);
stmt1.bind(iPosition++, iUserID);
stmt1.bind(iPosition++, chAccessTypeID);
//Execution gets to this point
stmt1.execDML();
//Execution fails to get to this point
if(!m_iMode)
{
StringCbPrintfA(szString,sizeof(szString),"DELETE FROM DepartmentAccessRequest WHERE (InsututionID = ? AND DeptNameID = ? AND UserID = ? AND RequestedAccess = ?)");
CppSQLite3Statement stmt2 = db.compileStatement(szString);
int iPosition = 1;
stmt2.bind(iPosition++, m_iInsututionID);
stmt2.bind(iPosition++, iDeptNameID);
stmt2.bind(iPosition++, iUserID);
stmt2.bind(iPosition++, chAccessTypeID);
stmt2.execDML();
}
return 1;
}
catch(CppSQLite3Exception & e)
{
char szString[200];
StringCbPrintfA(szString,sizeof(szString),"Error Code: %d\n Error Mesage: %s",e.errorCode(),e.errorMessage());
MessageBoxA(NULL,szString,"Save Or Delete Access Error(Department Access)",MB_OK);
}
return 0;
}