X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/5ef46cc08dc8723b3155ab1bec4e453293f2bcc9..69caa5be0e7aa4b274a98640d7b5f3334ec4894d:/Console.cpp diff --git a/Console.cpp b/Console.cpp index 7f97963..ef3de63 100644 --- a/Console.cpp +++ b/Console.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #include @@ -173,7 +174,20 @@ void Run(int socket, std::string &code, FILE *fout = NULL, bool expand = false) Run(socket, code.c_str(), code.size(), fout, expand); } -static void Console(int socket) { +static void Console(apr_pool_t *pool, int socket) { + passwd *passwd; + if (const char *username = getenv("LOGNAME")) + passwd = getpwnam(username); + else + passwd = getpwuid(getuid()); + + const char *basedir(apr_psprintf(pool, "%s/.cycript", passwd->pw_dir)); + const char *histfile(apr_psprintf(pool, "%s/history", basedir)); + size_t histlines(0); + + mkdir(basedir, 0700); + read_history(histfile); + bool bypass(false); bool debug(false); bool expand(false); @@ -227,6 +241,7 @@ static void Console(int socket) { fflush(fout); } add_history(line); + ++histlines; goto restart; } } @@ -280,6 +295,7 @@ static void Console(int socket) { std::cerr << error->message_ << std::endl; add_history(command.c_str()); + ++histlines; goto restart; } } @@ -306,6 +322,7 @@ static void Console(int socket) { } add_history(command.c_str()); + ++histlines; if (debug) std::cout << code << std::endl; @@ -313,6 +330,9 @@ static void Console(int socket) { Run(socket, code, fout, expand); } + _syscall(close(_syscall(open(histfile, O_CREAT | O_WRONLY, 0600)))); + append_history(histlines, histfile); + fputs("\n", fout); fflush(fout); } @@ -368,7 +388,7 @@ int main(int argc, char const * const argv[], char const * const envp[]) { fprintf(stderr, "usage: cycript [-c]" #ifdef CY_ATTACH - " [-p ]" + " [-p ]" #endif " [