Skip to content

Commit 7d03ff6

Browse files
authored
Merge pull request #1 from qbit/master
add changes for execpromises
2 parents e885f3b + 3b2f478 commit 7d03ff6

File tree

3 files changed

+11
-61
lines changed

3 files changed

+11
-61
lines changed

README

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Implements:
88

99
Works and has been tested on Lua 5.1, 5.2 and 5.3.
1010

11-
Note that pledge() (on the 19th January of 2016) will fail if you
12-
give it a list of paths as the second parameter:
11+
Note that pledge() pre 6.3 takes an optional set of paths
12+
as the second argument.
1313

1414
-- OK
1515
o.pledge('rpath stdio')
1616
-- Error
17-
o.pledge('rpath stdio', {})
17+
o.pledge('rpath stdio', 'stdio')
1818

1919
Build:
2020

example/openbsd-example.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ print(ret, s)
88
ret, s = o.pledge("rpath stdio", {})
99
print(ret, s)
1010

11-
-- Same as pledge("rpath", { "/var", "/home", ..., NULL })
12-
ret, s = o.pledge("rpath stdio", {"/var", "/home", "/test", "/more",
13-
"/asdf", "/test", "/stuff", "/meh",
14-
"/alestorm", "/tbdm", "/opeth",
15-
"/atthegates"})
11+
-- Same as pledge("rpath stdio wpath", "rpath stdio")
12+
ret, s = o.pledge("rpath stdio wpath", "rpath stdio")
13+
1614
print(ret, s)
1715

1816
print(o.arc4random())

src/lua-openbsd.c

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,11 @@ static void lo_die(lua_State *L, char const *e)
1515
lua_error(L);
1616
}
1717

18-
static void free_strings(char **str, size_t n)
19-
{
20-
size_t i = 0;
21-
22-
if (str) {
23-
for (; i < n; i++) {
24-
free(str[i]);
25-
}
26-
}
27-
free(str);
28-
}
29-
3018
int lua_pledge(lua_State *L)
3119
{
3220
char const *farg = NULL;
33-
char **dirs = NULL;
21+
char const *earg = NULL;
3422
int ret = 0;
35-
size_t idx = 0;
3623
int top = 0;
3724

3825
#ifndef HAVE_PLEDGE
@@ -44,51 +31,16 @@ int lua_pledge(lua_State *L)
4431
luaL_argcheck(L, lua_isstring(L, 1), 1,
4532
"pledge: first argument must be string");
4633
if (top == 2) {
47-
luaL_argcheck(L, lua_istable(L, 2), 1,
48-
"pledge: second argument must be table");
34+
luaL_argcheck(L, lua_isstring(L, 2), 1,
35+
"pledge: second argument must be string");
4936
} else if (top > 2) {
5037
lo_die(L, "pledge: too many arguments");
5138
}
5239

5340
farg = lua_tostring(L, 1);
41+
earg = lua_tostring(L, 2);
5442

55-
if (!lua_isnoneornil(L, 2)) {
56-
size_t sz = 1;
57-
dirs = calloc(2, sizeof(char*));
58-
if (dirs == NULL) {
59-
lo_die(L, "pledge: calloc");
60-
}
61-
62-
lua_pushnil(L);
63-
while (lua_next(L, 2)) {
64-
if (lua_isstring(L, -1)) {
65-
char const *str = lua_tostring(L, -1);
66-
67-
if (idx == (sz-1)) {
68-
char **tmp = NULL;
69-
70-
tmp = reallocarray(dirs, sz+10, sizeof(char*));
71-
if (tmp == NULL) {
72-
free_strings(dirs, idx+1);
73-
lo_die(L, "pledge: calloc()");
74-
}
75-
dirs = tmp;
76-
sz = sz + 10;
77-
}
78-
79-
dirs[idx] = strdup(str);
80-
if (dirs[idx] == NULL) {
81-
free_strings(dirs, idx+1);
82-
lo_die(L, "pledge: strdup");
83-
}
84-
++idx;
85-
}
86-
lua_pop(L, 1);
87-
}
88-
}
89-
90-
ret = pledge(farg, (char const **)dirs);
91-
free_strings(dirs, idx+1);
43+
ret = pledge(farg, earg);
9244

9345
lua_pushnumber(L, ret);
9446
if (ret == -1) {

0 commit comments

Comments
 (0)