a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen /* 0 = try locking without waiting */
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen /* 0 = 0600 */
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen /* 0 = default */
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen /* 0 = default */
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen /* If parent directory doesn't exist, mkdir() it with this mode.
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen 0 = don't mkdir(). The parent directories are assumed to be
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen potentially rmdir() simultaneously, so the mkdir()+locking may be
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen attempted multiple times. */
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen /* 0 = default */
d6e3deea85740b3af60e9f5bab32e98beba12d93Timo Sirainen /* 0 = default */
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen/* Either open an existing file and lock it, or create the file locked.
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen The creation is done by creating a temp file and link()ing it to path.
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen If link() fails, opening is retried again. Returns fd on success,
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen -1 on error. errno is preserved for the last failed syscall, so most
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen importantly ENOENT could mean that the directory doesn't exist and EAGAIN
3581ece16eb740a5003c4c11dd3c7d02839a24a4Timo Sirainen means locking timed out.
3581ece16eb740a5003c4c11dd3c7d02839a24a4Timo Sirainen If this function is used to create lock files, file_lock_set_unlink_on_free()
3581ece16eb740a5003c4c11dd3c7d02839a24a4Timo Sirainen should be used for the resulting lock. It attempts to avoid unlinking the
3581ece16eb740a5003c4c11dd3c7d02839a24a4Timo Sirainen file if there are already other processes using the lock. That can help to
3581ece16eb740a5003c4c11dd3c7d02839a24a4Timo Sirainen avoid "Creating a locked file ... keeps failing" errors */
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainenint file_create_locked(const char *path, const struct file_create_settings *set,
a63907c14bd96eec1493eb893a043137c1799485Timo Sirainen const char **error_r);