Mercurial > hg > rlgwebd
annotate options.js @ 165:59e62710cbb5
rlgwebd.js: prevent races when reading ttyrecs.
DglSession objects read a 12-byte TTYREC header, extract therefrom the
length of the data chunk, and then read the data. In between these two
reads, the file watcher could trigger another readchunk() invocation,
which might attempt to read a header from the beginning of the data
chunk. This usually results in expecting a data chunk of several GB
and failing to create a Buffer for it.
The race is remedied by setting a flag on the DglSession object
whenever readchunk() is called, clearing it when both reads complete,
and refusing to read if it is already set.
author | John "Elwin" Edwards |
---|---|
date | Wed, 07 Jan 2015 13:18:35 -0500 |
parents | 99fbc7c55b81 |
children |
rev | line source |
---|---|
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
1 function setup() { |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
2 if (!("lcred" in sessionStorage)) { |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
3 setstatus("You are not logged in."); |
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
4 return; |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
5 } |
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
6 var url = "/uinfo/email?key=" + sessionStorage.getItem("lcred"); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
7 var req = new XMLHttpRequest(); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
8 req.onreadystatechange = function () { |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
9 if (req.readyState != 4 || req.status != 200) |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
10 return; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
11 var reply = JSON.parse(req.responseText); |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
12 if (!("email" in reply)) { |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
13 setstatus("You are not logged in."); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
14 } |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
15 else { |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
16 setstatus("You are logged in as " + reply.u + "."); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
17 document.getElementById("input_email").value = reply["email"]; |
133
99fbc7c55b81
Options-related UI improvements.
John "Elwin" Edwards <elwin@sdf.org>
parents:
130
diff
changeset
|
18 //document.getElementById("switch").style.display = "block"; |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
19 } |
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
20 } |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
21 req.open('GET', url, true); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
22 req.send(); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
23 } |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
24 |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
25 function setstatus(stattext) { |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
26 var statnode = document.createTextNode(stattext); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
27 var statdiv = document.getElementById("ostat"); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
28 statdiv.replaceChild(statnode, statdiv.firstChild); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
29 } |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
30 |
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
31 function postemail() { |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
32 if (!("lcred" in sessionStorage)) |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
33 return; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
34 var posturl = "/uinfo/email?key=" + sessionStorage.getItem("lcred"); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
35 var msg = {"v": document.getElementById("input_email").value}; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
36 var req = new XMLHttpRequest(); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
37 req.open('POST', posturl, true); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
38 req.send(JSON.stringify(msg)); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
39 } |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
40 |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
41 function postpw() { |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
42 if (!("lcred" in sessionStorage)) |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
43 return; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
44 var posturl = "/uinfo/pw?key=" + sessionStorage.getItem("lcred"); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
45 var msg = {"v": document.getElementById("input_pw").value}; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
46 var req = new XMLHttpRequest(); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
47 req.open('POST', posturl, true); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
48 req.send(JSON.stringify(msg)); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
49 } |