Skip to content

Commit

Permalink
nginx-0.1.0-2004-09-27-20:03:21 import
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsysoev committed Sep 27, 2004
1 parent 4bed6e3 commit 6d2a14a
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 144 deletions.
1 change: 1 addition & 0 deletions auto/configure
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fi

. auto/make
. auto/lib/make
. auto/install

if [ "$PLATFORM" != win32 ]; then
. auto/unix
Expand Down
45 changes: 45 additions & 0 deletions auto/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

cat << END >> $MAKEFILE
install:
test -d $PREFIX || mkdir -p $PREFIX

test -d `dirname $SBIN_PATH` || mkdir -p `dirname $SBIN_PATH`
cp nginx $SBIN_PATH

test -d `dirname $CONF_PATH` || mkdir -p `dirname $CONF_PATH`

cp conf/koi-win `dirname $CONF_PATH`

test -f `dirname $CONF_PATH`/mime.types || \
cp conf/mime.types `dirname $CONF_PATH`/mime.types
cp conf/mime.types `dirname $CONF_PATH`/mime.types.default

test -f $CONF_PATH || cp conf/nginx.conf $CONF_PATH
cp conf/nginx.conf `dirname $CONF_PATH`/nginx.conf.default

test -d `dirname $PID_PATH` || mkdir -p `dirname $PID_PATH`
test -d `dirname $ERROR_LOG_PATH` || mkdir -p `dirname $ERROR_LOG_PATH`
test -d `dirname $HTTP_LOG_PATH` || mkdir -p `dirname $HTTP_LOG_PATH`

test -d $PREFIX/html || cp -r html $PREFIX

#test -d $PREFIX/temp || mkdir -p $PREFIX/temp
END


if test ! -f Makefile; then

cat << END > Makefile

build:
\$(MAKE) -f $OBJS/Makefile

install:
\$(MAKE) -f $OBJS/Makefile install

clean:
rm -rf Makefile $OBJS

END

fi
84 changes: 67 additions & 17 deletions auto/options
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ HTTP=YES
HTTP_CHARSET=YES
HTTP_GZIP=YES
HTTP_SSL=NO
HTTP_SSI=YES
HTTP_SSI=NO
HTTP_ACCESS=YES
HTTP_USERID=YES
HTTP_STATUS=YES
HTTP_STATUS=NO
HTTP_REWRITE=YES
HTTP_PROXY=YES

Expand Down Expand Up @@ -183,22 +183,72 @@ if [ ".$PREFIX" = "." ]; then
PREFIX=/usr/local/nginx
fi

if [ ".$SBIN_PATH" = "." ]; then
SBIN_PATH=$PREFIX/sbin/nginx
fi

if [ ".$CONF_PATH" = "." ]; then
CONF_PATH=$PREFIX/conf/nginx.conf
fi
case ".$SBIN_PATH" in
./*)
;;

if [ ".$PID_PATH" = "." ]; then
PID_PATH=$PREFIX/logs/nginx.pid
fi
.)
SBIN_PATH=$PREFIX/sbin/nginx
;;

if [ ".$ERROR_LOG_PATH" = "." ]; then
ERROR_LOG_PATH=$PREFIX/logs/error.log
fi
*)
SBIN_PATH=$PREFIX/$SBIN_PATH
;;
esac

if [ ".$HTTP_LOG_PATH" = "." ]; then
HTTP_LOG_PATH=$PREFIX/logs/access.log
fi

case ".$CONF_PATH" in
./*)
;;

.)
CONF_PATH=$PREFIX/conf/nginx.conf
;;

*)
CONF_PATH=$PREFIX/$CONF_PATH
;;
esac


case ".$PID_PATH" in
./*)
;;

.)
PID_PATH=$PREFIX/logs/nginx.pid
;;

*)
PID_PATH=$PREFIX/$PID_PATH
;;
esac


case ".$ERROR_LOG_PATH" in
./*)
;;

.)
ERROR_LOG_PATH=$PREFIX/logs/error.log
;;

*)
ERROR_LOG_PATH=$PREFIX/$ERROR_LOG_PATH
;;
esac


case ".$HTTP_LOG_PATH" in
./*)
;;

.)
HTTP_LOG_PATH=$PREFIX/logs/access.log
;;

*)
HTTP_LOG_PATH=$PREFIX/$HTTP_LOG_PATH
;;
esac
56 changes: 43 additions & 13 deletions src/core/nginx.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ int main(int argc, char *const *argv)
ctx.argc = argc;
ctx.argv = argv;

if (ngx_getopt(&ctx, &init_cycle) == NGX_ERROR) {
if (ngx_os_init(log) == NGX_ERROR) {
return 1;
}

if (ngx_os_init(log) == NGX_ERROR) {
if (!(init_cycle.pool = ngx_create_pool(1024, log))) {
return 1;
}

if (!(init_cycle.pool = ngx_create_pool(1024, log))) {
if (ngx_getopt(&ctx, &init_cycle) == NGX_ERROR) {
return 1;
}

Expand Down Expand Up @@ -338,6 +338,10 @@ static ngx_int_t ngx_getopt(ngx_master_ctx_t *ctx, ngx_cycle_t *cycle)
cycle->conf_file.data = (u_char *) NGX_CONF_PATH;
}

if (ngx_conf_full_name(cycle, &cycle->conf_file) == NGX_ERROR) {
return NGX_ERROR;
}

return NGX_OK;
}

Expand Down Expand Up @@ -372,6 +376,11 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_core_conf_t *ccf = conf;

#if !(WIN32)
struct passwd *pwd;
struct group *grp;
#endif

ngx_conf_init_value(ccf->daemon, 1);
ngx_conf_init_value(ccf->master, 1);
ngx_conf_init_value(ccf->worker_processes, 1);
Expand All @@ -384,24 +393,45 @@ static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)

#if !(WIN32)

/* TODO: default "nobody" user */
if (ccf->user == (uid_t) NGX_CONF_UNSET) {

pwd = getpwnam("nobody");
if (pwd == NULL) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"getpwnam(\"nobody\") failed");
return NGX_CONF_ERROR;
}

ccf->user = pwd->pw_uid;

grp = getgrnam("nobody");
if (grp == NULL) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"getgrnam(\"nobody\") failed");
return NGX_CONF_ERROR;
}

ccf->group = grp->gr_gid;
}

if (ccf->pid.len == 0) {
ccf->pid.len = sizeof(NGX_PID_PATH) - 1;
ccf->pid.data = NGX_PID_PATH;
ccf->newpid.len = sizeof(NGX_PID_PATH NGX_NEWPID_EXT) - 1;
ccf->newpid.data = NGX_PID_PATH NGX_NEWPID_EXT;
}

} else {
ccf->newpid.len = ccf->pid.len + sizeof(NGX_NEWPID_EXT);
if (ngx_conf_full_name(cycle, &ccf->pid) == NGX_ERROR) {
return NGX_CONF_ERROR;
}

if (!(ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len))) {
return NGX_CONF_ERROR;
}
ccf->newpid.len = ccf->pid.len + sizeof(NGX_NEWPID_EXT);

ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
NGX_NEWPID_EXT, sizeof(NGX_NEWPID_EXT));
if (!(ccf->newpid.data = ngx_palloc(cycle->pool, ccf->newpid.len))) {
return NGX_CONF_ERROR;
}

ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
NGX_NEWPID_EXT, sizeof(NGX_NEWPID_EXT));

#endif

return NGX_CONF_OK;
Expand Down
2 changes: 1 addition & 1 deletion src/core/nginx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _NGINX_H_INCLUDED_


#define NGINX_VER "nginx/0.0.12"
#define NGINX_VER "nginx/0.1.0"

#define NGINX_VAR "NGINX"
#define NGX_NEWPID_EXT ".newbin"
Expand Down
53 changes: 40 additions & 13 deletions src/core/ngx_conf_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,33 +549,56 @@ static char *ngx_conf_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_str_t *value, file;

value = cf->args->elts;
file = value[1];

if (value[1].data[0] == '/') {
return ngx_conf_parse(cf, &value[1]);
}

file.len = cf->cycle->root.len + value[1].len;
if (!(file.data = ngx_palloc(cf->pool, file.len + 1))) {
if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR){
return NGX_CONF_ERROR;
}

ngx_cpystrn(ngx_cpymem(file.data, cf->cycle->root.data,
cf->cycle->root.len),
value[1].data, value[1].len + 1);

ngx_log_error(NGX_LOG_INFO, cf->log, 0, "include %s", file.data);

return ngx_conf_parse(cf, &file);
}


ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name)
{
u_char *p;
ngx_str_t old;

if (name->data[0] == '/') {
return NGX_OK;
}

old = *name;

name->len = cycle->root.len + old.len;

if (!(name->data = ngx_palloc(cycle->pool, name->len + 1))) {
return NGX_ERROR;
}

p = ngx_cpymem(name->data, cycle->root.data, cycle->root.len),
ngx_cpystrn(p, old.data, old.len + 1);

return NGX_OK;
}


ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
{
ngx_str_t full;
ngx_uint_t i;
ngx_list_part_t *part;
ngx_open_file_t *file;

if (name) {
full = *name;

if (ngx_conf_full_name(cycle, &full) == NGX_ERROR) {
return NULL;
}

part = &cycle->open_files.part;
file = part->elts;

Expand All @@ -590,11 +613,11 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
i = 0;
}

if (name->len != file[i].name.len) {
if (full.len != file[i].name.len) {
continue;
}

if (ngx_strcmp(name->data, file[i].name.data) == 0) {
if (ngx_strcmp(full.data, file[i].name.data) == 0) {
return &file[i];
}
}
Expand All @@ -607,8 +630,12 @@ ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name)
file->fd = NGX_INVALID_FILE;

if (name) {
file->name = *name;
file->name = full;

} else {

/* stderr */

file->name.len = 0;
file->name.data = NULL;
}
Expand Down
1 change: 1 addition & 0 deletions src/core/ngx_conf_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ char *ngx_conf_check_num_bounds(ngx_conf_t *cf, void *post, void *data);
char *ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename);


ngx_int_t ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name);
ngx_open_file_t *ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name);
void ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
char *fmt, ...);
Expand Down
3 changes: 3 additions & 0 deletions src/core/ngx_cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle)
if (ccf->pid.len == old_ccf->pid.len
&& ngx_strcmp(ccf->pid.data, old_ccf->pid.data) == 0)
{

/* pid file name is the same */

return NGX_OK;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/ngx_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

} else {
cf->cycle->new_log->file->name = value[1];

if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name)
== NGX_ERROR)
{
return NGX_CONF_ERROR;
}
}

return ngx_set_error_log_levels(cf, cf->cycle->new_log);
Expand Down
Loading

0 comments on commit 6d2a14a

Please sign in to comment.