mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-06-02 08:20:51 +00:00
This commit is contained in:
parent
1caf4a52ad
commit
88cb57bc58
35
lsyncd.c
35
lsyncd.c
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +196,7 @@ stackdump(lua_State* l)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -272,8 +296,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user