| 248 | } |
| 249 | |
| 250 | void unable_to_lock_message(const char *path, int err, struct strbuf *buf) |
| 251 | { |
| 252 | if (err == EEXIST) { |
| 253 | const char *abs_path = absolute_path(path); |
| 254 | struct strbuf lock_path = STRBUF_INIT; |
| 255 | struct strbuf pid_path = STRBUF_INIT; |
| 256 | uintmax_t pid; |
| 257 | int pid_status = 0; /* 0 = unknown, 1 = running, -1 = stale */ |
| 258 | |
| 259 | get_lock_path(&lock_path, abs_path); |
| 260 | get_pid_path(&pid_path, abs_path); |
| 261 | |
| 262 | strbuf_addf(buf, _("Unable to create '%s': %s.\n\n"), |
| 263 | lock_path.buf, strerror(err)); |
| 264 | |
| 265 | /* |
| 266 | * Try to read PID file unconditionally - it may exist if |
| 267 | * core.lockfilePid was enabled. |
| 268 | */ |
| 269 | if (!read_lock_pid(pid_path.buf, &pid)) { |
| 270 | if (kill((pid_t)pid, 0) == 0 || errno == EPERM) |
| 271 | pid_status = 1; /* running (or no permission to signal) */ |
| 272 | else if (errno == ESRCH) |
| 273 | pid_status = -1; /* no such process - stale lock */ |
| 274 | } |
| 275 | |
| 276 | if (pid_status == 1) |
| 277 | strbuf_addf(buf, _("Lock may be held by process %" PRIuMAX "; " |
| 278 | "if no git process is running, the lock file " |
| 279 | "may be stale (PIDs can be reused)"), |
| 280 | pid); |
| 281 | else if (pid_status == -1) |
| 282 | strbuf_addf(buf, _("Lock was held by process %" PRIuMAX ", " |
| 283 | "which is no longer running; the lock file " |
| 284 | "appears to be stale"), |
| 285 | pid); |
| 286 | else |
| 287 | strbuf_addstr(buf, _("Another git process seems to be running in this repository, " |
| 288 | "or the lock file may be stale")); |
| 289 | |
| 290 | strbuf_release(&lock_path); |
| 291 | strbuf_release(&pid_path); |
| 292 | } else { |
| 293 | strbuf_addf(buf, _("Unable to create '%s.lock': %s"), |
| 294 | absolute_path(path), strerror(err)); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | NORETURN void unable_to_lock_die(const char *path, int err) |
| 299 | { |
no test coverage detected