mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Merge branch 'ticket20119'
This commit is contained in:
commit
c151f46445
3
changes/feature20119_1
Normal file
3
changes/feature20119_1
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
o Minor features (startup, safety):
|
||||||
|
- When configured to write a PID file, Tor now exits if it is unable to
|
||||||
|
do so. Previously, it would warn and continue. Closes ticket 20119.
|
@ -3691,8 +3691,9 @@ finish_daemon(const char *cp)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Write the current process ID, followed by NL, into <b>filename</b>.
|
/** 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)
|
write_pidfile(const char *filename)
|
||||||
{
|
{
|
||||||
FILE *pidfile;
|
FILE *pidfile;
|
||||||
@ -3700,13 +3701,19 @@ write_pidfile(const char *filename)
|
|||||||
if ((pidfile = fopen(filename, "w")) == NULL) {
|
if ((pidfile = fopen(filename, "w")) == NULL) {
|
||||||
log_warn(LD_FS, "Unable to open \"%s\" for writing: %s", filename,
|
log_warn(LD_FS, "Unable to open \"%s\" for writing: %s", filename,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
fprintf(pidfile, "%d\n", (int)_getpid());
|
int pid = (int)_getpid();
|
||||||
#else
|
#else
|
||||||
fprintf(pidfile, "%d\n", (int)getpid());
|
int pid = (int)getpid();
|
||||||
#endif
|
#endif
|
||||||
fclose(pidfile);
|
int rv = 0;
|
||||||
|
if (fprintf(pidfile, "%d\n", pid) < 0)
|
||||||
|
rv = -1;
|
||||||
|
if (fclose(pidfile) < 0)
|
||||||
|
rv = -1;
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ int path_is_relative(const char *filename);
|
|||||||
/* Process helpers */
|
/* Process helpers */
|
||||||
void start_daemon(void);
|
void start_daemon(void);
|
||||||
void finish_daemon(const char *desired_cwd);
|
void finish_daemon(const char *desired_cwd);
|
||||||
void write_pidfile(const char *filename);
|
int write_pidfile(const char *filename);
|
||||||
|
|
||||||
/* Port forwarding */
|
/* Port forwarding */
|
||||||
void tor_check_port_forwarding(const char *filename,
|
void tor_check_port_forwarding(const char *filename,
|
||||||
|
@ -1772,9 +1772,13 @@ options_act(const or_options_t *old_options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write our PID to the PID file. If we do not have write permissions we
|
/* Write our PID to the PID file. If we do not have write permissions we
|
||||||
* will log a warning */
|
* will log a warning and exit. */
|
||||||
if (options->PidFile && !sandbox_is_active()) {
|
if (options->PidFile && !sandbox_is_active()) {
|
||||||
write_pidfile(options->PidFile);
|
if (write_pidfile(options->PidFile) < 0) {
|
||||||
|
log_err(LD_CONFIG, "Unable to write PIDFile %s",
|
||||||
|
escaped(options->PidFile));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register addressmap directives */
|
/* Register addressmap directives */
|
||||||
|
Loading…
Reference in New Issue
Block a user