[#4346] Segmentation fault — Andrew Walrond <andrew@...>
FYI, just got this random unexpected crash
On 01 Feb 2005, at 07:33, Andrew Walrond wrote:
[#4360] Adding lastlog info to etc — "Berger, Daniel" <Daniel.Berger@...>
Hi all,
[#4368] 'when (cond):' causes SyntaxError — "NAKAMURA, Hiroshi" <nakahiro@...>
Hi,
[#4385] add color_set support to curses.c — Paul Duncan <pabs@...>
I'm not sure why this is missing from the Curses binding, but the
[#4392] HTTP Basic authentication for open_uri — Kent Sibilev <ksibilev@...>
Can somebody apply the following patch for open_uri in order to enable
[#4402] BUG: Struct.new(:a?).instance_methods — "Cs. Henk" <csaba-ml@...>
Hi, getting an ArgumentError with "NULL pointer given" doesn't seem to
[#4403] Re: Unknown OS X 10.2 Socket constants (+script to generate) — Sam Roberts <sroberts@...>
Quoteing matz@ruby-lang.org, on Tue, Feb 08, 2005 at 01:21:18PM +0900:
[#4427] Re: windows socket connection freeze — ville.mattila@...
[#4432] curses + threads = non-blocking getch — William Morgan <wmorgan-ruby-core@...>
Hello experts,
In article <20050214231544.GE26414@masanjin.net>,
[#4439] Thread-safe Ruby Status? — Vincent Isambart <vincent.isambart@...>
Hello,
[#4448] add persistent history to irb — "David A. Black" <dblack@...>
Hi --
[#4453] bug in IRB with $_ matching a range of regexps — Ryan Davis <ryand-ruby@...>
> % ruby -v
[#4468] Re: Strange argc check in stable snapshot — "Berger, Daniel" <Daniel.Berger@...>
> -----Original Message-----
[#4475] Re: Strange argc check in stable snapshot — "Berger, Daniel" <Daniel.Berger@...>
> -----Original Message-----
[#4479] Requesting addition to IRB (configurable standard output) — Sascha Ebach <se@...>
Hello,
Quoting se@digitale-wertschoepfung.de, on Fri, Feb 25, 2005 at 01:22:34AM +0900:
On 24 Feb 2005, at 19:51, Sam Roberts wrote:
Quoting drbrain@segment7.net, on Sat, Feb 26, 2005 at 02:43:31AM +0900:
On 25 Feb 2005, at 16:03, Sam Roberts wrote:
Quoting drbrain@segment7.net, on Sat, Feb 26, 2005 at 10:24:52AM +0900:
On 25 Feb 2005, at 18:55, Sam Roberts wrote:
Quoting drbrain@segment7.net, on Sat, Feb 26, 2005 at 03:49:49PM +0900:
Re: Adding lastlog info to etc
Hi,
At Sat, 5 Feb 2005 22:02:13 +0900,
Daniel Berger wrote in [ruby-core:04363]:
> > > Any chance of adding lastlog information to the etc module? I have a
> > > patch, but it only works for Solaris at the moment. Basically, it means
> > > altering the extconf.rb file and doing the following:
> >
> > Do you think it should be included in Passwd struct?
> >
> > --
> > Nobu Nakada
>
> Yes.
I can't agree.
1) Passwd can't contain all per-user information.
2) lastlog is a per-uid information but not per-logname like as
Passwd.
My proposal is to add Etc.lastlog method.
Index: ext/etc/etc.c
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/etc/etc.c,v
retrieving revision 1.16
diff -U2 -p -r1.16 etc.c
--- ext/etc/etc.c 24 Nov 2003 10:42:17 -0000 1.16
+++ ext/etc/etc.c 6 Feb 2005 04:08:06 -0000
@@ -24,4 +24,19 @@
#endif
+#ifdef HAVE_LASTLOG_H
+#include <lastlog.h>
+#include <fcntl.h>
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+# ifndef _PATH_LASTLOG
+# define _PATH_LASTLOG "/var/adm/lastlog"
+# endif
+#endif
+#endif
+
+#ifndef HAVE_TYPE_UID_T
+#define uid_t int
+#endif
+
static VALUE sPasswd, sGroup;
@@ -360,4 +375,70 @@ etc_getgrent(obj)
}
+#ifdef HAVE_LASTLOG_H
+static struct lastlog *
+getlastlog(uid, ll_entry)
+ uid_t uid;
+ struct lastlog *ll_entry;
+{
+ int fd;
+ unsigned int size;
+ off_t ofs;
+
+ if ((fd = open(_PATH_LASTLOG, O_RDONLY)) == -1) {
+ failed:
+ rb_sys_fail(_PATH_LASTLOG);
+ }
+
+ ofs = uid * (off_t)sizeof(*ll_entry);
+#ifdef HAVE_PREAD
+ if (pread(fd, ll_entry, sizeof(*ll_entry), ofs) != sizeof(*ll_entry))
+ goto failed;
+#else
+ if (lseek(fd, ofs, SEEK_SET) < 0)
+ goto failed;
+ if (read(fd, ll_entry, sizeof(*ll_entry)) != sizeof(*ll_entry))
+ goto failed;
+#endif
+ close(fd);
+
+ return ll_entry;
+}
+
+static VALUE sLastLog;
+
+static VALUE
+etc_lastlog(self, user)
+ VALUE self, user;
+{
+ VALUE nam;
+ uid_t uid;
+ struct lastlog ll_entry;
+ time_t time;
+
+ rb_secure(4);
+ nam = rb_check_string_type(user);
+ if (!NIL_P(nam)) {
+ struct passwd* pwd;
+ rb_check_safe_obj(nam);
+ pwd = getpwnam(RSTRING(nam)->ptr);
+ if (pwd == 0)
+ rb_raise(rb_eArgError, "can't find user for %s", RSTRING(nam)->ptr);
+ uid = pwd->pw_uid;
+ }
+ else {
+ uid = NUM2INT(user);
+ }
+
+ if (!getlastlog(uid, &ll_entry))
+
+ time = ll_entry.ll_time;
+ return rb_struct_new(sLastLog,
+ time ? rb_time_new(time, 0) : Qnil,
+ safe_setup_str(ll_entry.ll_line),
+ safe_setup_str(ll_entry.ll_host),
+ (VALUE)0);
+}
+#endif
+
static VALUE mEtc;
@@ -414,3 +495,9 @@ Init_etc()
rb_global_variable(&sGroup);
#endif
+
+#ifdef HAVE_LASTLOG_H
+ rb_define_module_function(mEtc, "lastlog", etc_lastlog, 1);
+ sLastLog = rb_struct_define("LastLog", "time", "line", "host", NULL);
+ rb_global_variable(&sLastLog);
+#endif
}
Index: ext/etc/extconf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/etc/extconf.rb,v
retrieving revision 1.5
diff -U2 -p -r1.5 extconf.rb
--- ext/etc/extconf.rb 24 Nov 2003 10:42:17 -0000 1.5
+++ ext/etc/extconf.rb 6 Feb 2005 04:13:35 -0000
@@ -15,4 +15,6 @@ if a or b or c
have_struct_member('struct passwd', 'pw_passwd', 'pwd.h')
have_struct_member('struct group', 'gr_passwd', 'grp.h')
+ have_header("lastlog.h") and have_header("paths.h")
+ have_type("uid_t");
create_makefile("etc")
end
--
Nobu Nakada