Exemple #1
0
vol_err_t vol_getmetadata(vol_t handle)
{
    struct volume* vhnd = handle;
    log_info("Fetching volume metadata.");
    vol_err_t err = vol_getheader(handle, &vhnd->header, 0);
    if (err)
        return err;

    /* Header verification
     * There might be a memory leak here
     */

    if (memcmp(" VOL", vhnd->header.ident, 4) == 0)
    {
        log_debug("Magic number recognized. Archive is Starsiege volume.");
        vhnd->format = VFMT_STARSIEGE;
    } else if (memcmp("PVOL", vhnd->header.ident, 4) == 0) {
        log_debug("Magic number recognized. Archive is Tribes 1 volume.");
        vhnd->format = VFMT_TRIBES;
    } else if (memcmp("VOLN", vhnd->header.ident, 4) == 0) {
        log_debug("Magic number recognized. Archive is Earthsiege/Earthsiege 2 volume.");
        log_critical("Currently, only Starsiege and Starsiege Tribes volumes are supported.");
        return VOL_ERR_UNSUPFORMAT;
    } else {
        log_critical("Magic number not recognized.");
        return VOL_ERR_NOTVOL;
    }

    return vol_getfooter(handle);
}
Exemple #2
0
void Timed::init_device_mode()
{
  current_mode = "(unknown)" ;
#if HAVE_DSME
  dsme_mode_handler = new dsme_mode_t ;
  QObject::connect(dsme_mode_handler, SIGNAL(mode_is_changing()), this, SLOT(dsme_mode_is_changing())) ;
  QObject::connect(dsme_mode_handler, SIGNAL(mode_reported(const string &)), this, SLOT(dsme_mode_reported(const string &))) ;
#if F_ACTING_DEAD
  if (scratchbox_mode)
  {
    int is_act_dead = is_act_dead_by_status_files() ;
    bool user_mode = is_act_dead==0, mode_known = is_act_dead==0 or is_act_dead==1 ;
    if (not mode_known)
      log_abort("can't detect running mode") ;
    device_mode_reached(user_mode) ;
  }
  else
#endif
  {
    dsme_mode_handler->init_request() ;
  }
#endif
  const char *startup_path="/com/nokia/startup/signal", *startup_iface="com.nokia.startup.signal" ;
  const char *desktop_visible_slot = SLOT(harmattan_desktop_visible()) ;
  const char *init_done_slot = SLOT(harmattan_init_done(int)) ;
  bool res1 = QDBusConnection::systemBus().connect("", startup_path, startup_iface, "desktop_visible", this, desktop_visible_slot) ;
  bool res2 = QDBusConnection::systemBus().connect("", startup_path, startup_iface, "init_done", this, init_done_slot) ;
  if (not res1)
    log_critical("can't connect to 'desktop_visible' signal") ;
  if (not res2)
    log_critical("can't connect to 'init_done' signal") ;
}
Exemple #3
0
static bool init_act_dead_v2(bool use_status_files)
{
  string s_dsme_mode ;
  int dsme_mode = is_act_dead_by_dsme(s_dsme_mode) ;
  if (0<=dsme_mode) // got a valid answer: user or act_dead
    return dsme_mode ;

  if (use_status_files)
  {
    int sb_mode = is_act_dead_by_status_files() ;
    if (0<=sb_mode)
      return sb_mode ;
  }

  // oops, we don't know which mode we're running in; let's die

  // how to die? it depends on dsme mode

  log_critical("can't decide in which mode to run (dsme mode: '%s')", s_dsme_mode.c_str()) ;

  if (s_dsme_mode=="SHUTDOWN" or s_dsme_mode=="REBOOT")
  {
    log_critical("go to sleep, waiting to be killed, bye...") ;
    while(true) sleep(239239239) ;
  }

  log_critical("will be terminated in two seconds, bye...") ;

  sleep(2) ;
  log_abort("aborting") ;
}
Exemple #4
0
int do_curses_photorec(struct ph_param *params, struct ph_options *options, const list_disk_t *list_disk)
{
  static alloc_data_t list_search_space={
    .list = TD_LIST_HEAD_INIT(list_search_space.list)
  };
  if(params->cmd_device==NULL)
  {
    char *saved_device=NULL;
    char *saved_cmd=NULL;
    session_load(&saved_device, &saved_cmd,&list_search_space);
    if(saved_device!=NULL && saved_cmd!=NULL && !td_list_empty(&list_search_space.list)
#ifdef HAVE_NCURSES
	&& ask_confirmation("Continue previous session ? (Y/N)")!=0
#endif
      )
    {
      /* yes */
      params->cmd_run=saved_cmd;
      params->cmd_device=saved_device;
    }
    else
    {
      free(saved_device);
      free(saved_cmd);
      free_list_search_space(&list_search_space);
    }
  }
  if(params->cmd_device!=NULL && params->cmd_run!=NULL)
  {
    params->disk=photorec_disk_selection_cli(params->cmd_device, list_disk, &list_search_space);
#ifdef HAVE_NCURSES
    if(params->disk==NULL)
    {
      log_critical("No disk found\n");
      return intrf_no_disk_ncurses("PhotoRec");
    }
    if(change_arch_type_cli(params->disk, options->verbose, &params->cmd_run)==0 ||
	change_arch_type_ncurses(params->disk, options->verbose)==0)
    {
      menu_photorec(params, options, &list_search_space);
    }
    return 0;
#else
    if(params->disk==NULL)
    {
      log_critical("No disk found\n");
      return 0;
    }
    change_arch_type_cli(params->disk, options->verbose, &params->cmd_run);
    menu_photorec(params, options, &list_search_space);
    return 0;
#endif
  }
#ifdef HAVE_NCURSES
  return photorec_disk_selection_ncurses(params, options, list_disk, &list_search_space);
#else
  return 0;
#endif
}
Exemple #5
0
void Timed::init_start_event_machine()
{
  if(not settings_storage->fix_files(false))
    log_critical("can't fix the primary settings file") ;
  if(not event_storage->fix_files(false))
    log_critical("can't fix the primary event queue file") ;
  am->process_transition_queue() ;
  am->start() ;
}
Exemple #6
0
static void sighup_hdlr(int sig)
{
  if(sig == SIGINT)
    log_critical("SIGINT detected! PhotoRec has been killed.\n");
  else
    log_critical("SIGHUP detected! PhotoRec has been killed.\n");
  log_flush();
  action.sa_handler=SIG_DFL;
  sigaction(sig,&action,NULL);
  kill(0, sig);
}
Exemple #7
0
/* get an object obj and check if its type is <type>. If not, print a message
 * (this is what parent and key are used for) and exit
 */
static inline void
assure_type_is(struct json_object *obj,
	       struct json_object *parent,
	       const char *key,
	       enum json_type type)
{
	if (!json_object_is_type(obj, type)) {
		log_critical("Invalid type for key %s", key);
		log_critical("%s", json_object_to_json_string(parent));
		exit(EXIT_INV_CONFIG);
	}
}
Exemple #8
0
int initialize_sockaddr(int addr_count, char **host_list,
		struct sockaddr_in **sockaddr_list) {
	int i = 0;
	int delta = 0;
	int len = 0;
	int port;
	int success_count = 0;
	struct sockaddr_in *sa_in = NULL;
	struct hostent *he = NULL;
	char buffer[100];
	char *host = NULL;
	char *error = NULL;
	for (i = 0; i < addr_count; i++) {
		sockaddr_list[i] = NULL;
		host = host_list[i];
		if (host == NULL ) {
			continue;
		}
		len = strlen(host);
		delta = strcspn(host, ":");
		strncpy(buffer, host, delta);
		buffer[delta] = '\0';
		he = gethostbyname(buffer);
		if (he == NULL || he->h_addr_list == NULL
				|| (he->h_addr_list)[0] == NULL ) {
			log_critical("Cannot resolve IP address %s", host);
			continue;
		}
		if (delta + 1 < len) {
			strcpy(buffer, &host[delta + 1]);
		} else {
			strcpy(buffer, DEFAULT_BANK_PORT);
		}
		errno = 0;
		port = (int) strtol(buffer, &error, 10);
		if (errno != 0) {
			log_critical("Invalid port number %s", host);
			continue;
		}
		sa_in = malloc(sizeof(struct sockaddr_in));
		bzero(sa_in, sizeof(*sa_in));
		sa_in->sin_family = AF_INET;
		sa_in->sin_port = htons(port);
		memcpy(&(sa_in->sin_addr), he->h_addr_list[0], he->h_length);
		sockaddr_list[i] = sa_in;
		success_count++;
	}
	return success_count > 0 ? 0 : 1;
}
Exemple #9
0
static int ntfs_dir(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const unsigned long int cluster, file_info_t *dir_list)
{
  ntfs_inode *inode;
  s64 pos;
  struct ntfs_dir_struct *ls=(struct ntfs_dir_struct*)dir_data->private_dir_data;
  ls->dir_list=dir_list;

  inode = ntfs_inode_open (ls->vol, cluster);
  if (!inode) {
    log_error("ntfs_dir: ntfs_inode_open failed\n");
    return -1;
  }

  /*
   * We now are at the final path component.  If it is a file just
   * list it.  If it is a directory, list its contents.
   */
  pos = 0;
  if (inode->mrec->flags & MFT_RECORD_IS_DIRECTORY) {
    if(ntfs_readdir(inode, &pos, ls, (ntfs_filldir_t)ntfs_td_list_entry)<0)
    {
      log_error("ntfs_readdir failed for cluster %lu: %s\n", cluster,
	  strerror(errno));
    }
  }
  else
    log_critical("ntfs_readdir BUG not MFT_RECORD_IS_DIRECTORY\n");
  /* Finished with the inode; release it. */
  ntfs_inode_close(inode);
  td_list_sort(&dir_list->list, filesort);
  return 0;
}
Exemple #10
0
void log(const std::string& log, LogPriority priority)
{
  if (!_enableLogging)
    return;

  switch (priority)
  {
  case PRIO_FATAL :
    log_fatal(log);
    break;
  case PRIO_CRITICAL :
    log_critical(log);
    break;
  case PRIO_ERROR :
    log_error(log);
    break;
  case PRIO_WARNING :
    log_warning(log);
    break;
  case PRIO_NOTICE :
    log_notice(log);
    break;
  case PRIO_INFORMATION :
    log_information(log);
    break;
  case PRIO_DEBUG :
    log_debug(log);
    break;
  case PRIO_TRACE :
    log_trace(log);
    break;
  default:
    OSS_VERIFY(false);
  }
}
Exemple #11
0
void Timed::init_backup_object()
{
  backup_object = new QObject ;
  new backup_t(this, backup_object) ;
  // XXX: what if we're using system bus: how should backup know this?
  // TODO: if using system bus, keep track of started/terminated sessions? (omg!)
  QDBusConnection conn = Maemo::Timed::bus() ;
  const char * const path = "/com/nokia/timed/backup" ;
  if (conn.registerObject(path, backup_object))
    log_info("backup interface object registered on path '%s'", path) ;
  else
  {
    log_critical("failed to register backup object on path '%s': %s", path, conn.lastError().message().toStdString().c_str()) ;
    log_critical("backup/restore not available") ;
  }
}
Exemple #12
0
/*
*TODO: Check for and handle [_res.options & RES_USE_INET6]
*/
static getdns_return_t extract_addrtuple(struct gaih_addrtuple **result_addrtuple, response_bundle *response, 
		char *intern_buffer, size_t buflen, uint32_t *respstatus)
{
	if(!response)
	{
		log_warning("extract_addrtuple():error parsing response.");
		return GETDNS_RETURN_GENERIC_ERROR;
	}else if(response->ipv4_count + response->ipv6_count <= 0)
	{
		log_info("extract_addrtuple(): No answers: %s.", getdns_get_errorstr_by_id(response->respstatus));
		*respstatus = GETDNS_RESPSTATUS_NO_NAME;
		return GETDNS_RETURN_GOOD;
	}
	size_t rec_count = 0, num_answers = 0;
	size_t idx, min_space, cname_len;
	num_answers = response->ipv4_count + response->ipv6_count;
    char *canon_name = response->cname;
    cname_len = strlen(canon_name) + 2;
    min_space = cname_len + (sizeof(struct gaih_addrtuple) * num_answers);
    if( buflen < min_space )
    {
        log_critical("GETDNS: Buffer too small: %zd\n", buflen);
        return GETDNS_RETURN_MEMORY_ERROR;
    }
    struct gaih_addrtuple *gaih_ptr = *result_addrtuple;
    /*Fill in hostname*/
    char *hname;
    hname = intern_buffer;
    memcpy(hname, canon_name, cname_len-2);
    memset(hname + cname_len-1, 0, sizeof(char));
    idx = cname_len;
    
    if(response->ipv6_count > 0)
    {
    	char **addr_list = malloc(sizeof(char*)*response->ipv6_count);
    	assert(addr_list);
    	int num = parse_addr_list(response->ipv6, addr_list, response->ipv6_count);
		for(rec_count = 0; rec_count < num; ++rec_count)
		{
		    add_addrtuple(addr_list[rec_count], AF_INET6);
		}
		free(addr_list);
    }
    if(response->ipv4_count > 0)
    {
    	char **addr_list = malloc(sizeof(char*)*response->ipv4_count);
    	assert(addr_list);
    	int num = parse_addr_list(response->ipv4, addr_list, response->ipv4_count);
		int addr_idx;
		for(addr_idx = 0; addr_idx < num; ++addr_idx)
		{
		    add_addrtuple(addr_list[addr_idx], AF_INET);
		    rec_count++;
		}
		free(addr_list);
    }
    assert(idx <= min_space); /*Check if we didn't write past the intended space...*/
    *respstatus = rec_count > 0 ? GETDNS_RESPSTATUS_GOOD : GETDNS_RESPSTATUS_NO_NAME;
	return GETDNS_RETURN_GOOD;
}
Exemple #13
0
static spt get_field_value(struct formatter_field *f, const uint8_t *data)
{
    uint64_t tmp = 0;
    unsigned int i;
    unsigned int dest_bit;

    if (f->endianness == FORMATTER_ENDIAN_BIG) {
        dest_bit = f->end_bit - f->start_bit;
    } else if (f->endianness == FORMATTER_ENDIAN_LITTLE) {
        dest_bit = 0;
    } else {
        log_critical ("Bug: Invalid endianness setting: %d\n", f->endianness);
        return (uint64_t) -1;
    }

    for (i = f->start_bit; i <= f->end_bit; i++) {
        const unsigned int byte     = i / 8;
        const unsigned int src_bit  = i % 8;

        const uint64_t val = (data[byte] >> src_bit) & 0x1;
        tmp |= val << dest_bit;

        if (f->endianness == FORMATTER_ENDIAN_BIG) {
            dest_bit--;
        } else if (f->endianness == FORMATTER_ENDIAN_LITTLE) {
            dest_bit++;
        }
    }

    return spt_from_uint64(tmp);
}
Exemple #14
0
Node *search_trie(Node *root, const char *val) {
	/*
	 * Search the Trie for the char array.
	 * Create new nodes if part of the array does not exist yet.
	 * Return the node corresponding to the end of the char array.
	 */
	if (root == NULL ) {
		log_warning("NULL root found in Trie search_trie.");
		return NULL ;
	}
	if (val == NULL ) {
		log_warning("Empty target string found in search_trie.");
		return NULL ;
	}
	if (strlen(val) + (root->level) > MAX_TRIE_LEVEL) {
		log_critical("Reached MAX_TRIE_LEVEL. Root level %d, Node %s",
				root->level, val);
		return NULL ;
	}

	Node *cur = root;
	Node *child = NULL;
	int i;
	int found;
	int cur_level = root->level;
	int len = strlen(val);
	char c;
	for (i = 0; i < len; i++, cur_level++) {
		child = cur->children;
		c = val[i];
		found = 0;
		while (child != NULL ) {
			if (child->val != c) {
				child = child->sibling;
			} else {
				found = 1;
				break;
			}
		}
		if (found == 0) {
			Node *n = get_new_node(c, cur_level + 1);
			if (n == NULL ) {
				return NULL ;
			}
			if (cur->children == NULL ) {
				cur->children = n;
			} else {
				child = cur->children;
				while (child->sibling != NULL ) {
					child = child->sibling;
				}
				child->sibling = n;
			}
			cur = n;
		} else {
			cur = child;
		}
	}
	return cur;
}
Exemple #15
0
static void apply_field_bits(const struct formatter_field *f,
                             uint64_t input_bits, uint8_t *data)
{
    unsigned int i, b;
    uint64_t src_bit;

    if (f->endianness == FORMATTER_ENDIAN_BIG) {
        src_bit = f->end_bit - f->start_bit;
    } else if (f->endianness == FORMATTER_ENDIAN_LITTLE) {
        src_bit = 0;
    } else {
        log_critical ("Bug: Invalid endianness setting: %d\n", f->endianness);
        return;
    }

    for (i = f->start_bit, b = 0; i <= f->end_bit; i++) {
        const unsigned int byte = i / 8;
        const unsigned int bit  = i % 8;

        if (input_bits & (1 << src_bit)) {
            data[byte] |= (1 << bit);
        } else {
            data[byte] &= ~(1 << bit);
        }

        if (f->endianness == FORMATTER_ENDIAN_BIG) {
            src_bit--;
        } else if (f->endianness == FORMATTER_ENDIAN_LITTLE) {
            src_bit++;
        }
    }

}
Exemple #16
0
void Timed::init_backup_dbus_name()
{
  // We're using an another name for backup interface
  //   to avoid mess while switching to system bus and back again (later)
  // XXX: But for now it's just the same connection as com.nokia.time
  QDBusConnection conn = Maemo::Timed::bus() ;
  const char * const name = "com.nokia.timed.backup" ;
  const string conn_name = conn.name().toStdString() ;
  if (conn.registerService(name))
    log_info("service name '%s' registered on bus '%s'", name, conn_name.c_str()) ;
  else
  {
    const string msg = conn.lastError().message().toStdString() ;
    log_critical("can't register service '%s' on bus '%s': '%s'", name, conn_name.c_str(), msg.c_str()) ;
    log_critical("backup/restore not available") ;
  }
}
Exemple #17
0
void Timed::init_main_interface_dbus_name()
{
  // We're misusing the dbus name as a some kind of mutex:
  //   only one instance of timed is allowed to run.
  // This is the why we can't drop the name later.

  const string conn_name = Maemo::Timed::bus().name().toStdString() ;
  if (Maemo::Timed::bus().registerService(Maemo::Timed::service()))
    log_info("service name '%s' registered on bus '%s'", Maemo::Timed::service(), conn_name.c_str()) ;
  else
  {
    const string msg = Maemo::Timed::bus().lastError().message().toStdString() ;
    log_critical("can't register service '%s' on bus '%s': '%s'", Maemo::Timed::service(), conn_name.c_str(), msg.c_str()) ;
    log_critical("aborting") ;
    ::exit(1) ;
  }
}
Exemple #18
0
int main(void)
{

	log_warning("Invalid attribute named %s", "INFO", "Sizwe");
	log_info("Invalid attribute named %s", "ERROR", "Position");
	log_error("Invalid attribute named %s", "WARNING", "rival");
	log_critical("Invalid attribute named %s", "CRITICAL", "Doom");
	return (0);
}
Exemple #19
0
/* search a key (what) in object "where", and return a pointer to its
 * associated object. If nullable is false, exit if key is not found */
static inline struct json_object*
get_in_object(struct json_object *where,
	      const char *what,
	      int nullable)
{
	struct json_object *to;
	json_bool ret;
	ret = json_object_object_get_ex(where, what, &to);
	if (!nullable && !ret) {
		log_critical(PFX "Error while parsing config\n" PFL);
		exit(EXIT_INV_CONFIG);
	}
	if (!nullable && strcmp(json_object_to_json_string(to), "null") == 0) {
		log_critical(PFX "Cannot find key %s", what);
		exit(EXIT_INV_CONFIG);
	}
	return to;
}
static int fat_copy_file(disk_t *disk, const partition_t *partition, const unsigned int block_size, const uint64_t start_data, const char *recup_dir, const unsigned int dir_num, const file_data_t *file)
{
  char *new_file;	
  FILE *f_out;
  unsigned int cluster;
#ifdef DJGPP
  unsigned int file_size=file->file_size;
#else
  unsigned int file_size=file->stat.st_size;
#endif
  unsigned long int no_of_cluster;
  unsigned char *buffer_file=(unsigned char *)MALLOC(block_size);
  cluster = file->stat.st_ino;
  new_file=(char *)MALLOC(1024);
  snprintf(new_file, 1024, "%s.%u/f%07u-%s", recup_dir, dir_num,
      (unsigned int)((start_data - partition->part_offset + (uint64_t)(cluster-2)*block_size)/disk->sector_size),
      file->name);
  log_info("fat_copy_file %s\n", new_file);
  f_out=fopen(new_file, "wb");
  if(!f_out)
  {
    log_critical("Can't create file %s: \n",new_file);
    free(new_file);
    free(buffer_file);
    return -1;
  }
  no_of_cluster=(partition->part_size - start_data) / block_size;
  while(cluster>=2 && cluster<=no_of_cluster+2 && file_size>0)
  {
    const uint64_t start=start_data + (uint64_t)(cluster-2)*block_size;
    unsigned int toread = block_size;
    if (toread > file_size)
      toread = file_size;
    if((unsigned)disk->pread(disk, buffer_file, toread, start) != toread)
    {
      log_error("fat_copy_file: Can't read cluster %u.\n", cluster);
    }
    if(fwrite(buffer_file, 1, toread, f_out) != toread)
    {
      log_error("fat_copy_file: no space left on destination.\n");
      fclose(f_out);
      set_date(new_file, file->stat.st_atime, file->stat.st_mtime);
      free(new_file);
      free(buffer_file);
      return -1;
    }
    file_size -= toread;
    cluster++;
  }
  fclose(f_out);
  set_date(new_file, file->stat.st_atime, file->stat.st_mtime);
  free(new_file);
  free(buffer_file);
  return 0;
}
Exemple #21
0
getdns_return_t add_addrinfo(struct addrinfo **result_ptr, struct addrinfo *hints, const char *addr_string, const int addr_size, const char *canon_name)
{
	int addrsize, family;
	family = (addr_size == IN_ADDRLEN) ? AF_INET : AF_INET6;
	char addr_data[sizeof(struct in6_addr)];
	inet_pton(family, addr_string, addr_data);
	struct addrinfo *ai;
	if(addr_size == IN_ADDRLEN && hints->ai_family == AF_INET6)
	{
		v42v6_map(addr_data);
		family = AF_INET6;
		addrsize = sizeof(struct sockaddr_in6);
	}else{
		addrsize = addr_size;
	}
	ai = _allocaddrinfo(family); 
	if(ai == NULL)
	{
		log_critical("Memory error (MALLOC).\n");
		return GETDNS_RETURN_MEMORY_ERROR;
	}
	ai->ai_addr->sa_family = family;
	memcpy(addr_data_ptr((struct sockaddr_storage*)(ai->ai_addr)), addr_data, sizeof(addr_data));
	COPY_ADDRINFO_PARAMS(ai, hints->ai_flags, family, hints->ai_socktype, hints->ai_protocol, ai->ai_addr, addrsize, NULL);
	if(canon_name != NULL)
	{
		ai->ai_canonname = strndup(canon_name, NI_MAXHOST);
		if(ai->ai_canonname == NULL)
		{
			log_critical("Memory error (strndup).\n");
			__freeaddrinfo(ai);
			return GETDNS_RETURN_MEMORY_ERROR;
		}    		
	}else{
		ai->ai_canonname = NULL;
	}
	if(*result_ptr != NULL){
		(*result_ptr)->ai_next = ai;
	}   
	*result_ptr = ai;
	return GETDNS_RETURN_GOOD;
}
Exemple #22
0
int ccnfdl_init(int pipeline_size)
{
    int len;

    _listener.interest_pipe_size = pipeline_size;
    int pool_size = INTEREST_FLOWS;
    //int pool_size = 1;
    if (tpool_create(&_listener.interest_pipeline, pool_size) < 0) {
        log_critical(g_log, "tpool_create: could not create interest thread pool!");
        return -1;
    }

    if ((_listener.sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
        log_critical(g_log, "socket: %s.", strerror(errno));
        return -1;
    }

    memset(&(_listener.local), 0, sizeof(struct sockaddr_un));

    _listener.local.sun_family = AF_UNIX;
    char sock_path[256];
    ccnf_did2sockpath(g_nodeId, sock_path, 256);
    strcpy(_listener.local.sun_path, sock_path);
    unlink(_listener.local.sun_path);

    len = sizeof(struct sockaddr_un);
    if (bind(_listener.sock, (struct sockaddr * ) &(_listener.local), len) == -1) {
        log_critical(g_log, "bind: %s.", strerror(errno));
        close(_listener.sock);
        return -1;
    }

    if (listen(_listener.sock, SOCK_QUEUE) == -1) {
        log_critical(g_log, "listen: %s.", strerror(errno));
        return -1;
    }

    log_important(g_log, "interest window: %d", _listener.interest_pipe_size);
    log_important(g_log, "max interest window: %d", MAX_INTEREST_PIPELINE);

    return 0;
}
Exemple #23
0
void
case_log_log()
{
    assert(log_open("test", "test.log", 0) == LOG_OK);
    log_debug("test message debug");
    log_info("test message info");
    log_warn("test message warn");
    log_error("test message error");
    log_critical("test message critical");
    log_close();
}
Exemple #24
0
void log_rotate(void) {

	uint64_t date;
	FILE *orig_out, *orig_err;
	chr_t *log_file = MEMORYBUF(1024);

	if (magma.output.file && magma.output.path && (date = time_datestamp()) != log_date) {

		orig_out = stdout;
		orig_err = stderr;
		log_date = date;

		if (snprintf(log_file, 1024, "%s%smagmad.%lu.log", magma.output.path, (*(ns_length_get(magma.output.path) + magma.output.path) == '/') ? "" : "/",
			date) >= 1024) {
			log_critical("Log file path exceeded available buffer. { file = %s%smagmad.%lu.log }", magma.output.path,
				(*(ns_length_get(magma.output.path) + magma.output.path) == '/') ? "" : "/", date);
			return;
		}

		pthread_mutex_lock(&log_mutex);
		if (!(stdout = freopen64(log_file, "a", stdout))) {
			stdout = orig_out;
			log_critical("Unable to rotate the error log. { file = %s }", log_file);
			pthread_mutex_unlock(&log_mutex);
			return;
		}


		if (!(stderr = freopen64(log_file, "a", stderr))) {
			fclose(stdout);
			stdout = orig_out;
			stderr = orig_err;
			log_critical("Unable to rotate the error log. { file = %s }", log_file);
			pthread_mutex_unlock(&log_mutex);
			return;
		}
		pthread_mutex_unlock(&log_mutex);
	}

	return;
}
Exemple #25
0
bool_t log_start(void) {

	FILE *file_out, *file_err;
	chr_t *log_file = MEMORYBUF(1024);

	// File logging.
	if (magma.output.file && magma.output.path) {

		log_date = time_datestamp();

		if (snprintf(log_file, 1024, "%s%smagmad.%lu.log", magma.output.path, (*(ns_length_get(magma.output.path) + magma.output.path) == '/') ? "" : "/",
			log_date) >= 1024) {
			log_critical("Log file path exceeded available buffer. { file = %s%smagmad.%lu.log }", magma.output.path,
				(*(ns_length_get(magma.output.path) + magma.output.path) == '/') ? "" : "/", log_date);
			return false;
		}

		if (folder_exists(NULLER(magma.output.path), false)) {
			log_critical("The path configured to hold the output log files does not exist. { path = %s }", magma.output.path);
			return false;
		}

		if (!(file_out = freopen64(log_file, "a+", stdout))) {
			log_critical("Unable to open the error log, sticking with standard out. { file = %s }", log_file);
			return false;
		}

		if (!(file_err = freopen64(log_file, "a+", stderr))) {
			log_critical("Unable to open the error log, sticking with standard error. { file = %s }", log_file);
			fclose(file_out);
			return false;
		}

		stdout = file_out;
		stderr = file_err;
	}

	fclose(stdin);
	return true;
}
Exemple #26
0
Node *get_new_node(char c, int level) {
	Node *n = malloc(sizeof(Node));
	if (n == NULL ) {
		log_critical("%s", "Fail to allocate memory for Node.");
		return NULL ;
	}
	n->val = c;
	n->level = level;
	n->hook = NULL;
	n->children = NULL;
	n->sibling = NULL;
	return n;
}
Exemple #27
0
void Timed::save_settings()
{
  iodata::record *tree = settings->save() ;
  int res = settings_storage->save(tree) ;

  if(res==0) // primary file
    log_info("wall clock settings written") ;
  else if(res==1)
    log_warning("wall clock settings written to secondary file") ;
  else
    log_critical("wall clock settings can't be saved") ;

  delete tree ;
}
Exemple #28
0
void machine_t::process_transition_queue()
{
  if(transition_in_progress())
  {
    log_debug("process_transition_queue() is already in progress, returning") ;
    return ; // never do it recursively
  }
  // log_debug("begin processing, states: %s tqueue: %s" , s_states().c_str(), s_transition_queue().c_str()) ;
  transition_start_time = ticker_t(now()) ;
  bool queue_changed = false ;
  for(; not transition_queue.empty(); queue_changed = true, transition_queue.pop_front())
  {
#define state_name(p) (p?p->name():"null")
    event_t *e = transition_queue.front().first ;
    abstract_state_t *new_state = transition_queue.front().second ;
    if (not is_event_registered(e))
    {
      log_error("requested to move destroyed event %p to state '%s'", e, state_name(new_state)) ;
      continue ;
    }
    abstract_state_t *old_state = e->get_state() ;
    log_notice("State transition %d:'%s'->'%s'", e->cookie.value(), state_name(old_state), state_name(new_state)) ;
    if (new_state==old_state)
      log_critical("Event %d: new_state=old_state='%s'", e->cookie.value(), old_state->name()) ;
#undef state_name
    if(old_state)
      old_state->leave(e) ;
    e->set_state(new_state) ;
    if(new_state)
    {
      new_state->enter(e) ;
      e->sort_and_run_actions(new_state->get_action_mask()) ;
    }
    else
    {
      log_notice("Destroying the event %u (event object %p)", e->cookie.value(), e) ;
      unregister_event(e) ;
      delete e ;
    }
  }
  // log_debug("processing done,  states: %s tqueue: %s" , s_states().c_str(), s_transition_queue().c_str()) ;
  transition_start_time = ticker_t(0) ;
  transition_time_adjustment.set(0) ;
  if(queue_changed)
    emit queue_to_be_saved() ;
  if(context_changed)
    send_queue_context() ;
  send_bootup_signal() ;
}
Exemple #29
0
void Timed::init_main_interface_object()
{
  new com_nokia_time(this) ;
  QDBusConnection conn = Maemo::Timed::bus() ;
  const char * const path = Maemo::Timed::objpath() ;
  if (conn.registerObject(path, this))
    log_info("main interface object registered on path '%s'", path) ;
  else
    log_critical("remote methods not available; failed to register dbus object: %s", Maemo::Timed::bus().lastError().message().toStdString().c_str()) ;
  // XXX:
  // probably it's a good idea to terminate if failed
  // (usually it means, the dbus connection is not available)
  // but on the other hand we can still provide some services (like setting time and zone)
  // Anyway, we will terminate if the mutex like name is not available
}
Exemple #30
0
int gen_pid_file(const char *pfname) {
	if (pfname == NULL ) {
		log_error("No pid file name specified.");
		return 1;
	}
	pid_t pid = getpid();
	FILE *f = fopen(pfname, "w");
	if (f == NULL ) {
		log_critical("Cannot open pid file for write: %s", pfname);
		return 1;
	}
	fprintf(f, "%d", (int) pid);
	fclose(f);
	log_debug("Saved pid %d to %s", (pid), pfname);
	return 0;
}