summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-09-08 08:56:53 -0400
committerNick Mathewson <nickm@torproject.org>2017-09-08 08:56:53 -0400
commitc151f46445ac76e5ab13688eba5612ada5c5af45 (patch)
treee61b45ff0c853bb99b1c563c38f8cc27aaa97271 /src/common
parentad3f0953e6da8bf95f2dd754b91705d4c7d80a1e (diff)
parent1098893e4f3753bf66248abf81702175dca980ee (diff)
downloadtor-c151f46445ac76e5ab13688eba5612ada5c5af45.tar.gz
tor-c151f46445ac76e5ab13688eba5612ada5c5af45.zip
Merge branch 'ticket20119'
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c15
-rw-r--r--src/common/util.h2
2 files changed, 12 insertions, 5 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 31d42a3e5c..36d0f4d068 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -3691,8 +3691,9 @@ finish_daemon(const char *cp)
#endif
/** Write the current process ID, followed by NL, into <b>filename</b>.
+ * Return 0 on success, -1 on failure.
*/
-void
+int
write_pidfile(const char *filename)
{
FILE *pidfile;
@@ -3700,13 +3701,19 @@ write_pidfile(const char *filename)
if ((pidfile = fopen(filename, "w")) == NULL) {
log_warn(LD_FS, "Unable to open \"%s\" for writing: %s", filename,
strerror(errno));
+ return -1;
} else {
#ifdef _WIN32
- fprintf(pidfile, "%d\n", (int)_getpid());
+ int pid = (int)_getpid();
#else
- fprintf(pidfile, "%d\n", (int)getpid());
+ int pid = (int)getpid();
#endif
- fclose(pidfile);
+ int rv = 0;
+ if (fprintf(pidfile, "%d\n", pid) < 0)
+ rv = -1;
+ if (fclose(pidfile) < 0)
+ rv = -1;
+ return rv;
}
}
diff --git a/src/common/util.h b/src/common/util.h
index f50cf043a4..073fb82aed 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -389,7 +389,7 @@ int path_is_relative(const char *filename);
/* Process helpers */
void start_daemon(void);
void finish_daemon(const char *desired_cwd);
-void write_pidfile(const char *filename);
+int write_pidfile(const char *filename);
/* Port forwarding */
void tor_check_port_forwarding(const char *filename,