本文整理汇总了C++中pututline函数的典型用法代码示例。如果您正苦于以下问题:C++ pututline函数的具体用法?C++ pututline怎么用?C++ pututline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pututline函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanup_utmp
static void cleanup_utmp(void)
{
#ifndef OMIT_UTMP
FILE *wtmp;
time_t uttime;
if (!pty_stamped_utmp)
return;
utmp_entry.ut_type = DEAD_PROCESS;
memset(utmp_entry.ut_user, 0, lenof(utmp_entry.ut_user));
time(&uttime);
utmp_entry.ut_time = uttime;
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
}
示例2: count_users
static int
count_users(void)
{
int total = 0;
#if HAVE_UTMPX_H
#define setutent setutxent
#define pututline pututxline
#define getutent getutxent
#define endutent endutxent
struct utmpx *utmp_p;
#else
struct utmp *utmp_p;
#endif
setutent();
while ((utmp_p = getutent()) != NULL) {
#ifndef UTMP_HAS_NO_TYPE
if (utmp_p->ut_type != USER_PROCESS)
continue;
#endif
#ifndef UTMP_HAS_NO_PID
/* This block of code fixes zombie user PIDs in the
utmp/utmpx file that would otherwise be counted as a
current user */
if (kill(utmp_p->ut_pid, 0) == -1 && errno == ESRCH) {
utmp_p->ut_type = DEAD_PROCESS;
pututline(utmp_p);
continue;
}
#endif
++total;
}
endutent();
return total;
}
示例3: clear_utmp
static int clear_utmp(struct initpid *ip, uint16_t count, pid_t pid)
{
uint16_t i;
for (i = 0; i < count; i++) {
if (ip->pid == pid) {
uint8_t *p = initpid[i].id;
/* Clear the utmp entry */
ut.ut_pid = 1;
ut.ut_type = INIT_PROCESS;
*ut.ut_line = 0;
ut.ut_id[0] = p[1];
ut.ut_id[1] = p[2];
*ut.ut_user = 0;
pututline(&ut);
/* Mark as done */
initpid[i].pid = 0;
/* Respawn the task if appropriate */
if ((p[3] & (1 << runlevel)) && p[4] == INIT_RESPAWN)
initpid[i].pid = spawn_process(p, 0);
return 0;
}
ip++;
}
return -1;
}
示例4: clear_zombies
/*
* Clear any dead processes
*/
static void clear_zombies(int flags)
{
int i;
pid_t pid = waitpid(-1, NULL, flags);
/* Interrupted ? */
if (pid < 0)
return;
/* See if we care what died. If we do then also check that
* do not need to respawn it
*/
for (i = 0; i < initcount; i++) {
if (initpid[i] == pid) {
uint8_t *p = initptr[i];
/* Clear the utmp entry */
ut.ut_pid = 1;
ut.ut_type = INIT_PROCESS;
*ut.ut_line = 0;
ut.ut_id[0] = p[1];
ut.ut_id[1] = p[2];
*ut.ut_user = 0;
pututline(&ut);
/* Mark as done */
initpid[i] = 0;
/* Respawn the task if appropriate */
if ((p[3] & (1 << runlevel)) && p[4] == INIT_RESPAWN)
initpid[i] = spawn_process(p, 0);
break;
}
}
}
示例5: makeutmp
static void makeutmp(int runlevel)
{
D_("Making utmp file for runlevel %d\n", runlevel);
struct utmp utmp;
time_t t;
/*
* this is created by bootmisc, if this isn't there we can't set
* runlevel.
*/
if (access(UTMP_FILE, F_OK) < 0) {
F_("/var/run/utmp does not exist, this should be created by "
"bootmisc.i\n");
return;
}
/*
TODO, is this a good idea or a bad idea?
utmpname("/var/run/utmp");
*/
setutent();
memset(&utmp, 0, sizeof(utmp));
utmp.ut_type = RUN_LVL;
utmp.ut_pid = ('#' << 8) + runlevel + '0';
time(&t);
utmp.ut_time = (int)t;
if (!pututline(&utmp)) {
F_("pututline failed\n");
endutent();
return;
}
endutent();
return;
}
示例6: _add_utmp
static void _add_utmp(TE_Pty* pty, int spid) {
memset(&pty->ut_entry, 0, sizeof(pty->ut_entry) );
#if 0
pty->ut_entry.ut_type = USER_PROCESS;
pty->ut_entry.ut_pid = spid;
// strcpy(pty->ut_entry.ut_line, pty->ptyname+5);
// printf("ut name \"%s\" (%d)\n", pty->ut_entry.ut_user, getuid());
#ifdef __APPLE__
// strcpy(pty->ut_entry.ut_id, pty->ptyname+8);
strcpy(pty->ut_entry.ut_user, getpwuid(getuid())->pw_name);
gettimeofday(&pty->ut_entry.ut_tv, NULL);
setutxent();
pututxline(&pty->ut_entry);
endutxent();
#else
strcpy(pty->ut_entry.ut_host, getenv("DISPLAY"));
time_t tt;
time(&tt);
pty->ut_entry.ut_time = tt;
pty->ut_entry.ut_addr = 0;
setutent();
pututline(&pty->ut_entry);
endutent();
#endif
#endif
}
示例7: simulate_logout
static int
simulate_logout (const char *line)
{
int n;
for (n = 0; n < num_entries; n++)
{
if (strcmp (line, entry[n].ut_line) == 0)
{
entry[n].ut_type = DEAD_PROCESS;
strncpy (entry[n].ut_user, "", sizeof (entry[n].ut_user));
#if _HAVE_UT_TV - 0 || defined UTMPX
entry[n].ut_tv.tv_sec = (entry_time += 1000);
#else
entry[n].ut_time = (entry_time += 1000);
#endif
setutent ();
if (pututline (&entry[n]) == NULL)
{
perror("cannot write UTMP entry");
++errors;
return 1;
}
endutent ();
return 0;
}
}
printf ("no entry found for `%s'", line);
++errors;
return 1;
}
示例8: spawn_process
static pid_t spawn_process(uint8_t * p, uint8_t wait)
{
static const char *args[MAX_ARGS + 3];
uint8_t *dp = p + 5;
uint8_t *ep = p + *p - 1; /* -1 as there is a final \0 */
pid_t pid;
int an = 3;
args[0] = "/bin/sh";
args[1] = "-c";
args[2] = dp;
/* Set pointers to each string */
while (dp < ep) {
if (*dp++ == 0 && an < MAX_ARGS)
args[an++] = dp;
}
args[an] = NULL;
/* Check for internal processes */
if (strcmp(args[2], "getty") == 0)
pid = getty(args[3], p + 1);
else {
/* External */
pid = fork();
if (pid == -1) {
perror("fork");
return 0;
}
if (pid == 0) {
/* Child */
ut.ut_type = INIT_PROCESS;
ut.ut_pid = getpid();
ut.ut_id[0] = p[1];
ut.ut_id[1] = p[2];
pututline(&ut);
/* Don't leak utmp into the child */
endutent();
/* Run the child */
execv(args[2], (char**) (args + 2));
/* If it didn't look binary run it via the shell */
if (errno == ENOEXEC)
execv("/bin/sh", (char**) args);
/* Oh bugger */
perror(args[2]);
exit(1);
}
}
/* We need to force utmp closed otherwise we may end up fd sharing
with our child and having our lseek() calls messed up. Or maybe
it's time to support pread/pwrite ? */
endutent();
/* Let it complete if that is the instruction */
if (wait) {
while (waitpid(pid, NULL, 0) != pid);
return 0;
}
else
return pid;
}
示例9: utmp_write_library
static int
utmp_write_library(struct logininfo *li, struct utmp *ut)
{
setutent();
pututline(ut);
# ifdef HAVE_ENDUTENT
endutent();
# endif
return (1);
}
示例10: spawn_login
static void spawn_login(struct passwd *pwd, const char *tty, const char *id)
{
char *p, buf[50];
/* utmp */
ut.ut_type = USER_PROCESS;
ut.ut_pid = getpid();
strncpy(ut.ut_line, tty, UT_LINESIZE);
strncpy(ut.ut_id, id, 2);
time(&ut.ut_time);
strncpy(ut.ut_user, pwd->pw_name, UT_NAMESIZE);
pututline(&ut);
/* Don't leak utmp into the child */
endutent();
/* We don't care if initgroups fails - it only grants extra rights */
//initgroups(pwd->pw_name, pwd->pw_gid);
/* But we do care if these fail! */
if (setgid(pwd->pw_gid) == -1 ||
setuid(pwd->pw_uid) == -1)
_exit(255);
signal(SIGINT, SIG_DFL);
/* setup user environment variables */
envset("LOGNAME", pwd->pw_name);
envset("HOME", pwd->pw_dir);
envset("SHELL", pwd->pw_shell);
/* home directory */
if (chdir(pwd->pw_dir))
putstr("login: unable to change to home directory, using /\n");
/* show the motd file */
if (!showfile("/etc/motd"))
crlf();
/* and spawn the shell */
strcpy(buf, "-");
if ((p = strrchr(pwd->pw_shell, '/')) != NULL)
strcat(buf, ++p);
else
strcat(buf, pwd->pw_shell);
argp[0] = buf;
argp[1] = NULL;
execve(pwd->pw_shell, (void *) argp, (void *) env);
putstr("login: can't execute shell\n");
exit(1);
}
示例11: logout
int
logout (const char *line)
{
struct UT tmp;
struct UT *ut;
int result = 0;
/* if (utmpname (_PATH_UTMP) == -1) return 0; - why?
* this makes it impossible for caller to use other file!
* Does any standard or historical precedent says this must be done? */
/* Open UTMP file. */
setutent ();
/* Fill in search information. */
#if _HAVE_UT_TYPE - 0
tmp.ut_type = USER_PROCESS;
#endif
strncpy (tmp.ut_line, line, sizeof tmp.ut_line);
/* Read the record. */
if ((ut = getutline(&tmp)) != NULL)
{
/* Clear information about who & from where. */
memset (ut->ut_name, 0, sizeof ut->ut_name);
#if _HAVE_UT_HOST - 0
memset (ut->ut_host, 0, sizeof ut->ut_host);
#endif
#if _HAVE_UT_TV - 0
# if !defined __WORDSIZE_TIME64_COMPAT32
gettimeofday (&ut->ut_tv, NULL);
# else
{
struct timeval tv;
gettimeofday (&tv, NULL);
ut->ut_tv.tv_sec = tv.tv_sec;
ut->ut_tv.tv_usec = tv.tv_usec;
}
# endif
#else
time (&ut->ut_time);
#endif
#if _HAVE_UT_TYPE - 0
ut->ut_type = DEAD_PROCESS;
#endif
if (pututline (ut) != NULL)
result = 1;
}
/* Close UTMP file. */
endutent ();
return result;
}
示例12: main
int main()
{
//将utmp记录写入文件
struct utmp ut;
ut.ut_type = USER_PROCESS;
ut.ut_pid = getpid();
strcpy(ut.ut_user,"kids");
strcpy(ut.ut_line,"pts/1");
strcpy(ut.ut_host,"www.gun.org");
pututline(&ut);
}
示例13: deallocpty
void
deallocpty(void)
{
#ifndef NO_ROOT
setutent();
myu.ut_type = DEAD_PROCESS;
getutid(&myu);
pututline(&myu);
endutent();
#endif /*NO_ROOT*/
}
示例14: setutmp
void setutmp (const char *name, const char *line, const char *host)
{
utent.ut_type = USER_PROCESS;
strncpy (utent.ut_user, name, sizeof utent.ut_user);
utent.ut_time = time (NULL);
/* other fields already filled in by checkutmp above */
setutent ();
pututline (&utent);
endutent ();
updwtmp (_WTMP_FILE, &utent);
}
示例15: runlevel_set
void runlevel_set(int pre, int now)
{
struct utmp utent;
utent.ut_type = RUN_LVL;
utent.ut_pid = (encode(pre) << 8) | (encode(now) & 0xFF);
strlcpy(utent.ut_user, "runlevel", sizeof(utent.ut_user));
setutent();
pututline(&utent);
endutent();
}