more general cleanup

master
mark 20 years ago
parent 785c362a9f
commit 7adc71403b

@ -5,7 +5,11 @@ INCLUDES = -I$(LUA)/include
LUA = /home/mark/src/lang/lua/lua-5.1-rc1 LUA = /home/mark/src/lang/lua/lua-5.1-rc1
mingw:; $(MAKE) -C w32api ex.dll default:; echo Choose platform: mingw cygwin posix
all: mingw cygwin
mingw:; $(MAKE) -C w32api ex.dll
cygwin:; $(MAKE) -C posix ex.dll cygwin:; $(MAKE) -C posix ex.dll
posix:; $(MAKE) -C posix ex.so
#"EX_LIB=ex.so" "DEFINES=-D_XOPEN_SOURCE=600" #"EX_LIB=ex.so" "DEFINES=-D_XOPEN_SOURCE=600"

@ -289,6 +289,7 @@ static int ex_unlock(lua_State *L)
return ex_lock(L); return ex_lock(L);
} }
static int closeonexec(int d) static int closeonexec(int d)
{ {
int fl = fcntl(d, F_GETFD); int fl = fcntl(d, F_GETFD);

@ -8,8 +8,6 @@
#include "posix_spawn.h" #include "posix_spawn.h"
#define nelemof(A) (sizeof A / sizeof *A)
int posix_spawn_file_actions_init(posix_spawn_file_actions_t *act) int posix_spawn_file_actions_init(posix_spawn_file_actions_t *act)
{ {
act->dups[0] = act->dups[1] = act->dups[2] = -1; act->dups[0] = act->dups[1] = act->dups[2] = -1;
@ -22,11 +20,11 @@ int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *act, int d, int
errno = EBADF; errno = EBADF;
return -1; return -1;
} }
if (2 < d) { if (2 < n) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
act->dups[d] = n; act->dups[n] = d;
return 0; return 0;
} }
@ -46,20 +44,19 @@ int posix_spawnp(pid_t *restrict ppid,
return EINVAL; return EINVAL;
if (attrp) if (attrp)
return EINVAL; return EINVAL;
/* check act actions? */
switch (*ppid = fork()) { switch (*ppid = fork()) {
case -1: return -1; case -1: return -1;
default: return 0; default: return 0;
case 0: case 0:
if (act) { if (act) {
size_t i; int i;
for (i = 0; i < nelemof(act->dups); i++) for (i = 0; i < 3; i++)
if (act->dups[i] > -1) if (act->dups[i] != -1 && -1 == dup2(act->dups[i], i))
dup2(i, act->dups[i]); _exit(111);
} }
environ = (char **)envp; environ = (char **)envp;
execvp(path, argv); execvp(path, argv);
_exit(EXIT_FAILURE); _exit(111);
/*NOTREACHED*/ /*NOTREACHED*/
} }
} }

@ -1,15 +1,12 @@
#include <assert.h>
#include <lua.h> #include <lua.h>
#include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h> #include <sys/wait.h>
#ifndef MISSING_POSIX_SPAWN #if MISSING_POSIX_SPAWN
#include <spawn.h>
#else
#include "posix_spawn.h" #include "posix_spawn.h"
#else
#include <spawn.h>
#endif #endif
#include "spawn.h" #include "spawn.h"
@ -21,7 +18,6 @@ struct spawn_params {
}; };
extern int push_error(lua_State *L); extern int push_error(lua_State *L);
extern FILE *check_file(lua_State *L, int idx, const char *argname);
struct spawn_params *spawn_param_init(lua_State *L) struct spawn_params *spawn_param_init(lua_State *L)
{ {
@ -105,7 +101,6 @@ void spawn_param_redirect(struct spawn_params *p, const char *stdname, FILE *f)
case 'o': d = STDOUT_FILENO; break; case 'o': d = STDOUT_FILENO; break;
case 'e': d = STDERR_FILENO; break; case 'e': d = STDERR_FILENO; break;
} }
debug("duplicating %d to %d\n", fileno(f), d);
posix_spawn_file_actions_adddup2(&p->redirect, fileno(f), d); posix_spawn_file_actions_adddup2(&p->redirect, fileno(f), d);
} }
@ -135,9 +130,6 @@ int spawn_param_execute(struct spawn_params *p)
return ret != 0 ? push_error(L) : 1; return ret != 0 ? push_error(L) : 1;
} }
extern int push_error(lua_State *L);
/* proc -- exitcode/nil error */ /* proc -- exitcode/nil error */
int process_wait(lua_State *L) int process_wait(lua_State *L)
{ {

@ -350,7 +350,6 @@ static int ex_unlock(lua_State *L)
} }
/* -- LUA_FILEHANDLE file file */
static int make_pipe(FILE **i, FILE **o) static int make_pipe(FILE **i, FILE **o)
{ {
HANDLE ph[2]; HANDLE ph[2];

@ -1,19 +1,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <lua.h> #include <lua.h>
#include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <windows.h> #include <windows.h>
#include "spawn.h" #include "spawn.h"
#include <assert.h> #define debug(...) /* fprintf(stderr, __VA_ARGS__) */
#define debug(...) fprintf(stderr, __VA_ARGS__) #define debug_stack(L) /* #include "../lds.c" */
#include "../lds.c"
extern HANDLE get_handle(FILE *f);
extern int push_error(lua_State *L); extern int push_error(lua_State *L);
extern HANDLE get_handle(FILE *f);
static int needs_quoting(const char *s) static int needs_quoting(const char *s)
{ {
@ -41,7 +39,6 @@ struct spawn_params *spawn_param_init(lua_State *L)
return p; return p;
} }
/* filename ... */
void spawn_param_filename(struct spawn_params *p, const char *filename) void spawn_param_filename(struct spawn_params *p, const char *filename)
{ {
p->cmdline = filename; p->cmdline = filename;
@ -82,7 +79,7 @@ void spawn_param_args(struct spawn_params *p)
p->cmdline = lua_tostring(L, -1); p->cmdline = lua_tostring(L, -1);
} }
/* ... envtab */ /* ... envtab/nil */
void spawn_param_env(struct spawn_params *p) void spawn_param_env(struct spawn_params *p)
{ {
lua_State *L = p->L; lua_State *L = p->L;

Loading…
Cancel
Save