Skip to content

Commit

Permalink
Attempt to execute a script
Browse files Browse the repository at this point in the history
Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Oct 28, 2024
1 parent b3778ea commit d624e6e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/zed/os/windows/zed.d/all-debug.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Get-Process

39 changes: 39 additions & 0 deletions cmd/zed/os/windows/zed_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,38 @@ _zed_exec_create_env(zed_strings_t *zsp)
return ((char **)buf);
}

void
launch_process(const char *path, const char *prog, char *env[])
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof (si));
si.cb = sizeof (si);
ZeroMemory(&pi, sizeof (pi));
char cmd[MAX_PATH];

fprintf(stderr, "Launching process '%s' in '%s'\r\n", prog, path);
fflush(stderr);

snprintf(cmd, sizeof (cmd),
"powershell.exe -ExecutionPolicy Bypass -File %s", path);

if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL,
&si, &pi)) {
zed_log_msg(LOG_WARNING,
"Failed to create process \"%s\": %s",
prog, strerror(GetLastError()));
return;
}

// While we debug
WaitForSingleObject(pi.hProcess, INFINITE);

// Close process and thread handles
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}

/*
* Fork a child process to handle event [eid]. The program [prog]
* in directory [dir] is executed with the environment [env].
Expand Down Expand Up @@ -168,6 +200,13 @@ _zed_exec_fork_child(uint64_t eid, const char *dir, const char *prog,
_exit(127);
}

#ifdef _WIN32
/*
* fork() always returns 1 (parent) above, so here we can spawn process
*/
launch_process(path, prog, env);
#endif

/* parent process */

node = calloc(1, sizeof (*node));
Expand Down
2 changes: 2 additions & 0 deletions cmd/zed/zed_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,14 @@ zed_conf_scan_dir(struct zed_conf *zcp)
direntp->d_name);
continue;
}
#ifndef _WIN32
if (!(st.st_mode & S_IXUSR)) {
zed_log_msg(LOG_INFO,
"Ignoring \"%s\": not executable by user",
direntp->d_name);
continue;
}
#endif
if ((st.st_mode & S_IWGRP) && !zcp->do_force) {
zed_log_msg(LOG_NOTICE,
"Ignoring \"%s\": writable by group",
Expand Down
2 changes: 1 addition & 1 deletion lib/libspl/include/os/windows/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ extern pid_t setsid(void);

static inline pid_t fork(void)
{
return (0);
return (1);
}

extern int mkostemps(char *templ, int suffixlen, DWORD flags);
Expand Down

0 comments on commit d624e6e

Please sign in to comment.