36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#ifdef _PATH_LASTLOG
#define LASTLOG_FILE _PATH_LASTLOG
#else
#define LASTLOG_FILE "/var/log/lastlog"
#endif
#endif
/*
* Set up a default for vaguely sane systems. The idea is that if
* OMIT_UTMP is not defined, then at least one of the symbols which
* enable particular forms of utmp processing should be, if only so
* that a link error can warn you that you should have defined
* OMIT_UTMP if you didn't want any. Currently HAVE_PUTUTLINE is
* the only such symbol.
*/
#ifndef OMIT_UTMP
#if !defined HAVE_PUTUTLINE
#define HAVE_PUTUTLINE
#endif
#endif
int pty_master_fd;
int pty_stamp_utmp = 1;
static int pty_stamped_utmp = 0;
static int pty_child_pid;
static sig_atomic_t pty_child_dead;
#ifndef OMIT_UTMP
static struct utmp utmp_entry;
#endif
char **pty_argv;
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
-
+
+
+
+
+
|
{
#ifndef OMIT_UTMP
#ifdef HAVE_LASTLOG
struct lastlog lastlog_entry;
FILE *lastlog;
#endif
struct passwd *pw;
char *location = get_x_display();
char *location;
FILE *wtmp;
if (!pty_stamp_utmp)
return;
pw = getpwuid(getuid());
location = get_x_display();
memset(&utmp_entry, 0, sizeof(utmp_entry));
utmp_entry.ut_type = USER_PROCESS;
utmp_entry.ut_pid = getpid();
strncpy(utmp_entry.ut_line, ttyname+5, lenof(utmp_entry.ut_line));
strncpy(utmp_entry.ut_id, ttyname+8, lenof(utmp_entry.ut_id));
strncpy(utmp_entry.ut_user, pw->pw_name, lenof(utmp_entry.ut_user));
strncpy(utmp_entry.ut_host, location, lenof(utmp_entry.ut_host));
|
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
|
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
151
152
153
154
155
156
157
158
159
160
161
162
|
+
+
+
+
+
+
|
if ((lastlog = fopen(LASTLOG_FILE, "r+")) != NULL) {
fseek(lastlog, sizeof(lastlog_entry) * getuid(), SEEK_SET);
fwrite(&lastlog_entry, 1, sizeof(lastlog_entry), lastlog);
fclose(lastlog);
}
#endif
pty_stamped_utmp = 1;
#endif
}
static void cleanup_utmp(void)
{
#ifndef OMIT_UTMP
FILE *wtmp;
if (!pty_stamp_utmp || !pty_stamped_utmp)
return;
utmp_entry.ut_type = DEAD_PROCESS;
memset(utmp_entry.ut_user, 0, lenof(utmp_entry.ut_user));
time(&utmp_entry.ut_time);
if ((wtmp = fopen(WTMP_FILE, "a")) != NULL) {
fwrite(&utmp_entry, 1, sizeof(utmp_entry), wtmp);
fclose(wtmp);
}
memset(utmp_entry.ut_line, 0, lenof(utmp_entry.ut_line));
utmp_entry.ut_time = 0;
#if defined HAVE_PUTUTLINE
utmpname(UTMP_FILE);
setutent();
pututline(&utmp_entry);
endutent();
#endif
pty_stamped_utmp = 0; /* ensure we never double-cleanup */
#endif
}
static void sigchld_handler(int signum)
{
pid_t pid;
int status;
|