Skip to content

Commit 0b333d4

Browse files
committed
Added cetara and paella
1 parent d6470d9 commit 0b333d4

File tree

12 files changed

+318
-0
lines changed

12 files changed

+318
-0
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Object files
2+
*.o
3+
*.ko
4+
*.obj
5+
*.elf
6+
*.lib
7+
*.a
8+
*.la
9+
*.lo
10+
*.dll
11+
*.so
12+
*.so.*
13+
*.dylib
14+
*.exe
15+
*.out
16+
*.app
17+
*.i*86
18+
*.x86_64
19+
*.hex
20+
21+
# C/C++
22+
*.gch
23+
*.pch
24+
*.d
25+
26+
# Python
27+
*.pyc
28+
29+
# CMake
30+
CMakeFiles/
31+
*.cmake
32+
CMakeCache.txt
33+
34+
# Eclipse
35+
.cproject
36+
.project

LICENSE

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
REDIS SOURCE AVAILABLE LICENSE AGREEMENT
2+
3+
Version 1, February 21, 2019
4+
5+
This Agreement sets forth the terms on which the Licensor makes available the Software. BY INSTALLING, DOWNLOADING, ACCESSING, USING OR DISTRIBUTING ANY OF THE SOFTWARE, YOU AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO SUCH TERMS AND CONDITIONS, YOU MUST NOT USE THE SOFTWARE. If you are receiving the Software on behalf of a legal entity, you represent and warrant that you have the actual authority to agree to the terms and conditions of this agreement on behalf of such entity.
6+
7+
8+
0. DEFINITIONS
9+
10+
The terms below have the meanings set forth below for purposes of this Agreement:
11+
12+
Agreement: this Redis Source Available License Agreement.
13+
14+
Database Product: any of the following products or services: (a) database; (b) caching engine; (c) stream processing engine; (d) search engine; (e) indexing engine; (f) machine learning or deep learning or artificial intelligence serving engine;
15+
(g) a product or service exposing the Redis API; (h) a product or service exposing the Redis Modules API; or
16+
(i) a product or service exposing the Software API.
17+
18+
License: the Redis Source Available License described in Section 1.
19+
20+
Licensor: Redis Labs Ltd.
21+
22+
Modification: a modification of the Software made by You under the License, Section 1.1(c).
23+
24+
Redis: the open source Redis software as described in redis.io.
25+
26+
Software: certain software components designed to work with Redis and provided to you under this Agreement.
27+
28+
You: the recipient of this Software, an individual, or the entity on whose behalf you are receiving the Software.
29+
30+
Your Application: an application developed by or for You, where such application is not a Database Product.
31+
32+
1. LICENSE GRANT AND CONDITIONS
33+
34+
1.1 Subject to the terms and conditions of this Section 1, Licensor hereby grants to You a non-exclusive, royalty-free, worldwide, non-transferable license during the term of this Agreement to:
35+
(a) distribute or make available the Software or your Modifications under the terms of this Agreement, only as part of Your Application, so long as you include the following notice on any copy you distribute: "This software is subject to the terms of the Redis Source Available License Agreement".
36+
(b) use the Software, or your Modifications, only as part of Your Application, but not in connection with any Database Product that is distributed or otherwise made available by any third party.
37+
(c) modify the Software, provided that Modifications remain subject to the terms of this License.
38+
(d) reproduce the Software as necessary for the above.
39+
40+
1.2. Sublicensing. You may sublicense the right to use the Software fully embedded in Your Application as distributed by you in accordance with Section 1.1(a), pursuant to a written license that disclaims all warranties and liabilities on behalf of Licensor.
41+
42+
1.3. Notices. On all copies of the Software that you make, you must retain all copyright or other proprietary notices.
43+
44+
2. TERM AND TERMINATION. This Agreement will continue unless and until earlier terminated as set forth herein. If You breach any of its conditions or obligations under this Agreement, this Agreement will terminate automatically and the licenses granted herein will terminate automatically.
45+
46+
3. INTELLECTUAL PROPERTY. As between the parties, Licensor retains all right, title, and interest in the Software, and to Redis or other Licensor trademarks or service marks, and all intellectual property rights therein. Licensor hereby reserves all rights not expressly granted to You in this Agreement.
47+
48+
4. DISCLAIMER. TO THE EXTENT ALLOWABLE UNDER LAW, LICENSOR HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, AND SPECIFICALLY DISCLAIMS ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE SOFTWARE. Licensor has no obligation to support the Software.
49+
50+
5. LIMITATION OF LIABILITY. TO THE EXTENT ALLOWABLE UNDER LAW, LICENSOR WILL NOT BE LIABLE FOR ANY DAMAGES OF ANY KIND, INCLUDING BUT NOT LIMITED TO, LOST PROFITS OR ANY CONSEQUENTIAL, SPECIAL, INCIDENTAL, INDIRECT, OR DIRECT DAMAGES, ARISING OUT OF OR RELATING TO THIS AGREEMENT.
51+
52+
6. GENERAL. You are not authorized to assign Your rights under this Agreement to any third party. Licensor may freely assign its rights under this Agreement to any third party. This Agreement is the entire agreement between the parties on the subject matter hereof. No amendment or modification hereof will be valid or binding upon the parties unless made in writing and signed by the duly authorized representatives of both parties. In the event that any provision, including without limitation any condition, of this Agreement is held to be unenforceable, this Agreement and all licenses and rights granted hereunder will immediately terminate. Failure by Licensor to exercise any right hereunder will not be construed as a waiver of any subsequent breach of that right or as a waiver of any other right. This Agreement will be governed by and interpreted in accordance with the laws of the state of California, without reference to its conflict of laws principles. If You are located within the United States, all disputes arising out of this Agreement are subject to the exclusive jurisdiction of courts located in Santa Clara County, California. USA. If You are located outside of the United States, any dispute, controversy or claim arising out of or relating to this Agreement will be referred to and finally determined by arbitration in accordance with the JAMS before a single arbitrator in Santa Clara County, California. Judgment upon the award rendered by the arbitrator may be entered in any court having jurisdiction thereof.

cetara/diag/gdb.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
#include "readies/cetara/diag/gdb.h"
6+
7+
#include <string.h>
8+
#include <errno.h>
9+
#include <unistd.h>
10+
#include <stdint.h>
11+
#include <sys/ptrace.h>
12+
#include <sys/wait.h>
13+
14+
///////////////////////////////////////////////////////////////////////////////////////////////
15+
16+
#ifdef __linux__
17+
18+
#if 1
19+
20+
static inline bool _via_gdb()
21+
{
22+
int pid;
23+
int from_child[2] = {-1, -1};
24+
25+
if (pipe(from_child) < 0) {
26+
fprintf(stderr, "Debugger check failed: Error opening internal pipe: %s", strerror(errno));
27+
return false;
28+
}
29+
30+
pid = fork();
31+
if (pid == -1) {
32+
fprintf(stderr, "Debugger check failed: Error forking: %s", strerror(errno));
33+
return false;
34+
}
35+
36+
if (pid == 0) // child
37+
{
38+
uint8_t ret = 0;
39+
int ppid = getppid();
40+
41+
close(from_child[0]); // close parent's side
42+
43+
if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0)
44+
{
45+
waitpid(ppid, NULL, 0); // wait for the parent to stop
46+
write(from_child[1], &ret, sizeof(ret)); // tell the parent what happened
47+
48+
ptrace(PTRACE_DETACH, ppid, NULL, NULL);
49+
exit(0);
50+
}
51+
52+
ret = 1;
53+
write(from_child[1], &ret, sizeof(ret)); // tell the parent what happened
54+
55+
exit(0);
56+
57+
}
58+
else // parent
59+
{
60+
uint8_t ret = -1;
61+
62+
// child writes a 1 if pattach failed else 0.
63+
// read may be interrupted by pattach, hence the loop.
64+
while (read(from_child[0], &ret, sizeof(ret)) < 0 && errno == EINTR)
65+
;
66+
67+
// ret not updated
68+
if (ret < 0)
69+
fprintf(stderr, "Debugger check failed: Error getting status from child: %s", strerror(errno));
70+
71+
// close the pipes here, to avoid races with pattach (if we did it above)
72+
close(from_child[1]);
73+
close(from_child[0]);
74+
75+
waitpid(pid, NULL, 0); // collect the status of the child
76+
77+
return ret == 1;
78+
}
79+
}
80+
81+
#else
82+
83+
static inline bool _via_gdb()
84+
{
85+
const int status_fd = open("/proc/self/status", O_RDONLY);
86+
if (status_fd == -1)
87+
return false;
88+
89+
char buf[4096];
90+
const ssize_t num_read = read(status_fd, buf, sizeof(buf) - 1);
91+
if (num_read <= 0)
92+
return false;
93+
94+
buf[num_read] = '\0';
95+
constexpr char tracer_pid[] = "TracerPid:";
96+
const auto tracer_pid_p = strstr(buf, tracer_pid);
97+
if (!tracer_pid_p)
98+
return false;
99+
100+
for (const char *p = tracer_pid_p + sizeof(tracer_pid) - 1; p <= buf + num_read; ++p)
101+
{
102+
if (isspace(*p))
103+
continue;
104+
return isdigit(*p) && *p != '0';
105+
}
106+
107+
return false;
108+
}
109+
110+
#endif // 1
111+
112+
#elif defined(__APPLE__)
113+
114+
static inline bool _via_gdb()
115+
{
116+
}
117+
118+
#endif
119+
120+
//---------------------------------------------------------------------------------------------
121+
122+
bool __via_gdb = false;
123+
124+
__attribute__((constructor))
125+
static void initialize(void)
126+
{
127+
__via_gdb = _via_gdb();
128+
}
129+
130+
///////////////////////////////////////////////////////////////////////////////////////////////

cetara/diag/gdb.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#pragma once
3+
4+
#include <stdbool.h>
5+
6+
extern bool __via_gdb;
7+
8+
#define BB do { if (__via_gdb) { __asm__("int $3"); } } while(0);

paella/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
from .debug import *
3+
from .utils import *
4+
from .files import *
5+
# from .docopt import docopt
6+
from .log import *
7+
8+
#----------------------------------------------------------------------------------------------
9+
10+
import sys
11+
12+
class global_injector:
13+
def __init__(self):
14+
try:
15+
# Python 2
16+
self.__dict__['builtin'] = sys.modules['__builtin__'].__dict__
17+
except KeyError:
18+
# Python 3
19+
self.__dict__['builtin'] = sys.modules['builtins'].__dict__
20+
def __setattr__(self,name,value):
21+
self.builtin[name] = value
22+
23+
Global = global_injector()
24+
25+
#----------------------------------------------------------------------------------------------
26+
27+
Global.bb = bb
28+
Global.eprint = eprint
29+
Global.fatal = fatal

paella/debug.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import os
3+
4+
#----------------------------------------------------------------------------------------------
5+
6+
if 'PYDEBUG' in os.environ:
7+
from pdb import set_trace as bb
8+
else:
9+
def bb(): pass
10+
11+
#----------------------------------------------------------------------------------------------

paella/docopt1.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
from docopt import docopt as docopt1
3+
from collections import namedtuple
4+
import re
5+
6+
def dict_to_obj(d):
7+
def add_to_dict_if_match(r, k, v, d):
8+
m = re.match(r, k)
9+
if m:
10+
d[m[1].replace('-', '_')] = v
11+
return not not m
12+
13+
d1 = dict()
14+
for k, v in d.items():
15+
if isinstance(v, dict):
16+
d1[k] = dict_to_obj(v)
17+
elif add_to_dict_if_match('--(.*)', k, v, d1):
18+
pass
19+
elif add_to_dict_if_match('\<(.*)\>', k, v, d1):
20+
pass
21+
return namedtuple('object', d1.keys())(*d1.values())
22+
23+
def docopt(*args, **kwargs):
24+
a = docopt1(*args, **kwargs)
25+
return dict_to_obj(a)

paella/files.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
def fread(fname, mode = 'rb'):
3+
with open(fname, mode) as file:
4+
return file.read()

paella/log.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
import os
3+
4+
def fatal(text):
5+
eprint("%s: %s" %(os.path.basename(__file__), text))
6+
exit(1)

paella/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
import sys
3+
4+
if (sys.version_info > (3, 0)):
5+
from .utils3 import *
6+
else:
7+
from .utils2 import *

0 commit comments

Comments
 (0)