summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console
Side-by-side diff
Diffstat (limited to 'noncore/apps/opie-console') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-console/filereceive.cpp4
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp4
-rw-r--r--noncore/apps/opie-console/logger.cpp4
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp3
-rw-r--r--noncore/apps/opie-console/script.cpp6
5 files changed, 15 insertions, 6 deletions
diff --git a/noncore/apps/opie-console/filereceive.cpp b/noncore/apps/opie-console/filereceive.cpp
index 452be60..41e6888 100644
--- a/noncore/apps/opie-console/filereceive.cpp
+++ b/noncore/apps/opie-console/filereceive.cpp
@@ -1,37 +1,38 @@
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
+#include <opie2/odebug.h>
#include <qsocketnotifier.h>
#include "io_layer.h"
#include "procctl.h"
#include "filereceive.h"
FileReceive::FileReceive( Type t, IOLayer* lay, const QString& dir )
: ReceiveLayer(lay, dir ), m_type( t )
{
m_fd = -1;
m_not = 0l;
m_proc = 0l;
}
FileReceive::~FileReceive() {
}
void FileReceive::receive() {
receive( currentDir() );
}
void FileReceive::receive( const QString& dir ) {
m_prog = -1;
m_fd = layer()->rawIO();
m_curDir = dir;
if (pipe( m_comm ) < 0 )
m_comm[0] = m_comm[1] = 0;
if (pipe( m_info ) < 0 )
m_info[0] = m_info[1] = 0;
m_pid = fork();
switch( m_pid ) {
case -1:
//emit error
@@ -119,44 +120,45 @@ void FileReceive::setupChild() {
if (m_info[0] )
close(m_info[0] );
/*
* FD_CLOEXEC will close the
* fd on successful exec
*/
if (m_info[1] )
fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
if (m_comm[0] )
close( m_comm[0] );
/*
* now set the communication
* m_fd STDIN_FILENO
* STDOUT_FILENO
* STDERR_FILENO
*/
dup2( m_fd, STDIN_FILENO );
dup2( m_fd, STDOUT_FILENO );
dup2( m_comm[1], STDERR_FILENO );
}
void FileReceive::slotRead() {
QByteArray ar(4096);
int len = read(m_comm[0], ar.data(), 4096 );
for (int i = 0; i < len; i++ ) {
// printf("%c", ar[i] );
}
ar.resize( len );
QString str( ar );
}
void FileReceive::slotExec() {
char buf[2];
- ::read(m_term[0], buf, 1 );
+ if (::read(m_term[0], buf, 1 ) == -1)
+ owarn << "read of m_term[0] failed" << oendl;
delete m_proc;
delete m_not;
m_not = m_proc = 0l;
close( m_term[0] );
close( m_term[1] );
close( m_comm[0] );
close( m_comm[1] );
layer()->closeRawIO(m_fd);
emit received(QString::null);
}
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
index 7eebc65..6e2d2d5 100644
--- a/noncore/apps/opie-console/filetransfer.cpp
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -1,38 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
+#include <opie2/odebug.h>
#include <qsocketnotifier.h>
#include "procctl.h"
#include "filetransfer.h"
FileTransfer::FileTransfer( Type t, IOLayer* lay )
: FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) {
signal(SIGPIPE, SIG_IGN );
m_pid = 0;
m_not = 0l;
m_proc = 0l;
}
FileTransfer::~FileTransfer() {
}
/**
* now we will send the file.
*
* we request an fd. The IOLayer should be closed
* then we will setup a pipe for progress communication
* then we will dup2 the m_fd in the forked process
* to do direct IO from and to the fd
*/
void FileTransfer::sendFile( const QString& file ) {
m_prog =-1;
m_fd = layer()->rawIO();
//
// m_fd = ::open("/dev/ttyS0", O_RDWR);
m_file = file;
@@ -205,44 +206,45 @@ void FileTransfer::slotProgress( const QStringList& list ) {
total = progi[1].toULong(&complete );
if (!complete || total == 0) {
return;
}
double pro = (double)sent/total;
int prog = pro * 100;
// speed
progi = QStringList::split(':', list[3].simplifyWhiteSpace() );
bps = progi[1].toInt();
// time
progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
min = progi[0].toInt();
sec = progi[1].toInt();
if ( prog > m_prog ) {
m_prog = prog;
emit progress(m_file, m_prog, bps, -1, min , sec );
}
}
void FileTransfer::cancel() {
if(m_pid > 0) ::kill(m_pid,9 );
}
void FileTransfer::slotExec() {
char buf[2];
- ::read(m_term[0], buf, 1 );
+ if (::read(m_term[0], buf, 1 ) == -1)
+ owarn << "read of m_term[0] failed" << oendl;
delete m_proc;
delete m_not;
m_proc = m_not = 0l;
close( m_term[0] );
close( m_term[1] );
close( m_comm[0] );
close( m_comm[1] );
layer()->closeRawIO( m_fd );
emit sent();
m_pid = 0;
}
diff --git a/noncore/apps/opie-console/logger.cpp b/noncore/apps/opie-console/logger.cpp
index 6620faf..0fdeca0 100644
--- a/noncore/apps/opie-console/logger.cpp
+++ b/noncore/apps/opie-console/logger.cpp
@@ -1,20 +1,22 @@
#include <qfile.h>
#include <qtextstream.h>
+#include <opie2/odebug.h>
#include "logger.h"
Logger::Logger() {}
Logger::Logger(const QString fileName) {
m_file.setName(fileName);
- m_file.open(IO_ReadWrite);
+ if ( !m_file.open(IO_ReadWrite) )
+ owarn << "failed to open " << m_file.name() << oendl;
}
Logger::~Logger() {
m_file.close();
}
void Logger::append(QByteArray ar) {
m_file.writeBlock(ar);
}
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index 18c0434..aba7244 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -795,40 +795,41 @@ void MainWindow::slotSaveLog() {
QStringList text;
text << "text/plain";
map.insert(tr("Log"), text );
Opie::Core::OConfig cfg("opie-console");
cfg.setGroup("defaults");
QString startDir = cfg.readEntry("defaultlogdir", QPEApplication::documentDir() );
QString m_logName = OFileDialog::getSaveFileName(2, startDir, QString::null, map, 0, startDir);
if (m_logName.isEmpty() ) return;
m_recordLog->setText( tr("Stop log") );
m_recordingLog = true;
currentSession()->emulationHandler()->startLogging(m_logName);
}
}
void MainWindow::slotSaveHistory() {
QMap<QString, QStringList> map;
QStringList text;
text << "text/plain";
map.insert(tr("History"), text );
QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
if (filename.isEmpty() ) return;
QFileInfo info(filename);
DocLnk nf;
nf.setType("text/plain");
nf.setFile(filename);
nf.setName(info.fileName());
QFile file(filename);
- file.open(IO_WriteOnly );
+ if ( !file.open(IO_WriteOnly ) ) return;
+
QTextStream str(&file );
if ( currentSession() )
currentSession()->emulationHandler()->emulation()->streamHistory(&str);
file.close();
nf.writeLink();
}
diff --git a/noncore/apps/opie-console/script.cpp b/noncore/apps/opie-console/script.cpp
index faea412..8d35776 100644
--- a/noncore/apps/opie-console/script.cpp
+++ b/noncore/apps/opie-console/script.cpp
@@ -1,29 +1,31 @@
#include <qfile.h>
#include "script.h"
Script::Script() {
}
Script::Script(const QString fileName) {
QFile file(fileName);
- file.open(IO_ReadOnly );
+ if ( !file.open(IO_ReadOnly ) )
+ return;
m_script = file.readAll();
}
void Script::saveTo(const QString fileName) const {
QFile file(fileName);
- file.open(IO_WriteOnly);
+ if ( !file.open(IO_WriteOnly) )
+ return;
file.writeBlock(m_script);
file.close();
}
void Script::append(const QByteArray &data) {
int size = m_script.size();
m_script.resize(size + data.size());
memcpy(m_script.data() + size, data.data(), data.size());
}
QByteArray Script::script() const {
return m_script;
}