- if (!stat(rc->log_file, &st))
- create_new = 0;
- else if (errno == ENOENT)
- create_new = 1;
- else
- return -EINVAL;
-
- if (create_new) {
- log_dbg("Creating LUKS reencryption log file %s.", rc->log_file);
- flags = opt_directio ? O_RDWR|O_CREAT|O_DIRECT : O_RDWR|O_CREAT;
- rc->log_fd = open(rc->log_file, flags, S_IRUSR|S_IWUSR);
- if (rc->log_fd == -1)
- return -EINVAL;
- } else {
+ rc->log_fd = open(rc->log_file, O_RDWR|O_EXCL|O_CREAT|flags, S_IRUSR|S_IWUSR);
+ if (rc->log_fd != -1) {
+ log_dbg("Created LUKS reencryption log file %s.", rc->log_file);
+ } else if (errno == EEXIST) {