Merge lp:~lihow731/ubuntu/saucy/cpufreqd/fix-for-1162160 into lp:ubuntu/trusty/cpufreqd

Proposed by Leon Liao
Status: Rejected
Rejected by: Jamie Strandboge
Proposed branch: lp:~lihow731/ubuntu/saucy/cpufreqd/fix-for-1162160
Merge into: lp:ubuntu/trusty/cpufreqd
Diff against target: 553 lines (+11/-481)
6 files modified
.pc/619913.patch/src/cpufreqd_acpi_battery.c (+0/-401)
.pc/applied-patches (+0/-2)
.pc/path_max.patch/src/cpufreqd.h (+0/-59)
debian/changelog (+7/-0)
src/cpufreqd.h (+1/-7)
src/cpufreqd_acpi_battery.c (+3/-12)
To merge this branch: bzr merge lp:~lihow731/ubuntu/saucy/cpufreqd/fix-for-1162160
Reviewer Review Type Date Requested Status
Jamie Strandboge Disapprove
Review via email: mp+202195@code.launchpad.net
To post a comment you must log in.
10. By Leon Liao

* Merge 2.4.2-2ubuntu1 from trusty for the buffer overflow bug.
* path_max.patch: Pull upstream patch to fix MAX_PATH_LEN (LP: #1162160 , LP: #1190389)

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Thanks for the patch! I am going to reject this for now because https://launchpad.net/ubuntu/+source/cpufreqd/2.4.2-2ubuntu0.1 was uploaded to saucy-proposed yesterday. Note, normally when preparing an SRU you will provide an isolated patch rather than do a merge like you.

review: Disapprove

Unmerged revisions

10. By Leon Liao

* Merge 2.4.2-2ubuntu1 from trusty for the buffer overflow bug.
* path_max.patch: Pull upstream patch to fix MAX_PATH_LEN (LP: #1162160 , LP: #1190389)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed directory '.pc/619913.patch'
=== removed directory '.pc/619913.patch/src'
=== removed file '.pc/619913.patch/src/cpufreqd_acpi_battery.c'
--- .pc/619913.patch/src/cpufreqd_acpi_battery.c 2013-03-23 21:42:31 +0000
+++ .pc/619913.patch/src/cpufreqd_acpi_battery.c 1970-01-01 00:00:00 +0000
@@ -1,401 +0,0 @@
1/*
2 * Copyright (C) 2002-2006 Mattia Dongili <malattia@linux.it>
3 * George Staikos <staikos@0wned.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <dirent.h>
21#include <errno.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include "cpufreqd_plugin.h"
26#include "cpufreqd_acpi.h"
27#include "cpufreqd_acpi_event.h"
28#include "cpufreqd_acpi_battery.h"
29
30#define POWER_SUPPLY "power_supply"
31#define BATTERY_TYPE "Battery"
32#define ENERGY_FULL "energy_full"
33#define ENERGY_NOW "energy_now"
34#define CHARGE_FULL "charge_full"
35#define CHARGE_NOW "charge_now"
36#define PRESENT "present"
37#define STATUS "status"
38#define CURRENT_NOW "current_now"
39
40struct battery_info {
41 int capacity;
42 int remaining;
43 int present_rate;
44 int level; /* computed percentage */
45 int is_present;
46
47 struct sysfs_class_device *cdev;
48 struct sysfs_attribute *energy_full; /* last full capacity */
49 struct sysfs_attribute *energy_now; /* remaining capacity */
50 struct sysfs_attribute *present;
51 struct sysfs_attribute *status;
52 struct sysfs_attribute *current_now; /* present rate */
53
54 int open;
55};
56
57struct battery_interval {
58 int min, max;
59 struct battery_info *bat;
60};
61
62/* don't want to handle more than 8 batteries... yet */
63static struct battery_info info[8];
64static int bat_dir_num;
65static int avg_battery_level;
66static double check_timeout;
67static double old_time;
68extern struct acpi_configuration acpi_config;
69
70/* validate if the requested battery exists */
71static struct battery_info *get_battery_info(const char *name)
72{
73 int i;
74 struct battery_info *ret = NULL;
75
76 for (i = 0; i < bat_dir_num; i++) {
77 if (strncmp(info[i].cdev->name, name, SYSFS_NAME_LEN) == 0) {
78 ret = &info[i];
79 break;
80 }
81 }
82 return ret;
83}
84
85/* close all the attributes and reset the open status */
86static void close_battery(struct battery_info *binfo) {
87
88 if (!binfo->open) return;
89
90 if (binfo->energy_full)
91 put_attribute(binfo->energy_full);
92 if (binfo->energy_now)
93 put_attribute(binfo->energy_now);
94 if (binfo->present)
95 put_attribute(binfo->present);
96 if (binfo->status)
97 put_attribute(binfo->status);
98 if (binfo->current_now)
99 put_attribute(binfo->current_now);
100
101 binfo->open = 0;
102}
103/* read battery levels as reported by hw */
104static int read_battery(struct battery_info *binfo) {
105 clog(LOG_DEBUG, "%s - reading battery levels\n", binfo->cdev->name);
106
107 if (read_int(binfo->current_now, &binfo->present_rate) != 0) {
108 clog(LOG_ERR, "Skipping %s\n", binfo->cdev->name);
109 return -1;
110 }
111 if (read_int(binfo->energy_now, &binfo->remaining) != 0) {
112 clog(LOG_ERR, "Skipping %s\n", binfo->cdev->name);
113 return -1;
114 }
115 if (read_value(binfo->status) != 0) {
116 clog(LOG_ERR, "Skipping %s\n", binfo->cdev->name);
117 return -1;
118 }
119 clog(LOG_DEBUG, "%s - remaining capacity: %d\n",
120 binfo->cdev->name, binfo->remaining);
121 return 0;
122}
123/* open all the required attributes and set the open status */
124static int open_battery(struct battery_info *binfo) {
125 binfo->open = 1;
126
127 binfo->energy_full = get_class_device_attribute(binfo->cdev, ENERGY_FULL);
128 if (!binfo->energy_full) {
129 /* try the "charge_full" name */
130 binfo->energy_full = get_class_device_attribute(binfo->cdev,
131 CHARGE_FULL);
132 if (!binfo->energy_full)
133 return -1;
134 }
135 binfo->energy_now = get_class_device_attribute(binfo->cdev, ENERGY_NOW);
136 if (!binfo->energy_now) {
137 /* try the "charge_now" name */
138 binfo->energy_now = get_class_device_attribute(binfo->cdev, CHARGE_NOW);
139 if (!binfo->energy_now)
140 return -1;
141 }
142 binfo->present = get_class_device_attribute(binfo->cdev, PRESENT);
143 if (!binfo->present)
144 return -1;
145 binfo->status = get_class_device_attribute(binfo->cdev, STATUS);
146 if (!binfo->status)
147 return -1;
148 binfo->current_now = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
149 if (!binfo->current_now)
150 return -1;
151
152 /* read the last full capacity, this is not going to change
153 * very often, so no need to poke it later */
154 if (read_int(binfo->energy_full, &binfo->capacity) != 0) {
155 clog(LOG_WARNING, "Couldn't read %s capacity (%s)\n",
156 binfo->cdev->name, strerror(errno));
157 return -1;
158 }
159 return 0;
160}
161
162/* set the battery class device into the battery_info array */
163static int clsdev_callback(struct sysfs_class_device *cdev) {
164 clog(LOG_DEBUG, "Got device %s\n", cdev->name);
165 info[bat_dir_num].cdev = cdev;
166 bat_dir_num++;
167 return 0;
168}
169
170/* int acpi_battery_init(void)
171 *
172 * this never fails since batteries are hotpluggable and
173 * we can easily rescan for availability later (see acpi_battery_update
174 * when an event is pending)
175 */
176short int acpi_battery_init(void) {
177 int i;
178
179 find_class_device(POWER_SUPPLY, BATTERY_TYPE, &clsdev_callback);
180 if (bat_dir_num <= 0) {
181 clog(LOG_INFO, "No Batteries found\n");
182 return 0;
183 }
184 /* open the required attributes */
185 for (i = 0; i < bat_dir_num; i++) {
186 clog(LOG_DEBUG, "Opening %s attributes\n", info[i].cdev->name);
187 if (open_battery(&info[i]) != 0) {
188 clog(LOG_WARNING, "Couldn't open %s attributes\n",
189 info[i].cdev->name);
190 close_battery(&info[i]);
191 }
192 }
193 clog(LOG_INFO, "found %d Batter%s\n", bat_dir_num,
194 bat_dir_num > 1 ? "ies" : "y");
195 return 0;
196}
197short int acpi_battery_exit(void) {
198 /* also reset values since this is called on pending
199 * acpi events to rescan batteries
200 */
201 while (--bat_dir_num >= 0) {
202 close_battery(&info[bat_dir_num]);
203 put_class_device(info[bat_dir_num].cdev);
204 info[bat_dir_num].cdev = NULL;
205 }
206 bat_dir_num = 0;
207 clog(LOG_INFO, "exited.\n");
208 return 0;
209}
210/*
211 * Parses entries of the form %d-%d (min-max)
212 */
213int acpi_battery_parse(const char *ev, void **obj) {
214 char battery_name[32];
215 struct battery_interval *ret = calloc(1, sizeof(struct battery_interval));
216 if (ret == NULL) {
217 clog(LOG_ERR, "couldn't make enough room for battery_interval (%s)\n",
218 strerror(errno));
219 return -1;
220 }
221
222 clog(LOG_DEBUG, "called with: %s\n", ev);
223
224 /* try to parse the %[a-zA-Z0-9]:%d-%d format first */
225 if (sscanf(ev, "%32[a-zA-Z0-9]:%d-%d", battery_name, &(ret->min), &(ret->max)) == 3) {
226 /* validate battery name and assign pointer to struct battery_info */
227 if ((ret->bat = get_battery_info(battery_name)) == NULL) {
228 clog(LOG_ERR, "non existent battery %s!\n",
229 battery_name);
230 free(ret);
231 return -1;
232 }
233 clog(LOG_INFO, "parsed %s %d-%d\n", ret->bat->cdev->name, ret->min, ret->max);
234
235 } else if (sscanf(ev, "%32[a-zA-Z0-9]:%d", battery_name, &(ret->min)) == 2) {
236 /* validate battery name and assign pointer to struct battery_info */
237 if ((ret->bat = get_battery_info(battery_name)) == NULL) {
238 clog(LOG_ERR, "non existent battery %s!\n",
239 battery_name);
240 free(ret);
241 return -1;
242 }
243 ret->max = ret->min;
244 clog(LOG_INFO, "parsed %s %d\n", ret->bat->cdev->name, ret->min);
245
246 } else if (sscanf(ev, "%d-%d", &(ret->min), &(ret->max)) == 2) {
247 clog(LOG_INFO, "parsed %d-%d\n", ret->min, ret->max);
248
249 } else if (sscanf(ev, "%d", &(ret->min)) == 1) {
250 ret->max = ret->min;
251 clog(LOG_INFO, "parsed %d\n", ret->min);
252
253 } else {
254 free(ret);
255 return -1;
256 }
257
258 if (ret->min > ret->max) {
259 clog(LOG_ERR, "Min higher than Max?\n");
260 free(ret);
261 return -1;
262 }
263
264 *obj = ret;
265 return 0;
266}
267
268
269int acpi_battery_evaluate(const void *s) {
270 const struct battery_interval *bi = (const struct battery_interval *)s;
271 int level = avg_battery_level;
272
273 if (bi != NULL && bi->bat != NULL) {
274 level = bi->bat->present->value ? bi->bat->level : -1;
275 }
276
277 clog(LOG_DEBUG, "called %d-%d [%s:%d]\n", bi->min, bi->max,
278 bi != NULL && bi->bat != NULL ? bi->bat->cdev->name : "Avg", level);
279
280 return (level >= bi->min && level <= bi->max) ? MATCH : DONT_MATCH;
281}
282
283/* static int acpi_battery_update(void)
284 *
285 * reads temperature valuse ant compute a medium value
286 */
287int acpi_battery_update(void) {
288 int i = 0, total_capacity = 0, total_remaining = 0, n_read = 0;
289 double elapsed_time = 0.0;
290 double current_time = 0.0;
291#if 0
292 int remaining_hours=0, remaining_minutes=0;
293 double remaining_secs = 0.0;
294#endif
295 struct cpufreqd_info * cinfo = get_cpufreqd_info();
296
297 current_time = (double)cinfo->timestamp.tv_sec + (cinfo->timestamp.tv_usec/1000000.0);
298 elapsed_time = current_time - old_time;
299 old_time = current_time;
300 /* decrement timeout */
301 check_timeout -= elapsed_time;
302
303 /* if there is a pending event rescan batteries */
304 if (is_event_pending()) {
305 clog(LOG_NOTICE, "Re-scanning available batteries\n");
306 acpi_battery_exit();
307 acpi_battery_init();
308 /* force timeout expiration */
309 check_timeout = -1;
310 }
311
312 /* Read battery informations */
313 for (i = 0; i < bat_dir_num; i++) {
314
315 if (read_int(info[i].present, &info[i].is_present) != 0) {
316 clog(LOG_INFO, "Skipping %s\n", info[i].cdev->name);
317 continue;
318 }
319
320 /* if battery not open or not present skip to the next one */
321 if (!info[i].open || !info[i].is_present || info[i].capacity <= 0) {
322 continue;
323 }
324 clog(LOG_INFO, "%s - present\n", info[i].cdev->name);
325
326 /* if check_timeout is expired */
327 if (check_timeout <= 0) {
328 if (read_battery(&info[i]) == 0)
329 n_read++;
330 else
331 clog(LOG_INFO, "Unable to read battery %s\n",
332 info[i].cdev->name);
333 } else {
334 /* estimate battery life */
335 clog(LOG_DEBUG, "%s - estimating battery life (timeout: %0.2f"
336 " - status: %s)\n",
337 info[i].cdev->name, check_timeout,
338 info[i].status->value);
339
340 if (strncmp(info[i].status->value, "Discharging", 11) == 0)
341 info[i].remaining -= ((float)info[i].present_rate * elapsed_time) / 3600.0;
342
343 else if (strncmp(info[i].status->value, "Full", 4) != 0 &&
344 (int)info[i].remaining < info[i].capacity)
345 info[i].remaining += ((float)info[i].present_rate * elapsed_time) / 3600.0;
346
347 clog(LOG_DEBUG, "%s - remaining capacity: %d\n",
348 info[i].cdev->name, info[i].remaining);
349 }
350 n_read++;
351 total_remaining += info[i].remaining;
352 total_capacity += info[i].capacity;
353
354 info[i].level = 100 * (info[i].remaining / (double)info[i].capacity);
355 clog(LOG_INFO, "battery life for %s is %d%%\n", info[i].cdev->name, info[i].level);
356#if 0
357 if (info[i].present_rate > 0) {
358 remaining_secs = 3600 * info[i].remaining / info[i].present_rate;
359 remaining_hours = (int) remaining_secs / 3600;
360 remaining_minutes = (remaining_secs - (remaining_hours * 3600)) / 60;
361 clog(LOG_INFO, "battery time for %s is %d:%0.2d\n",
362 info[i].cdev->name, remaining_hours, remaining_minutes);
363 }
364#endif
365 } /* end info loop */
366
367 /* check_timeout is global for all batteries, so update it after all batteries got updated */
368 if (check_timeout <= 0) {
369 check_timeout = acpi_config.battery_update_interval;
370 }
371
372 /* calculates medium battery life between all batteries */
373 if (total_capacity > 0)
374 avg_battery_level = 100 * (total_remaining / (double)total_capacity);
375 else
376 avg_battery_level = -1;
377
378 clog(LOG_INFO, "average battery life %d%%\n", avg_battery_level);
379
380 return 0;
381}
382
383
384#if 0
385static struct cpufreqd_keyword kw[] = {
386 { .word = "battery_interval", .parse = &acpi_battery_parse, .evaluate = &acpi_battery_evaluate },
387 { .word = NULL, .parse = NULL, .evaluate = NULL, .free = NULL }
388};
389
390static struct cpufreqd_plugin acpi_battery = {
391 .plugin_name = "acpi_battery_plugin", /* plugin_name */
392 .keywords = kw, /* config_keywords */
393 .plugin_init = &acpi_battery_init, /* plugin_init */
394 .plugin_exit = &acpi_battery_exit, /* plugin_exit */
395 .plugin_update = &acpi_battery_update, /* plugin_update */
396};
397
398struct cpufreqd_plugin *create_plugin (void) {
399 return &acpi_battery;
400}
401#endif
4020
=== removed file '.pc/applied-patches'
--- .pc/applied-patches 2014-01-04 03:51:23 +0000
+++ .pc/applied-patches 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1619913.patch
2path_max.patch
30
=== removed directory '.pc/path_max.patch'
=== removed directory '.pc/path_max.patch/src'
=== removed file '.pc/path_max.patch/src/cpufreqd.h'
--- .pc/path_max.patch/src/cpufreqd.h 2014-01-04 03:51:23 +0000
+++ .pc/path_max.patch/src/cpufreqd.h 1970-01-01 00:00:00 +0000
@@ -1,59 +0,0 @@
1/*
2 * Copyright (C) 2002-2008 Mattia Dongili <malattia@linux.it>
3 * George Staikos <staikos@0wned.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#ifndef __CPUFREQD_H__
25#define __CPUFREQD_H__
26
27#define __CPUFREQD_VERSION__ VERSION
28#define __CPUFREQD_MAINTAINER__ "malattia@linux.it"
29
30#ifdef __GNUC__
31# define __UNUSED__ __attribute__((unused))
32#else
33# define __UNUSED__
34#endif
35
36#ifndef CPUFREQD_CONFDIR
37# define CPUFREQD_CONFDIR "/etc/"
38#endif
39
40#ifndef CPUFREQD_LIBDIR
41# define CPUFREQD_LIBDIR "/usr/lib/cpufreqd/"
42#endif
43
44#ifndef CPUFREQD_STATEDIR
45# define CPUFREQD_STATEDIR "/var/"
46#endif
47
48#define CPUFREQD_CONFIG CPUFREQD_CONFDIR"cpufreqd.conf"
49# define CPUFREQD_PIDFILE CPUFREQD_STATEDIR"run/cpufreqd.pid"
50#define CPUFREQD_SOCKFILE "/tmp/cpufreqd.sock"
51
52
53#define DEFAULT_POLL 1
54#define DEFAULT_VERBOSITY 3
55
56#define MAX_STRING_LEN 255
57#define MAX_PATH_LEN 512
58
59#endif /* __CPUFREQD_H__ */
600
=== modified file 'debian/changelog'
--- debian/changelog 2014-01-04 03:51:23 +0000
+++ debian/changelog 2014-01-18 09:14:08 +0000
@@ -1,3 +1,10 @@
1cpufreqd (2.4.2-2ubuntu1ppa) saucy; urgency=low
2
3 * Merge 2.4.2-2ubuntu1 from trusty for the buffer overflow bug.
4 - fix bug LP: #1190389 , too.
5
6 -- Li-Hao Liao (Leon Liao) <lihow731@gmail.com> Sat, 18 Jan 2014 15:16:52 +0800
7
1cpufreqd (2.4.2-2ubuntu1) trusty; urgency=medium8cpufreqd (2.4.2-2ubuntu1) trusty; urgency=medium
29
3 * path_max.patch: Pull upstream patch to fix MAX_PATH_LEN (LP: #1162160)10 * path_max.patch: Pull upstream patch to fix MAX_PATH_LEN (LP: #1162160)
411
=== modified file 'src/cpufreqd.h'
--- src/cpufreqd.h 2014-01-04 03:51:23 +0000
+++ src/cpufreqd.h 2014-01-18 09:14:08 +0000
@@ -54,12 +54,6 @@
54#define DEFAULT_VERBOSITY 354#define DEFAULT_VERBOSITY 3
5555
56#define MAX_STRING_LEN 25556#define MAX_STRING_LEN 255
5757#define MAX_PATH_LEN 512
58#ifdef HAVE_LIMITS_H
59#include <limits.h>
60#define MAX_PATH_LEN PATH_MAX
61#else
62#define MAX_PATH_LEN 512
63#endif
6458
65#endif /* __CPUFREQD_H__ */59#endif /* __CPUFREQD_H__ */
6660
=== modified file 'src/cpufreqd_acpi_battery.c'
--- src/cpufreqd_acpi_battery.c 2013-03-23 21:42:31 +0000
+++ src/cpufreqd_acpi_battery.c 2014-01-18 09:14:08 +0000
@@ -36,7 +36,6 @@
36#define PRESENT "present"36#define PRESENT "present"
37#define STATUS "status"37#define STATUS "status"
38#define CURRENT_NOW "current_now"38#define CURRENT_NOW "current_now"
39#define POWER_NOW "power_now"
4039
41struct battery_info {40struct battery_info {
42 int capacity;41 int capacity;
@@ -146,13 +145,9 @@
146 binfo->status = get_class_device_attribute(binfo->cdev, STATUS);145 binfo->status = get_class_device_attribute(binfo->cdev, STATUS);
147 if (!binfo->status)146 if (!binfo->status)
148 return -1;147 return -1;
149 binfo->current_now = get_class_device_attribute(binfo->cdev, POWER_NOW);148 binfo->current_now = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
150 if (!binfo->current_now) {149 if (!binfo->current_now)
151 /* try the "current_now" name */150 return -1;
152 binfo->current_now = get_class_device_attribute(binfo->cdev, CURRENT_NOW);
153 if (!binfo->current_now)
154 return -1;
155 }
156151
157 /* read the last full capacity, this is not going to change152 /* read the last full capacity, this is not going to change
158 * very often, so no need to poke it later */153 * very often, so no need to poke it later */
@@ -316,10 +311,6 @@
316311
317 /* Read battery informations */312 /* Read battery informations */
318 for (i = 0; i < bat_dir_num; i++) {313 for (i = 0; i < bat_dir_num; i++) {
319 if (!info[i].open) {
320 clog(LOG_INFO, "Skipping %s (closed)\n", info[i].cdev->name);
321 continue;
322 }
323314
324 if (read_int(info[i].present, &info[i].is_present) != 0) {315 if (read_int(info[i].present, &info[i].is_present) != 0) {
325 clog(LOG_INFO, "Skipping %s\n", info[i].cdev->name);316 clog(LOG_INFO, "Skipping %s\n", info[i].cdev->name);

Subscribers

People subscribed via source and target branches

to all changes: