[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] bugfix: stop trying to write to a stderr that may not be th...
- To: or-cvs@freehaven.net
- Subject: [or-cvs] bugfix: stop trying to write to a stderr that may not be th...
- From: arma@seul.org (Roger Dingledine)
- Date: Sat, 28 Feb 2004 18:21:32 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Sat, 28 Feb 2004 18:21:49 -0500
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/common
Modified Files:
tortls.c util.c util.h
Log Message:
bugfix: stop trying to write to a stderr that may not be there
also, tell start_daemon our desired cwd
Index: tortls.c
===================================================================
RCS file: /home/or/cvsroot/src/common/tortls.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- tortls.c 20 Jan 2004 02:14:12 -0000 1.35
+++ tortls.c 28 Feb 2004 23:21:29 -0000 1.36
@@ -370,7 +370,7 @@
return r;
}
if (err == TOR_TLS_WANTWRITE || err == TOR_TLS_WANTREAD) {
- log_fn(LOG_INFO,"wantwrite or wantread. remembering the number %d.",n);
+// log_fn(LOG_INFO,"wantwrite or wantread. remembering the number %d.",n);
tls->wantwrite_n = n;
}
return err;
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- util.c 18 Feb 2004 21:23:50 -0000 1.53
+++ util.c 28 Feb 2004 23:21:29 -0000 1.54
@@ -701,7 +701,7 @@
static int start_daemon_called = 0;
static int finish_daemon_called = 0;
static int daemon_filedes[2];
-void start_daemon(void)
+void start_daemon(char *desired_cwd)
{
pid_t pid;
@@ -709,16 +709,18 @@
return;
start_daemon_called = 1;
+ if(!desired_cwd)
+ desired_cwd = "/";
/* Don't hold the wrong FS mounted */
- if (chdir("/") < 0) {
- perror("chdir");
+ if (chdir(desired_cwd) < 0) {
+ log_fn(LOG_ERR,"chdir to %s failed. Exiting.",desired_cwd);
exit(1);
}
pipe(daemon_filedes);
pid = fork();
if (pid < 0) {
- perror("fork");
+ log_fn(LOG_ERR,"fork failed. Exiting.");
exit(1);
}
if (pid) { /* Parent */
@@ -745,7 +747,7 @@
* This means that we, as a non-session group leader, can never regain a
* controlling terminal. This part is recommended by Stevens's
* _Advanced Programming in the Unix Environment_.
- */
+ */
if (fork() != 0) {
exit(0);
}
@@ -760,13 +762,13 @@
if (finish_daemon_called)
return;
if (!start_daemon_called)
- start_daemon();
+ start_daemon(NULL);
finish_daemon_called = 1;
nullfd = open("/dev/null",
- O_CREAT | O_RDWR | O_APPEND);
+ O_CREAT | O_RDWR | O_APPEND);
if (nullfd < 0) {
- perror("/dev/null");
+ log_fn(LOG_ERR,"/dev/null can't be opened. Exiting.");
exit(1);
}
/* close fds linking to invoking terminal, but
@@ -776,7 +778,7 @@
if (dup2(nullfd,0) < 0 ||
dup2(nullfd,1) < 0 ||
dup2(nullfd,2) < 0) {
- perror("dup2"); /* Should never happen... */
+ log_fn(LOG_ERR,"dup2 failed. Exiting.");
exit(1);
}
write(daemon_filedes[1], &c, sizeof(char)); /* signal success */
Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- util.h 3 Jan 2004 22:40:49 -0000 1.30
+++ util.h 28 Feb 2004 23:21:29 -0000 1.31
@@ -91,7 +91,7 @@
* until finish_daemon is called. (Note: it's safe to call this more
* than once: calls after the first are ignored.)
*/
-void start_daemon(void);
+void start_daemon(char *desired_cwd);
/* Finish putting the process into daemon mode: drop standard fds, and tell
* the parent process to exit. (Note: it's safe to call this more than once:
* calls after the first are ignored. Calls start_daemon first if it hasn't