Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "prio.h"
7 #include "prprf.h"
8 #include "prinit.h"
9 #include "prthread.h"
10 #include "prproces.h"
11 #include "prinrval.h"
13 #include "plgetopt.h"
15 #include <stdlib.h>
17 static PRInt32 dally = 0;
18 static PRFileDesc *err = NULL;
19 static PRBool verbose = PR_FALSE, force = PR_FALSE;
21 static void Help(void)
22 {
23 PR_fprintf(err, "Usage: [-t s] [-h]\n");
24 PR_fprintf(err, "\t-d Verbose output (default: FALSE)\n");
25 PR_fprintf(err, "\t-x Forced termination (default: FALSE)\n");
26 PR_fprintf(err, "\t-t Time for thread to block (default: 10 seconds)\n");
27 PR_fprintf(err, "\t-h This message and nothing else\n");
28 } /* Help */
30 static void Dull(void *arg)
31 {
32 PR_Sleep(PR_SecondsToInterval(dally));
33 if (verbose && force)
34 PR_fprintf(err, "If you see this, the test failed\n");
35 } /* Dull */
37 static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
38 {
39 PLOptStatus os;
40 PLOptState *opt = PL_CreateOptState(argc, argv, "ht:dx");
42 err = PR_GetSpecialFD(PR_StandardError);
44 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
45 {
46 if (PL_OPT_BAD == os) continue;
47 switch (opt->option)
48 {
49 case 'd': /* verbosity */
50 verbose = PR_TRUE;
51 break;
52 case 'x': /* force exit */
53 force = PR_TRUE;
54 break;
55 case 't': /* seconds to dally in child */
56 dally = atoi(opt->value);
57 break;
58 case 'h': /* user wants some guidance */
59 default:
60 Help(); /* so give him an earful */
61 return 2; /* but not a lot else */
62 }
63 }
64 PL_DestroyOptState(opt);
66 if (0 == dally) dally = 10;
68 /*
69 * Create LOCAL and GLOBAL threads
70 */
71 (void)PR_CreateThread(
72 PR_USER_THREAD, Dull, NULL, PR_PRIORITY_NORMAL,
73 PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
75 (void)PR_CreateThread(
76 PR_USER_THREAD, Dull, NULL, PR_PRIORITY_NORMAL,
77 PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
79 if (verbose)
80 PR_fprintf(
81 err, "Main is exiting now. Program should exit %s.\n",
82 (force) ? "immediately" : "after child dally time");
84 if (force)
85 {
86 PR_ProcessExit(0);
87 if (verbose)
88 {
89 PR_fprintf(err, "You should not have gotten here.\n");
90 return 1;
91 }
92 }
93 return 0;
95 }
98 int main(int argc, char **argv)
99 {
100 PRIntn rv;
102 PR_STDIO_INIT();
103 rv = PR_Initialize(RealMain, argc, argv, 0);
104 return rv;
105 } /* main */