error: ‘scmp_filter_ctx’ was not declared in this scope - sandbox

I am getting compilation error:error: ‘scmp_filter_ctx’ was not declared in this scope.
I have declared a seccomp filter.
scmp_filter_ctx ctx;
I have included the library #include <linux/seccomp.h>
and already installed the library libseccomp-dev using
sudo apt-get install libseccomp-dev.
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <unistd.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <bits/stdc++.h>
void create_sandbox(){
scmp_filter_ctx ctx;
ctx = seccomp_init(SCMP_ACT_KILL); // default action: kill
seccomp_load(ctx);
}

I managed to solve this error using the following:
Replaced #include <linux/seccomp.h> with #include <seccomp.h>
and while compiling, used g++ filename.cpp -lseccomp.
This worked for me.

Related

How to fix QDialog transparent background afterimage issue in qt embedded (QT4.7.3)?

I am using embedded system and I'm testing transparent QWS server where is my Qt4.7.3.
I faced the afterimage in the QDialog when moving cursor in test program which as the QWS client, but it didn't happen in the QMainWindow which in QWS server program.
Can anyone help me to fix the issue?
There is the issue
Here is test program source code.
#include "mainwindow.h"
#include <QApplication>
#include<QWSServer>
#include <QDialog>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include "qscreenlinuxfb_qws.h"
#include "qscreendriverfactory_qws.h"
#include <errno.h>
extern "C" {
extern int Test();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog w;
QWSServer::setBackground(QColor(0,0,0,0));
QWSServer::setCursorVisible(false);
w.setStyleSheet("background-color:transparent;");
w.show();
return a.exec();
}
OK I found the issue. In QT source code.
src\gui\embedded\qscreen_qws.cpp
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
}
to
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
QPixmap temp = QPixmap(blendSize);
temp.fill(Qt::transparent);
**blendbuffer = temp.toImage();
}

RapidJson: error C2061: syntax error: identifier 'stack_'

I am using below code in my program
#include "stdafx.h"
#include "RapidJson\rapidjson.h"
#include "RapidJson\document.h"
#include "RapidJson\stringbuffer.h"
using namespace std;
using namespace rapidjson;
....
,......
Document doc;
doc.Parse(s.c_str());
When I compile I see error
rapidjson\document.h(2425): error C2061: syntax error: identifier 'stack_'
1> rapidjson\document.h(2425): note: while compiling class template member function 'bool rapidjson::GenericDocument::StartArray(void)'
1> rapidjson\reader.h(2004): note: see reference to function template instantiation 'bool rapidjson::GenericDocument::StartArray(void)' being compiled
1>
Can someone please help me to fix the issue.
Thanks
Santhi
The issue is solved by providing different order
#include "targetver.h"
#include <stdio.h>
#include <new>
#include <tchar.h>
#include <rapidjson.h>
#include <document.h>
#include <stringbuffer.h>
#include <writer.h>
#include <prettywriter.h>
#include <Windows.h>
#include <vector>

Error: Function stoi Not Declared (-std=c++11 is Enabled)

I'm using Code::Blocks 16.01 on Windows 10.
I need to convert a string to an integer.
So I'm trying to use stoi, but it says it's not declared.
I have enabled -std=c++11 in compiler settings but it still gives me an error:
'stoi' was not declared in this scope
Screenshot of Code::Blocks:
The part of the code which causes the error is:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main() {
int n,m,k;
string nmk;
ifstream test("input00.txt");
if (test.is_open())
{
getline (test,nmk,' ');
n = stoi (nmk,NULL,10);
getline (test,nmk,' ');
m = stoi (nmk,NULL,10);
getline (test,nmk, '\n');
k = stoi (nmk,NULL,10);
}
}

where fcntl saves locking information

I wonder to understand where fcntl c++ function saves information about locked files. I know that it saves some information on /proc/locks , but fcntl identify lock even if it locked by another host
In my first host I locked some file By F_WRLCK.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include<iostream>
main() {
int fd;
struct flock lock;
lock.l_type=F_WRLCK;
lock.l_start=0;
lock.l_whence= SEEK_SET;
lock.l_len=0;
printf("open %d\n",fd=open("/u/embedit/places/scratch/gtevos/ts16nxq42p11assrl16kaa03/ts16nxq42p11assrl16kaa.cpj", O_RDWR ));
int rc = fcntl(fd, F_SETLK, &lock);
std::cout<<rc<<std::endl;
std::cin>>fd;
}
When I am traying to lock the same file on my second host by F_RDONLY it doesn't work.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include<iostream>
main() {
int fd;
struct flock lock;
lock.l_type=F_RDLCK;
lock.l_start=0;
lock.l_whence= SEEK_SET;
lock.l_len=0;
printf("open %d\n",fd=open("/u/embedit/places/scratch/gtevos/ts16nxq42p11assrl16kaa03/ts16nxq42p11assrl16kaa.cpj", O_RDONLY ));
int rc = fcntl(fd, F_SETLK, &lock);
std::cout<<rc<<std::endl;
std::cin>>fd;
}
I just want to understand which mechanism is used that provide ability to right identify locks.

getting CLOCK_TICK_RATE value in linux

I'm trying to print the value of CLOCK_TICK_RATE with the following program:
#include <fcntl.h>
#include <getopt.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/kd.h>
#include <linux/timex.h>
int main() {
printf("%d\n",CLOCK_TICK_RATE);
}
I get an compilation error:
error: ‘CLOCK_TICK_RATE’ undeclared.
I looked for the definition of CLOCK_TICK_RATE, I found that in timex.h, but even after I included timex.h CLOCK_TICK_RATE is still undeclared.
thanks in advance.
Maybe you are looking for this?
#include <stdio.h>
#include <unistd.h>
int main (void) {
printf (
"%ld\n",
sysconf(_SC_CLK_TCK)
);
return 0;
}
It's in hertz and is normally 100.

Resources