This commit is contained in:
Axel Kittenberger 2010-10-17 20:26:37 +00:00
parent 1caf4a52ad
commit 88cb57bc58
2 changed files with 51 additions and 27 deletions

View File

@ -50,11 +50,11 @@ volatile sig_atomic_t reset = 0;
void * void *
s_calloc(size_t nmemb, size_t size) s_calloc(size_t nmemb, size_t size)
{ {
void *r = calloc(nmemb, size); void *r = calloc(nmemb, size);
if (r == NULL) { if (r == NULL) {
printf("Out of memory!\n"); printf("Out of memory!\n");
exit(-1); // ERRNO exit(-1); // ERRNO
} }
return r; return r;
} }
@ -65,11 +65,11 @@ s_calloc(size_t nmemb, size_t size)
void * void *
s_malloc(size_t size) s_malloc(size_t size)
{ {
void *r = malloc(size); void *r = malloc(size);
if (r == NULL) { if (r == NULL) {
printf("Out of memory!\n"); printf("Out of memory!\n");
exit(-1); // ERRNO exit(-1); // ERRNO
} }
return r; return r;
} }
@ -96,14 +96,37 @@ add_watch(lua_State *L)
static int static int
exec(lua_State *L) exec(lua_State *L)
{ {
const char *path = luaL_checkstring(L, 1); const char *binary = luaL_checkstring(L, 1);
int argc = lua_gettop(L) - 1; int argc = lua_gettop(L) - 1;
pid_t pid;
int i; int i;
const char **argv = s_calloc(argc + 1, sizeof(char *)); char const **argv = s_calloc(argc + 2, sizeof(char *));
for(i = 0; i < argc; i++) {
argv[i] = luaL_checkstring(L, i + 2); argv[0] = binary;
for(i = 1; i < argc; i++) {
argv[i] = luaL_checkstring(L, i + 1);
printf("%d.%s\n", i, argv[i]);
}
argv[i] = NULL;
pid = fork();
if (pid == 0) {
//if (!log->flag_nodaemon && log->logfile) {
// if (!freopen(log->logfile, "a", stdout)) {
// printlogf(log, ERROR, "cannot redirect stdout to [%s].", log->logfile);
// }
// if (!freopen(log->logfile, "a", stderr)) {
// printlogf(log, ERROR, "cannot redirect stderr to [%s].", log->logfile);
// }
//}
execv(binary, (char **)argv);
// in a sane world execv does not return!
printf("Failed executing [%s]!\n", binary);
exit(-1); // ERRNO
} }
free(argv);
return 0; return 0;
} }
@ -165,14 +188,15 @@ stackdump(lua_State* l)
case LUA_TBOOLEAN: case LUA_TBOOLEAN:
printf("%d boolean %s\n", i, lua_toboolean(l, i) ? "true" : "false"); printf("%d boolean %s\n", i, lua_toboolean(l, i) ? "true" : "false");
break; break;
case LUA_TNUMBER: case LUA_TNUMBER:
printf("%d number: %g\n", i, lua_tonumber(l, i)); printf("%d number: %g\n", i, lua_tonumber(l, i));
break; break;
default: /* other values */ default: /* other values */
printf("%d %s\n", i, lua_typename(l, t)); printf("%d %s\n", i, lua_typename(l, t));
break; break;
} }
} }
printf("\n"); printf("\n");
return 0; return 0;
} }
@ -191,9 +215,9 @@ sub_dirs (lua_State *L)
int idx = 1; int idx = 1;
d = opendir(dirname); d = opendir(dirname);
if (d == NULL) { if (d == NULL) {
printf("cannot open dir %s.\n", dirname); printf("cannot open dir %s.\n", dirname);
return 0; return 0;
} }
lua_newtable(L); lua_newtable(L);
@ -270,12 +294,11 @@ main(int argc, char *argv[])
} }
/* open inotify */ /* open inotify */
inotify_fd = inotify_init(); inotify_fd = inotify_init();
if (inotify_fd == -1) { if (inotify_fd == -1) {
printf("Cannot create inotify instance! (%d:%s)", printf("Cannot create inotify instance! (%d:%s)", errno, strerror(errno));
errno, strerror(errno)); return -1; // ERRNO
return -1; // ERRNO }
}
/* initialize */ /* initialize */
lua_getglobal(L, "lsyncd_initialize"); lua_getglobal(L, "lsyncd_initialize");

View File

@ -82,7 +82,7 @@ function lsyncd_initialize()
local target = { path = o.targetpath } local target = { path = o.targetpath }
table.insert(targets, target) table.insert(targets, target)
origin[i].target = target origin[i].target = target
attend_dir(lsyncd.real_dir(o.source), "", target) attend_dir(o.source, "", target)
end end
end end
@ -94,7 +94,7 @@ end
---- ----
-- Add one directory to be watched. -- Add one directory to be watched.
function add(source_dir, target_path) function add(source_dir, target_path)
local o = { source = source_dir, targetpath = target_path } local o = { source = lsyncd.real_dir(source_dir), targetpath = target_path }
table.insert(origin, o) table.insert(origin, o)
return o return o
end end
@ -111,7 +111,8 @@ function default_startup()
print("--- STARTUP ---") print("--- STARTUP ---")
local pids = { } local pids = { }
for i, o in ipairs(origin) do for i, o in ipairs(origin) do
pid = lsyncd.exec("/usr/bin/rsyc", "-ltrs", o.source, o.targetpath) print("/usr/bin/rsync", "-ltrs", o.source, o.targetpath)
pid = lsyncd.exec("/usr/bin/rsync", "-ltrs", o.source, o.targetpath)
print("started ", pid) print("started ", pid)
table.insert(pids, pid) table.insert(pids, pid)
end end