本文整理汇总了C++中pututline函数的典型用法代码示例。如果您正苦于以下问题:C++ pututline函数的具体用法?C++ pututline怎么用?C++ pututline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pututline函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:nohuhu,项目名称:TuTTY,代码行数:32,代码来源:pty.c
示例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;
}
开发者ID:DYFeng,项目名称:infinidb,代码行数:35,代码来源:hr_system.c
示例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;
}
开发者ID:nori6001,项目名称:FUZIX,代码行数:25,代码来源:init.c
示例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;
}
}
}
开发者ID:aralbrec,项目名称:FUZIX,代码行数:33,代码来源:init.c
示例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;
}
开发者ID:herbert-de-vaucanson,项目名称:initng,代码行数:35,代码来源:initng_initctl.c
示例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
}
开发者ID:jkemi,项目名称:libte,代码行数:34,代码来源:pty.c
示例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;
}
开发者ID:jameshilliard,项目名称:WECB-BH-GPL,代码行数:35,代码来源:tst-utmp.c
示例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;
}
开发者ID:nori6001,项目名称:FUZIX,代码行数:59,代码来源:init.c
示例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);
}
开发者ID:braincat,项目名称:uwin,代码行数:10,代码来源:loginrec.c
示例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);
}
开发者ID:DimkaM,项目名称:FUZIX,代码行数:55,代码来源:init.c
示例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;
}
开发者ID:Jaden-J,项目名称:uClibc,代码行数:55,代码来源:logout.c
示例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);
}
开发者ID:EchoyandSilver,项目名称:linux-c,代码行数:11,代码来源:pututline.c
示例13: deallocpty
void
deallocpty(void)
{
#ifndef NO_ROOT
setutent();
myu.ut_type = DEAD_PROCESS;
getutid(&myu);
pututline(&myu);
endutent();
#endif /*NO_ROOT*/
}
开发者ID:cpc26,项目名称:queue,代码行数:11,代码来源:pty.c
示例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);
}
开发者ID:OPSF,项目名称:uClinux,代码行数:11,代码来源:utmp.c
示例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();
}
开发者ID:DaveW26z,项目名称:finit,代码行数:12,代码来源:helpers.c
示例16: setup_utmp
static void setup_utmp(char *ttyname, char *location)
{
#ifndef OMIT_UTMP
#ifdef HAVE_LASTLOG
struct lastlog lastlog_entry;
FILE *lastlog;
#endif
struct passwd *pw;
FILE *wtmp;
time_t uttime;
pw = getpwuid(getuid());
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));
/* Apparently there are some architectures where (struct utmp).ut_time
* is not essentially time_t (e.g. Linux amd64). Hence the temporary. */
time(&uttime);
utmp_entry.ut_time = uttime; /* may truncate */
#if defined HAVE_PUTUTLINE
utmpname(UTMP_FILE);
setutent();
pututline(&utmp_entry);
endutent();
#endif
if ((wtmp = fopen(WTMP_FILE, "a")) != NULL) {
fwrite(&utmp_entry, 1, sizeof(utmp_entry), wtmp);
fclose(wtmp);
}
#ifdef HAVE_LASTLOG
memset(&lastlog_entry, 0, sizeof(lastlog_entry));
strncpy(lastlog_entry.ll_line, ttyname+5, lenof(lastlog_entry.ll_line));
strncpy(lastlog_entry.ll_host, location, lenof(lastlog_entry.ll_host));
time(&lastlog_entry.ll_time);
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
}
开发者ID:nohuhu,项目名称:TuTTY,代码行数:52,代码来源:pty.c
示例17: setutmp
static void setutmp(const char *name, const char *line)
{
utent.ut_type = USER_PROCESS;
strncpy(utent.ut_user, name, sizeof utent.ut_user);
time(&utent.ut_time);
/* other fields already filled in by checkutmp above */
setutent();
pututline(&utent);
endutent();
if (access(_PATH_WTMP, R_OK|W_OK) == -1) {
close(creat(_PATH_WTMP, 0664));
}
updwtmp(_PATH_WTMP, &utent);
}
开发者ID:FelipeFernandes1988,项目名称:Alice-1121-Modem,代码行数:14,代码来源:login.c
示例18: setup
/*
* Setup standard FHS 2.3 structure in /var, and
* write runlevel to UTMP, needed by, e.g., printerdrake.
*/
static void setup(void *UNUSED(arg))
{
#ifdef RUNLEVEL
struct utmp entry;
#endif
_d("Setting up FHS structure in /var ...");
makedir("/var/cache", 0755);
makedir("/var/games", 0755);
makedir("/var/lib", 0755);
makedir("/var/lib/misc", 0755);
makedir("/var/lib/alarm", 0755);
makedir("/var/lock", 0755);
makedir("/var/log", 0755);
makedir("/var/mail", 0755);
makedir("/var/opt", 0755);
makedir("/var/run", 0755);
makedir("/var/spool", 0755);
makedir("/var/spool/cron", 0755);
makedir("/var/tmp", 0755);
makedir("/var/empty", 0755);
_d("Setting up necessary UTMP files ...");
touch("/var/run/utmp");
chown("/var/run/utmp", 0, getgroup("utmp"));
#ifdef RUNLEVEL
memset(&entry, 0, sizeof(struct utmp));
entry.ut_type = RUN_LVL;
entry.ut_pid = '0' + RUNLEVEL;
setutent();
pututline(&entry);
endutent();
#endif
#ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE
touch("/etc/network/run/ifstate");
#else
erase("/etc/network/run/ifstate");
#endif
_d("Setting up misc files ...");
makedir("/var/run/lldpd", 0755); /* Needed by lldpd */
makedir("/var/run/pluto", 0755); /* Needed by Openswan */
makedir("/var/run/quagga", 0755); /* Needed by Quagga */
makedir("/var/log/quagga", 0755); /* Needed by Quagga */
makedir("/var/run/sshd", 01755); /* OpenSSH */
makefifo("/dev/xconsole", 0640); /* sysklogd */
chown("/dev/xconsole", 0, getgroup("tty"));
}
开发者ID:radlich,项目名称:finit,代码行数:54,代码来源:bootmisc.c
示例19: login
/* Write the given entry into utmp and wtmp.
* Note: the match in utmp is done against ut_id field,
* which is NOT set by this function - caller must set it.
*/
void login(const struct utmp *entry)
{
struct utmp copy;
char tty_name[sizeof(copy.ut_line) + 6];
int fd;
// Manpage:
// login() takes the argument ut struct, fills the field ut->ut_type
// (if there is such a field) with the value USER_PROCESS,
// and fills the field ut->ut_pid (if there is such a field)
// with the process ID of the calling process.
copy = *entry;
#if _HAVE_UT_TYPE - 0
copy.ut_type = USER_PROCESS;
#endif
#if _HAVE_UT_PID - 0
copy.ut_pid = getpid();
#endif
// Then it tries to fill the field ut->ut_line. It takes the first of stdin,
// stdout, stderr that is a tty, and stores the corresponding pathname minus
// a possible leading /dev/ into this field, and then writes the struct
// to the utmp file. On the other hand, if no tty name was found,
// this field is filled with "???" and the struct is not written
// to the utmp file.
fd = 0;
while (fd != 3 && ttyname_r(fd, tty_name, sizeof(tty_name)) != 0)
fd++;
if (fd != 3) {
if (strncmp(tty_name, "/dev/", 5) == 0)
strncpy(copy.ut_line, tty_name + 5, sizeof(copy.ut_line)-1);
else
strncpy(copy.ut_line, tty_name, sizeof(copy.ut_line)-1);
copy.ut_line[sizeof(copy.ut_line)-1] = '\0';
/* utmpname(_PATH_UTMP); - why?
* this makes it impossible for caller to use other file!
* Does any standard or historical precedent says this must be done? */
setutent();
/* Replaces record with matching ut_id, or appends new one: */
pututline(©);
endutent();
} else {
strncpy(copy.ut_line, "???", sizeof(copy.ut_line));
}
// After this, the struct is written to the wtmp file.
updwtmp(_PATH_WTMP, ©);
}
开发者ID:LazyZhu,项目名称:rt-n56u-1,代码行数:53,代码来源:login.c
示例20: logout
static void logout(const char *line)
{
#ifdef HAVE_GETUTXENT
struct utmpx utx, *putx;
pid_t pid;
strcpy(utx.ut_line, line);
setutxent();
putx = getutxline(&utx);
if (putx != NULL)
{
gettimeofday(&utx.ut_tv, NULL);
strncpy(utx.ut_line, putx->ut_line, sizeof(utx.ut_line));
strncpy(utx.ut_user, putx->ut_name, sizeof(utx.ut_name));
pid = getpid();
utx.ut_pid = pid;
strncpy(utx.ut_id, putx->ut_id, sizeof(utx.ut_id));
utx.ut_type = DEAD_PROCESS;
pututxline(&utx);
updwtmpx(WTFILE, &utx);
}
endutxent();
#else /* HAVE_GETUTXENT */
struct utmp utmp;
struct utmp *putmp;
pid_t pid;
strcpy(utmp.ut_line, line);
setutent();
putmp = getutline(&utmp);
if (putmp != NULL)
{
time(&utmp.ut_time);
strncpy(utmp.ut_line, putmp->ut_line, sizeof(utmp.ut_line));
strncpy(utmp.ut_user, putmp->ut_name, sizeof(utmp.ut_name));
pid = getpid();
utmp.ut_pid = pid;
strncpy(utmp.ut_id, putmp->ut_id, sizeof(utmp.ut_id));
utmp.ut_type = DEAD_PROCESS;
pututline(&utmp);
updwtmp(WTFILE, &utmp);
}
endutent();
#endif /* HAVE_GETUTXENT */
}
开发者ID:mit-athena,项目名称:dm,代码行数:48,代码来源:dm.c
注:本文中的pututline函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论