Welcome! Log In Create A New Profile

Advanced

About the format type specifiers

姚伟斌
July 24, 2012 03:36AM
1. The type of 'ngx_msec_int_t', from the source code, It's defined like this:

typedef ngx_int_t ngx_rbtree_key_int_t;
typedef ngx_rbtree_key_int_t ngx_msec_int_t;

So It should be an ngx_int_t.

In the file of ngx_http_log_module.c, It appears like this:

static u_char *
ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op)
{
ngx_time_t *tp;
ngx_msec_int_t ms;

tp = ngx_timeofday();

ms = (ngx_msec_int_t)
((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec));
ms = ngx_max(ms, 0);

return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000);
}


2. The type of '' ngx_gid_t" and "ngx_uid_t", from the source code.
They are defined like this:

typedef uid_t ngx_uid_t;
typedef gid_t ngx_gid_t;

And I googled [1][2] about the types of uid_t and gid_t and They seem
to unsigned integer.

In the file of ngx_process_cycle.c, it appears like this:

if (geteuid() == 0) {
if (setgid(ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setgid(%d) failed", ccf->group);
/* fatal */
exit(2);
}

if (initgroups(ccf->username, ccf->group) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"initgroups(%s, %d) failed",
ccf->username, ccf->group);
}

if (setuid(ccf->user) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"setuid(%d) failed", ccf->user);
/* fatal */
exit(2);
}
}

I want to know the correct format specifiers with ngx_msec_int_t,
uid_t and gid_t. I'm a little confused with above codes.

Thanks.

[1] http://www.delorie.com/gnu/docs/glibc/libc_608.html
[2] http://stackoverflow.com/questions/1922761/size-of-pid-t-uid-t-gid-t-on-linux

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

About the format type specifiers

姚伟斌 1538 July 24, 2012 03:36AM

Re: About the format type specifiers

Maxim Dounin 552 July 24, 2012 06:46AM

Re: About the format type specifiers

姚伟斌 733 July 24, 2012 09:32AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 254
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready