Skip to content
This repository has been archived by the owner on Jul 18, 2018. It is now read-only.

Commit

Permalink
Update to new list implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Jul 2, 2017
1 parent 1bbf96a commit 9dab3bc
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions su_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,21 @@ static void sigpipe_handler(int sig) {
// Maintain the lists periodically
static void *collector(void *args) {
LOGD("su: collector started\n");
struct list_head *pos, *temp;
struct su_info *node;
while(1) {
sleep(1);
pthread_mutex_lock(&list_lock);
list_for_each(pos, &active_list) {
node = list_entry(pos, struct su_info, pos);
--node->clock;
// Timeout, move to waiting list
if (node->clock == 0) {
temp = pos;
pos = pos->prev;
list_pop(temp);
list_insert_end(&waiting_list, temp);
list_for_each(node, &active_list, struct su_info, pos) {
if (--node->clock == 0) {
// Timeout, move to waiting list
__ = list_pop(&node->pos);
list_insert_end(&waiting_list, &node->pos);
}
}
list_for_each(pos, &waiting_list) {
node = list_entry(pos, struct su_info, pos);
// Nothing is using the info, remove it
list_for_each(node, &waiting_list, struct su_info, pos) {
if (node->count == 0) {
temp = pos;
pos = pos->prev;
list_pop(temp);
// Nothing is using the info, remove it
__ = list_pop(&node->pos);
pthread_mutex_destroy(&node->lock);
free(node);
}
Expand All @@ -102,7 +94,6 @@ void su_daemon_receiver(int client) {
LOGD("su: request from client: %d\n", client);

struct su_info *info = NULL, *node;
struct list_head *pos;
int new_request = 0;

pthread_mutex_lock(&list_lock);
Expand All @@ -118,8 +109,7 @@ void su_daemon_receiver(int client) {
get_client_cred(client, &credential);

// Search for existing in the active list
list_for_each(pos, &active_list) {
node = list_entry(pos, struct su_info, pos);
list_for_each(node, &active_list, struct su_info, pos) {
if (node->uid == credential.uid)
info = node;
}
Expand Down

0 comments on commit 9dab3bc

Please sign in to comment.