Exemple #1
0
int main(int argc, char * const *argv) {
  log_asl_client = asl_open(NULL, "com.your.program", 0);
  
  // -- your code here --
  
  asl_close(log_asl_client);
  return 0;
}
Exemple #2
0
void ssyasl_close(void) {
    if (ssyasl_gAslClient != NULL) {
        asl_close(ssyasl_gAslClient) ;
        ssyasl_gAslClient = NULL ;
    }

    if (ssyasl_gFileDescriptor != 0) {
        close(ssyasl_gFileDescriptor) ;
        ssyasl_gFileDescriptor = 0 ;
    }
}
Exemple #3
0
void
closelog()
{
	pthread_mutex_lock(&_sl_lock);

	if (_sl_asl != NULL) asl_close(_sl_asl);
	_sl_asl = NULL;

	if (_sl_ident != NULL) free(_sl_ident);
	_sl_ident = NULL;

	pthread_mutex_unlock(&_sl_lock);
}
void IOHIDEventSystemStatistics::close(IOHIDSessionRef session, IOOptionBits options)
{
    (void) session;
    (void) options;
    
    if (_logStrings) {
        CFRelease(_logStrings);
        _logStrings = NULL;
    }
    
    if (_asl) {
        asl_close(_asl);
        if (_logfd != -1) ::close(_logfd);
    }
}
Exemple #5
0
void _init_asl(int source, int to_stderr)
{
	if (asl != NULL){
		asl_close(asl);;
		asl = NULL;
	}
    if (log_file_fd >= 0)
        close(log_file_fd);

	char source_desc[64];
	log_get_source_desc(source, source_desc, sizeof(source_desc));
	
	int opt = (to_stderr)?ASL_OPT_STDERR:0;
	asl = asl_open(FCT_LOG_IDENTITY, source_desc, opt);
    log_file_fd = open(sock_file,  O_WRONLY | O_CREAT | O_TRUNC, 0644);  
    if (log_file_fd >= 0)
        asl_add_log_file(asl, log_file_fd); 
}
Exemple #6
0
void
openlog(const char *ident, int opts, int logfac)
{
	const char *facility;
	uint32_t asl_opts;

	pthread_mutex_lock(&_sl_lock);

	/* close existing aslclient */
	if (_sl_asl != NULL) asl_close(_sl_asl);
	_sl_asl = NULL;

	if (_sl_ident != NULL) free(_sl_ident);
	_sl_ident = NULL;

	/* open with specified parameters */

	if (ident != NULL) _sl_ident = strdup(ident);
	/* NB we allow the strdup to fail silently */

	_sl_fac = logfac;
	facility = asl_syslog_faciliy_num_to_name(_sl_fac);

	_sl_opts = opts;
	asl_opts = ASL_OPT_SYSLOG_LEGACY;

	if (_sl_opts & LOG_NO_NOTIFY) asl_opts |= ASL_OPT_NO_REMOTE;
	if (_sl_opts & LOG_PERROR) asl_opts |= ASL_OPT_STDERR;

	_sl_mask = ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG);

	_sl_asl = asl_open(_sl_ident, facility, asl_opts);
	asl_set_filter(_sl_asl, _sl_mask);

	pthread_mutex_unlock(&_sl_lock);
}
Exemple #7
0
int main(int argc, char * const *argv) {
  uint32_t client_opts, send_level;
  const char *identity, *facility;
  
  // ASL client options
  client_opts = 0;
  
  // What level of messages are sent to syslogd
  send_level = ASL_LEVEL_NOTICE;
  
  // Sender identity. This should be NULL, as asl_open() will set this to the
  // name of the program. Only set this if you really need to.
  identity = NULL;
  
  // This should be your UTI
  facility = "se.hunch.asl.example";
  
  // Options accepted by our example program
  int ch;
  static struct option longopts[] = {
    { "debug", no_argument, NULL, 'd' },
    { "stderr", no_argument, NULL, 's' },
    { "no-remote", no_argument, NULL, 'n' },
    { "help", no_argument, NULL, 'h' },
    { NULL, 0, NULL, '\0' }
  };
  
  // Parse options
  while ((ch = getopt_long(argc, argv, "dsnh", longopts, NULL)) != -1) switch (ch) {
    
    case 'd':
      // Send all messages
      send_level = ASL_LEVEL_DEBUG;
      // This disables the remote-control mechanism for adjusting
      // filter levers for processes using e.g. syslog -c ...
      client_opts |= ASL_OPT_NO_REMOTE;
      break;
    
    case 's':
      // Print messages to stderr (adds stderr as an output file descriptor)
      client_opts |= ASL_OPT_STDERR;
      break;
    
    case 'n':
      // Send no messages at all. This does only affect what messages are sent
      // to the server and does not restrict which message are printed to
      // stderr, if enabled.
      send_level = -1;
      break;
    
    // Print usage and help
    default:
      usage(argv[0]);
      exit(1);
  }
  argc -= optind;
  argv += optind;
  
  // Setting ASL_OPT_NO_DELAY connects to the server immediately when calling asl_open()
  client_opts |= ASL_OPT_NO_DELAY;
  
  // Open connection to ASL (log_asl_client is defined in logging.h)
  // See /usr/include/asl.h for more details.
  log_asl_client = asl_open(identity, facility, client_opts);
  // The log_asl_client variable is used by the log_* and Log_* macros in logging.h
  
  // Handle errors from asl_open()
  if (log_asl_client == NULL) {
    perror("asl_open");
    exit(2);
  }
  
  // Set the level for which messages are sent to the server
  log_set_send_filter(send_level);
  
  // Emit one message for each level
  log_emerg("This is a emerg-level message -- this message may propagate "
            "to all TTYs and/or other user interfaces");
  log_alert("This is a alert-level message");
  log_crit("This is a crit-level message");
  log_err("This is a err-level message");
  log_warn("This is a warn-level message");
  log_notice("This is a notice-level message");
  log_info("This is a info-level message");
  log_debug("This message is a debug-level message");
  
  // Close connection to syslogd
  asl_close(log_asl_client);
  
  return 0;
}
Exemple #8
0
void uvccExit()
{
	if(uvcc_port) mach_port_deallocate(mach_task_self(), uvcc_port);
    if(logger) asl_close(logger);
}
Exemple #9
0
static void client_finalize(value v) {
  asl_close(Asl_val(v));
}