mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
Server's stdio can be redirected controled by acl_master.
This commit is contained in:
parent
2669546783
commit
51c476c1cf
@ -42,6 +42,8 @@ typedef struct ACL_MASTER_SERV {
|
||||
int max_proc; /* upper bound on # processes */
|
||||
int prefork_proc; /* prefork processes */
|
||||
//char *command; /* command in configure */
|
||||
char *stdout_log; /* file to store stdout */
|
||||
char *stderr_log; /* file to store stderr */
|
||||
char *cmdext; /* extname of the command */
|
||||
char *path; /* command pathname */
|
||||
char *conf; /* service configure filepath */
|
||||
|
@ -787,6 +787,20 @@ static int service_env(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void service_misc(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv)
|
||||
{
|
||||
const char *ptr = get_str_ent(xcp, ACL_VAR_MASTER_SERV_STDOUT, NULL);
|
||||
|
||||
if (ptr && *ptr) {
|
||||
serv->stdout_log = acl_mystrdup(ptr);
|
||||
}
|
||||
|
||||
ptr = get_str_ent(xcp, ACL_VAR_MASTER_SERV_STDERR, NULL);
|
||||
if (ptr && *ptr) {
|
||||
serv->stderr_log = acl_mystrdup(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static int valid_extname(const char *filename)
|
||||
{
|
||||
ACL_ITER iter;
|
||||
@ -861,8 +875,6 @@ ACL_MASTER_SERV *acl_master_ent_get()
|
||||
acl_msg_info("%s(%d), %s: load service file = %s",
|
||||
__FILE__, __LINE__, __FUNCTION__, STR(path_buf));
|
||||
|
||||
acl_vstring_strcpy(__config_file, STR(path_buf));
|
||||
|
||||
serv = acl_master_ent_load(STR(path_buf));
|
||||
if (serv != NULL) {
|
||||
acl_vstring_free(path_buf);
|
||||
@ -877,6 +889,8 @@ ACL_MASTER_SERV *acl_master_ent_load(const char *filepath)
|
||||
ACL_MASTER_SERV *serv;
|
||||
const char *ptr;
|
||||
|
||||
acl_vstring_strcpy(__config_file, filepath);
|
||||
|
||||
if (xcp == NULL) {
|
||||
acl_msg_error("%s(%d), %s: load %s error %s", __FILE__,
|
||||
__LINE__, __FUNCTION__, filepath, acl_last_serror());
|
||||
@ -920,7 +934,10 @@ ACL_MASTER_SERV *acl_master_ent_load(const char *filepath)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* linked for children */
|
||||
/* The other configure entries */
|
||||
service_misc(xcp, serv);
|
||||
|
||||
/* Linked for children */
|
||||
acl_ring_init(&serv->children);
|
||||
|
||||
/* Backoff time in case a service is broken. */
|
||||
|
@ -131,6 +131,8 @@ extern int acl_var_master_start_timeo;
|
||||
#define ACL_VAR_MASTER_SERV_CHROOT "master_chroot"
|
||||
#define ACL_VAR_MASTER_SERV_WAKEUP "master_wakeup"
|
||||
#define ACL_VAR_MASTER_SERV_LOG "master_log"
|
||||
#define ACL_VAR_MASTER_SERV_STDOUT "master_stdout"
|
||||
#define ACL_VAR_MASTER_SERV_STDERR "master_stderr"
|
||||
#define ACL_VAR_MASTER_SERV_COMMAND "master_command"
|
||||
#define ACL_VAR_MASTER_SERV_CMDEXT "master_cmdext"
|
||||
#define ACL_VAR_MASTER_SERV_ARGS "master_args"
|
||||
|
@ -112,9 +112,11 @@ static void prepare_child_fds(ACL_MASTER_SERV *serv)
|
||||
acl_msg_fatal("%s: flow pipe read descriptor <= %d",
|
||||
myname, ACL_MASTER_FLOW_READ);
|
||||
}
|
||||
|
||||
if (dup2(acl_var_master_flow_pipe[0], ACL_MASTER_FLOW_READ) < 0) {
|
||||
acl_msg_fatal("%s: dup2: %s", myname, strerror(errno));
|
||||
}
|
||||
|
||||
if (close(acl_var_master_flow_pipe[0]) < 0) {
|
||||
acl_msg_fatal("close %d: %s",
|
||||
acl_var_master_flow_pipe[0], strerror(errno));
|
||||
@ -169,6 +171,26 @@ static void start_child(ACL_MASTER_SERV *serv)
|
||||
prepare_child_fds(serv);
|
||||
}
|
||||
|
||||
/* Redirect stdout to local file */
|
||||
if (serv->stdout_log) {
|
||||
int oflags = O_APPEND | O_WRONLY | O_CREAT;
|
||||
int fd = open(serv->stdout_log, oflags, 0600);
|
||||
if (fd >= 0 && fd != 1) {
|
||||
dup2(fd, 1);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
/* Redirect stderr to local file */
|
||||
if (serv->stderr_log) {
|
||||
int oflags = O_APPEND | O_WRONLY | O_CREAT;
|
||||
int fd = open(serv->stderr_log, oflags, 0600);
|
||||
if (fd >= 0 && fd != 2) {
|
||||
dup2(fd, 2);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
acl_vstring_sprintf(env_gen, "%s=%o", ACL_MASTER_GEN_NAME,
|
||||
master_generation);
|
||||
if (putenv(acl_vstring_str(env_gen)) < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user