[BusyBox] getty and utmp update

Vladimir N. Oleynik dzo at simtreas.ru
Sat Dec 22 06:27:33 UTC 2001


Giulio,
 
> I've a libc5 boot disk. init is some minimal sysv init found somewhere a
> while ago.
> I was using mingetty and wanted to switch to busybox getty.
> 
> getty would not start a login because:
> tty2 no utmp entry ...
> 
> I suppose init didn't update /var/run/utmp?
> 
> so, in getty.c,  I changed
>  error("%s: no utmp entry", line);
> to
>  return

 The author of port seems has got confused in wtmp/utmp. 
Here in general must be: "wtmp entry". But in wtmp any process does not search
for record,
and always records from init, getty, login and again init only are added.

I think, require universal libbb function for libc5/uclibc/glibc:

#if FEATURE_UPDATE_WTMP_ENTRY

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>  
#include <sys/file.h>
#include <utmp.h>

#include <paths.h>

#ifndef LOGDIR
#define LOGDIR                  "/var/log"
#endif

#define _PATH_WTMP              LOGDIR "/wtmp"
#define _PATH_WTMPLOCK          "/etc/wtmplock"
 
void bb_updwtmp(const struct utmp *ut)
{
#if !(__GNU_LIBRARY__ < 5) && !defined(__UCLIBC__)
        {
                extern void updwtmp(const char *, const struct utmp *);

                updwtmp(_PATH_WTMP, &ut);
        }
#else
	{
 	int ut_fd;
        int lf;

        if ((lf = open(_PATH_WTMPLOCK, O_CREAT|O_WRONLY, 0660)) >= 0) {
            flock(lf, LOCK_EX);
            if ((ut_fd = open(_PATH_WTMP, O_APPEND|O_WRONLY)) >= 0) {
                write(ut_fd, &ut, sizeof(ut));
                close(ut_fd);
            }
            flock(lf, LOCK_UN);
            close(lf);
        }      
	}
#endif
}
#endif




--w
vodz




More information about the busybox mailing list