| 136 | } |
| 137 | |
| 138 | static int read_lock_pid(const char *pid_path, uintmax_t *pid_out) |
| 139 | { |
| 140 | struct strbuf content = STRBUF_INIT; |
| 141 | const char *val; |
| 142 | int ret = -1; |
| 143 | |
| 144 | if (strbuf_read_file(&content, pid_path, LOCK_PID_MAXLEN) <= 0) |
| 145 | goto out; |
| 146 | |
| 147 | strbuf_rtrim(&content); |
| 148 | |
| 149 | if (skip_prefix(content.buf, "pid ", &val)) { |
| 150 | char *endptr; |
| 151 | *pid_out = strtoumax(val, &endptr, 10); |
| 152 | if (*pid_out > 0 && !*endptr) |
| 153 | ret = 0; |
| 154 | } |
| 155 | |
| 156 | if (ret) |
| 157 | warning(_("malformed lock pid file '%s'"), pid_path); |
| 158 | |
| 159 | out: |
| 160 | strbuf_release(&content); |
| 161 | return ret; |
| 162 | } |
| 163 | |
| 164 | /* Make sure errno contains a meaningful value on error */ |
| 165 | static int lock_file(struct lock_file *lk, const char *path, int flags, |
no test coverage detected