enable logging in loaders

This commit is contained in:
Jack May 2018-10-16 16:33:31 -07:00 committed by Grimes
parent 912eb5e8e9
commit 64efa62a74
4 changed files with 28 additions and 10 deletions

View File

@ -7,6 +7,7 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
bincode = "1.0.0"
byteorder = "1.2.1"
elf = "0.0.10"
env_logger = "0.5.12"
libc = "0.2.43"
log = "0.4.2"
rbpf = { git = "https://github.com/qmonnet/rbpf", rev="bc41ec47d9b51751585f6ddcde1d1eb1afe2be69" }

View File

@ -1,15 +1,16 @@
pub mod bpf_verifier;
extern crate bincode;
extern crate byteorder;
extern crate elf;
extern crate env_logger;
extern crate libc;
extern crate rbpf;
extern crate solana_program_interface;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate log;
pub mod bpf_verifier;
extern crate rbpf;
#[macro_use]
extern crate serde_derive;
extern crate solana_program_interface;
use bincode::{deserialize, serialize};
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
@ -22,6 +23,7 @@ use std::io::Error;
use std::mem;
use std::path::PathBuf;
use std::str;
use std::sync::{Once, ONCE_INIT};
/// Dynamic link library prefixs
const PLATFORM_FILE_PREFIX_BPF: &str = "";
@ -115,6 +117,12 @@ pub enum BpfLoader {
#[no_mangle]
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
static INIT: Once = ONCE_INIT;
INIT.call_once(|| {
// env_logger can only be initialized once
env_logger::init();
});
if keyed_accounts[0].account.executable {
let prog: Vec<u8>;
if let Ok(program) = deserialize(&keyed_accounts[0].account.userdata) {

View File

@ -5,6 +5,7 @@ authors = ["Solana Maintainers <maintainers@solana.com>"]
[dependencies]
bincode = "1.0.0"
env_logger = "0.5.12"
log = "0.4.2"
rlua = "0.15.2"
serde = "1.0.27"

View File

@ -1,16 +1,18 @@
extern crate bincode;
extern crate rlua;
extern crate solana_program_interface;
#[macro_use]
extern crate serde_derive;
extern crate env_logger;
#[macro_use]
extern crate log;
extern crate rlua;
#[macro_use]
extern crate serde_derive;
extern crate solana_program_interface;
use bincode::{deserialize, serialize};
use rlua::{Lua, Result, Table};
use solana_program_interface::account::KeyedAccount;
use solana_program_interface::loader_instruction::LoaderInstruction;
use std::str;
use std::sync::{Once, ONCE_INIT};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum LuaLoader {
@ -59,6 +61,12 @@ fn run_lua(keyed_accounts: &mut [KeyedAccount], code: &str, data: &[u8]) -> Resu
#[no_mangle]
pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) -> bool {
static INIT: Once = ONCE_INIT;
INIT.call_once(|| {
// env_logger can only be initialized once
env_logger::init();
});
if keyed_accounts[0].account.executable {
let prog: Vec<u8>;
if let Ok(program) = deserialize(&keyed_accounts[0].account.userdata) {