Merge lp:~zhangew401/yelp-scope/bug-fixes into lp:yelp-scope

Proposed by Zhang Enwei
Status: Work in progress
Proposed branch: lp:~zhangew401/yelp-scope/bug-fixes
Merge into: lp:yelp-scope
Diff against target: 198 lines (+73/-40)
6 files modified
.bzrignore (+8/-0)
CMakeLists.txt (+23/-9)
manifest.json (+0/-16)
manifest.json.in (+1/-1)
src/yelp.go (+20/-10)
tests/autopilot/yelp/test_generic.py.in (+21/-4)
To merge this branch: bzr merge lp:~zhangew401/yelp-scope/bug-fixes
Reviewer Review Type Date Requested Status
Kyle Nitzsche Pending
Review via email: mp+306831@code.launchpad.net

Description of the change

Fix lp:1626381.
My first thought is to catch the panic, but I found it is throw by runtime.throw, not by runtime.panic. Therefore I cannot catch it by recover().
The "freelist empty" error generally means that the garbage collector has
collected a pointer that is still live. The GC put the memory on the
freelist, but then the memory was changed by the program, breaking the
freelist.

To post a comment you must log in.
Revision history for this message
Zhang Enwei (zhangew401) wrote :

I reproduced it. Checking.

lp:~zhangew401/yelp-scope/bug-fixes updated
74. By Zhang Enwei

add some error checking

Unmerged revisions

74. By Zhang Enwei

add some error checking

73. By Zhang Enwei

Remove useless code

72. By Zhang Enwei

Format the code

71. By Zhang Enwei

Fix null pointer panic

70. By Zhang Enwei

fix lp:1626381 and lp:1609282

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2016-03-29 15:19:44 +0000
3+++ .bzrignore 2016-10-11 12:25:38 +0000
4@@ -29,3 +29,11 @@
5 src/com.canonical.scopes.yelp_yelp
6 src/com.canonical.scopes.yelp_yelp.ini
7 src/com.canonical.scopes.yelp_yelp.ini.needtranslate
8+temp.json
9+test.sh
10+data/content.json
11+src/yelp1.go
12+src/yelp2.go
13+src/yelp_dep.go
14+src/CMakeLists_.txt
15+scope-registry.log
16
17=== modified file 'CMakeLists.txt'
18--- CMakeLists.txt 2016-07-11 02:26:09 +0000
19+++ CMakeLists.txt 2016-10-11 12:25:38 +0000
20@@ -20,7 +20,7 @@
21 set(IS_GO_SCOPE True)
22 set(USES_DEPARTMENTS True)
23 set(SEARCH_TEST_TERM test)
24-set(VERSION 1.6)
25+set(VERSION 1.7)
26 set(PACKAGE_NAME com.canonical.scopes.yelp)
27
28 set(PKG_PREFIX "com.canonical.scopes")
29@@ -36,13 +36,27 @@
30 add_Subdirectory(po)
31 add_subdirectory(tests)
32
33-configure_file (
34- "manifest.json.in"
35- "manifest.json"
36+#This command figures out the target architecture and puts it into the manifest file
37+execute_process(
38+ COMMAND dpkg-architecture -qDEB_HOST_ARCH
39+ OUTPUT_VARIABLE CLICK_ARCH
40+ OUTPUT_STRIP_TRAILING_WHITESPACE
41 )
42
43-install(FILES manifest.json DESTINATION "/")
44-install(FILES "scope-security.json" DESTINATION "/")
45-
46-
47-install (PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/src/${SCOPE_CONFINED_NAME} DESTINATION ${SCOPE_INSTALLDIR})
48+if (${CLICK_ARCH} STREQUAL "arm64")
49+ set(TOOLCHAIN_PREFIX aarch64-linux-gnu)
50+elseif (${CLICK_ARCH} STREQUAL "armhf")
51+ set(TOOLCHAIN_PREFIX arm-linux-gnueabihf)
52+elseif (${CLICK_ARCH} STREQUAL "i386")
53+ set(TOOLCHAIN_PREFIX i386-linux-gnu)
54+elseif (${CLICK_ARCH} STREQUAL "amd64")
55+ set(TOOLCHAIN_PREFIX x86_64-linux-gnu)
56+endif()
57+
58+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/manifest.json.in ${CMAKE_CURRENT_BINARY_DIR}/manifest.json)
59+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scope-security.json ${CMAKE_CURRENT_BINARY_DIR}/scope-security.json)
60+
61+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.json DESTINATION "/")
62+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/scope-security.json DESTINATION "/")
63+
64+install (PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/src/${SCOPE_CONFINED_NAME} DESTINATION ${SCOPE_INSTALLDIR}/${TOOLCHAIN_PREFIX})
65
66=== removed file 'manifest.json'
67--- manifest.json 2016-07-11 02:26:09 +0000
68+++ manifest.json 1970-01-01 00:00:00 +0000
69@@ -1,16 +0,0 @@
70-{
71- "description": "Yelp scope",
72- "framework": "ubuntu-sdk-15.04.4",
73- "architecture": "armhf",
74- "hooks": {
75- "yelp": {
76- "scope": "yelp",
77- "apparmor": "scope-security.json"
78- }
79- },
80- "icon": "icon",
81- "maintainer": "Canonical Content Partners <canonical-content-partners@canonical.com>",
82- "name": "com.canonical.scopes.yelp",
83- "title": "Yelp scope",
84- "version": "1.6"
85-}
86
87=== modified file 'manifest.json.in'
88--- manifest.json.in 2016-04-28 07:37:52 +0000
89+++ manifest.json.in 2016-10-11 12:25:38 +0000
90@@ -1,7 +1,7 @@
91 {
92 "description": "Yelp scope",
93 "framework": "ubuntu-sdk-15.04.4",
94- "architecture": "armhf",
95+ "architecture": "@CLICK_ARCH@",
96 "hooks": {
97 "yelp": {
98 "scope": "yelp",
99
100=== modified file 'src/yelp.go'
101--- src/yelp.go 2016-04-14 15:41:23 +0000
102+++ src/yelp.go 2016-10-11 12:25:38 +0000
103@@ -184,19 +184,25 @@
104 var client http.Client
105 var method string = "GET"
106 var url string = yl.buildUrl(params)
107- req, _ := oauth.NewRequest(method, url, params, credentials)
108-
109- resp, _ := client.Do(req.HttpRequest())
110- defer resp.Body.Close()
111- decoder := json.NewDecoder(resp.Body)
112- return decoder.Decode(result)
113-
114+ req, reqerr := oauth.NewRequest(method, url, params, credentials)
115+ if reqerr != nil {
116+ log.Println("=== YELP. NewRequest error:", reqerr.Error())
117+ return reqerr
118+ }
119+
120+ resp, err := client.Do(req.HttpRequest())
121+ if resp != nil {
122+ defer resp.Body.Close()
123+ }
124+ if err != nil {
125+ return err
126+ }
127+ return json.NewDecoder(resp.Body).Decode(result)
128 }
129
130 func (yl *YelpScope) getDepts(result interface{}) error {
131 deptfile, _ := os.Open(yl.Dir + "/depts.json")
132- decoder := json.NewDecoder(deptfile)
133- return decoder.Decode(result)
134+ return json.NewDecoder(deptfile).Decode(result)
135 }
136
137 func (yl *YelpScope) getLayout() string {
138@@ -366,7 +372,10 @@
139 var deptlist1 deptlist
140 err = yl.getDepts(&deptlist1)
141 for _, v := range deptlist1.Depts {
142- newdept, _ := scopes.NewDepartment(v.Label, q, gettext.Gettext(v.Name))
143+ newdept, err := scopes.NewDepartment(v.Label, q, gettext.Gettext(v.Name))
144+ if err != nil {
145+ continue
146+ }
147 rootDept.AddSubdepartment(newdept)
148 if len(v.Subs) != 0 {
149 for _, s := range v.Subs {
150@@ -419,6 +428,7 @@
151 }
152 // call to the web api
153 if err := yl.get(queryParams, &response); err != nil {
154+ log.Printf("=== YELP. get method return error:%q\n", err.Error())
155 return err
156 }
157 if response.Error.Text != "" {
158
159=== modified file 'tests/autopilot/yelp/test_generic.py.in'
160--- tests/autopilot/yelp/test_generic.py.in 2016-07-11 02:26:09 +0000
161+++ tests/autopilot/yelp/test_generic.py.in 2016-10-11 12:25:38 +0000
162@@ -94,15 +94,32 @@
163
164 def test_executable_exists(self):
165 """Verify the go executable or .so exists"""
166-
167+ cmd = ["dpkg", "--print-architecture"]
168+ outp = subprocess.check_output(cmd)
169+ outstring = outp.decode(encoding).strip()
170+ if outstring == "armhf":
171+ libpath = "arm-linux-gnueabihf"
172+ elif outstring == "arm64":
173+ libpath = "aarch64-linux-gnu"
174+ elif outstring == "i386":
175+ libpath = "i386-linux-gnu"
176+ elif outstring == "amd64":
177+ libpath = "x86_64-linux-gnu"
178+ else:
179+ libpath = ""
180 if @IS_GO_SCOPE@:
181 exec_path = os.path.join(scope_path, scope_id)
182- self.assertTrue(os.path.isfile(exec_path), exec_path + ' does not exist')
183- self.assertTrue(os.access(exec_path, os.X_OK), 'access error on ' + exec_path)
184+ exec_path_platform = os.path.join(scope_path, libpath, scope_id)
185+ exec_exist = os.path.isfile(exec_path) or os.path.isfile(exec_path_platform)
186+ self.assertTrue(exec_exist, exec_path + ' or ' + exec_path_platform + ' does not exist')
187+ exec_access = os.access(exec_path, os.X_OK) or os.access(exec_path_platform, os.X_OK)
188+ self.assertTrue(exec_access, 'access error on ' + exec_path + ' or ' + exec_path_platform)
189 else:
190 lib = "lib" + scope_id + ".so"
191 so_path = os.path.join(scope_path, lib)
192- self.assertTrue(os.path.isfile(so_path), so_path + ' does not exist')
193+ so_path_platform = os.path.join(scope_path, libpath, lib)
194+ so_file_exist = os.path.isfile(so_path) or os.path.isfile(so_path_platform)
195+ self.assertTrue(so_file_exist, so_path + ' or ' + so_path_platform + ' does not exist')
196
197 def test_ini_scopeconfig_fields_untranslated(self):
198 """Verify the ini file has some REQUIRED key/value pairs"""

Subscribers

People subscribed via source and target branches

to all changes: