Skip to content

Commit 8ee6683

Browse files
author
zhengshuxin
committed
optimize acl_master for managing more no-acl modules
1 parent b38d470 commit 8ee6683

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

app/master/daemon/master/master.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct ACL_MASTER_SERV {
3030
int flags; /* status, features, etc. */
3131
char *name; /* service endpoint name */
3232
char *owner; /* service running privilege if not null*/
33+
char *home; /* service working home default */
3334
long start; /* service start running time */
3435
int type; /* UNIX-domain, INET, etc. */
3536
int wakeup_time; /* wakeup interval */

app/master/daemon/master/master_ent.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,13 @@ static int service_args(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv,
629629
serv->owner = NULL;
630630
}
631631

632+
ptr_const = get_str_ent(xcp, ACL_VAR_MASTER_SERV_HOME, "");
633+
if (ptr_const && *ptr_const) {
634+
serv->home = acl_mystrdup(ptr_const);
635+
} else {
636+
serv->home = NULL;
637+
}
638+
632639
/* Path to command */
633640
command = get_str_ent(xcp, ACL_VAR_MASTER_SERV_COMMAND, "");
634641
if (command == NULL || *command == 0) {
@@ -946,8 +953,9 @@ void acl_master_ent_print(ACL_MASTER_SERV *serv)
946953
acl_msg_info("max_proc: %d", serv->max_proc);
947954
acl_msg_info("prefork_proc: %d", serv->prefork_proc);
948955
acl_msg_info("path: %s", serv->path);
949-
for (cpp = serv->args->argv; *cpp; cpp++)
956+
for (cpp = serv->args->argv; *cpp; cpp++) {
950957
acl_msg_info("arg[%d]: %s", (int) (cpp - serv->args->argv), *cpp);
958+
}
951959
acl_msg_info("prefork_proc: %d", serv->prefork_proc);
952960
acl_msg_info("avail_proc: %d", serv->avail_proc);
953961
acl_msg_info("total_proc: %d", serv->total_proc);
@@ -1002,6 +1010,9 @@ void acl_master_ent_free(ACL_MASTER_SERV *serv)
10021010
if (serv->owner) {
10031011
acl_myfree(serv->owner);
10041012
}
1013+
if (serv->home) {
1014+
acl_myfree(serv->home);
1015+
}
10051016
if (serv->notify_addr) {
10061017
acl_myfree(serv->notify_addr);
10071018
}

app/master/daemon/master/master_params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ extern int acl_var_master_start_timeo;
135135
#define ACL_VAR_MASTER_SERV_CMDEXT "master_cmdext"
136136
#define ACL_VAR_MASTER_SERV_ARGS "master_args"
137137
#define ACL_VAR_MASTER_SERV_OWNER "master_owner"
138+
#define ACL_VAR_MASTER_SERV_HOME "master_home"
138139
#define ACL_VAR_MASTER_SERV_ENV "master_env"
139140
#define ACL_VAR_MASTER_NOTIFY_ADDR "master_notify_addr"
140141
#define ACL_VAR_MASTER_NOTIFY_RECIPIENTS "master_notify_recipients"

app/master/daemon/master/master_spawn.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,25 @@ static void start_child(ACL_MASTER_SERV *serv)
189189
acl_msg_info("%s: cmd = %s", myname, serv->path);
190190
}
191191

192+
/* Help app to change working directory */
193+
if (serv->home && *serv->home) {
194+
if (chdir(serv->home) == -1) {
195+
acl_msg_error("%s: chdir to %s error %s",
196+
myname, serv->home, acl_last_serror());
197+
} else {
198+
acl_msg_info("%s: %s chdir to %s ok",
199+
myname, serv->path, serv->home);
200+
}
201+
}
202+
192203
/* Help programs written by golang to change runing privilege */
193204
if (serv->owner && *serv->owner) {
194205
acl_msg_info("%s: acl_chroot_uid %s", myname, serv->owner);
195206
acl_chroot_uid(NULL, serv->owner);
196207
}
197208

198209
log_argv(serv->path, serv->args);
210+
199211
execvp(serv->path, serv->args->argv);
200212
acl_msg_fatal("%s: exec %s: %s", myname, serv->path, strerror(errno));
201213
}

0 commit comments

Comments
 (0)