Diffstat (limited to 'library/qcopenvelope_qws.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | library/qcopenvelope_qws.cpp | 66 |
1 files changed, 20 insertions, 46 deletions
diff --git a/library/qcopenvelope_qws.cpp b/library/qcopenvelope_qws.cpp index 81bb0f5..0aac32b 100644 --- a/library/qcopenvelope_qws.cpp +++ b/library/qcopenvelope_qws.cpp | |||
@@ -104,4 +104,5 @@ QCopEnvelope::~QCopEnvelope() | |||
104 | if ( qcopfile.open(IO_WriteOnly | IO_Append) ) { | 104 | if ( qcopfile.open(IO_WriteOnly | IO_Append) ) { |
105 | #ifndef Q_OS_WIN32 | ||
105 | if(flock(qcopfile.handle(), LOCK_EX)) { | 106 | if(flock(qcopfile.handle(), LOCK_EX)) { |
106 | /* some error occured */ | 107 | /* some error occurred */ |
107 | qWarning(QString("Failed to obtain file lock on %1 (%2)") | 108 | qWarning(QString("Failed to obtain file lock on %1 (%2)") |
@@ -109,48 +110,21 @@ QCopEnvelope::~QCopEnvelope() | |||
109 | } | 110 | } |
110 | /* file locked, but might be stale (e.g. program for whatever | 111 | #endif |
111 | reason did not start). I modified more than 1 minute ago, | 112 | { |
112 | truncate the file */ | 113 | QDataStream ds(&qcopfile); |
113 | struct stat buf; | 114 | ds << ch << msg << data; |
114 | time_t t; | 115 | qcopfile.flush(); |
115 | if (!fstat(qcopfile.handle(), &buf) && (time(&t) != (time_t)-1) ) { | 116 | #ifndef Q_OS_WIN32 |
116 | // success on fstat, lets compare times | 117 | flock(qcopfile.handle(), LOCK_UN); |
117 | if (buf.st_ctime + 60 < t) { | 118 | #endif |
118 | qWarning("stale file " + qcopfn + " found. Truncating"); | 119 | qcopfile.close(); |
119 | ftruncate(qcopfile.handle(), 0); | ||
120 | qcopfile.reset(); | ||
121 | } | ||
122 | } | 120 | } |
123 | 121 | ||
124 | if ( !QCopChannel::isRegistered(ch) ) { | 122 | QByteArray b; |
125 | int fsize = qcopfile.size(); | 123 | QDataStream stream(b, IO_WriteOnly); |
126 | { | 124 | stream << QString(ch.mid(pref)); |
127 | QDataStream ds(&qcopfile); | 125 | QCopChannel::send("QPE/Server", "processQCop(QString)", b); |
128 | ds << ch << msg << data; | 126 | delete device(); |
129 | flock(qcopfile.handle(), LOCK_UN); | 127 | return; |
130 | qcopfile.close(); | ||
131 | } | ||
132 | |||
133 | if (fsize == 0) { | ||
134 | QString cmd = ch.mid(pref); | ||
135 | Global::execute(cmd); | ||
136 | } | ||
137 | |||
138 | char c; | ||
139 | for (int i=0; (c=msg[i]); i++) { | ||
140 | if ( c == ' ' ) { | ||
141 | // Return-value required | ||
142 | // ###### wait for it | ||
143 | break; | ||
144 | } else if ( c == '(' ) { | ||
145 | // No return value | ||
146 | break; | ||
147 | } | ||
148 | } | ||
149 | goto end; | ||
150 | } // endif isRegisterd | ||
151 | flock(qcopfile.handle(), LOCK_UN); | ||
152 | qcopfile.close(); | ||
153 | qcopfile.remove(); | ||
154 | } else { | 128 | } else { |
155 | qWarning(QString("Failed to obtain file lock on %1") | 129 | qWarning(QString("Failed to open file %1") |
156 | .arg(qcopfn)); | 130 | .arg(qcopfn)); |
@@ -162,3 +136,3 @@ QCopEnvelope::~QCopEnvelope() | |||
162 | QString endpoint = ch.mid(9); | 136 | QString endpoint = ch.mid(9); |
163 | 137 | ||
164 | ch = "QPE/SOAP"; | 138 | ch = "QPE/SOAP"; |
@@ -167,4 +141,4 @@ QCopEnvelope::~QCopEnvelope() | |||
167 | } | 141 | } |
142 | |||
168 | QCopChannel::send(ch,msg,data); | 143 | QCopChannel::send(ch,msg,data); |
169 | end: | ||
170 | delete device(); | 144 | delete device(); |