To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit e35cc186 authored by john's avatar john
Browse files

add property file reader, for conversion from commandline to property file setup

parent 15fe301b
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
/*
#include <stdio.h>
#include <stdlib.h>
......@@ -22,9 +30,9 @@
struct option_s {
struct option_s* next;
const char* option;
char* option;
int length;
const char* argument;
char* argument;
int argLength;
};
......@@ -82,7 +90,7 @@ void reportOptionsList() {
}
}
void makeOptionList(const char* options) {
void makeOptionList(char* options) {
if (options != NULL) {
int start = 0;
while (options[start]!='\0') {
......@@ -125,3 +133,201 @@ void makeOptionList(const char* options) {
reportOptionsList();
}
#define CONFIG_FILE_NAME "config.txt"
#define DEFAULT_DIR "."
#define FILE_SEP_CHAR '/'
#define FILE_TYPE int
#define FILE_IS_CLOSED -1
#define FILE_FLAGS (O_RDONLY)
#define FILE_MODE (S_IRUSR)
/*
close(logFile);
logFile = open(f,FILE_FLAGS,FILE_MODE);
logFileSequenceLength += write(logFile,b,(e)*(n));
ssize_t read(int fd, void *buf, size_t count);
*/
enum State {
UNKNOWN,
COMMENT,
KEY,
KEY_ESCAPE,
VALUE,
VALUE_ESCAPE
};
void append(char** buf, int* length, int* maxLength, char c)
{
if (*length == *maxLength) {
*maxLength = 2 * *maxLength;
char* tmp = (char*)malloc(sizeof(char) * *maxLength);
int i;
for(i = 0; i < *length; i++) tmp[i] = (*buf)[i];
free(*buf);
*buf = tmp;
}
(*buf)[*length] = c;
*length = *length + 1;
}
void makeOptionListFromFile(char* agentDir)
{
char* fileName = CONFIG_FILE_NAME;
char* fullFileName = NULL;
if (agentDir == NULL) agentDir = DEFAULT_DIR;
int length = strlen(agentDir);
if (agentDir[length] != FILE_SEP_CHAR) {
fullFileName = (char*)malloc(sizeof(char)*(length + 1 + strlen(fileName)));
strcpy(fullFileName, agentDir);
fullFileName[length] = FILE_SEP_CHAR;
strcpy(fullFileName + length + 1, fileName);
} else {
strcpy(fullFileName, agentDir);
strcpy(fullFileName + length, fileName);
}
FILE_TYPE fh = open(fullFileName,FILE_FLAGS,FILE_MODE);
if (fh == FILE_IS_CLOSED) {
fprintf(stderr, "unable to read config file %s\n", fullFileName);
exit(10);
}
char c = '\0';
size_t bytes = read(fh, &c, sizeof(char));
enum State state = UNKNOWN;
int keyLength = 0;
int keyMaxLength = 128;
char* key = (char*)malloc(keyMaxLength);
int valueLength = 0;
int valueMaxLength = 1024;
char* value = (char*)malloc(valueMaxLength);
while (bytes != 0) {
if (state == UNKNOWN) {
switch (c) {
case '-': case '#':
state = COMMENT;
break;
case '\n': case '\r':
break;
case '\\':
state = KEY_ESCAPE;
break;
default:
state = KEY;
append(&key, &keyLength, &keyMaxLength, c);
break;
}
} else if (state == KEY) {
switch (c) {
case '\\':
state = KEY_ESCAPE;
break;
case '=':
state = VALUE;
break;
default:
append(&key, &keyLength, &keyMaxLength, c);
break;
}
} else if (state == KEY_ESCAPE) {
switch (c) {
case 'n':
append(&key, &keyLength, &keyMaxLength, '\n');
break;
case 'r':
append(&key, &keyLength, &keyMaxLength, '\r');
break;
case 't':
append(&key, &keyLength, &keyMaxLength, '\t');
break;
default:
append(&key, &keyLength, &keyMaxLength, c);
break;
}
state = KEY;
} else if (state == VALUE) {
switch (c) {
case '\\':
state = VALUE_ESCAPE;
break;
case '\r': case '\n':
state = UNKNOWN;
struct option_s* opt = (struct option_s*)malloc(sizeof(struct option_s));
opt->next = NULL;
opt->option = (char*)malloc(sizeof(char)*(keyLength+1));
opt->length = keyLength;
strncpy(opt->option,key,sizeof(char)*keyLength);
opt->option[keyLength] = '\0';
opt->argument = (char*)malloc(sizeof(char)*(valueLength+1));
opt->argLength = valueLength;
strncpy(opt->argument,value,sizeof(char)*valueLength);
opt->argument[valueLength] = '\0';
if (optionList == NULL)
optionList = optionTail = opt;
else {
optionTail->next = opt;
optionTail = opt;
}
keyLength = 0;
valueLength = 0;
break;
default:
append(&value, &valueLength, &valueMaxLength, c);
break;
}
} else if (state == VALUE_ESCAPE) {
switch (c) {
case 'n':
append(&value, &valueLength, &valueMaxLength, '\n');
break;
case 'r':
append(&value, &valueLength, &valueMaxLength, '\r');
break;
case 't':
append(&value, &valueLength, &valueMaxLength, '\t');
break;
default:
append(&value, &valueLength, &valueMaxLength, c);
break;
}
state = VALUE;
} else if (state == COMMENT) {
switch (c) {
case '\r': case '\n':
state = UNKNOWN;
break;
default:
break;
}
} else {
fprintf(stderr, "we should never reach this state\n");
exit(10);
}
bytes = read(fh, &c, sizeof(char));
}
close(fh);
free(fullFileName);
}
......@@ -31,6 +31,7 @@
_Bool isSelected(const char* option, char** argument);
_Bool hasArgument(const char* option);
void reportOptionsList();
void makeOptionList(const char* options);
void makeOptionList(char* options);
void makeOptionListFromFile(char* agentDir);
#endif
......@@ -5,81 +5,92 @@ import java.util.Vector;
public final class Agent {
public static boolean firstReportSinceForceGC = false;
public static boolean firstReportSinceForceGC = false;
private static Runtime runtime = Runtime.getRuntime();
private static long callChainCount = 0;
private static long callChainFrequency = 1;
private static long agentIntervalTime = 0; // the number of milliseconds the agent should act on
private static long callChainCount = 0;
private static long callChainFrequency = 1;
private static long agentIntervalTime = 0; // the number of milliseconds the
// agent should act on
private static boolean callChainEnable = false;
private static Object waiter = new Object();
private static Object waiter = new Object();
private static AgentThread agentThread = null;
private static ThreadLocal<DelayAllocReport> delayAllocReport = new ThreadLocal<DelayAllocReport>();
// private static final String LOG_PREFIX_CLASS_INITIALIZATION = "CI";
// private static final String LOG_PREFIX_CLASS_INITIALIZATION = "CI";
private static class AgentThread extends Thread {
boolean agentThreadStarted = false;
boolean logon = false;
public AgentThread() {
super("agent thread");
setDaemon(true);
}
public synchronized boolean setLogon(boolean value) {
boolean tmp = logon;
logon = value;
if (!tmp && value) notify();
if (!tmp && value)
notify();
return value != tmp;
}
private synchronized void startup() {
agentThreadStarted = true;
notify();
}
public synchronized void started() {
while (! agentThreadStarted) {
try { wait(); } catch (Exception e) { }
while (!agentThreadStarted) {
try {
wait();
} catch (Exception e) {
}
}
}
public void run() {
startup();
if (0 < agentIntervalTime)
for(;;) intervalAgent();
for (;;)
intervalAgent();
}
private synchronized void waitForLogon() {
while (! logon) {
try { wait(); } catch (Exception e) { }
while (!logon) {
try {
wait();
} catch (Exception e) {
}
}
}
private void intervalAgent() {
// set a start time.
long currentTime = System.currentTimeMillis();
waitForLogon();
agentThread(this);
// set up an alarm...
long tempTime = System.currentTimeMillis();
long tempTime = System.currentTimeMillis();
long sleepTime = agentIntervalTime + tempTime - currentTime;
// set new current time, to next interval
currentTime += agentIntervalTime*((tempTime - currentTime)%agentIntervalTime + 1);
currentTime += agentIntervalTime
* ((tempTime - currentTime) % agentIntervalTime + 1);
// wait what ever time required
if (sleepTime>0)
try {
this.sleep(sleepTime);
} catch (Exception e) { }
if (sleepTime > 0)
try {
this.sleep(sleepTime);
} catch (Exception e) {
}
}
};
......@@ -88,95 +99,102 @@ public final class Agent {
private static final int BEFORE = 0;
private static final int OBJECT = 1;
private static final int AFTER = 2;
private static final int AFTER = 2;
private static final int POINTERS_PER_PUTFIELD = 3;
int delayCount = 0;
Object[][] nodes = new Object[DEFAULT_SIZE][DEFAULT_SIZE];
int[] depth = new int[DEFAULT_SIZE];
int size = 0;
Object[] putfields = new Object[POINTERS_PER_PUTFIELD*DEFAULT_SIZE];
int putfieldsSize = 0;
int[] depth = new int[DEFAULT_SIZE];
int size = 0;
Object[] putfields = new Object[POINTERS_PER_PUTFIELD * DEFAULT_SIZE];
int putfieldsSize = 0;
void extend(int newSize) {
if (nodes.length <= newSize) {
// System.err.println("Extending#"+hashCode()+":to "+newSize);
newSize = DEFAULT_SIZE * ((newSize / DEFAULT_SIZE) + 1);
Object[][] tmpNodes = new Object[newSize][];
int[] tmpDepth = new int[newSize];
for(int i=0; i<nodes.length; ++i) {
int[] tmpDepth = new int[newSize];
for (int i = 0; i < nodes.length; ++i) {
tmpNodes[i] = nodes[i];
tmpDepth[i] = depth[i];
nodes[i] = null;
}
for(int i=nodes.length; i<newSize; ++i) {
for (int i = nodes.length; i < newSize; ++i) {
tmpNodes[i] = new Object[DEFAULT_SIZE];
tmpDepth[i] = 0;
}
nodes = tmpNodes;
depth = tmpDepth;
}
size = newSize;
}
void inc() {
void inc() {
++delayCount;
// System.err.println("INC#"+hashCode()+":"+delayCount);
}
void dec() {
void dec() {
--delayCount;
// System.err.println("DEC#"+hashCode()+":"+delayCount);
}
void report(Object obj) {
if (obj==null) return;
if (size<=delayCount)
extend(delayCount+1);
if (obj == null)
return;
if (size <= delayCount)
extend(delayCount + 1);
Object[] stack = nodes[delayCount];
int slot = depth[delayCount];
int slot = depth[delayCount];
if (stack.length <= slot) {
Object[] tmpStack = new Object[stack.length + DEFAULT_SIZE];
// System.err.println("AddSlot#"+hashCode()+":["+delayCount+"]to "+stack.length);
for(int i = 0; i < stack.length; ++i) {
for (int i = 0; i < stack.length; ++i) {
tmpStack[i] = stack[i];
stack[i] = null;
}
stack = tmpStack;
nodes[delayCount] = stack;
}
stack[slot] = obj;
stack[slot] = obj;
depth[delayCount] = slot + 1;
}
void putfield(Object after, Object obj, Object before) {
if (0<delayCount) {
if (0 < delayCount) {
if (putfields.length < putfieldsSize) {
Object[] tmp = new Object[putfields.length + POINTERS_PER_PUTFIELD*DEFAULT_SIZE];
for(int i = 0; i<putfields.length; i++)
Object[] tmp = new Object[putfields.length
+ POINTERS_PER_PUTFIELD * DEFAULT_SIZE];
for (int i = 0; i < putfields.length; i++)
tmp[i] = putfields[i];
putfields = tmp;
}
putfields[putfieldsSize+BEFORE] = before;
putfields[putfieldsSize+OBJECT] = obj;
putfields[putfieldsSize+AFTER] = after;
putfields[putfieldsSize + BEFORE] = before;
putfields[putfieldsSize + OBJECT] = obj;
putfields[putfieldsSize + AFTER] = after;
putfieldsSize += POINTERS_PER_PUTFIELD;
} else {
internalLogPointerChange(Thread.currentThread(), after, obj, before);
internalLogPointerChange(Thread.currentThread(), after, obj,
before);
}
}
void done() {
if (delayCount==0) {
if (delayCount == 0) {
Thread t = Thread.currentThread();
for(int i = 0; i < size; ++i) {
for(int j = 0, d = depth[i]; j < d; ++j) {
for (int i = 0; i < size; ++i) {
for (int j = 0, d = depth[i]; j < d; ++j) {
if (nodes[i][j] != null) {
// System.err.println("Alloc:"+nodes[i][j].getClass());
internalAllocReport(t,nodes[i][j],nodes[i][j].getClass());
internalAllocReport(t, nodes[i][j], nodes[i][j]
.getClass());
if (firstReportSinceForceGC) {
reportHeapAfterForceGC();
}
......@@ -186,181 +204,194 @@ public final class Agent {
depth[i] = 0;
}
size = 0;
for(int i = 0; i<putfieldsSize; i += 3) {
internalLogPointerChange(t, putfields[i+AFTER], putfields[i+OBJECT], putfields[i+BEFORE]);
putfields[i+BEFORE] = null;
putfields[i+OBJECT] = null;
putfields[i+AFTER] = null;
for (int i = 0; i < putfieldsSize; i += 3) {
internalLogPointerChange(t, putfields[i + AFTER],
putfields[i + OBJECT], putfields[i + BEFORE]);
putfields[i + BEFORE] = null;
putfields[i + OBJECT] = null;
putfields[i + AFTER] = null;
}
putfieldsSize = 0;
}
}
};
// private static class DelayAllocReport {
// private static final int DEFAULT_SIZE = 16;
//
// int delayCount = 0;
//
// Object[][] nodes = new Object[DEFAULT_SIZE][DEFAULT_SIZE];
// int[] depth = new int[DEFAULT_SIZE];
// int size = 0;
//
// void extend(int newSize) {
// if (nodes.length <= newSize) {
// newSize = DEFAULT_SIZE * ((newSize / DEFAULT_SIZE) + 1);
//
// Object[][] tmpNodes = new Object[newSize][];
// int[] tmpDepth = new int[newSize];
//
// for(int i=0; i<nodes.length; ++i) {
// tmpNodes[i] = nodes[i];
// tmpDepth[i] = depth[i];
//
// nodes[i] = null;
// }
// for(int i=nodes.length; i<newSize; ++i) {
// tmpNodes[i] = new Object[DEFAULT_SIZE];
// tmpDepth[i] = 0;
// }
//
// nodes = tmpNodes;
// depth = tmpDepth;
// }
// size = newSize;
// }
// void inc() { ++delayCount; }
// void dec() { --delayCount; }
// void report(Object obj) {
// if (size<=delayCount)
// extend(delayCount+1);
// Object[] stack = nodes[delayCount];
// int slot = depth[delayCount];
// if (stack.length <= slot) {
// Object[] tmpStack = new Object[stack.length + DEFAULT_SIZE];
// for(int i = 0; i < stack.length; ++i) {
// tmpStack[i] = stack[i];
// stack[i] = null;
// }
// stack = tmpStack;
// nodes[delayCount] = stack;
// }
// stack[slot] = obj;
// depth[delayCount] = slot + 1;
// }
// void done() {
// for(int i = 0; i < size; ++i) {
// for(int j = 0, d = depth[i]; j < d; ++j) {
// if (nodes[i][j] != null) {
// // internalAllocReport(nodes[i][j]);
// nodes[i][j] = null;
// }
// }
// depth[i] = 0;
// }
// }
// };
// private static class DelayAllocReport {
// private static final int DEFAULT_SIZE = 16;
//
// int delayCount = 0;
//