Ejemplo n.º 1
0
void w_log(int level, const char *fmt, ...)
{
    char buf[4096];
    va_list ap;
    int len;
    uint32_t tid = (uint32_t)(uintptr_t)pthread_self();
    bool fatal = false;

    if (level == W_LOG_FATAL) {
        level = W_LOG_ERR;
        fatal = true;
    }

    len = snprintf(buf, sizeof(buf),
                   "%d: tid=%" PRIu32 " ", (int)time(NULL), tid);
    va_start(ap, fmt);
    len += vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
    va_end(ap);

    if (level <= log_level) {
        ignore_result(write(STDERR_FILENO, buf, len));
    }

    w_log_to_clients(level, buf);

    if (fatal) {
        log_stack_trace();
        abort();
    }
}
Ejemplo n.º 2
0
void w_log(int level, const char *fmt, ...)
{
  char buf[4096];
  va_list ap;
  int len;
  bool fatal = false;
  struct timeval tv;
  char timebuf[64];
  struct tm tm;

  bool should_log_to_stderr = level <= log_level;
  bool should_log_to_clients = w_should_log_to_clients(level);

  if (!(should_log_to_stderr || should_log_to_clients)) {
    // Don't bother formatting the log message if nobody's listening.
    return;
  }

  if (level == W_LOG_FATAL) {
    level = W_LOG_ERR;
    fatal = true;
  }

  gettimeofday(&tv, NULL);
  localtime_r(&tv.tv_sec, &tm);
  strftime(timebuf, sizeof(timebuf), "%Y-%m-%dT%H:%M:%S", &tm);

  len = snprintf(buf, sizeof(buf), "%s,%03d: [%s] ",
         timebuf, (int)tv.tv_usec / 1000, w_get_thread_name());
  va_start(ap, fmt);
  vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
  va_end(ap);

  len = strlen(buf);
  if (buf[len - 1] != '\n') {
    if (len < (int)sizeof(buf) - 1) {
      buf[len] = '\n';
      buf[len + 1] = 0;
      len++;
    } else {
      buf[len - 1] = '\n';
    }
  }

  if (should_log_to_stderr) {
    ignore_result(write(STDERR_FILENO, buf, len));
  }

  if (should_log_to_clients) {
    w_log_to_clients(level, buf);
  }

  if (fatal) {
    log_stack_trace();
    abort();
  }
}
Ejemplo n.º 3
0
static void exit_server_common(enum server_exit_reason how,
	const char *const reason)
{
	struct smbd_server_connection *sconn = smbd_server_conn;

	if (!exit_firsttime)
		exit(0);
	exit_firsttime = false;

	change_to_root_user();

	if (sconn && sconn->smb1.negprot.auth_context) {
		TALLOC_FREE(sconn->smb1.negprot.auth_context);
	}

	if (sconn) {
		if (lp_log_writeable_files_on_exit()) {
			bool found = false;
			files_forall(sconn, log_writeable_file_fn, &found);
		}
		(void)conn_close_all(sconn);
		invalidate_all_vuids(sconn);
	}

	/* 3 second timeout. */
	print_notify_send_messages(sconn->msg_ctx, 3);

	/* delete our entry in the serverid database. */
	if (am_parent) {
		/*
		 * For children the parent takes care of cleaning up
		 */
		serverid_deregister(sconn_server_id(sconn));
	}

#ifdef WITH_DFS
	if (dcelogin_atmost_once) {
		dfs_unlogin();
	}
#endif

#ifdef USE_DMAPI
	/* Destroy Samba DMAPI session only if we are master smbd process */
	if (am_parent) {
		if (!dmapi_destroy_session()) {
			DEBUG(0,("Unable to close Samba DMAPI session\n"));
		}
	}
#endif

	if (am_parent) {
		rpc_wkssvc_shutdown();
#ifdef ACTIVE_DIRECTORY
		rpc_dssetup_shutdown();
#endif
#ifdef DEVELOPER
		rpc_rpcecho_shutdown();
#endif
#ifdef DFS_SUPPORT
		rpc_netdfs_shutdown();
#endif
		rpc_initshutdown_shutdown();
#ifdef EXTRA_SERVICES
		rpc_eventlog_shutdown();
		rpc_svcctl_shutdown();
		rpc_ntsvcs_shutdown();
#endif
#ifdef PRINTER_SUPPORT
		rpc_spoolss_shutdown();
#endif

		rpc_srvsvc_shutdown();
#ifdef WINREG_SUPPORT
		rpc_winreg_shutdown();
#endif

#ifdef NETLOGON_SUPPORT
		rpc_netlogon_shutdown();
#endif
#ifdef SAMR_SUPPORT
		rpc_samr_shutdown();
#endif
#ifdef LSA_SUPPORT
		rpc_lsarpc_shutdown();
#endif
	}

	/*
	 * we need to force the order of freeing the following,
	 * because smbd_msg_ctx is not a talloc child of smbd_server_conn.
	 */
	sconn = NULL;
	TALLOC_FREE(smbd_server_conn);
	server_messaging_context_free();
	server_event_context_free();
	TALLOC_FREE(smbd_memcache_ctx);

	locking_end();
	printing_end();

	if (how != SERVER_EXIT_NORMAL) {
		DEBUGSEP(0);
		DEBUG(0,("Abnormal server exit: %s\n",
			reason ? reason : "no explanation provided"));
		DEBUGSEP(0);

		log_stack_trace();

		dump_core();

		/* Notreached. */
		exit(1);
	} else {
		DEBUG(3,("Server exit (%s)\n",
			(reason ? reason : "normal exit")));
		if (am_parent) {
			pidfile_unlink();
		}
		gencache_stabilize();
	}

	exit(0);
}
Ejemplo n.º 4
0
static void exit_server_common(enum server_exit_reason how,
	const char *const reason)
{
	static int firsttime=1;

	if (!firsttime) {
#ifndef _XBOX
		exit(0);
#endif
	}
	firsttime = 0;

	change_to_root_user();

	if (negprot_global_auth_context) {
		(negprot_global_auth_context->free)(&negprot_global_auth_context);
	}

	conn_close_all();

	invalidate_all_vuids();
#ifndef _XBOX
	print_notify_send_messages(3); /* 3 second timeout. */
#endif
	/* delete our entry in the connections database. */
	yield_connection(NULL,"");

	respond_to_all_remaining_local_messages();
	decrement_smbd_process_count();

#ifdef WITH_DFS
	if (dcelogin_atmost_once) {
		dfs_unlogin();
	}
#endif

#ifndef _XBOX
	locking_end();
	printing_end();
#endif

	if (how != SERVER_EXIT_NORMAL) {
		int oldlevel = DEBUGLEVEL;
		char *last_inbuf = get_InBuffer();

		DEBUGLEVEL = 10;

		DEBUGSEP(0);
		DEBUG(0,("Abnormal server exit: %s\n",
			reason ? reason : "no explanation provided"));
		DEBUGSEP(0);

#ifndef _XBOX
		log_stack_trace();
#endif
		if (last_inbuf) {
			DEBUG(0,("Last message was %s\n", LAST_MESSAGE()));
			show_msg(last_inbuf);
		}

		DEBUGLEVEL = oldlevel;
#if DUMP_CORE
		dump_core();
#endif

	} else {    
		DEBUG(3,("Server exit (%s)\n",
			(reason ? reason : "normal exit")));
	}

#ifndef _XBOX
	exit(0);
#endif
}