File: sysos.c

package info (click to toggle)
ppxp 0.99120923-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,812 kB
  • ctags: 3,704
  • sloc: ansic: 24,532; tcl: 3,992; makefile: 517; sh: 80
file content (38 lines) | stat: -rw-r--r-- 846 bytes parent folder | download | duplicates (3)
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
#include <stdio.h>
#include <string.h>
#include <utmp.h>
#include <sys/types.h>
#include <sys/file.h>

#include <config.h>

int
SysWtmp(char *line, char *user, char *host)
{
    struct utmp utmp;
    int fd;

    memset((char *)&utmp, 0, sizeof(utmp));

    strncpy(utmp.ut_line, line, sizeof(utmp.ut_line));
    strncpy(utmp.ut_id, line + 3, sizeof(utmp.ut_id));
    time(&(utmp.ut_time));
    if (user) {
	/* start */
	utmp.ut_type = USER_PROCESS;
	utmp.ut_pid = getpid();
	strncpy(utmp.ut_user, user, sizeof(utmp.ut_user));
	if (host) strncpy(utmp.ut_host, host, sizeof(utmp.ut_host));
    } else {
	/* stop */
	utmp.ut_type = DEAD_PROCESS;
    }
    fd = open(_PATH_WTMP, O_APPEND|O_WRONLY|O_CREAT, 0644);
    if (fd < 0) {
	LogError(_PATH_WTMP);
	return(-1);
    }
    write(fd, (char *)&utmp, sizeof(utmp));
    close(fd);
    return(0);
}