Skip to content

Instantly share code, notes, and snippets.

@DanielO
Created December 2, 2013 21:45
Show Gist options
  • Save DanielO/7759660 to your computer and use it in GitHub Desktop.
Save DanielO/7759660 to your computer and use it in GitHub Desktop.
Index: python/Makefile
===================================================================
--- python/Makefile (revision 165)
+++ python/Makefile (working copy)
@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-VERSION := 0.5.r152
+VERSION := 0.5.r .r165
VERSIONED := _ash_log.py advanced_shell_history/*.py ash_query.py
ARGPARSE := advanced_shell_history/argparse.py
Index: python/_ash_log.py
===================================================================
--- python/_ash_log.py (revision 165)
+++ python/_ash_log.py (working copy)
@@ -23,7 +23,7 @@
__author__ = 'Carl Anderson (carl.anderson@gmail.com)'
# NOTE: This variable is set automatically by the Makefile.
-__version__ = '0.5.r152'
+__version__ = '0.5.r .r165'
import logging
Index: python/advanced_shell_history/util.py
===================================================================
--- python/advanced_shell_history/util.py (revision 165)
+++ python/advanced_shell_history/util.py (working copy)
@@ -23,7 +23,7 @@
__author__ = 'Carl Anderson (carl.anderson@gmail.com)'
# NOTE: This variable is set automatically by the Makefile.
-__version__ = '0.5.r152'
+__version__ = '0.5.r .r165'
import argparse
Index: python/ash_query.py
===================================================================
--- python/ash_query.py (revision 165)
+++ python/ash_query.py (working copy)
@@ -25,7 +25,7 @@
__author__ = 'Carl Anderson (carl.anderson@gmail.com)'
# NOTE: This variable is set automatically by the Makefile.
-__version__ = '0.5.r152'
+__version__ = '0.5.r .r165'
import csv
Index: src/Makefile
===================================================================
--- src/Makefile (revision 165)
+++ src/Makefile (working copy)
@@ -14,7 +14,7 @@
# limitations under the License.
#
-VERSION := 0.5.r152
+VERSION := 0.5.r .r165
LOGGER := _ash_log
QUERIER := ash_query
EXES := ${LOGGER} ${QUERIER}
@@ -25,27 +25,29 @@
TRASH := ${OBJS} ${EXES} core
CPP := g++
C := gcc
-FLAGS := -g -Wall -DASH_VERSION="\"${VERSION}\"" -ansi -pedantic -O2
-RT_LIB := -lrt
+FLAGS := -g -Wall -DASH_VERSION="\"${VERSION}\"" -ansi -pedantic -O0
+#RT_LIB := -lrt
+SQLITE_CFLAGS := $(shell pkg-config --cflags sqlite3)
+SQLITE_LIB := $(shell pkg-config --libs sqlite3)
.PHONY: all clean distclean new reallyclean
all: ${EXES}
-${QUERIER}: sqlite3.o ${OBJ_Q}
- ${CPP} ${FLAGS} -o ${@} ${<} ${OBJ_Q} ${RT_LIB}
+${QUERIER}: ${OBJ_Q}
+ ${CPP} ${FLAGS} -o ${@} ${OBJ_Q} ${RT_LIB} ${SQLITE_LIB}
-${LOGGER}: sqlite3.o ${OBJ_L}
- ${CPP} ${FLAGS} -o ${@} ${<} ${OBJ_L} ${RT_LIB}
+${LOGGER}: ${OBJ_L}
+ ${CPP} ${FLAGS} -o ${@} ${OBJ_L} ${RT_LIB} ${SQLITE_LIB}
%.o: %.cpp %.hpp
- ${CPP} -c ${FLAGS} -o ${@} ${<} ${RT_LIB}
+ ${CPP} ${SQLITE_CFLAGS} -c ${FLAGS} -o ${@} ${<} ${RT_LIB}
queries.cpp: queries.hpp queries.l
flex -o queries.cpp queries.l
sqlite3.c:
./fetch_sqlite.sh
-
+
sqlite3.o: sqlite3.c
${C} -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_THREADSAFE=0 -c sqlite3.c
@@ -73,7 +75,7 @@
# This handy target does some minor magic to represent the include dependencies
# and keep the Makefile up-to-date.
#
-Makefile: ${CPPS}
+___Makefile: ${CPPS}
sed -i -e '/^# DEPENDENCIES:/q' Makefile
grep '^#include "' *.cpp \
| sed -e 's/:#include / /;s:"::g' \
@@ -97,10 +99,21 @@
ash_query.o: ash_query.hpp command.hpp config.hpp database.hpp flags.hpp formatter.hpp logger.hpp queries.hpp session.hpp
command.o: command.hpp unix.hpp util.hpp
config.o: config.hpp
-database.o: database.hpp config.hpp logger.hpp sqlite3.h
+database.o: database.hpp config.hpp logger.hpp
flags.o: flags.hpp
formatter.o: formatter.hpp database.hpp logger.hpp
logger.o: logger.hpp config.hpp
queries.o: queries.hpp logger.hpp
session.o: session.hpp unix.hpp
unix.o: unix.hpp config.hpp database.hpp logger.hpp util.hpp
+_ash_log.o: _ash_log.hpp command.hpp config.hpp database.hpp flags.hpp logger.hpp session.hpp unix.hpp
+ash_query.o: ash_query.hpp command.hpp config.hpp database.hpp flags.hpp formatter.hpp logger.hpp queries.hpp session.hpp
+command.o: command.hpp unix.hpp util.hpp
+config.o: config.hpp
+database.o: database.hpp config.hpp logger.hpp
+flags.o: flags.hpp
+formatter.o: formatter.hpp database.hpp logger.hpp
+logger.o: logger.hpp config.hpp
+queries.o: queries.hpp logger.hpp
+session.o: session.hpp unix.hpp
+unix.o: unix.hpp config.hpp database.hpp logger.hpp util.hpp
Index: src/database.cpp
===================================================================
--- src/database.cpp (revision 165)
+++ src/database.cpp (working copy)
@@ -26,6 +26,11 @@
#include <stdlib.h> /* for rand, srand */
#include <string.h> /* for strerror */
#include <time.h> /* for time */
+#include <unistd.h> /* for getpid */
+#ifdef __APPLE__
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
#include <iostream>
#include <list>
@@ -161,7 +166,29 @@
}
}
+#ifdef __APPLE__
+int
+osx_clock_gettime(clock_id_t id, struct timespec *ts) {
+ clock_serv_t host_clock;
+ mach_timespec_t now;
+
+ if (host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &host_clock) != KERN_SUCCESS) {
+ errno = EINVAL;
+ return 1;
+ }
+
+ if (clock_get_time(host_clock, &now) != KERN_SUCCESS) {
+ errno = EFAULT;
+ return 1;
+ }
+
+ ts->tv_sec = now.tv_sec;
+ ts->tv_nsec = now.tv_nsec;
+ return 0;
+}
+#endif
+
/**
* This method is only to be invoked if the database were locked when an insert
* or other query was attempted.
@@ -197,7 +224,13 @@
// Measure a timestamp to count how long we actually slept.
struct timespec before_ts, after_ts;
- if (clock_gettime(CLOCK_MONOTONIC, &before_ts)) {
+ if (
+#ifdef __APPLE__
+ osx_clock_gettime(SYSTEM_CLOCK, &before_ts)
+#else
+ clock_gettime(CLOCK_MONOTONIC, &before_ts)
+#endif
+ ) {
perror("clock_gettime failed");
}
@@ -217,7 +250,11 @@
--sleep_attempts;
// Sleep and verify the return code.
+#ifdef __APPLE__
+ int rval = nanosleep(&to_sleep, &remaining);
+#else
int rval = clock_nanosleep(CLOCK_MONOTONIC, 0, &to_sleep, &remaining);
+#endif
switch (rval) {
case -1:
LOG(ERROR) << "Failed to clock_nanosleep: " << strerror(errno);
@@ -253,7 +290,13 @@
}
// Check to see how long has passed since ash_sleep began.
- if (clock_gettime(CLOCK_MONOTONIC, &after_ts)) {
+ if (
+#ifdef __APPLE__
+ osx_clock_gettime(SYSTEM_CLOCK, &before_ts)
+#else
+clock_gettime(CLOCK_MONOTONIC, &after_ts)
+#endif
+ ) {
perror("clock_gettime failed");
}
Index: src/unix.cpp
===================================================================
--- src/unix.cpp (revision 165)
+++ src/unix.cpp (working copy)
@@ -60,7 +60,11 @@
* Returns the current working directory.
*/
const string unix::cwd() {
+#ifdef linux
char * c = get_current_dir_name();
+#else
+ char * c = getwd(NULL);
+#endif
if (!c) return DBObject::quote(0);
string cwd(c);
free(c);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment