mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/syslog/syslog.c: Cut redundancy.
* ext/syslog/syslog.c: Do not leak ident. * ext/syslog/syslog.c, ext/syslog/test.rb: Syslog.close should raise RuntimeError when not opened. * ext/syslog/syslog.c, ext/syslog/test.rb: Syslog.{ident,options,facility,mask} should all return nil when not opened. * ext/syslog/syslog.c, ext/syslog/test.rb: Change back the output format of inspect(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ad42685bf4
commit
34558b71c7
2 changed files with 54 additions and 27 deletions
18
ChangeLog
18
ChangeLog
|
@ -1,12 +1,20 @@
|
|||
Wed Nov 27 17:39:38 2002 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* ext/syslog/syslog.c: Cut redundancy.
|
||||
|
||||
* ext/syslog/syslog.c: Do not leak ident.
|
||||
|
||||
Wed Nov 27 17:25:29 2002 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* ext/syslog/test.rb: Syslog.close should raise RuntimeError when
|
||||
* ext/syslog/syslog.c, ext/syslog/test.rb: Syslog.close should
|
||||
raise RuntimeError when not opened.
|
||||
|
||||
* ext/syslog/syslog.c, ext/syslog/test.rb:
|
||||
Syslog.{ident,options,facility,mask} should all return nil when
|
||||
not opened.
|
||||
|
||||
* ext/syslog/test.rb: Syslog.{ident,options,facility,mask} should
|
||||
all return nil when not opened.
|
||||
|
||||
* ext/syslog/test.rb: Change back the output format of inspect().
|
||||
* ext/syslog/syslog.c, ext/syslog/test.rb: Change back the output
|
||||
format of inspect().
|
||||
|
||||
Wed Nov 27 16:25:43 2002 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
|
|
|
@ -37,7 +37,15 @@ static void syslog_write(int pri, int argc, VALUE *argv)
|
|||
/* Syslog module methods */
|
||||
static VALUE mSyslog_close(VALUE self)
|
||||
{
|
||||
if (!syslog_opened) {
|
||||
rb_raise(rb_eRuntimeError, "syslog not opened");
|
||||
}
|
||||
|
||||
closelog();
|
||||
|
||||
free((void *)syslog_ident);
|
||||
syslog_ident = NULL;
|
||||
syslog_options = syslog_facility = syslog_mask = -1;
|
||||
syslog_opened = 0;
|
||||
|
||||
return Qnil;
|
||||
|
@ -51,26 +59,33 @@ static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self)
|
|||
if (syslog_opened) {
|
||||
rb_raise(rb_eRuntimeError, "syslog already open");
|
||||
}
|
||||
|
||||
rb_scan_args(argc, argv, "03", &ident, &opt, &fac);
|
||||
|
||||
if (NIL_P(ident)) {
|
||||
ident = rb_gv_get("$0");
|
||||
}
|
||||
if (NIL_P(opt)) {
|
||||
opt = INT2NUM(LOG_PID | LOG_CONS);
|
||||
}
|
||||
if (NIL_P(fac)) {
|
||||
fac = INT2NUM(LOG_USER);
|
||||
}
|
||||
|
||||
#ifdef SafeStringValue
|
||||
SafeStringValue(ident);
|
||||
#else
|
||||
Check_SafeStr(ident);
|
||||
#endif
|
||||
syslog_ident = (const char *)strdup(RSTRING(ident)->ptr);
|
||||
syslog_ident = strdup(RSTRING(ident)->ptr);
|
||||
|
||||
if (NIL_P(opt)) {
|
||||
syslog_options = LOG_PID | LOG_CONS;
|
||||
} else {
|
||||
syslog_options = NUM2INT(opt);
|
||||
}
|
||||
|
||||
if (NIL_P(fac)) {
|
||||
syslog_facility = LOG_USER;
|
||||
} else {
|
||||
syslog_facility = NUM2INT(fac);
|
||||
}
|
||||
|
||||
openlog(syslog_ident, syslog_options, syslog_facility);
|
||||
|
||||
syslog_opened = 1;
|
||||
|
||||
setlogmask(syslog_mask = setlogmask(0));
|
||||
|
@ -97,22 +112,22 @@ static VALUE mSyslog_isopen(VALUE self)
|
|||
|
||||
static VALUE mSyslog_ident(VALUE self)
|
||||
{
|
||||
return rb_str_new2(syslog_ident);
|
||||
return syslog_opened ? rb_str_new2(syslog_ident) : Qnil;
|
||||
}
|
||||
|
||||
static VALUE mSyslog_options(VALUE self)
|
||||
{
|
||||
return INT2NUM(syslog_options);
|
||||
return syslog_opened ? INT2NUM(syslog_options) : Qnil;
|
||||
}
|
||||
|
||||
static VALUE mSyslog_facility(VALUE self)
|
||||
{
|
||||
return INT2NUM(syslog_facility);
|
||||
return syslog_opened ? INT2NUM(syslog_facility) : Qnil;
|
||||
}
|
||||
|
||||
static VALUE mSyslog_get_mask(VALUE self)
|
||||
{
|
||||
return INT2NUM(syslog_mask);
|
||||
return syslog_opened ? INT2NUM(syslog_mask) : Qnil;
|
||||
}
|
||||
|
||||
static VALUE mSyslog_set_mask(VALUE self, VALUE mask)
|
||||
|
@ -150,14 +165,18 @@ static VALUE mSyslog_inspect(VALUE self)
|
|||
{
|
||||
char buf[1024];
|
||||
|
||||
if (syslog_opened) {
|
||||
snprintf(buf, sizeof(buf),
|
||||
"<#%s: ident=\"%s\", options=%d, facility=%d, mask=%d%s>",
|
||||
"<#%s: opened=true, ident=\"%s\", options=%d, facility=%d, mask=%d>",
|
||||
rb_class2name(self),
|
||||
syslog_ident,
|
||||
syslog_options,
|
||||
syslog_facility,
|
||||
syslog_mask,
|
||||
syslog_opened ? ", opened" : "");
|
||||
syslog_mask);
|
||||
} else {
|
||||
snprintf(buf, sizeof(buf),
|
||||
"<#%s: opened=false>", rb_class2name(self));
|
||||
}
|
||||
|
||||
return rb_str_new2(buf);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue