-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmsdiskstorage.cpp
executable file
·82 lines (67 loc) · 2.09 KB
/
smsdiskstorage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <asm/errno.h>
#include "smsdiskstorage.h"
using namespace std;
namespace SMS {
CSMSDiskStorage* __smsDiskStorage;
void __smsDiskStorage_notify_handler(int sig, siginfo_t *si, void *data)
{
__smsDiskStorage->OnNotify();
}
int CSMSDiskStorage::set_notifier() {
if (m_IncomingDirectory.length()<1) {
return SUCCESS;
}
if (m_IncomingBackupDirectory.length()>1) {
struct stat buf;
if ((lstat(m_IncomingBackupDirectory.c_str(),&buf))<0) {
if (errno==ENOENT) {
mkdir(m_IncomingBackupDirectory.c_str(),0755);
}
}
}
struct sigaction act;
act.sa_sigaction = __smsDiskStorage_notify_handler;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &act, NULL);
if (m_fp==0) {
retry:
m_fp=open(m_IncomingDirectory.c_str(), O_RDONLY);
if (m_fp<0) {
if (errno==ENOENT) {
if (!mkdir(m_IncomingDirectory.c_str(),0755))
goto retry;
}
syslog(LOG_ERR," open dir %s error: %d!", m_IncomingDirectory.c_str(), errno);
exit(-1);
}
}
syslog(LOG_ERR, "start monitor: %s %d", m_IncomingDirectory.c_str(),m_fp);
if (fcntl(m_fp, F_SETSIG, SIGUSR1)<0) {
syslog(LOG_ERR," fcntl F_SETSIG failed : %d ",errno);
exit(-1);
}
if (fcntl(m_fp, F_NOTIFY, DN_CREATE|DN_MULTISHOT )<0) {
syslog(LOG_ERR," fcntl F_NOTIFY failed : %d ", errno);
exit(-1);
}
return 0;
}
CSMSDiskStorage::CSMSDiskStorage(CSMSProtocol *pSMSPProtocol, const string & OutgoingDirectory, const string & IncomingDirectory, const string& IncomingBackupDirectory, const string& errorDirectory):m_OutgoingDirectory(OutgoingDirectory),
m_IncomingDirectory(IncomingDirectory),m_pDIR(NULL),m_dataSize(0),m_pDataBuf(NULL),m_bufSize(0),CSMSStorage(pSMSPProtocol),m_IncomingBackupDirectory(IncomingBackupDirectory), m_errorDirectory(errorDirectory){
__smsDiskStorage=this;
m_fp=0;
m_count=0;
}
CSMSDiskStorage::~CSMSDiskStorage(){
delete[] m_pDataBuf;
__smsDiskStorage=NULL;
}
}