-rw-r--r-- | src/eyefiservice.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc index 5c4e308..9ef4bb6 100644 --- a/src/eyefiservice.cc +++ b/src/eyefiservice.cc | |||
@@ -181,48 +181,48 @@ int eyefiService::UploadPhoto( | |||
181 | int fd=open(f.c_str(),O_CREAT|O_WRONLY,0666); | 181 | int fd=open(f.c_str(),O_CREAT|O_WRONLY,0666); |
182 | if(fd<0) | 182 | if(fd<0) |
183 | throw std::runtime_error(gnu::autosprintf("failed to create output file '%s'",f.c_str())); | 183 | throw std::runtime_error(gnu::autosprintf("failed to create output file '%s'",f.c_str())); |
184 | if(!a.read_data_into_fd(fd)) | 184 | if(!a.read_data_into_fd(fd)) |
185 | throw std::runtime_error(gnu::autosprintf("failed to untar file into '%s'",f.c_str())); | 185 | throw std::runtime_error(gnu::autosprintf("failed to untar file into '%s'",f.c_str())); |
186 | close(fd); | 186 | close(fd); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | if(tf.empty()) throw std::runtime_error("haven't seen THE file"); | 191 | if(tf.empty()) throw std::runtime_error("haven't seen THE file"); |
192 | if(digest!=idigest) throw std::runtime_error("integrity digest verification failed"); | 192 | if(digest!=idigest) throw std::runtime_error("integrity digest verification failed"); |
193 | 193 | ||
194 | std::string::size_type ls = tf.rfind('/'); | 194 | std::string::size_type ls = tf.rfind('/'); |
195 | // XXX: actually, lack of '/' signifies error here | 195 | // XXX: actually, lack of '/' signifies error here |
196 | std::string tbn = (ls==std::string::npos)?tf:tf.substr(ls+1); | 196 | std::string tbn = (ls==std::string::npos)?tf:tf.substr(ls+1); |
197 | ls = lf.rfind('/'); | 197 | ls = lf.rfind('/'); |
198 | std::string lbn = (ls==std::string::npos)?lf:lf.substr(ls+1); | 198 | std::string lbn = (ls==std::string::npos)?lf:lf.substr(ls+1); |
199 | std::string ttf,tlf; | 199 | std::string ttf,tlf; |
200 | bool success = false; | 200 | bool success = false; |
201 | for(int i=0;i<32767;++i) { | 201 | for(int i=0;i<32767;++i) { |
202 | const char *fmt = i ? "%1$s/(%3$05d)%2$s" : "%1$s/%2$s"; | 202 | const char *fmt = i ? "%1$s/(%3$05d)%2$s" : "%1$s/%2$s"; |
203 | ttf = (const char*)gnu::autosprintf(fmt,td.c_str(),tbn.c_str(),i); | 203 | ttf = (const char*)gnu::autosprintf(fmt,td.c_str(),tbn.c_str(),i); |
204 | if(!lf.empty()) tlf = (const char*)gnu::autosprintf(fmt,td.c_str(),lbn.c_str(),i); | 204 | if(!lf.empty()) tlf = (const char*)gnu::autosprintf(fmt,td.c_str(),lbn.c_str(),i); |
205 | if( (!link(tf.c_str(),ttf.c_str())) && (lf.empty()) || !link(lf.c_str(),tlf.c_str()) ) { | 205 | if( (!link(tf.c_str(),ttf.c_str())) && (lf.empty() || !link(lf.c_str(),tlf.c_str())) ) { |
206 | unlink(tf.c_str()); | 206 | unlink(tf.c_str()); |
207 | if(!lf.empty()) unlink(lf.c_str()); | 207 | if(!lf.empty()) unlink(lf.c_str()); |
208 | success=true; | 208 | success=true; |
209 | break; | 209 | break; |
210 | } | 210 | } |
211 | } | 211 | } |
212 | std::string cmd = eyekinfig.get_on_upload_photo(); | 212 | std::string cmd = eyekinfig.get_on_upload_photo(); |
213 | if(success && !cmd.empty()) { | 213 | if(success && !cmd.empty()) { |
214 | if(detached_child()) { | 214 | if(detached_child()) { |
215 | putenv( gnu::autosprintf("EYEFI_UPLOADED_ORIG=%s",tbn.c_str()) ); | 215 | putenv( gnu::autosprintf("EYEFI_UPLOADED_ORIG=%s",tbn.c_str()) ); |
216 | putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) ); | 216 | putenv( gnu::autosprintf("EYEFI_MACADDRESS=%s",macaddress.c_str()) ); |
217 | putenv( gnu::autosprintf("EYEFI_UPLOADED=%s",ttf.c_str()) ); | 217 | putenv( gnu::autosprintf("EYEFI_UPLOADED=%s",ttf.c_str()) ); |
218 | if(!lf.empty()) putenv( gnu::autosprintf("EYEFI_LOG=%s",tlf.c_str()) ); | 218 | if(!lf.empty()) putenv( gnu::autosprintf("EYEFI_LOG=%s",tlf.c_str()) ); |
219 | char *argv[] = { (char*)"/bin/sh", (char*)"-c", (char*)cmd.c_str(), 0 }; | 219 | char *argv[] = { (char*)"/bin/sh", (char*)"-c", (char*)cmd.c_str(), 0 }; |
220 | execv("/bin/sh",argv); | 220 | execv("/bin/sh",argv); |
221 | syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str()); | 221 | syslog(LOG_ERR,"Failed to execute '%s'",cmd.c_str()); |
222 | _exit(-1); | 222 | _exit(-1); |
223 | } | 223 | } |
224 | } | 224 | } |
225 | 225 | ||
226 | r.success = true; | 226 | r.success = true; |
227 | return SOAP_OK; | 227 | return SOAP_OK; |
228 | } | 228 | } |