Exemplo n.º 1
0
void players_in_received_handler(DictionaryIterator *iter) {
	Tuple *tuple = dict_find(iter, APP_KEY_METHOD);
	if (!tuple) return;
	free_safe(error);
	switch (tuple->value->uint8) {
		case KEY_METHOD_ERROR: {
			tuple = dict_find(iter, APP_KEY_STATUS);
			error = malloc(tuple->length);
			strncpy(error, tuple->value->cstring, tuple->length);
			players_reload_data_and_mark_dirty();
			break;
		}
		case KEY_METHOD_SIZE:
			free_safe(players);
			num_players = dict_find(iter, APP_KEY_INDEX)->value->uint8;
			players = malloc(sizeof(Player) * num_players);
			if (players == NULL) num_players = 0;
			break;
		case KEY_METHOD_DATA: {
			if (!players_count()) break;
			uint8_t index = dict_find(iter, APP_KEY_INDEX)->value->uint8;
			Player *player = players_get(index);
			player->index = index;
			player->mediaplayer = dict_find(iter, APP_KEY_PLAYER)->value->uint8;
			strncpy(player->title, dict_find(iter, APP_KEY_TITLE)->value->cstring, sizeof(player->title) - 1);
			LOG("player: %d '%s' '%s'", player->index, player->title, player_to_str(player->mediaplayer));
			players_reload_data_and_mark_dirty();
			if (index == current_player) win_players_push_player();
			break;
		}
	}
}
Exemplo n.º 2
0
void products_deinit(void) {
	free_safe(error);
	free_safe(products);
	for (uint i = 0; i < NUM_RESOURCE_IMAGES; i++) {
		gbitmap_destroy_safe(resource_images[i].image);
	}
	win_products_deinit();
}
Exemplo n.º 3
0
static void destroy_lines(void) {
  for (uint8_t l = 0; l < num_lines; l += 1) {
    free_safe(lines[l]->name);
    free_safe(lines[l]->status);
    free_safe(lines[l]);
  }
  free_safe(lines);
  num_lines = 0;
}
Exemplo n.º 4
0
void products_in_received_handler(DictionaryIterator *iter) {
	Tuple *tuple = dict_find(iter, APP_KEY_METHOD);
	if (!tuple) return;
	free_safe(error);
	switch (tuple->value->uint8) {
		case KEY_METHOD_ERROR: {
			tuple = dict_find(iter, APP_KEY_NAME);
			if (!tuple) break;
			error = malloc(tuple->length);
			if (error)
				strncpy(error, tuple->value->cstring, tuple->length);
			products_reload_data_and_mark_dirty();
			break;
		}
		case KEY_METHOD_SIZE:
			free_safe(products);
			tuple = dict_find(iter, APP_KEY_INDEX);
			if (!tuple) break;
			num_products = tuple->value->uint8;
			products = malloc(sizeof(Product) * num_products);
			if (products == NULL) num_products = 0;
			break;
		case KEY_METHOD_DATA: {
			if (!products_count()) break;
			tuple = dict_find(iter, APP_KEY_INDEX);
			if (!tuple) break;
			uint8_t index = tuple->value->uint8;
			Product *product = products_get(index);
			product->index = index;
			tuple = dict_find(iter, APP_KEY_RESOURCE);
			if (tuple) {
				product->resource = resource_images[tuple->value->uint32];
			}
			tuple = dict_find(iter, APP_KEY_NAME);
			if (tuple) {
				strncpy(product->name, tuple->value->cstring, sizeof(product->name) - 1);
			}
			tuple = dict_find(iter, APP_KEY_ESTIMATE);
			if (tuple) {
				strncpy(product->estimate, tuple->value->cstring, sizeof(product->estimate) - 1);
			}
			tuple = dict_find(iter, APP_KEY_SURGE);
			if (tuple) {
				strncpy(product->surge, tuple->value->cstring, sizeof(product->surge) - 1);
			}
			LOG("product: %d '%s' '%s' '%s'", product->index, product->name, product->estimate, product->surge);
			products_reload_data_and_mark_dirty();
			break;
		}
	}
}
Exemplo n.º 5
0
void loading_layer_set_text(LoadingLayer* layer, char* text) {
  LoadingData* data = (LoadingData*)layer_get_data(layer);
  free_safe(data->message);
  data->message = malloc(strlen(text) + 1);
  strcpy(data->message, text);
  layer_mark_dirty(layer);
}
Exemplo n.º 6
0
static void handle_details(char* data) {
  free_safe(details);
  data_processor_init(data, '|');
  details = data_processor_get_string();
  if (details_handler) {
    details_handler(details);
  }
}
static void
_mechanism_finalize(CFTypeRef value)
{
    mechanism_t mech = (mechanism_t)value;
    
    CFReleaseSafe(mech->data);
    free_safe(mech->string);
}
Exemplo n.º 8
0
Arquivo: volstd.c Projeto: kobara/siso
int volstd_init(struct volume *vol, void *options)
{
    struct volume_standard *volstd = NULL;
    int rv = 0;
    int err = 0;

    vol->ops.notify = &volstd_notify;
    vol->ops.exec = &volstd_exec;
    vol->ops.sync_cache = &volstd_sync_cache;

    volstd = malloc_safe(sizeof(struct volume_standard));
    if (volstd == NULL) {
	log_err("Unable to allocate memory ("U32_FMT" bytes).\n",
		sizeof(struct volume_standard));
	rv = -ENOMEM;
	goto failure;
    }
    volstd->cond_cmdq = PTHREAD_COND_INIT;

    volstd->fd = 0;

    ASSERT((vol->ext == NULL), "vol->ext(%p) != NULL\n", vol->ext);
    vol->ext = volstd;

    volstd->vol = vol;
    
    pthread_cond_init(&(volstd->cond_cmdq), NULL);

    log_dbg3("Open/Create file \"%s\"\n", vol->pathname);
    volstd->fd = open(vol->pathname,
		      O_CREAT|O_SYNC|O_RDWR,
		      S_IRUSR | S_IWUSR);
//    volstd->fd = open(vol->pathname, O_CREAT|O_RDWR);
    err = errno;
    log_dbg3("volstd->fd=%d, errno=%d\n", volstd->fd, err);
    if (volstd->fd == -1) {
	log_err("Unable to open file \"%s\" (errno=%d)\n",
		vol->pathname, err);
	rv = err;
	goto failure;
    }

    return 0;

failure:
    if (volstd != NULL) {
	if (memcmp(&(volstd->cond_cmdq), &PTHREAD_COND_INIT, sizeof(pthread_cond_t))) {
	    pthread_cond_destroy(&(volstd->cond_cmdq));
	}
	if (volstd->fd) {
	    close(volstd->fd);
	}
	free_safe(volstd, sizeof(struct volume_standard));
	volstd = NULL;
    }
     return rv;
} // volstd_init
Exemplo n.º 9
0
void send_wrap_split_data(socket_fd send_socket_fd, char *data, char tail)
{
	int wrap_data_length = strlen(data) * sizeof(char) + sizeof(tail);
	char *wrap_data = (char *)malloc_string_safe(wrap_data, wrap_data_length);
	wrap(data, tail, wrap_data);
	send_split_data(send_socket_fd, wrap_data);
	free_safe(wrap_data);
	
}
Exemplo n.º 10
0
void send_split_data(socket_fd send_socket_fd, char *send_data)
{
	int send_data_length = strlen(send_data) + 2;
	for (int i = 0; i <= send_data_length / SEND_BUFSIZE; i += 1) {
		char *sendbuf = (char *)malloc_string_safe(sendbuf, SEND_BUFSIZE * sizeof(char));
		strncpy(sendbuf, send_data + i * SEND_BUFSIZE, SEND_BUFSIZE);
		send(send_socket_fd, sendbuf, strlen(sendbuf), 0);
		free_safe(sendbuf);
	}
}
Exemplo n.º 11
0
void loading_layer_destroy(LoadingLayer* layer) {
  if (layer == NULL) {
    return;
  }
  LoadingData* data = (LoadingData*)layer_get_data(layer);
  if (data) {
    free_safe(data->message);
  }
  layer_destroy(layer);
}
Exemplo n.º 12
0
Arquivo: iscsi.c Projeto: kobara/siso
 /**
  * Free DS(DataSegment) memory
  */
int iscsi_free_dsbuf(struct iscsi_conn *conn, byte *ds, uint32 dslen)
{
    free_safe(ds, dslen);

    conn->dslen_total -= dslen;

    log_dbg3("Free memory (conn->dslen_total="U32_FMT").\n",
	    conn->dslen_total);

    return 0;
} // iscsi_free_dsbuf
Exemplo n.º 13
0
/**
 * Destroy an iSCSI session.
 * @param[in,out] session  An iSCSI session
 */
int iscsi_destroy_session(
    struct iscsi_session *session)
{
    ASSERT((session != NULL), "session == NULL\n");
    ASSERT((session->target != NULL), "session->target == NULL\n");
    ASSERT((iscsi_is_session_empty(session)), "!iscsi_is_session_empty(session)\n");

    free_safe(session, sizeof(struct iscsi_session));

    return 0;
} // iscsi_destroy_session
Exemplo n.º 14
0
Arquivo: volstd.c Projeto: kobara/siso
int volstd_alloc_bufvec(struct volume *vol, uint64 lba, uint32 len, struct buffer_vec **dsvec, uint32 *dsvec_cnt)
{
    int rv = 0;

    *dsvec = NULL;
    *dsvec_cnt = 1;

    *dsvec = malloc_safe(sizeof(struct buffer_vec));
    if (*dsvec == NULL) {
	rv = -ENOMEM;
	log_err("Unable to allocate memory ("U32_FMT" bytes).\n",
		sizeof(struct buffer_vec));
	goto failure;
    }

    (*dsvec)->buflen = len * vol->sector_size;
    (*dsvec)->buf = malloc_safe((*dsvec)->buflen);
    if ((*dsvec)->buf == NULL) {
	rv = -ENOMEM;
	log_err("Unable to allocate memory ("U32_FMT" bytes).\n",
		(*dsvec)->buflen);
	goto failure;
    }
    (*dsvec)->offset = 0;
    (*dsvec)->len = (*dsvec)->buflen;

    return 0;

failure:
    if (*dsvec != NULL) {
	if ((*dsvec)->buf != NULL) {
	    free_safe((*dsvec)->buf, (*dsvec)->buflen);
	}
	free_safe(*dsvec, sizeof(struct buffer_vec));
    }
    *dsvec = NULL;
    *dsvec_cnt = 0;
    return rv;
} // volstd_alloc_bufvec
Exemplo n.º 15
0
static char*
read_string (int fd)
{
	/* We only accept a max of 8K from the daemon */
	#define MAX_LENGTH 8192
	
	char buf[256];
	char *ret = NULL;
	int r, len = 0;
	
	for (;;) {
		r = read (fd, buf, sizeof (buf));
		if (r < 0) {
			if (errno == EAGAIN)
				continue;
			free_safe (ret);
			return NULL;
			
		} else  { 
			char *n = realloc (ret, len + r + 1);
			if (!n) {
				free_safe (ret);
				errno = ENOMEM;
				return NULL;
			}
			memset(n + len, 0, r + 1); 
			ret = n;
			len = len + r;
			
			strncat (ret, buf, r);
		}
		
		if (r == 0 || len > MAX_LENGTH)
			break;
	}
	
	return ret;
}
Exemplo n.º 16
0
void subscriptions_in_received_handler(DictionaryIterator *iter) {
	Tuple *tuple = dict_find(iter, APP_KEY_METHOD);
	if (!tuple) return;
	free_safe(error);
	switch (tuple->value->uint8) {
		case KEY_METHOD_ERROR: {
			tuple = dict_find(iter, APP_KEY_TITLE);
			if (!tuple) break;
			error = malloc(tuple->length);
			strncpy(error, tuple->value->cstring, tuple->length);
			subscriptions_reload_data_and_mark_dirty();
			break;
		}
		case KEY_METHOD_SIZE:
			free_safe(subscriptions);
			tuple = dict_find(iter, APP_KEY_INDEX);
			if (!tuple) break;
			num_subscriptions = tuple->value->uint8;
			subscriptions = malloc(sizeof(Subscription) * num_subscriptions);
			if (subscriptions == NULL) num_subscriptions = 0;
			break;
		case KEY_METHOD_DATA: {
			if (!subscriptions_count()) break;
			tuple = dict_find(iter, APP_KEY_INDEX);
			if (!tuple) break;
			uint8_t index = tuple->value->uint8;
			Subscription *subscription = subscriptions_get(index);
			subscription->index = index;
			tuple = dict_find(iter, APP_KEY_TITLE);
			if (tuple) {
				strncpy(subscription->title, tuple->value->cstring, sizeof(subscription->title) - 1);
			}
			LOG("subscription: %d '%s'", subscription->index, subscription->title);
			subscriptions_reload_data_and_mark_dirty();
			break;
		}
	}
}
Exemplo n.º 17
0
void hash_resize(HashTable *ht, int n_new)
{
    HashNode *new_elts;
    int a,b;
    int i;
    HashNode *n;
    U32 off;
    
    // size must be power of 2, find msb and double that
    a = n_new;
    do
    {
        b = a;
        a=(a&(a-1));
    } while(a);
    if(b<=0)
        b = 16;
    n_new = b*2;
    
    // do this first to give realloc a chance to keep this in the
    // same spot
    new_elts = calloc(sizeof(*ht->elts),n_new);
    for(i = 0; i<ht->n_elts; ++i)
    {
        HashNode *n_old = ht->elts + i;
        int j;
        
        if(!n_old->hash)
            continue;
        for(j = 0; j < n_new; ++j)
        {
            off = ((n_old->hash + j) & (n_new - 1));
            n = new_elts + off;
            if(!n->hash)
            {
                *n = *n_old;
                break;
            }
        }
        if(j == n_new)
            abassert(0 && "failed to re-hash");
    }
    free_safe(ht->elts);
    ht->elts = new_elts;
    ht->n_elts = n_new;
}
Exemplo n.º 18
0
void abfclose(File *f)
{
    if(!f)
        return;
    switch (f->type)
    {
    case FileType_Mem:
        free_safe(f->fp.mem.p);
        break;
    case FileType_CRT:
        fclose(f->fp.crt);
        break;
    default:
        abassert(0 && "unknown enum");
        break;
    }
	free(f->fn);
    free(f);
}
Exemplo n.º 19
0
static int
stop_daemon (pam_handle_t *ph, struct passwd *pwd)
{
	const char *spid = NULL;
	char *apid = NULL;
	pid_t pid;
	
	assert (pwd);

	pam_get_data (ph, "gkr-pam-pid", (const void**)&spid);
	
	/* 
	 * No pid, no worries, maybe we didn't start mate-keyring-daemon
	 * Or this the calling (PAM using) application is hopeless and 
	 * wants to call different PAM callbacks from different processes.
	 * 
	 * In any case we live and let live.
	 */
	if (!spid)
		goto done;
	
	/* Make sure it parses out nicely */
	pid = (pid_t)atoi (spid);
	if (pid <= 0) {
		syslog (GKR_LOG_ERR, "gkr-pam: invalid mate-keyring-daemon process id: %s", spid);
		goto done;
	}
	
    	if (kill (pid, SIGTERM) < 0 && errno != ESRCH) {
    		syslog (GKR_LOG_ERR, "gkr-pam: couldn't kill mate-keyring-daemon process %d: %s", 
    		        (int)pid, strerror (errno));
    		goto done;
    	}    		

done:
	free_safe (apid);
	
	/* Don't bother user when daemon can't be stopped */
	return PAM_SUCCESS;
}
Exemplo n.º 20
0
void send_message(char *friend_name, char *message){
	struct friend *this = (struct friend *)malloc_safe(this, sizeof(struct friend));
	
	int result = find_connector_by_name(&connectors, friend_name, this, MESSAGE_CONNECT);//is connectted?
	if (result) {
			
		socket_fd friend_socket_fd;
		memset(&friend_socket_fd, 0, sizeof(socket_fd));
		
		
		//connect
		friend_socket_fd = connect_TCP_by_name(friend_name);
		if (friend_socket_fd <= 2) 
			goto end;
		
		//create talk thread message mode
		pthread_t talk_thread_id;
		struct talk_thread_arg *tt_arg = malloc_safe(tt_arg, sizeof(struct talk_thread_arg));
		tt_arg->connect_socket_fd = friend_socket_fd;
		tt_arg->connect_launcher = TRUE;
		tt_arg->connect_type = MESSAGE_CONNECT;
		tt_arg->file_trans_fd = -1;
		pthread_create(&talk_thread_id, NULL, talk_thread, (void *)tt_arg);
		
		//wait fot connect established
		while(find_connector_by_name(&connectors, friend_name,  NULL, MESSAGE_CONNECT)){
			usleep(50);
		}
		this->friend_socket_fd = friend_socket_fd;
	}
	
	//send message	
	send_wrap_split_data(this->friend_socket_fd, message, ETB);

	show(friend_name, message, SHOW_DIRECTION_OUT);
	
	end:
	free_safe(this);
	
}
Exemplo n.º 21
0
Arquivo: iscsi.c Projeto: kobara/siso
/**
 * Destroy an iSCSI PDU
 */
void iscsi_remove_pdu(struct iscsi_conn *conn, struct iscsi_pdu *pdu)
{
    uint32 i;

    log_dbg3("Remove PDU (opcode=0x%02X, ITT=0x%08lX\n",
	    pdu->opcode, pdu->itt);

    for (i = 0; i < pdu->dsvec_cnt; i++) {
	ASSERT(pdu->dsvec[i].buf != NULL,
	       "pdu->dsvec["U32_FMT"].buf == NULL\n");
	log_dbg3("pdu->dsvec["U32_FMT"].{buf=%p, buflen="U32_FMT", offset="U32_FMT", len="U32_FMT", page=%p}\n",
		i,
		pdu->dsvec[i].buf,
		pdu->dsvec[i].buflen, 
		pdu->dsvec[i].offset,
		pdu->dsvec[i].len,
		pdu->dsvec[i].page);
	if (pdu->dsvec[i].page == NULL) {
	    log_dbg3("pdu->dsvec["U32_FMT"].page == NULL\n", i);
	    iscsi_free_dsbuf(conn, pdu->dsvec[i].buf, pdu->dsvec[i].buflen);
	} else {
	    log_dbg3("pdu->dsvec["U32_FMT"].page(%p) != NULL\n", i, pdu->dsvec[i].page);
	    if (pdu->task != NULL) {
		ASSERT((pdu->task->list_page.len > 0),
		       "pdu->task->list_page.len == 0\n");
		ASSERT((pdu->task->list_page.head != NULL),
		       "pdu->task->list_page.head == NULL\n");
	    }
	}
    }
    log_dbg3("Free an iSCSI PDU (pdu->{opcode=0x%02X, itt=0x%08lX}, conn->pdus="U32_FMT").\n",
	    pdu->opcode, pdu->itt, conn->pdus-1);

    free_safe(pdu, sizeof(struct iscsi_pdu));

    conn->pdus--;

    return;
} // iscsi_remove_pdu
Exemplo n.º 22
0
Arquivo: iscsi.c Projeto: kobara/siso
/**
 * Remove iSCSI task
 *   This function removes PDUs which are included the task.
 */
int iscsi_remove_task(struct iscsi_conn *conn, struct iscsi_task *task)
{
    struct iscsi_pdu *pdu;

    log_dbg3("Remove iSCSI task (task->list_pdu.len="U32_FMT", conn->list_task.len="U32_FMT", conn->pdus="U32_FMT").\n",
	    task->list_pdu.len, conn->list_task.len, conn->pdus);
    ASSERT((conn->list_task.len > 0), "conn->list_task.len == 0\n");

    list_unlist_elem(&(conn->list_task), &(task->listelem));

    // Removes PDUs which are included the task.
    if (list_is_empty(&(task->list_pdu))) {
	log_dbg3("task->list_pdu is empty\n");
    } else {
	log_dbg3("task->list_pdu is NOT empty\n");
	while (1) {
	    pdu = (struct iscsi_pdu *)list_unlist_head_elem(&(task->list_pdu));
	    if (pdu == NULL) {
		break;
	    }
	    iscsi_dump_pdu(conn, pdu);
	    iscsi_remove_pdu(conn, pdu);
	}
    }
    ASSERT(task->list_pdu.head == NULL, "task->list_pdu.head(%p) != NULL\n", task->list_pdu.head);
    ASSERT(task->list_pdu.len == 0, "task->list_pdu.len("U32_FMT") > 0\n", task->list_pdu.len);

    if (! list_is_empty(&(task->list_page))) {
	int rv;
	rv = vol_free_buf(task->vol, &(task->list_page));
	ASSERT((!rv), "rv\n");
    }
    free_safe(task, sizeof(struct iscsi_task));

    log_dbg3("Remove iSCSI task (conn->task_cnt="U32_FMT", conn->pdus="U32_FMT").\n",
	    conn->list_task.len, conn->pdus);

    return 0;
} // iscsi_remove_task
Exemplo n.º 23
0
void strpool_cleanup(StrPool *p)
{
	int i;

	if(!p)
		return;

	for(i = 0; i < DEREF(p->dict,n_elts); ++i)
	{
		HashNode *n = p->dict->elts + i;
		if(!n->key)
			continue;
		if(!str_in_block(p,n->key))
			continue;
		free(n->key);
	}

	for(i = 0; i < ap_size(&p->strblocks); ++i)
		free(p->strblocks[i]);
	ap_destroy(&p->strblocks,NULL);
	free_safe(p->dict);
	p->dict = 0;
}
Exemplo n.º 24
0
Arquivo: target.c Projeto: kobara/siso
struct iscsi_target *iscsi_target_create(
struct siso_info *siso,
const char *target_name)
{
    ASSERT((target_name != NULL), "target_name == NULL\n");

    struct iscsi_target *target = NULL;

    target = malloc_safe(sizeof(struct iscsi_target));
    if (target == NULL) {
	log_err("Unable to allocate memory (%d bytes).\n",
		sizeof(struct iscsi_target));
	goto failure;
    }

    target->siso = siso;

    listelem_init(&(target->listelem), target);

    strncpy(target->name, target_name, sizeof(target->name));
    if (target->name[sizeof(target->name) -1] != '\0') {
	// overflow
	log_err("TargetName \"%s\" is too long.\n", target_name);
	goto failure;
    }
    log_dbg3("TargetName = \"%s\"\n", target->name);

    target->auth = ISCSI_AUTH_NONE;
    target->username[0] = '\0';
    target->secret[0] = '\0';

    list_init(&(target->list_vol));
    list_init(&(target->list_session));

    pthread_mutex_init(&(target->lock_list_session), NULL);
/*
    int rv;
    rv = iscsi_target_load_config(target, pathname_conf);
    if (rv) {
	goto failure;
    }

    rv = init_server_side_sockets(target);
    if (rv < 1) {
	goto failure;
    }
    vol_run(target);
*/

    return target;

failure:
    //   vol_stop
    //   vol_destroy
    //   close_server_side_sockets(target)
    if (target != NULL) {
	free_safe(target, sizeof(struct iscsi_target));
	target = NULL;
    }
    return NULL;
} // iscsi_target_create
Exemplo n.º 25
0
status_t timers_restore(void) {
  timers_clear();

  if (! persist_exists(STORAGE_TIMER_START)) {
    return 0;
  }

  int block = 0;
  TimerBlock* timerBlock = malloc(sizeof(TimerBlock));
  persist_read_data(STORAGE_TIMER_START, timerBlock, sizeof(TimerBlock));

  uint8_t timer_count = timerBlock->count;
  int seconds_elapsed = 0;
  if (settings()->resume_timers) {
    int save_time = timerBlock->time;
    seconds_elapsed = time(NULL) - save_time;
  }

  for (int t = 0; t < timer_count; t += 1) {

    if (t > 0 && t % TIMER_BLOCK_SIZE == 0) {
      block += 1;
      free_safe(timerBlock);
      timerBlock = malloc(sizeof(TimerBlock));
      persist_read_data(STORAGE_TIMER_START + block, timerBlock, sizeof(TimerBlock));
    }

    Timer* timer = timer_clone(&timerBlock->timers[t % TIMER_BLOCK_SIZE]);
    timers_add(timer);

    timer->app_timer = NULL;
    if (! settings()->resume_timers) {
      timer_reset(timer);
      continue;
    }
    if (TIMER_STATUS_RUNNING != timer->status) {
      continue;
    }
    if (TIMER_DIRECTION_UP == timer->direction) {
      timer->time_left += seconds_elapsed;
    }
    else {
      if (true == timer->repeat) {
        timer->time_left -= (seconds_elapsed % timer->length);
        if (timer->time_left <= 0) {
          timer->time_left += timer->length;
        }
      }
      else {
        timer->time_left -= seconds_elapsed;
        if (0 >= timer->time_left) {
          timer->time_left = 0;
          timer->status = TIMER_STATUS_FINISHED;
          continue;
        }
      }
    }
    timer_resume(timer);
  }
  free_safe(timerBlock);
  return 0;
}
Exemplo n.º 26
0
void timers_remove(int pos) {
  Timer* tmr = timers_get(pos);
  free_safe(tmr);
  linked_list_remove(timers, pos);
}
Exemplo n.º 27
0
static int
start_daemon (pam_handle_t *ph, struct passwd *pwd, const char *password)
{
	struct sigaction defsact, oldsact, ignpipe, oldpipe;
	int inp[2] = { -1, -1 };
	int outp[2] = { -1, -1 };
	int errp[2] = { -1, -1 };
	int ret = PAM_SERVICE_ERR;
	pid_t pid;
	char *output = NULL;
	char *outerr = NULL;
	int failed, status;
	
	assert (pwd);

	/* 
	 * Make sure that SIGCHLD occurs. Otherwise our waitpid below
	 * doesn't work properly. We need to wait on the process to 
	 * get the daemon exit status.
	 */
	memset (&defsact, 0, sizeof (defsact));
	memset (&oldsact, 0, sizeof (oldsact));
	defsact.sa_handler = SIG_DFL;
	sigaction (SIGCHLD, &defsact, &oldsact);
	
	/*
	 * Make sure we don't exit with a SIGPIPE while doing this, that 
	 * would be very annoying to a user trying to log in.
	 */	
	memset (&ignpipe, 0, sizeof (ignpipe));
	memset (&oldpipe, 0, sizeof (oldpipe));
	ignpipe.sa_handler = SIG_IGN;
	sigaction (SIGPIPE, &ignpipe, &oldpipe);
	
	/* Create the necessary pipes */
	if (pipe (inp) < 0 || pipe (outp) < 0 || pipe (errp) < 0) {
	    	syslog (GKR_LOG_ERR, "gkr-pam: couldn't create pipes: %s", 
	    	        strerror (errno));
	    	goto done;
	}

	/* Start up daemon child process */
	switch (pid = fork ()) {
	case -1:
		syslog (GKR_LOG_ERR, "gkr-pam: couldn't fork: %s", 
		        strerror (errno));
		goto done;
		
	/* This is the child */
	case 0:
		setup_child (inp, outp, errp, ph, pwd);
		/* Should never be reached */
		break;
		
	/* This is the parent */
	default:
		break;
	};

	/* Close our unneeded ends of the pipes */
	close (inp[READ_END]);
	close (outp[WRITE_END]);
	close (errp[WRITE_END]);
	inp[READ_END] = outp[WRITE_END] = errp[WRITE_END] = -1; 

	/*
	 * We always pass in a --login argument, even when we have a NULL password
	 * since this controls the startup behavior. When using --login daemon waits
	 * for a password. Closing input signifies password is done.
	 */

	if (password)
		write_string (inp[WRITE_END], password);
	close (inp[WRITE_END]);

	/* 
	 * Note that we're not using select() or any such. We know how the 
	 * daemon sends its data.
	 */

	/* Read any stdout and stderr data */
	output = read_string (outp[READ_END]);
	outerr = read_string (errp[READ_END]);
	if (!output || !outerr) {
		syslog (GKR_LOG_ERR, "gkr-pam: couldn't read data from mate-keyring-daemon: %s", 
		        strerror (errno));
		goto done;
	}

	/* Wait for the initial process to exit */
	if (waitpid (pid, &status, 0) < 0) {
		syslog (GKR_LOG_ERR, "gkr-pam: couldn't wait on mate-keyring-daemon process: %s",
		        strerror (errno));
		goto done;
	}
	
	failed = !WIFEXITED (status) || WEXITSTATUS (status) != 0;
	if (outerr && outerr[0])
		foreach_line (outerr, log_problem, &failed);
	
	/* Failure from process */
	if (failed) {
		syslog (GKR_LOG_ERR, "gkr-pam: mate-keyring-daemon didn't start properly properly");
		goto done;
	}
		
	ret = foreach_line (output, setup_environment, ph);

done:
	/* Restore old handler */
	sigaction (SIGCHLD, &oldsact, NULL);
	sigaction (SIGPIPE, &oldpipe, NULL);
	
	close_safe (inp[0]);
	close_safe (inp[1]);
	close_safe (outp[0]);
	close_safe (outp[1]);
	close_safe (errp[0]);
	close_safe (errp[1]);
	
	free_safe (output);
	free_safe (outerr);

	return ret;
}
Exemplo n.º 28
0
static void
cleanup_free (pam_handle_t *ph, void *data, int pam_end_status)
{
	free_safe (data);
}
Exemplo n.º 29
0
void subscriptions_deinit(void) {
	free_safe(error);
	free_safe(subscriptions);
	win_subscriptions_deinit();
}
Exemplo n.º 30
0
void hash_free_cleanupcb(HashNode *n, void *ctxt)
{
	ctxt;
	free_safe(n->key);
	free_safe(n->p);
}