From 2ef89b220a96cca8c1c92e434548a0a9cd0e0567 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 15 Dec 2004 17:29:01 +0000 Subject: * cygwin.din: Add utmpx symbols. * syscalls.cc: Include utmpx.h. Implement utmpx functions as stubs to utmp functions. (copy_ut_to_utx): New static function. (pututline): Change from void to struct utmp * as on Linux. (setutxent): New function. (endutxent): New function. (getutxent): New function. (getutxid): New function. (getutxline): New function. (pututxline): New function. * include/utmpx.h: New file. * include/cygwin/utmp.h: New file. * include/cygwin/version.h: Bump API minor number. * include/sys/utmp.h: Include cygwin/utmp.h. Move stuff common with utmpx functionality there. (pututline): Declare struct utmp *. --- winsup/cygwin/ChangeLog | 20 ++++++++++ winsup/cygwin/cygwin.din | 6 +++ winsup/cygwin/include/cygwin/utmp.h | 40 +++++++++++++++++++ winsup/cygwin/include/cygwin/version.h | 3 +- winsup/cygwin/include/sys/utmp.h | 23 ++--------- winsup/cygwin/include/utmpx.h | 45 +++++++++++++++++++++ winsup/cygwin/syscalls.cc | 71 ++++++++++++++++++++++++++++++++-- 7 files changed, 184 insertions(+), 24 deletions(-) create mode 100644 winsup/cygwin/include/cygwin/utmp.h create mode 100644 winsup/cygwin/include/utmpx.h (limited to 'winsup') diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 67d9664..d48abfb 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,23 @@ +2004-12-15 Corinna Vinschen + + * cygwin.din: Add utmpx symbols. + * syscalls.cc: Include utmpx.h. Implement utmpx functions as stubs + to utmp functions. + (copy_ut_to_utx): New static function. + (pututline): Change from void to struct utmp * as on Linux. + (setutxent): New function. + (endutxent): New function. + (getutxent): New function. + (getutxid): New function. + (getutxline): New function. + (pututxline): New function. + * include/utmpx.h: New file. + * include/cygwin/utmp.h: New file. + * include/cygwin/version.h: Bump API minor number. + * include/sys/utmp.h: Include cygwin/utmp.h. Move stuff common with + utmpx functionality there. + (pututline): Declare struct utmp *. + 2004-12-14 Corinna Vinschen * tty.cc (tty_list::terminate): Guard releasing the tty with tty_mutex. diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 13deed8..666d770 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -404,6 +404,7 @@ endpwent NOSIGFE _endpwent = endpwent NOSIGFE endutent SIGFE _endutent = endutent SIGFE +endutxent SIGFE envz_add SIGFE __envz_add = envz_add SIGFE envz_entry NOSIGFE @@ -682,6 +683,9 @@ getutid SIGFE _getutid = getutid SIGFE getutline SIGFE _getutline = getutline SIGFE +getutxent SIGFE +getutxid SIGFE +getutxline SIGFE getw SIGFE _getw = getw SIGFE getwd SIGFE @@ -1067,6 +1071,7 @@ puts SIGFE _puts = puts SIGFE pututline SIGFE _pututline = pututline SIGFE +pututxline SIGFE putw SIGFE _putw = putw SIGFE qsort NOSIGFE @@ -1215,6 +1220,7 @@ _setuid = setuid SIGFE _setuid32 = setuid32 SIGFE setutent SIGFE _setutent = setutent SIGFE +setutxent SIGFE setvbuf SIGFE _setvbuf = setvbuf SIGFE sexecl = sexecve_is_bad SIGFE diff --git a/winsup/cygwin/include/cygwin/utmp.h b/winsup/cygwin/include/cygwin/utmp.h new file mode 100644 index 0000000..56a137f --- /dev/null +++ b/winsup/cygwin/include/cygwin/utmp.h @@ -0,0 +1,40 @@ +/* cygwin/utmp.h + + Copyright 2004 Red Hat, Inc. + + This software is a copyrighted work licensed under the terms of the + Cygwin license. Please consult the file "CYGWIN_LICENSE" for + details. */ + +#ifndef CYGWIN_UTMP_H +#define CYGWIN_UTMP_H + +#include +#include +#include + +#define WTMP_FILE _PATH_WTMP + +#ifdef __cplusplus +extern "C" { +#endif + +#define UT_LINESIZE 16 +#define UT_NAMESIZE 16 +#define UT_HOSTSIZE 256 +#define UT_IDLEN 2 + +#define RUN_LVL 1 +#define BOOT_TIME 2 +#define NEW_TIME 3 +#define OLD_TIME 4 + +#define INIT_PROCESS 5 +#define LOGIN_PROCESS 6 +#define USER_PROCESS 7 +#define DEAD_PROCESS 8 + +#ifdef __cplusplus +} +#endif +#endif /* CYGWIN_UTMP_H */ diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index cc2fe35..f81bc2a 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -244,12 +244,13 @@ details. */ 115: Export flockfile, ftrylockfile, funlockfile, getgrgid_r, getgrnam_r, getlogin_r. 116: Export atoll. + 117: Export utmpx functions, Return utmp * from pututent. */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 116 +#define CYGWIN_VERSION_API_MINOR 117 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/include/sys/utmp.h b/winsup/cygwin/include/sys/utmp.h index b78c563..ebc70b9 100644 --- a/winsup/cygwin/include/sys/utmp.h +++ b/winsup/cygwin/include/sys/utmp.h @@ -1,6 +1,6 @@ /* sys/utmp.h - Copyright 2001 Red Hat, Inc. + Copyright 2001, 2004 Red Hat, Inc. This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for @@ -9,21 +9,14 @@ #ifndef UTMP_H #define UTMP_H -#include -#include -#include +#include #define UTMP_FILE _PATH_UTMP -#define WTMP_FILE _PATH_WTMP #ifdef __cplusplus extern "C" { #endif -#define UT_LINESIZE 16 -#define UT_NAMESIZE 16 -#define UT_HOSTSIZE 256 -#define UT_IDLEN 2 #define ut_name ut_user struct utmp @@ -38,22 +31,12 @@ struct utmp long ut_addr; }; -#define RUN_LVL 1 -#define BOOT_TIME 2 -#define NEW_TIME 3 -#define OLD_TIME 4 - -#define INIT_PROCESS 5 -#define LOGIN_PROCESS 6 -#define USER_PROCESS 7 -#define DEAD_PROCESS 8 - extern struct utmp *_getutline (struct utmp *); extern struct utmp *getutent (void); extern struct utmp *getutid (struct utmp *); extern struct utmp *getutline (struct utmp *); +extern struct utmp *pututline (struct utmp *); extern void endutent (void); -extern void pututline (struct utmp *); extern void setutent (void); extern void utmpname (const char *); diff --git a/winsup/cygwin/include/utmpx.h b/winsup/cygwin/include/utmpx.h new file mode 100644 index 0000000..395c7a0 --- /dev/null +++ b/winsup/cygwin/include/utmpx.h @@ -0,0 +1,45 @@ +/* utmpx.h + + Copyright 2004 Red Hat, Inc. + + This software is a copyrighted work licensed under the terms of the + Cygwin license. Please consult the file "CYGWIN_LICENSE" for + details. */ + +#ifndef UTMPX_H +#define UTMPX_H + +#include +#include + +#define UTMPX_FILE _PATH_UTMP + +#ifdef __cplusplus +extern "C" { +#endif + +/* Must be kept in sync with struct utmp as defined in sys/utmp.h! */ +struct utmpx +{ + short ut_type; + pid_t ut_pid; + char ut_line[UT_LINESIZE]; + char ut_id[UT_IDLEN]; + time_t ut_time; + char ut_user[UT_NAMESIZE]; + char ut_host[UT_HOSTSIZE]; + long ut_addr; + struct timeval ut_tv; +}; + +extern void endutxent (void); +extern struct utmpx *getutxent (void); +extern struct utmpx *getutxid (const struct utmpx *id); +extern struct utmpx *getutxline (const struct utmpx *line); +extern struct utmpx *pututxline (const struct utmpx *utmpx); +extern void setutxent (void); + +#ifdef __cplusplus +} +#endif +#endif /* UTMPX_H */ diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index c6a662f..e7abeab 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -29,6 +29,7 @@ details. */ #include #include #include +#include #include #include #include @@ -2559,6 +2560,17 @@ static unsigned utix = 0; utmp_data_buf + utix++; \ }) +static struct utmpx * +copy_ut_to_utx (struct utmp *ut, struct utmpx *utx) +{ + if (!ut) + return NULL; + memcpy (utx, ut, sizeof *ut); + utx->ut_tv.tv_sec = ut->ut_time; + utx->ut_tv.tv_usec = 0; + return utx; +} + extern "C" struct utmp * getutent () { @@ -2635,16 +2647,16 @@ getutline (struct utmp *line) return NULL; } -extern "C" void +extern "C" struct utmp * pututline (struct utmp *ut) { if (check_null_invalid_struct (ut)) - return; + return NULL; internal_setutent (true); if (utmp_fd < 0) { debug_printf ("error: utmp_fd %d", utmp_fd); - return; + return NULL; } debug_printf ("ut->ut_type %d, ut->ut_pid %d, ut->ut_line '%s', ut->ut_id '%s'\n", ut->ut_type, ut->ut_pid, ut->ut_line, ut->ut_id); @@ -2659,6 +2671,59 @@ pututline (struct utmp *ut) } else locked_append (utmp_fd, ut, sizeof *ut); + return ut; +} + +extern "C" void +setutxent () +{ + internal_setutent (false); +} + +extern "C" void +endutxent () +{ + endutent (); +} + +extern "C" struct utmpx * +getutxent () +{ + static struct utmpx utx; + return copy_ut_to_utx (getutent (), &utx); +} + +extern "C" struct utmpx * +getutxid (const struct utmpx *id) +{ + static struct utmpx utx; + + if (__check_invalid_read_ptr (id, sizeof *id)) + return NULL; + ((struct utmpx *)id)->ut_time = id->ut_tv.tv_sec; + return copy_ut_to_utx (getutid ((struct utmp *) id), &utx); +} + +extern "C" struct utmpx * +getutxline (const struct utmpx *line) +{ + static struct utmpx utx; + + if (__check_invalid_read_ptr (line, sizeof *line)) + return NULL; + ((struct utmpx *)line)->ut_time = line->ut_tv.tv_sec; + return copy_ut_to_utx (getutline ((struct utmp *) line), &utx); +} + +extern "C" struct utmpx * +pututxline (const struct utmpx *utmpx) +{ + static struct utmpx utx; + + if (__check_invalid_read_ptr (utmpx, sizeof *utmpx)) + return NULL; + ((struct utmpx *)utmpx)->ut_time = utmpx->ut_tv.tv_sec; + return copy_ut_to_utx (pututline ((struct utmp *) utmpx), &utx); } extern "C" -- cgit v1.1