From a997fdf020b2b57b8c6ec43aa6c4743c15f0ec5d Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Wed, 3 May 2017 12:00:23 +0930 Subject: [PATCH] Fallback to file rename if linking fails --- server.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server.c b/server.c index ba2f1a15..976e1582 100644 --- a/server.c +++ b/server.c @@ -420,10 +420,15 @@ static int server_write_pid() return 1; } } else { - WHYF_perror("Cannot link temporary pidfile %s to %s", tmpfile_path, pidfile_path); - close(fd); - unlink(tmpfile_path); - return -1; + WARNF_perror("Cannot link temporary pidfile %s to %s", tmpfile_path, pidfile_path); + // Android 6 wont let us link, giving a permission error (sigh), lets just rename it then + if (rename(tmpfile_path, pidfile_path)==-1){ + WHYF_perror("Cannot link or rename temporary pidfile %s to %s", tmpfile_path, pidfile_path); + close(fd); + unlink(tmpfile_path); + return -1; + } + break; } } DEBUGF(server, "Created pidfile %s", pidfile_path);