File: getutent.3

package info (click to toggle)
manpages-es 1.24a-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,256 kB
  • ctags: 7
  • sloc: makefile: 66; sh: 62
file content (150 lines) | stat: -rw-r--r-- 5,415 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
.\" Copyright 1995 Mark D. Roth (roth@uiuc.edu)
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
.\" USA.
.\"
.\" References consulted:
.\"     Linux libc source code
.\"     Solaris manpages
.\"
.\" Modified Thu Jul 25 14:43:46 MET DST 1996 by Michael Haardt
.\" <michael@cantor.informatik.rwth-aachen.de> 
.\" Translated into Spanish Wed Feb 25 20:49:51 CET 1998 by Gerardo
.\" Aburruzaga Garca <gerardo.aburruzaga@uca.es>
.\"
.TH GETUTENT 3 "25 Febrero 1998" "Linux" "Funciones de biblioteca"
.SH NOMBRE
getutent, getutid, getutline, pututline, setutent, endutent, utmpname
\- acceden a las entradas del fichero utmp
.SH SINOPSIS
.B #include <utmp.h>
.sp
.B struct utmp *getutent(void);
.br
.BI "struct utmp *getutid(struct utmp *" ut ");"
.br
.BI "struct utmp *getutline(struct utmp *" ut ");"
.sp
.BI "void pututline(struct utmp *" ut ");"
.sp
.B void setutent(void);
.br
.B void endutent(void);
.sp
.BI "void utmpname(const char *" fichero ");"
.SH DESCRIPCIN
\fButmpname\fP() establece qu nombre tiene el fichero en formato utmp
al que van a acceder las otras funciones descritas aqu. Si
\fButmpname\fP() no se llama para establecer el nombre de fichero
antes de que se usen las otras funciones, se asume el nombre
\fB_PATH_UTMP\fP, como se define en \fI<paths.h>\fP.
.PP
\fBsetutent\fP() rebobina el indicador de fichero al principio del
fichero utmp. Generalmente es una Buena Idea llamar a esta funcin
antes que cualquiera de las siguientes.
.PP
\fBendutent\fP() cierra el fichero utmp. Debe llamarse cuando el
cdigo de usuario ha terminado de acceder al fichero con las otras
funciones. 
.PP
\fBgetutent\fP() lee una lnea desde donde est actualmente el
indicador de posicin del fichero en el de formato utmp. Devuelve un
puntero a una estructura que contiene los campos correspondientes a la
lnea.
.PP
\fBgetutid\fP() busca hacia adelante desde la posicin actual en el
fichero utmp segn \fIut\fP.  Si \fIut\fP\fB->ut_type\fP es \fBRUN_LVL\fP,
\fBBOOT_TIME\fP, \fBNEW_TIME\fP, u \fBOLD_TIME\fP, \fBgetutid\fP()
encontrar la primera entrada cuyo campo \fBut_type\fP concuerde con
\fIut\fP\fB->ut_type\fP. 
Si \fIut\fP\fB->ut_type\fP es uno de \fBINIT_PROCESS\fP, \fBLOGIN_PROCESS\fP,
\fBUSER_PROCESS\fP, o \fBDEAD_PROCESS\fP, \fBgetutid\fP() encontrar la
primera entrada cuyo campo \fBut_id\fP coincida con \fIut\fP\fB->ut_id\fP.
.PP
\fBgetutline\fP() busca hacia adelante desde la posicin actual en el
fichero utmp.  Rastrea las entradas cuyo campo ut_type sea \fBUSER_PROCESS\fP
o \fBLOGIN_PROCESS\fP y devuelve la primera cuyo campo \fBut_line\fP
coincida con \fIut\fP\fB->ut_line\fP.
.PP
\fBpututline\fP() escribe la estructura utmp \fIut\fP en el fichero
utmp. Utiliza \fBgetutid\fP() para buscar el sitio correcto en el
fichero donde insertar la nueva entrada. Si no puede encontrar un
sitio apropiado para \fIut\fP,
\fBpututline\fP() aadir la nueva entrada al final del fichero.
.SH "VALOR DEVUELTO"
\fBgetutent\fP(), \fBgetutid\fP() y \fBgetutline\fP() devuelven un
puntero a una \fBstatic struct utmp\fP.
.SH "ERRORES"
En caso de error, se devuelve \fB(struct utmp*)0\fP.
.SH EJEMPLO
El siguiente ejemplo aade y quita un registro utmp, suponiendo que se
ejecuta desde una pseudo-terminal. Para un uso correcto en una
aplicacin ms realstica, se deberan comprobar los valores devueltos
por getpwuid() y ttyname().
.PP
.nf
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
#include <unistd.h>
#include <time.h>
#include <utmp.h>

int main(int argc, char *argv[])
{
  struct utmp entrada;

  system("echo antes de aadir la entrada:;who");

  entrada.ut_type = USER_PROCESS;
  entrada.ut_pid = getpid();
  strcpy(entrada.ut_line, ttyname(0) + strlen("/dev/"));
  /* slo correcto para ptys llamadas /dev/tty[pqr][0-9a-z] */
  strcpy(entrada.ut_id, ttyname(0) + strlen("/dev/tty"));
  time(&entrada.ut_time);
  strcpy(entrada.ut_user, getpwuid(getuid())->pw_name);
  memset(entrada.ut_host, 0, UT_HOSTSIZE);
  entrada.ut_addr = 0;
  setutent();
  pututline(&entrada);

  system("echo tras aadir la entrada:;who");

  entrada.ut_type = DEAD_PROCESS;
  memset(entrada.ut_line, 0, UT_LINESIZE);
  entrada.ut_time = 0;
  memset(entrada.ut_user, 0, UT_NAMESIZE);
  setutent();
  pututline(&entrada);

  system("echo tras borrar la entrada:;who");

  endutent();
  return 0;
}
.fi
.SH FICHEROS
/var/run/utmp	datos de los usuarios que estn en el sistema
.br
/var/log/wtmp	datos de entradas de usuario anteriores
.SH "CONFORME A"
XPG 2, SVID 2, Linux FSSTND 1.2
.SH "VASE TAMBIN"
\fButmp\fP(5)