diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2005-05-06 02:43:04 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2005-05-06 02:43:04 +0000 |
commit | 4e506c9aefe5b89970ae6894d05ad53c81af0d83 (patch) | |
tree | 2fac98df209e72eaba773cad2d7b90c99d9d9249 /mdk-stage1/dietlibc/libugly/utent.c | |
parent | 793707b39bf2e9df40a6d2d60b83b3061088ae9e (diff) | |
download | drakx-4e506c9aefe5b89970ae6894d05ad53c81af0d83.tar drakx-4e506c9aefe5b89970ae6894d05ad53c81af0d83.tar.gz drakx-4e506c9aefe5b89970ae6894d05ad53c81af0d83.tar.bz2 drakx-4e506c9aefe5b89970ae6894d05ad53c81af0d83.tar.xz drakx-4e506c9aefe5b89970ae6894d05ad53c81af0d83.zip |
use installed dietlibc, not our forked cvs version
Diffstat (limited to 'mdk-stage1/dietlibc/libugly/utent.c')
-rw-r--r-- | mdk-stage1/dietlibc/libugly/utent.c | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/mdk-stage1/dietlibc/libugly/utent.c b/mdk-stage1/dietlibc/libugly/utent.c deleted file mode 100644 index d8d5d1ba7..000000000 --- a/mdk-stage1/dietlibc/libugly/utent.c +++ /dev/null @@ -1,103 +0,0 @@ -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <utmp.h> - -static const char *utmp_file_name = _PATH_UTMP; -static int fd = -1; - -static int lock_record(int type) { - struct flock fl; - fl.l_whence = SEEK_CUR; - fl.l_start = 0; - fl.l_len = sizeof(struct utmp); - fl.l_pid = 0; - fl.l_type = type; - return fcntl(fd, F_SETLKW, &fl); -} - -static int unlock_record() { - struct flock fl; - fl.l_whence = SEEK_CUR; - fl.l_start = -sizeof(struct utmp); - fl.l_len = sizeof(struct utmp); - fl.l_pid = 0; - fl.l_type = F_UNLCK; - return fcntl(fd, F_SETLK, &fl); -} - -void utmpname(const char *file) { - if (file) - utmp_file_name = file; - else - utmp_file_name = _PATH_UTMP; -} - -void setutent() { - if (fd<0) fd = open(utmp_file_name,O_RDWR); - if (fd<0) fd = open(utmp_file_name,O_RDONLY); - fcntl (fd, F_SETFD, FD_CLOEXEC); - lseek(fd,0,SEEK_SET); -} - -void endutent() { - if (fd<0) return; - close(fd); fd=-1; -} - -struct utmp *getutent(void) { - static struct utmp getutent_tmp; - int ret; - - if (fd<0) { - setutent(); - if (fd<0) return 0; - } - if (lock_record(F_RDLCK)) return 0; - ret=read(fd, &getutent_tmp, sizeof(struct utmp)); - unlock_record(); - if (ret<1) return 0; - return &getutent_tmp; -} - -struct utmp *getutid(struct utmp *ut) { - struct utmp *tmp; - - while ((tmp = getutent())) { - if (ut->ut_type && (ut->ut_type <= OLD_TIME)) { - if (ut->ut_type == tmp->ut_type) break; - } - if ((ut->ut_type >= INIT_PROCESS) && (ut->ut_type <= DEAD_PROCESS)) { - if (!strncmp(ut->ut_id,tmp->ut_id,4)) break; - } - } - return tmp; -} - -struct utmp *getutline(struct utmp *ut) { - struct utmp *tmp; - - while ((tmp = getutent())) { - if ((tmp->ut_type == USER_PROCESS) || (tmp->ut_type == LOGIN_PROCESS)) { - if (!strncmp(ut->ut_line,tmp->ut_line,UT_LINESIZE)) break; - } - } - return tmp; -} - -void pututline(struct utmp *ut) { - struct utmp *tmp; - - if ((tmp = getutid(ut))) { - lseek(fd, - (off_t)sizeof(struct utmp), SEEK_CUR); - if (lock_record(F_WRLCK)) return; - write(fd, ut, sizeof(struct utmp)); - } - else { - lseek(fd, 0, SEEK_END); - if (lock_record(F_WRLCK)) return; - write(fd, ut, (off_t)sizeof(struct utmp)); - } - unlock_record(); -} - |