nacl: readdir on an httpfs mount returns an empty folder - google-nativeclient

I modified nacl_sdk/pepper_49/examples/demo/flock/flock.cc with the following change:
...
// Mount the images directory as an HTTP resource.
mount("images", "/images", "httpfs", 0, "");
// NEW CODE HERE
DIR *dir = opendir("/images");
struct dirent *entry;
while((entry = readdir(dir)) != NULL)
{
fprintf(stdout, "Found '%s'\n", entry->d_name);
}
closedir(dir);
FILE* fp = fopen("/images/flock_green.raw", "rb");
...
but I am only getting this
Found '.'
Found '..'
opening the file /images/flock_green.raw using fopen works fine. I just cannot see it with readdir. Is there a way to get readdir to work in NACL? or is it some kind of sandbox restriction?

Related

File descriptors not properly passed to processes generated with execve() system call

I'm reading a unix book and specifically the part about execve() system call. The book says that file descriptors related to opened file are passed to child processes and also ( default behaviour ) after a process calls execve().
However, when I tried this code to read an opened file descriptor delivered to a process generated with execve() it doesn't seem to work. What's the problem ?
Program that calls execve() :
int main(int arg,char *argv[],char **env){
int fd;
if ( (fd = open("text.txt",O_RDWR | O_CREAT, ALL_OWNER )) == -1 ){
printf("Open failed\n");
exit(1);
};
printf("%d\n",fd); // 3
char buff [] = "Hello World\n";
write(fd,buff,strlen(buff));
int res;
if ( (res = execl("./demo",(char *)0)) == -1 ){
exit(1);
};
}
Program demo invoked by execve() :
setbuf(stdout,NULL);
printf("Demo executing...\n");
ssize_t r;
char buff[1024];
while ( (r = read(3,buff,sizeof(buff))) > 0 ){
write(STDOUT_FILENO,buff,r);
}
I'm using a Mac OS
The "demo" process inherit file descriptor and can read the file, but the file offset is at the end of the file. Use lseek(fd, 0, SEEK_SET) before calling execl(), or do it in "demo" before reading the file.

SCP always returns the same error code

I have a problem copying files with scp. I use Qt and copy my files with scp using QProcess. And when something bad happens I always get exitCode=1. It always returns 1. I tried copying files with a terminal. The first time I got the error "Permission denied" and the exit code was 1. Then I unplugged my Ethernet cable and got the error "Network is unreachable". And the return code was still 1. It confuses me very much cause in my application I have to distinct these types of errors.
Any help is appreciated. Thank you so much!
See this code as a working example:
bool Utility::untarScript(QString filename, QString& statusMessages)
{
// Untar tar-bzip2 file, only extract script to temp-folder
QProcess tar;
QStringList arguments;
arguments << "-xvjf";
arguments << filename;
arguments << "-C";
arguments << QDir::tempPath();
arguments << "--strip-components=1";
arguments << "--wildcards";
arguments << "*/folder.*";
// tar -xjf $file -C $tmpDir --strip-components=1 --wildcards
tar.start("tar", arguments);
// Wait for tar to finish
if (tar.waitForFinished(10000) == true)
{
if (tar.exitCode() == 0)
{
statusMessages.append(tar.readAllStandardError());
return true;
}
}
statusMessages.append(tar.readAllStandardError());
statusMessages.append(tar.readAllStandardOutput());
statusMessages.append(QString("Exitcode = %1\n").arg(tar.exitCode()));
return false;
}
It gathers all available process output for you to analyse. Especially look at readAllStandardError().

Files getting corrupted when being downloaded using QNetworkAcessManager

I'm developing a client app whose purpose is to download some files from a web server, temporarily store them in the Temp folder, check for file integrity, then send them to a FTP server in a Embedded Linux device.
Recently I got problems when doing the process in a preliminary development stage when I was trying to do the download from my local machine (see related question here). Now I'm able to download and upload without errors and with verification (I'm using QCryptographicHash + file size to check for any nonconformities) from my machine, but the same doesn't happen when I try downloading from the HTTP server.
There is a total of 8 files being downloaded: three .tar.gz, one simple text, two programs and two binaries. I'm able to successfully download all compressed files, the text file and one of the binaries, but the others, namely the two programs and one of the binaries (a Linux Kernel image) are always being incorrectly downloaded.
I check this by noticing not only that the hash returns error for them, but also for their sizes: their sizes are always wrong (and always the same erroneous value for any download attempt). And the files in the server are all correct.
My first suspicion was that I need to configure the HTTP download in a way that differs from the common FTP download from the local machine, but I'm unaware on how would that be. Moreover if this extra configuration was needed, then why some of the files always return correctly?
Here is the relevant code as for now:
void MainWindow::processNextDownload()
{
QUrl ulrTemp(updateData.at(transferStep).downloadUrl.arg(ui->leID->text())); //"//" +
if (updateData.at(transferStep).downloadUrl.contains("http"))
ulrTemp.setScheme("http");
else
ulrTemp.setScheme("file");
// ulrTemp.setUserName();
// ulrTemp.setPassword();
// ulrTemp.setPort();
qDebug() << "Downloading" << transferStep << "from" << ulrTemp;
#if 1
poReply = downloadNetworkManager->get(QNetworkRequest(ulrTemp));
#else
QNetworkRequest request;
request.setUrl(ulrTemp);
request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17");
poReply = downloadNetworkManager->get(request);
#endif
connect(poReply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(slotDownloadProgress(qint64,qint64)));
ui->statusBar->showMessage(tr("Downloading: %1").arg(updateData.at(transferStep).itemName));
}
void MainWindow::slotFileDownloaded(QNetworkReply* reply)
{
if (reply && (reply->error() != QNetworkReply::NoError))
{
ui->statusBar->clearMessage();
if (!isSingleFile)
{
const QString strTemp = tr("An error occurred while downloading \"%1\": %2 (error message: %3)")
.arg(updateData.at(transferStep).downloadName).arg(reply->error()).arg(reply->errorString());
QMessageBox::critical(this,tr("Error in download"),strTemp);
}
else
{
//irrelevant...
}
finished(false);
return;
}
qDebug() << "To write: " << reply->bytesAvailable();
QByteArray downloadedData = reply->readAll();
reply->deleteLater();
poReply->deleteLater();
//![]
static const QString tempFilePath = QDir::tempPath();
if (!isSingleFile)
{
QFile file(tempFilePath + "/" + updateData.at(transferStep).downloadName);
if (!file.open(QFile::WriteOnly | QFile::Truncate))
{
qDebug() << "Failure opening temp file to write: " << file.fileName();
QMessageBox::critical(this,
tr("Error"),
tr("An error occured while trying to open a temporary file to write the downloaded data (file: %1).").arg(file.fileName()));
transferStep = downloadStepCount;
slotFileUploaded(NULL);
return;
}
qint32 bytesWritten = file.write(downloadedData);
file.flush();
if (downloadedData.size() != bytesWritten)
qDebug() << "Write failed, wrote" << bytesWritten << "out of" << downloadedData.size() << "bytes.";
else
qDebug() << "Wrote " << bytesWritten << "bytes.";
file.close();
//![]
if (++transferStep >= downloadStepCount)
{
qDebug() << "Start hash check";
slotStartHashCheck();
return;
}
processNextDownload();
}
else
{
//irrelevant...
}
}
And this is why I get (the last number value after the "=" in the hash code is the file size):
So what am I missing?

Remove too deep folders in bash on OSX

a program created folders recursively. it is too deep, the full path string length is longer than the MAX (getconf ARG_MAX), for example:
/A/B/C/A/B/C/A/B/C//A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C
……
so "sudo rm -fr /A" says "Bad address".
How to create a script to deal with it?
Thanks,
Interesting problem.
I guess you could create a command line tool with Xcode (file -> new project -> command line tool, insert code, then click the "run" toolbar button).
int main(int argc, const char * argv[])
{
#autoreleasepool {
NSURL *url = [NSURL fileURLWithPath:#"/a/b/c/d/..."];
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtURL:url error:&error];
if (error) {
NSLog(#"%#", error);
}
}
return 0;
}
If it's a separate disk with its own filesystem mounted at /A, unmount it and reformat it.
If not, run something like this (very untested):
cd /A
then
cd A || cd B || cd C && rm -rf A* B* C*
and keep executing it, hitting up arrow to repeat and executing again till it works...
Good luck!

How use Procedure.Exec with C++Builder XE

I have a piece of code as show belowe, wich run well with C++Builder-6.
Now I have moved tha program to C++Builder-XE and the call to "RiconfiguraNodo << nomeNodo ...." give me the ambguity error report belowe.
I tried several way to rewrite the call to the ole proceudre "RiconfiguraNodo", but I didn't find a working solution.
How can I rewrite this snippet of code in way suitable for C++BuilderXE
Error reported:
[BCC32 Error] UnitMain.cpp(262): E2015 Ambiguity between 'operator
System::AutoCmd::<<(const System::Currency) at c:\program files
(x86)\embarcadero\rad studio\8.0\include\windows\rtl\sysvari.h:3561'
and 'operator System::AutoCmd::<<(const System::TDateTime)
at c:\program files (x86)\embarcadero\rad
studio\8.0\include\windows\rtl\sysvari.h:3562'
Full parser context
UnitMain.cpp(245): parsing: void _fastcall TFormMain::RiconfiguraNodo(System::UnicodeString,System::UnicodeString,System::UnicodeString,System::UnicodeString)
Sample code:
Procedure RiconfiguraNodo( L"RiconfiguraNodo" );
if (VarServerPmvManager.IsEmpty() || VarServerPmvManager.IsNull())
{
VarServerPmvManager = VarServerPmvManager.CreateObject(ProgId_ServerPmvmanager);
}
try
{
VarServerPmvManager.Exec( RiconfiguraNodo << nomeNodo << ipAddress << tipoPmv << cmdType );
}
catch (Exception & ex)
{
Mylog(Fun + Sysutils::Format("ERROR=[%s] ", ARRAYOFCONST((ex.Message))));
}
I found the solution.
The procedure exec simply require Variant instead of plain string
Variant vNomeNodo, vIpAddress, vTipoPmv, vCmdType;
vNomeNodo = nomeNodo;
vIpAddress = ipAddress;
vTipoPmv = tipoPmv;
vCmdType = cmdType;
VarServerPmvManager.Exec( RiconfiguraNodo << vNomeNodo << vIpAddress << vTipoPmv << vCmdType );

Resources