84
|
1 |
--- aria2-0.9.0/src/main.cc.orig2 2006-12-12 15:19:39.816899000 +0800
|
|
2 |
+++ aria2-0.9.0/src/main.cc 2006-12-19 16:32:55.069763000 +0800
|
|
3 |
@@ -52,9 +52,14 @@
|
|
4 |
#include <unistd.h>
|
|
5 |
#include <libgen.h>
|
|
6 |
#include <utility>
|
|
7 |
+#include <sys/types.h>
|
|
8 |
+#include <sys/stat.h>
|
|
9 |
+#include <fcntl.h>
|
|
10 |
extern char* optarg;
|
|
11 |
extern int optind, opterr, optopt;
|
|
12 |
#include <getopt.h>
|
|
13 |
+#include <vector>
|
|
14 |
+#include <iterator>
|
|
15 |
|
|
16 |
#ifdef ENABLE_METALINK
|
|
17 |
#include "MetalinkRequestInfo.h"
|
|
18 |
@@ -74,6 +79,40 @@
|
|
19 |
|
|
20 |
bool timeoutSpecified;
|
|
21 |
|
|
22 |
+int daemon( int nochdir, int noclose )
|
|
23 |
+{
|
|
24 |
+ int fd;
|
|
25 |
+
|
|
26 |
+ switch (fork()) {
|
|
27 |
+ case -1:
|
|
28 |
+ return(-1);
|
|
29 |
+ case 0:
|
|
30 |
+ break;
|
|
31 |
+ default:
|
|
32 |
+ _exit(0);
|
|
33 |
+ }
|
|
34 |
+
|
|
35 |
+ if (setsid() == -1)
|
|
36 |
+ return(-1);
|
|
37 |
+
|
|
38 |
+ /* Make certain we are not a session leader, or else we
|
|
39 |
+ * might reacquire a controlling terminal */
|
|
40 |
+ if (fork())
|
|
41 |
+ _exit(0);
|
|
42 |
+
|
|
43 |
+ if (!nochdir)
|
|
44 |
+ chdir("/");
|
|
45 |
+
|
|
46 |
+ if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
|
|
47 |
+ dup2(fd, STDIN_FILENO);
|
|
48 |
+ dup2(fd, STDOUT_FILENO);
|
|
49 |
+ dup2(fd, STDERR_FILENO);
|
|
50 |
+ if (fd > 2)
|
|
51 |
+ close(fd);
|
|
52 |
+ }
|
|
53 |
+ return(0);
|
|
54 |
+}
|
|
55 |
+
|
|
56 |
void setSignalHander(int signal, void (*handler)(int), int flags) {
|
|
57 |
struct sigaction sigact;
|
|
58 |
sigact.sa_handler = handler;
|
|
59 |
@@ -708,7 +747,13 @@
|
|
60 |
exit(EXIT_FAILURE);
|
|
61 |
}
|
|
62 |
}
|
|
63 |
- Strings args(argv+optind, argv+argc);
|
|
64 |
+
|
|
65 |
+ vector<string> V_argv;
|
|
66 |
+ for ( int i=0; i<argc; i++){
|
|
67 |
+ V_argv.insert(V_argv.begin(), argv[i]);
|
|
68 |
+ }
|
|
69 |
+
|
|
70 |
+ Strings args(V_argv.begin()+optind, V_argv.end());
|
|
71 |
|
|
72 |
#ifdef HAVE_LIBSSL
|
|
73 |
// for SSL initialization
|