| 107 | } |
| 108 | |
| 109 | static struct tempfile *create_lock_pid_file(const char *pid_path, int mode) |
| 110 | { |
| 111 | struct strbuf content = STRBUF_INIT; |
| 112 | struct tempfile *pid_tempfile = NULL; |
| 113 | int fd; |
| 114 | |
| 115 | if (!lockfile_pid_enabled) |
| 116 | goto out; |
| 117 | |
| 118 | fd = open(pid_path, O_WRONLY | O_CREAT | O_EXCL, mode); |
| 119 | if (fd < 0) |
| 120 | goto out; |
| 121 | |
| 122 | strbuf_addf(&content, "pid %" PRIuMAX "\n", (uintmax_t)getpid()); |
| 123 | if (write_in_full(fd, content.buf, content.len) < 0) { |
| 124 | warning_errno(_("could not write lock pid file '%s'"), pid_path); |
| 125 | close(fd); |
| 126 | unlink(pid_path); |
| 127 | goto out; |
| 128 | } |
| 129 | |
| 130 | close(fd); |
| 131 | pid_tempfile = register_tempfile(pid_path); |
| 132 | |
| 133 | out: |
| 134 | strbuf_release(&content); |
| 135 | return pid_tempfile; |
| 136 | } |
| 137 | |
| 138 | static int read_lock_pid(const char *pid_path, uintmax_t *pid_out) |
| 139 | { |
no test coverage detected