summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2013-02-12 21:50:00 (UTC)
committer Michael Krelin <hacker@klever.net>2013-02-12 21:50:00 (UTC)
commit41f437eeadaae0dce4a3dad3da6dde2bd3c3de99 (patch) (unidiff)
tree0978b584286773cdcc29c3f174fd6ac9cdacee2f
parent13fb4abba3fd3cac0d5cb25d3eccddc298220d41 (diff)
downloadiii-41f437eeadaae0dce4a3dad3da6dde2bd3c3de99.zip
iii-41f437eeadaae0dce4a3dad3da6dde2bd3c3de99.tar.gz
iii-41f437eeadaae0dce4a3dad3da6dde2bd3c3de99.tar.bz2
moved sqlite initialization
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/eyefiworker.cc6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/eyefiworker.cc b/src/eyefiworker.cc
index 1979b46..645069e 100644
--- a/src/eyefiworker.cc
+++ b/src/eyefiworker.cc
@@ -1,104 +1,104 @@
1#include <signal.h> 1#include <signal.h>
2#ifndef NDEBUG 2#ifndef NDEBUG
3# include <sys/resource.h> 3# include <sys/resource.h>
4#endif 4#endif
5#include <syslog.h> 5#include <syslog.h>
6#include <cassert> 6#include <cassert>
7#include <iostream> 7#include <iostream>
8#include <fstream> 8#include <fstream>
9#include <stdexcept> 9#include <stdexcept>
10#include <iterator> 10#include <iterator>
11#include <algorithm> 11#include <algorithm>
12#include <sys/wait.h> 12#include <sys/wait.h>
13#include <autosprintf.h> 13#include <autosprintf.h>
14#include "eyekinfig.h" 14#include "eyekinfig.h"
15#include "eyetil.h" 15#include "eyetil.h"
16#include "eyefiworker.h" 16#include "eyefiworker.h"
17#ifdef HAVE_SQLITE 17#ifdef HAVE_SQLITE
18# include "iiidb.h" 18# include "iiidb.h"
19#endif 19#endif
20 20
21eyefiworker::eyefiworker() 21eyefiworker::eyefiworker()
22 : eyefiService(SOAP_IO_STORE|SOAP_IO_KEEPALIVE) { 22 : eyefiService(SOAP_IO_STORE|SOAP_IO_KEEPALIVE) {
23 bind_flags = SO_REUSEADDR; max_keep_alive = 0; 23 bind_flags = SO_REUSEADDR; max_keep_alive = 0;
24 socket_flags = 24 socket_flags =
25#if defined(MSG_NOSIGNAL) 25#if defined(MSG_NOSIGNAL)
26 MSG_NOSIGNAL 26 MSG_NOSIGNAL
27#elif defined(SO_NOSIGPIPE) 27#elif defined(SO_NOSIGPIPE)
28 SO_NOSIGPIPE 28 SO_NOSIGPIPE
29#else 29#else
30#error Something is wrong with sigpipe prevention on the platform 30#error Something is wrong with sigpipe prevention on the platform
31#endif 31#endif
32 ; 32 ;
33#ifdef HAVE_SQLITE
34 sqlite3_initialize();
35#endif
33 } 36 }
34eyefiworker::~eyefiworker() { 37eyefiworker::~eyefiworker() {
35} 38}
36 39
37int eyefiworker::run(int bindport) { 40int eyefiworker::run(int bindport) {
38#ifdef HAVE_SQLITE
39 sqlite3_initialize();
40#endif
41 if(!soap_valid_socket(bind(0,bindport,64))) 41 if(!soap_valid_socket(bind(0,bindport,64)))
42 throw std::runtime_error("failed to bind()"); 42 throw std::runtime_error("failed to bind()");
43 signal(SIGCHLD,SIG_IGN); 43 signal(SIGCHLD,SIG_IGN);
44 while(true) { 44 while(true) {
45 if(!soap_valid_socket(accept())) 45 if(!soap_valid_socket(accept()))
46 throw std::runtime_error("failed to accept()"); 46 throw std::runtime_error("failed to accept()");
47 pid_t p = fork(); 47 pid_t p = fork();
48 if(p<0) throw std::runtime_error("failed to fork()"); 48 if(p<0) throw std::runtime_error("failed to fork()");
49 if(!p) { 49 if(!p) {
50 recv_timeout = 600; send_timeout = 120; 50 recv_timeout = 600; send_timeout = 120;
51 (void)serve(); 51 (void)serve();
52 soap_destroy(this); soap_end(this); soap_done(this); 52 soap_destroy(this); soap_end(this); soap_done(this);
53#ifndef NDEBUG 53#ifndef NDEBUG
54 struct rusage ru; 54 struct rusage ru;
55 if(getrusage(RUSAGE_SELF,&ru)) { 55 if(getrusage(RUSAGE_SELF,&ru)) {
56 syslog(LOG_NOTICE,"Failed to getrusage(): %d",errno); 56 syslog(LOG_NOTICE,"Failed to getrusage(): %d",errno);
57 }else{ 57 }else{
58 syslog(LOG_INFO,"maxrss: %ld\n",ru.ru_maxrss); 58 syslog(LOG_INFO,"maxrss: %ld\n",ru.ru_maxrss);
59 } 59 }
60#endif /* NDEBUG */ 60#endif /* NDEBUG */
61 throw throwable_exit(0); 61 throw throwable_exit(0);
62 } 62 }
63 close(socket); socket = SOAP_INVALID_SOCKET; 63 close(socket); socket = SOAP_INVALID_SOCKET;
64 } 64 }
65} 65}
66 66
67static binary_t session_nonce; 67static binary_t session_nonce;
68#ifdef HAVE_SQLITE 68#ifdef HAVE_SQLITE
69 static struct { 69 static struct {
70 std::string filesignature; 70 std::string filesignature;
71 long filesize; 71 long filesize;
72 std::string filename; 72 std::string filename;
73 inline void reset() { filesignature.erase(); filename.erase(); filesize=0; } 73 inline void reset() { filesignature.erase(); filename.erase(); filesize=0; }
74 inline void set(const std::string n,const std::string sig,long siz) { 74 inline void set(const std::string n,const std::string sig,long siz) {
75 filename = n; filesignature = sig; filesize = siz; 75 filename = n; filesignature = sig; filesize = siz;
76 } 76 }
77 inline bool is(const std::string n,const std::string sig,long siz) { 77 inline bool is(const std::string n,const std::string sig,long siz) {
78 return filesize==siz && filename==n && filesignature==sig; 78 return filesize==siz && filename==n && filesignature==sig;
79 } 79 }
80 } already; 80 } already;
81#endif /* HAVE_SQLITE */ 81#endif /* HAVE_SQLITE */
82 82
83static bool detached_child() { 83static bool detached_child() {
84 pid_t p = fork(); 84 pid_t p = fork();
85 if(p<0) { 85 if(p<0) {
86 syslog(LOG_ERR,"Failed to fork away for hook execution"); 86 syslog(LOG_ERR,"Failed to fork away for hook execution");
87 _exit(-1); 87 _exit(-1);
88 } 88 }
89 if(!p) { 89 if(!p) {
90 setsid(); 90 setsid();
91 for(int i=getdtablesize();i>=0;--i) close(i); 91 for(int i=getdtablesize();i>=0;--i) close(i);
92 int i=open("/dev/null",O_RDWR); assert(i==0); 92 int i=open("/dev/null",O_RDWR); assert(i==0);
93 i = dup(i); assert(i==1); 93 i = dup(i); assert(i==1);
94 i = dup(i); assert(i==2); 94 i = dup(i); assert(i==2);
95 return true; 95 return true;
96 } 96 }
97 return false; 97 return false;
98} 98}
99 99
100static int E(eyefiworker* efs,const char *c,const std::exception& e) { 100static int E(eyefiworker* efs,const char *c,const std::exception& e) {
101 efs->keep_alive=0; 101 efs->keep_alive=0;
102 syslog(LOG_ERR,"error while processing %s: %s",c,e.what()); 102 syslog(LOG_ERR,"error while processing %s: %s",c,e.what());
103 return soap_sender_fault(efs,gnu::autosprintf("error processing %s",c),0); 103 return soap_sender_fault(efs,gnu::autosprintf("error processing %s",c),0);
104} 104}