Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds c++ support for OSX #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2017 Carl Anderson
# Copyright 2023 Carl Anderson
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,9 +14,9 @@
# limitations under the License.
#

REV := r2
VERSION := 0.8
UPDATED := 2018-01-03
REV := r0
VERSION := 0.9
UPDATED := 2023-01-21
RVERSION := ${VERSION}${REV}
ETC_DIR := /usr/local/etc/advanced-shell-history
LIB_DIR := /usr/local/lib/advanced_shell_history
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,12 @@ command.
options necessary for the magic to work.

## Bugs
* The C++ version does not compile in OSX because the CLOCK_MONOTONIC symbol is undefined.
* Use the python version for now.
* Doesn't capture exec'ed commands: example: `exec rm /tmp/foo # is lost`
* The python version is about 10x slower than the C++ version.
* multi-line commands only include the first line in history

### Author
[email protected] (Carl Anderson)

### Updated
2018-01-03
2023-01-21
2 changes: 1 addition & 1 deletion python/_ash_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from __future__ import print_function

__author__ = 'Carl Anderson ([email protected])'
__version__ = '0.8r2'
__version__ = '0.9r0'


import logging
Expand Down
2 changes: 1 addition & 1 deletion python/advanced_shell_history/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""

__author__ = 'Carl Anderson ([email protected])'
__version__ = '0.8r2'
__version__ = '0.9r0'


import argparse
Expand Down
2 changes: 1 addition & 1 deletion python/ash_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from __future__ import print_function

__author__ = 'Carl Anderson ([email protected])'
__version__ = '0.8r2'
__version__ = '0.9r0'


import csv
Expand Down
7 changes: 6 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2017 Carl Anderson
# Copyright 2023 Carl Anderson
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,12 @@ TRASH := ${OBJS} ${EXES} core Makefile-e
CPP := g++
C := gcc
FLAGS := -g -Wall -DASH_VERSION="\"${VERSION}\"" -ansi -pedantic -O2
SYSTEM := $(shell ${C} -dumpmachine)
ifeq (apple, $(findstring apple,${SYSTEM}))
RT_LIB :=
else
RT_LIB := -lrt
endif

.PHONY: all clean distclean new
all: ${EXES}
Expand Down
6 changes: 5 additions & 1 deletion src/database.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2011 Carl Anderson
Copyright 2023 Carl Anderson

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -217,7 +217,10 @@ void ash_sleep() {
}
--sleep_attempts;

#ifdef __APPLE__
// Sleep and verify the return code.
int rval = 0;
#else
int rval = clock_nanosleep(CLOCK_MONOTONIC, 0, &to_sleep, &remaining);
switch (rval) {
case -1:
Expand All @@ -238,6 +241,7 @@ void ash_sleep() {
default:
LOG(ERROR) << "Unexpected rval from clock_nanosleep: " << rval;
}
#endif

// If there is any time remaining, prepare to sleep again.
if (remaining.tv_sec == 0
Expand Down
5 changes: 5 additions & 0 deletions src/unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ const string proc_stat(const int target, const pid_t pid) {
* Returns the current working directory.
*/
const string unix::cwd() {
#ifdef _GNU_SOURCE
char * c = get_current_dir_name();
#else
char * c = (char *) malloc(PATH_MAX * sizeof(char));
getcwd(c, PATH_MAX);
#endif
if (!c) return DBObject::quote(0);
string cwd(c);
free(c);
Expand Down