Skip to content

Commit 261ed75

Browse files
author
The Android Open Source Project
committed
auto import from //branches/cupcake/...@132276
1 parent 1b8e5a6 commit 261ed75

File tree

6 files changed

+173
-45
lines changed

6 files changed

+173
-45
lines changed

init/devices.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,13 @@ static struct perms_ devperms[] = {
123123
{ "/dev/msm_pcm_ctl", 0660, AID_SYSTEM, AID_AUDIO, 1 },
124124
{ "/dev/msm_snd", 0660, AID_SYSTEM, AID_AUDIO, 1 },
125125
{ "/dev/msm_mp3", 0660, AID_SYSTEM, AID_AUDIO, 1 },
126+
{ "/dev/msm_audpre", 0660, AID_SYSTEM, AID_AUDIO, 0 },
127+
{ "/dev/htc-acoustic", 0660, AID_SYSTEM, AID_AUDIO, 0 },
126128
{ "/dev/smd0", 0640, AID_RADIO, AID_RADIO, 0 },
127129
{ "/dev/qmi", 0640, AID_RADIO, AID_RADIO, 0 },
128130
{ "/dev/qmi0", 0640, AID_RADIO, AID_RADIO, 0 },
129131
{ "/dev/qmi1", 0640, AID_RADIO, AID_RADIO, 0 },
130132
{ "/dev/qmi2", 0640, AID_RADIO, AID_RADIO, 0 },
131-
{ "/dev/htc-acoustic", 0640, AID_RADIO, AID_RADIO, 0 },
132133
{ NULL, 0, 0, 0, 0 },
133134
};
134135

libpixelflinger/Android.mk

+8-6
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ ifeq ($(TARGET_ARCH),arm)
4848
PIXELFLINGER_CFLAGS += -fstrict-aliasing -fomit-frame-pointer
4949
endif
5050

51-
LOCAL_SHARED_LIBRARIES := \
52-
libhardware_legacy \
53-
libcutils
51+
LOCAL_SHARED_LIBRARIES := libcutils
5452

5553
ifneq ($(TARGET_ARCH),arm)
5654
# Required to define logging functions on the simulator.
@@ -63,15 +61,19 @@ endif
6361
# Shared library
6462
#
6563

66-
ifneq ($(BUILD_TINY_ANDROID),true)
6764
LOCAL_MODULE:= libpixelflinger
6865
LOCAL_SRC_FILES := $(PIXELFLINGER_SRC_FILES)
69-
LOCAL_CFLAGS := $(PIXELFLINGER_CFLAGS) -DWITH_LIB_HARDWARE
66+
LOCAL_CFLAGS := $(PIXELFLINGER_CFLAGS)
67+
ifneq ($(BUILD_TINY_ANDROID),true)
68+
# Really this should go away entirely or at least not depend on
69+
# libhardware, but this at least gets us built.
70+
LOCAL_SHARED_LIBRARIES += libhardware_legacy
71+
LOCAL_CFLAGS += -DWITH_LIB_HARDWARE
72+
endif
7073
ifeq ($(TARGET_ARCH),arm)
7174
LOCAL_WHOLE_STATIC_LIBRARIES := libpixelflinger_armv6
7275
endif
7376
include $(BUILD_SHARED_LIBRARY)
74-
endif
7577

7678
#
7779
# Static library version

toolbox/top.c

+53-19
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@
4141

4242
struct cpu_info {
4343
long unsigned utime, ntime, stime, itime;
44+
long unsigned iowtime, irqtime, sirqtime;
4445
};
4546

47+
#define PROC_NAME_LEN 64
48+
#define THREAD_NAME_LEN 32
49+
4650
struct proc_info {
4751
struct proc_info *next;
4852
pid_t pid;
4953
pid_t tid;
5054
uid_t uid;
5155
gid_t gid;
52-
char name[256];
56+
char name[PROC_NAME_LEN];
57+
char tname[THREAD_NAME_LEN];
5358
char state;
5459
long unsigned utime;
5560
long unsigned stime;
@@ -69,7 +74,7 @@ struct proc_list {
6974
#define die(...) { fprintf(stderr, __VA_ARGS__); exit(EXIT_FAILURE); }
7075

7176
#define INIT_PROCS 50
72-
#define THREAD_MULT 4
77+
#define THREAD_MULT 8
7378
static struct proc_info **old_procs, **new_procs;
7479
static int num_old_procs, num_new_procs;
7580
static struct proc_info *free_procs;
@@ -228,7 +233,8 @@ static void read_procs(void) {
228233

229234
file = fopen("/proc/stat", "r");
230235
if (!file) die("Could not open /proc/stat.\n");
231-
fscanf(file, "cpu %lu %lu %lu %lu", &new_cpu.utime, &new_cpu.ntime, &new_cpu.stime, &new_cpu.itime);
236+
fscanf(file, "cpu %lu %lu %lu %lu %lu %lu %lu", &new_cpu.utime, &new_cpu.ntime, &new_cpu.stime,
237+
&new_cpu.itime, &new_cpu.iowtime, &new_cpu.irqtime, &new_cpu.sirqtime);
232238
fclose(file);
233239

234240
proc_num = 0;
@@ -237,7 +243,9 @@ static void read_procs(void) {
237243
continue;
238244

239245
pid = atoi(pid_dir->d_name);
240-
246+
247+
struct proc_info cur_proc;
248+
241249
if (!threads) {
242250
proc = alloc_proc();
243251

@@ -254,6 +262,12 @@ static void read_procs(void) {
254262

255263
proc->num_threads = 0;
256264
} else {
265+
sprintf(filename, "/proc/%d/cmdline", pid);
266+
read_cmdline(filename, &cur_proc);
267+
268+
sprintf(filename, "/proc/%d/status", pid);
269+
read_status(filename, &cur_proc);
270+
257271
proc = NULL;
258272
}
259273

@@ -275,11 +289,9 @@ static void read_procs(void) {
275289
sprintf(filename, "/proc/%d/task/%d/stat", pid, tid);
276290
read_stat(filename, proc);
277291

278-
sprintf(filename, "/proc/%d/task/%d/cmdline", pid, tid);
279-
read_cmdline(filename, proc);
280-
281-
sprintf(filename, "/proc/%d/task/%d/status", pid, tid);
282-
read_status(filename, proc);
292+
strcpy(proc->name, cur_proc.name);
293+
proc->uid = cur_proc.uid;
294+
proc->gid = cur_proc.gid;
283295

284296
add_proc(proc_num++, proc);
285297
} else {
@@ -315,8 +327,9 @@ static int read_stat(char *filename, struct proc_info *proc) {
315327
if (!open_paren || !close_paren) return 1;
316328

317329
*open_paren = *close_paren = '\0';
318-
strcpy(proc->name, open_paren + 1);
319-
330+
strncpy(proc->tname, open_paren + 1, THREAD_NAME_LEN);
331+
proc->tname[THREAD_NAME_LEN-1] = 0;
332+
320333
/* Scan rest of string. */
321334
sscanf(close_paren + 1, " %c %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
322335
"%lu %lu %*d %*d %*d %*d %*d %*d %*d %lu %ld",
@@ -347,8 +360,11 @@ static int read_cmdline(char *filename, struct proc_info *proc) {
347360
if (!file) return 1;
348361
fgets(line, MAX_LINE, file);
349362
fclose(file);
350-
if (strlen(line) > 0)
351-
strcpy(proc->name, line);
363+
if (strlen(line) > 0) {
364+
strncpy(proc->name, line, PROC_NAME_LEN);
365+
proc->name[PROC_NAME_LEN-1] = 0;
366+
} else
367+
proc->name[0] = 0;
352368
return 0;
353369
}
354370

@@ -391,16 +407,34 @@ static void print_procs(void) {
391407
}
392408
}
393409

394-
total_delta_time = (new_cpu.utime + new_cpu.ntime + new_cpu.stime + new_cpu.itime)
395-
- (old_cpu.utime + old_cpu.ntime + old_cpu.stime + old_cpu.itime);
410+
total_delta_time = (new_cpu.utime + new_cpu.ntime + new_cpu.stime + new_cpu.itime
411+
+ new_cpu.iowtime + new_cpu.irqtime + new_cpu.sirqtime)
412+
- (old_cpu.utime + old_cpu.ntime + old_cpu.stime + old_cpu.itime
413+
+ old_cpu.iowtime + old_cpu.irqtime + old_cpu.sirqtime);
396414

397415
qsort(new_procs, num_new_procs, sizeof(struct proc_info *), proc_cmp);
398416

399417
printf("\n\n\n");
418+
printf("User %ld%%, System %ld%%, IOW %ld%%, IRQ %ld%%\n",
419+
((new_cpu.utime + new_cpu.ntime) - (old_cpu.utime + old_cpu.ntime)) * 100 / total_delta_time,
420+
((new_cpu.stime ) - (old_cpu.stime)) * 100 / total_delta_time,
421+
((new_cpu.iowtime) - (old_cpu.iowtime)) * 100 / total_delta_time,
422+
((new_cpu.irqtime + new_cpu.sirqtime)
423+
- (old_cpu.irqtime + old_cpu.sirqtime)) * 100 / total_delta_time);
424+
printf("User %ld + Nice %ld + Sys %ld + Idle %ld + IOW %ld + IRQ %ld + SIRQ %ld = %ld\n",
425+
new_cpu.utime - old_cpu.utime,
426+
new_cpu.ntime - old_cpu.ntime,
427+
new_cpu.stime - old_cpu.stime,
428+
new_cpu.itime - old_cpu.itime,
429+
new_cpu.iowtime - old_cpu.iowtime,
430+
new_cpu.irqtime - old_cpu.irqtime,
431+
new_cpu.sirqtime - old_cpu.sirqtime,
432+
total_delta_time);
433+
printf("\n");
400434
if (!threads)
401435
printf("%5s %4s %1s %5s %7s %7s %-8s %s\n", "PID", "CPU%", "S", "#THR", "VSS", "RSS", "UID", "Name");
402436
else
403-
printf("%5s %5s %4s %1s %7s %7s %-8s %s\n", "PID", "TID", "CPU%", "S", "VSS", "RSS", "UID", "Name");
437+
printf("%5s %5s %4s %1s %7s %7s %-8s %-15s %s\n", "PID", "TID", "CPU%", "S", "VSS", "RSS", "UID", "Thread", "Proc");
404438

405439
for (i = 0; i < num_new_procs; i++) {
406440
proc = new_procs[i];
@@ -423,10 +457,10 @@ static void print_procs(void) {
423457
}
424458
if (!threads)
425459
printf("%5d %3ld%% %c %5d %6ldK %6ldK %-8.8s %s\n", proc->pid, proc->delta_time * 100 / total_delta_time, proc->state, proc->num_threads,
426-
proc->vss / 1024, proc->rss * getpagesize() / 1024, user_str, proc->name);
460+
proc->vss / 1024, proc->rss * getpagesize() / 1024, user_str, proc->name[0] != 0 ? proc->name : proc->tname);
427461
else
428-
printf("%5d %5d %3ld%% %c %6ldK %6ldK %-8.8s %s\n", proc->pid, proc->tid, proc->delta_time * 100 / total_delta_time, proc->state,
429-
proc->vss / 1024, proc->rss * getpagesize() / 1024, user_str, proc->name);
462+
printf("%5d %5d %3ld%% %c %6ldK %6ldK %-8.8s %-15s %s\n", proc->pid, proc->tid, proc->delta_time * 100 / total_delta_time, proc->state,
463+
proc->vss / 1024, proc->rss * getpagesize() / 1024, user_str, proc->tname, proc->name);
430464
}
431465
}
432466

vold/misc.c

+75-15
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ void *read_file(char *filename, ssize_t *_size)
4949

5050
/* slurp it into our buffer */
5151
ret = read(fd, buffer, size);
52-
if (ret != size)
52+
if (ret != size) {
53+
free(buffer);
54+
buffer = NULL;
5355
goto bail;
56+
}
5457

5558
/* let the caller know how big it is */
5659
*_size = size;
@@ -59,33 +62,90 @@ void *read_file(char *filename, ssize_t *_size)
5962
close(fd);
6063
return buffer;
6164
}
62-
char *truncate_sysfs_path(char *path, int num_elements_to_remove, char *buffer)
65+
66+
char *truncate_sysfs_path(char *path, int count, char *buffer, size_t bufflen)
6367
{
64-
int i;
68+
char* p;
6569

66-
strcpy(buffer, path);
70+
strlcpy(buffer, path, bufflen);
71+
p = buffer + strlen(buffer);
6772

68-
for (i = 0; i < num_elements_to_remove; i++) {
69-
char *p = &buffer[strlen(buffer)-1];
73+
for ( ; count > 0; count-- ) {
74+
while (p > buffer && p[-1] != '/') {
75+
p--;
76+
}
77+
if (p == buffer)
78+
break;
7079

71-
for (p = &buffer[strlen(buffer) -1]; *p != '/'; p--);
72-
*p = '\0';
80+
p -= 1;
7381
}
82+
p[0] = '\0';
7483

7584
return buffer;
7685
}
7786

78-
char *read_sysfs_var(char *buffer, size_t maxlen, char *devpath, char *var)
87+
/* used to read the first line of a /sys file into a heap-allocated buffer
88+
* this assumes that reading the file returns a list of zero-terminated strings,
89+
* each could also have a terminating \n before the 0
90+
*
91+
* returns NULL on error, of a new string on success, which must be freed by the
92+
* caller.
93+
*/
94+
char *read_first_line_of(const char* filepath)
7995
{
80-
char filename[255];
81-
char *p;
96+
char *p, *q, *line;
97+
size_t len;
8298
ssize_t sz;
8399

84-
sprintf(filename, "/sys%s/%s", devpath, var);
85-
p = read_file(filename, &sz);
86-
p[(strlen(p) - 1)] = '\0';
87-
strncpy(buffer, p, maxlen);
100+
p = read_file((char*)filepath, &sz);
101+
if (p == NULL)
102+
goto FAIL;
103+
104+
/* search end of first line */
105+
q = memchr(p, sz, '\0');
106+
if (q == NULL)
107+
q = p + sz; /* let's be flexible */
108+
109+
len = (size_t)(q - p); /* compute line length */
110+
if (len == 0)
111+
goto FAIL;
112+
113+
if (p[len-1] == '\n') { /* strip trailing \n */
114+
len -= 1;
115+
if (len == 0)
116+
goto FAIL;
117+
}
118+
119+
line = malloc(len+1);
120+
if (line == NULL)
121+
goto FAIL;
122+
123+
memcpy(line, p, len);
124+
line[len] = 0;
88125
free(p);
126+
127+
return line;
128+
129+
FAIL:
130+
if (p != NULL)
131+
free(p);
132+
133+
return NULL;
134+
}
135+
136+
char *read_sysfs_var(char *buffer, size_t maxlen, char *devpath, char *var)
137+
{
138+
char filename[255], *line;
139+
140+
snprintf(filename, sizeof filename, "/sys%s/%s", devpath, var);
141+
142+
line = read_first_line_of(filename);
143+
if (line == NULL)
144+
return NULL;
145+
146+
snprintf(buffer, maxlen, "%s", line);
147+
free(line);
148+
89149
return buffer;
90150
}
91151

vold/uevent.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static struct uevent_dispatch dispatch_table[] = {
7272
};
7373

7474
static boolean low_batt = false;
75-
static boolean door_open = false;
75+
static boolean door_open = true;
7676

7777
int process_uevent_message(int socket)
7878
{

vold/volmgr.c

+34-3
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ int volmgr_notify_eject(blkdev_t *dev, void (* cb) (blkdev_t *))
356356
LOG_VOL("Volmgr notified of %d:%d eject", dev->major, dev->minor);
357357

358358
volume_t *v;
359+
int rc;
359360

360361
// XXX: Partitioning support is going to need us to stop *all*
361362
// devices in this volume
@@ -371,9 +372,38 @@ int volmgr_notify_eject(blkdev_t *dev, void (* cb) (blkdev_t *))
371372

372373
if (v->state == volstate_mounted ||
373374
v->state == volstate_ums ||
374-
v->state == volstate_checking)
375+
v->state == volstate_checking) {
376+
375377
volume_setstate(v, volstate_badremoval);
376-
else if (v->state == volstate_formatting) {
378+
379+
/*
380+
* Stop any devmapper volumes which
381+
* are using us as a source
382+
* XXX: We may need to enforce stricter
383+
* order here
384+
*/
385+
volume_t *dmvol = vol_root;
386+
while (dmvol) {
387+
if ((dmvol->media_type == media_devmapper) &&
388+
(dmvol->dm->src_type == dmsrc_loopback) &&
389+
(!strncmp(dmvol->dm->type_data.loop.loop_src,
390+
v->mount_point, strlen(v->mount_point)))) {
391+
392+
pthread_mutex_lock(&dmvol->lock);
393+
if (dmvol->state != volstate_nomedia) {
394+
rc = volmgr_shutdown_volume(dmvol, _cb_volstopped_for_devmapper_teardown, false);
395+
if (rc != -EINPROGRESS) {
396+
if (rc)
397+
LOGE("unable to shutdown volume '%s'", v->mount_point);
398+
pthread_mutex_unlock(&dmvol->lock);
399+
}
400+
} else
401+
pthread_mutex_unlock(&dmvol->lock);
402+
}
403+
dmvol = dmvol->next;
404+
}
405+
406+
} else if (v->state == volstate_formatting) {
377407
/*
378408
* The device is being ejected due to
379409
* kernel disk revalidation.
@@ -409,7 +439,8 @@ static void _cb_volume_stopped_for_eject(volume_t *v, void *arg)
409439
LOG_VOL("Volume %s has been stopped for eject", v->mount_point);
410440
#endif
411441

412-
eject_cb(v->dev);
442+
if (eject_cb)
443+
eject_cb(v->dev);
413444
v->dev = NULL; // Clear dev because its being ejected
414445
}
415446

0 commit comments

Comments
 (0)