175 lines
4.1 KiB
Diff
175 lines
4.1 KiB
Diff
From 49e370aec2435420aa5a69920e7519046371ee46 Mon Sep 17 00:00:00 2001
|
|
From: Martell Malone <martellmalone@gmail.com>
|
|
Date: Thu, 25 Jun 2015 23:48:43 +0100
|
|
Subject: [PATCH 4/8] serverutil hackery for windows
|
|
|
|
---
|
|
include/h2o/serverutil.h | 16 ++++++++++++
|
|
lib/common/serverutil.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++-
|
|
2 files changed, 79 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/include/h2o/serverutil.h b/include/h2o/serverutil.h
|
|
index b084096..92e14b5 100644
|
|
--- a/include/h2o/serverutil.h
|
|
+++ b/include/h2o/serverutil.h
|
|
@@ -23,7 +23,23 @@
|
|
#define h2o__server_starter_h
|
|
|
|
#include <stddef.h>
|
|
+#ifndef _WIN32
|
|
#include <pwd.h>
|
|
+#else
|
|
+
|
|
+
|
|
+struct passwd {
|
|
+ char *pw_name; /* user name */
|
|
+ char *pw_passwd; /* encrypted password */
|
|
+ int pw_uid; /* user uid */
|
|
+ int pw_gid; /* user gid */
|
|
+ char *pw_comment; /* comment */
|
|
+ char *pw_gecos; /* Honeywell login info */
|
|
+ char *pw_dir; /* home directory */
|
|
+ char *pw_shell; /* default shell */
|
|
+};
|
|
+
|
|
+#endif
|
|
|
|
/* taken from sysexits.h */
|
|
#ifndef EX_SOFTWARE
|
|
diff --git a/lib/common/serverutil.c b/lib/common/serverutil.c
|
|
index 0b843b0..a027118 100644
|
|
--- a/lib/common/serverutil.c
|
|
+++ b/lib/common/serverutil.c
|
|
@@ -21,19 +21,66 @@
|
|
*/
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
-#include <grp.h>
|
|
+#ifndef _WIN32
|
|
+# include <grp.h>
|
|
+#endif
|
|
#include <pthread.h>
|
|
#include <signal.h>
|
|
+#ifdef _WIN32
|
|
+#define sigemptyset(x) memset((x), 0, sizeof(*(x)))
|
|
+#ifndef SIGHUP
|
|
+# define SIGHUP -1
|
|
+#endif
|
|
+#ifndef SIGPIPE
|
|
+# define SIGPIPE -1
|
|
+#endif
|
|
+struct sigaction
|
|
+{
|
|
+ void (*sa_handler)(int);
|
|
+ int sa_flags;
|
|
+ int sa_mask;
|
|
+};
|
|
+int sigaction(int sig, struct sigaction *action, struct sigaction *old)
|
|
+{
|
|
+ if (sig == -1)
|
|
+ return 0;
|
|
+ if (old == NULL)
|
|
+ {
|
|
+ if (signal(sig, SIG_DFL) == SIG_ERR)
|
|
+ return -1;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ if (signal(sig, action->sa_handler) == SIG_ERR)
|
|
+ return -1;
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+#define waitpid(a,b,c) _cwait(b,a,c)
|
|
+#define pipe(a) _pipe((a), 0, _O_BINARY | _O_NOINHERIT)
|
|
+typedef struct
|
|
+{
|
|
+ int __allocated;
|
|
+ int __used;
|
|
+ struct __spawn_action *__actions;
|
|
+ int __pad[16];
|
|
+} posix_spawn_file_actions_t;
|
|
+#else
|
|
#include <spawn.h>
|
|
+#endif
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
+#ifndef _WIN32
|
|
#include <sys/wait.h>
|
|
+#endif
|
|
#include <unistd.h>
|
|
#if !defined(_SC_NPROCESSORS_ONLN)
|
|
+#ifndef _WIN32
|
|
#include <sys/sysctl.h>
|
|
#endif
|
|
+#endif
|
|
#include "cloexec.h"
|
|
#include "h2o/memory.h"
|
|
#include "h2o/serverutil.h"
|
|
@@ -52,6 +99,7 @@ void h2o_set_signal_handler(int signo, void (*cb)(int signo))
|
|
|
|
int h2o_setuidgid(struct passwd *passwd)
|
|
{
|
|
+#ifndef _WIN32
|
|
if (setgid(passwd->pw_gid) != 0) {
|
|
fprintf(stderr, "setgid(%d) failed:%s\n", (int)passwd->pw_gid, strerror(errno));
|
|
return -1;
|
|
@@ -64,6 +112,7 @@ int h2o_setuidgid(struct passwd *passwd)
|
|
fprintf(stderr, "setuid(%d) failed:%s\n", (int)passwd->pw_uid, strerror(errno));
|
|
return -1;
|
|
}
|
|
+#endif
|
|
|
|
return 0;
|
|
}
|
|
@@ -101,6 +150,7 @@ size_t h2o_server_starter_get_fds(int **_fds)
|
|
return fds.size;
|
|
}
|
|
|
|
+#ifndef _WIN32
|
|
pid_t h2o_spawnp(const char *cmd, char **argv, const int *mapped_fds, int cloexec_mutex_is_locked)
|
|
{
|
|
#if defined(__linux__)
|
|
@@ -191,9 +241,14 @@ Error:
|
|
|
|
#endif
|
|
}
|
|
+#endif
|
|
|
|
int h2o_read_command(const char *cmd, char **argv, h2o_buffer_t **resp, int *child_status)
|
|
{
|
|
+#ifdef _WIN32
|
|
+ return -1;
|
|
+#else
|
|
+
|
|
int respfds[2] = {-1, -1};
|
|
pid_t pid = -1;
|
|
int mutex_locked = 0, ret = -1;
|
|
@@ -206,7 +261,13 @@ int h2o_read_command(const char *cmd, char **argv, h2o_buffer_t **resp, int *chi
|
|
/* create pipe for reading the result */
|
|
if (pipe(respfds) != 0)
|
|
goto Exit;
|
|
+
|
|
+#ifdef _WIN32
|
|
+ u_long nonblock = 0;
|
|
+ ioctlsocket(respfds[0], FIONBIO, &nonblock);
|
|
+#else
|
|
fcntl(respfds[0], F_SETFD, O_CLOEXEC);
|
|
+#endif
|
|
|
|
/* spawn */
|
|
int mapped_fds[] = {respfds[1], 1, /* stdout of the child process is read from the pipe */
|
|
@@ -251,6 +312,7 @@ Exit:
|
|
h2o_buffer_dispose(resp);
|
|
|
|
return ret;
|
|
+#endif
|
|
}
|
|
|
|
size_t h2o_numproc()
|
|
--
|
|
2.4.4
|
|
|