| 227 | |
| 228 | |
| 229 | static int |
| 230 | openSharedFile(string const& name, int flags) |
| 231 | { |
| 232 | int fd; |
| 233 | int errno_bkp; |
| 234 | |
| 235 | // try to create, truncate & open file |
| 236 | |
| 237 | dmtcp::string dir = jalib::Filesystem::DirName(name); |
| 238 | |
| 239 | JTRACE("shared file dir:")(dir); |
| 240 | jalib::Filesystem::mkdir_r(dir, 0755); |
| 241 | |
| 242 | if ((fd = open(name.c_str(), O_EXCL | O_CREAT | O_TRUNC | flags, 0600)) >= |
| 243 | 0) { |
| 244 | return fd; |
| 245 | } |
| 246 | errno_bkp = errno; |
| 247 | |
| 248 | if ((fd < 0) && (errno_bkp == EEXIST)) { |
| 249 | errno = 0; |
| 250 | if ((fd = open(name.c_str(), flags, 0600)) >= 0) { |
| 251 | return fd; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // unable to create & open OR open |
| 256 | JASSERT(false)(name)(strerror(errno)).Text("Cannot open file"); |
| 257 | return -1; |
| 258 | } |
| 259 | |
| 260 | static void |
| 261 | pidVirt_PostRestart() |
no test coverage detected