116 |
::close(fd); |
::close(fd); |
117 |
return file; |
return file; |
118 |
} |
} |
119 |
|
int err = errno; |
120 |
|
::close(fd); |
121 |
|
|
122 |
if (errno == EEXIST) |
if (err == EEXIST) { |
123 |
continue; |
continue; |
124 |
|
} |
125 |
|
|
126 |
if (retrycount > 20) |
if (retrycount > 20) |
127 |
throw std::runtime_error("to many retry attempt at creating spool file"); |
throw std::runtime_error("to many retry attempt at creating spool file"); |
133 |
|
|
134 |
void Spooler::lock() |
void Spooler::lock() |
135 |
{ |
{ |
136 |
fd = open(spooldir.c_str() , O_RDONLY); |
lockfd = open(spooldir.c_str() , O_RDONLY); |
137 |
|
|
138 |
if (fd == -1) { |
if (lockfd == -1) { |
139 |
errnoException("Couldn open lockfile"); |
errnoException("Couldn open lockfile"); |
140 |
} |
} |
141 |
|
|
142 |
int status = flock(fd, LOCK_EX); |
int status = flock(lockfd, LOCK_EX); |
143 |
|
|
144 |
if (status == -1) { |
if (status == -1) { |
145 |
errnoException(); |
errnoException(); |
148 |
|
|
149 |
void Spooler::unlock() |
void Spooler::unlock() |
150 |
{ |
{ |
151 |
flock(fd, LOCK_UN); |
flock(lockfd, LOCK_UN); |
152 |
|
close(lockfd); |
153 |
} |
} |
154 |
|
|
155 |
string Spooler::getFilename() |
string Spooler::getFilename() |