这篇教程C++ utmpname函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中utmpname函数的典型用法代码示例。如果您正苦于以下问题:C++ utmpname函数的具体用法?C++ utmpname怎么用?C++ utmpname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了utmpname函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: do_teststatic intdo_test (int argc, char *argv[]){ int result = 0; utmpname (name); result |= do_init (); result |= do_check (); result |= simulate_login ("tty1", "erwin"); result |= do_check (); result |= simulate_login ("ttyp1", "paul"); result |= do_check (); result |= simulate_logout ("tty2"); result |= do_check (); result |= simulate_logout ("ttyp0"); result |= do_check (); result |= simulate_login ("ttyp2", "richard"); result |= do_check (); result |= check_login ("tty1"); result |= check_logout ("ttyp0"); result |= check_id ("p1"); result |= check_id ("2"); result |= check_id ("si"); result |= check_type (BOOT_TIME); result |= check_type (RUN_LVL); return result;}
开发者ID:jameshilliard,项目名称:WECB-BH-GPL,代码行数:35,
示例2: check_utmpint check_utmp (int total_unused) { /* replace total_unused with the minimum of * total_unused and the shortest utmp idle time. */ typedef struct utmp utmp_t; utmp_t *u; int min_idle=2*max_unused; utmpname(UTMP_FILE); setutent(); while ((u=getutent())) { if (u->ut_type == USER_PROCESS) { /* get tty. From w.c in procps by Charles Blake. */ char tty[5 + sizeof u->ut_line + 1] = "/dev/"; int i; for (i=0; i < sizeof u->ut_line; i++) { /* clean up tty if garbled */ if (isalnum(u->ut_line[i]) || (u->ut_line[i]=='/')) { tty[i+5] = u->ut_line[i]; } else { tty[i+5] = '/0'; } } int cur_idle=idletime(tty); min_idle = (cur_idle < min_idle) ? cur_idle : min_idle; } } /* The shortest idle time is the real idle time */ total_unused = (min_idle < total_unused) ? min_idle : total_unused; if (debug && total_unused == min_idle) printf("sleepd: activity: utmp %d seconds/n", min_idle); return total_unused;}
开发者ID:jstrunk,项目名称:sleepd,代码行数:34,
示例3: uv_uptimeint uv_uptime(double* uptime) { struct utmp *utmp_buf; size_t entries = 0; time_t boot_time; boot_time = 0; utmpname(UTMP_FILE); setutent(); while ((utmp_buf = getutent()) != NULL) { if (utmp_buf->ut_user[0] && utmp_buf->ut_type == USER_PROCESS) ++entries; if (utmp_buf->ut_type == BOOT_TIME) boot_time = utmp_buf->ut_time; } endutent(); if (boot_time == 0) return UV_ENOSYS; *uptime = time(NULL) - boot_time; return 0;}
开发者ID:abouthiroppy,项目名称:node,代码行数:25,
示例4: cleanup_utmpstatic 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,
示例5: runlevel_mainint runlevel_main(int argc UNUSED_PARAM, char **argv){ struct utmp *ut; char prev; if (argv[1]) utmpname(argv[1]); setutent(); while ((ut = getutent()) != NULL) { if (ut->ut_type == RUN_LVL) { prev = ut->ut_pid / 256; if (prev == 0) prev = 'N'; printf("%c %c/n", prev, ut->ut_pid % 256); if (ENABLE_FEATURE_CLEAN_UP) endutent(); return 0; } } puts("unknown"); if (ENABLE_FEATURE_CLEAN_UP) endutent(); return 1;}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:25,
示例6: utmpxnamestatic int utmpxname(const char *file) { int result; result = utmpname(file);#ifdef IS_BIONIC /* Yeah bionic is that weird */ result = result - 1;#endif return result;}
开发者ID:ArikaChen,项目名称:lxc,代码行数:11,
示例7: setup_utmpstatic 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,
示例8: _getloginstatic char *_getlogin() { /* find name of the controlling terminal of the calling process */ char *tty; /* if the controlling terminal name cannot be determined, return a NULL pointer. * `errno` will have been appropriately set by `ttyname(3)`. */ if ((tty = ttyname(STDIN_FILENO)) == NULL) return NULL; /* the static data structure used for all calls to this function */ static char login[GETLOGIN_LOGIN_MAX]; utmpname(GETLOGIN_UTMP_FILE); /* search for an entry in the utmp file where the ut_line field matches * that of the controlling terminal name */ errno = 0; setutxent(); if (errno != 0) return NULL; struct utmpx *entry, criteria; char *line; /* drop the leading slash, if any */ if (tty[0] == '/') ++tty; /* remove the `dev/` prefix from the ttyname, if existent */ if ((line = strchr(tty, '/')) == NULL) line = tty; else /* dev/pts/0 becomes pts/0 */ ++line; strncpy(criteria.ut_line, line, __UT_LINESIZE); if ((entry = getutxline(&criteria)) == NULL) return NULL; strncpy(login, entry->ut_user, GETLOGIN_LOGIN_MAX); /* finish the reading of the utmp file */ errno = 0; endutxent(); if (errno != 0) return NULL; return login;}
开发者ID:rmascarenhas,项目名称:lpi,代码行数:50,
示例9: mainmain(){ struct utmp *ut; utmpname(_PATH_UTMP); setutent(); printf("User TTY Login-time/n"); while(ut = getutent()) { if(ut->ut_type == USER_PROCESS) printf("%-8s %-2s %s", ut->ut_user, ut->ut_id, ctime(&ut->ut_time)); } endutent();}
开发者ID:LambdaCalculus379,项目名称:SLS-1.02,代码行数:15,
示例10: wallvoidwall(void){ /* write to all users, that the system is going down. */ struct utmp *ut; utmpname(_PATH_UTMP); setutent(); while((ut = getutent())) { if(ut->ut_type == USER_PROCESS) write_user(ut); } endutent();}
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:15,
示例11: setup_utmpstatic 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; 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)); time(&utmp_entry.ut_time);#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:AshKash,项目名称:kit-sink,代码行数:48,
示例12: login/* Write the given entry into utmp and wtmp. */void login (const struct utmp *entry){ struct utmp copy = *entry; utmpname(_PATH_UTMP); setutent();#if _HAVE_UT_TYPE - 0 copy.ut_type = USER_PROCESS;#endif #if _HAVE_UT_PID - 0 copy.ut_pid = getpid();#endif strncpy (copy.ut_line, entry->ut_line, UT_LINESIZE); pututline(entry); endutent();}
开发者ID:Brainiarc7,项目名称:ralink_sdk,代码行数:17,
示例13: logoutintlogout (const char *line){ struct utmp tmp, utbuf; struct utmp *ut; int result = 0; /* Tell that we want to use the UTMP file. */ if (utmpname (_PATH_UTMP) == -1) return 0; /* 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 (getutline_r (&tmp, &utbuf, &ut) >= 0) { /* Clear information about who & from where. */ bzero (ut->ut_name, sizeof ut->ut_name);#if _HAVE_UT_HOST - 0 bzero (ut->ut_host, sizeof ut->ut_host);#endif#if _HAVE_UT_TV - 0 gettimeofday (&ut->ut_tv, NULL);#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:BackupTheBerlios,项目名称:wl530g-svn,代码行数:46,
示例14: print_filevoid print_file(char * name, char *id, char *line) { struct utmp *u; if (utmpname(name)) { fprintf(stderr, "utmp database %s open failed/n", name); return; } setutent(); printf("%s:/n====================/n", name); while ((u=get_next_line(id, line))) { print_utmp_entry(u); /* POSIX requires us to clear the static data before * calling getutline or getutid again */ memset(u, 0, sizeof(struct utmp)); } endutent();}
开发者ID:iloveloveyou,项目名称:chirico,代码行数:18,
示例15: get_boot_time_1voidget_boot_time_1 (const char *filename, int newest){ struct utmp ut, *utp; int desc; if (filename) { /* On some versions of IRIX, opening a nonexistent file name is likely to crash in the utmp routines. */ desc = emacs_open (filename, O_RDONLY, 0); if (desc < 0) return; emacs_close (desc); utmpname (filename); } setutent (); while (1) { /* Find the next reboot record. */ ut.ut_type = BOOT_TIME; utp = getutid (&ut); if (! utp) break; /* Compare reboot times and use the newest one. */ if (utp->ut_time > boot_time) { boot_time = utp->ut_time; if (! newest) break; } /* Advance on element in the file so that getutid won't repeat the same one. */ utp = getutent (); if (! utp) break; } endutent ();}
开发者ID:damianjb,项目名称:emacs,代码行数:43,
示例16: utmp_logstatic voidutmp_log (int login){ char id[UT_LINESIZE + 1]; struct utmp ut; struct timeval tv; int pid; pid = getpid (); snprintf (id, UT_LINESIZE, "%d", pid); assert (pwd != NULL); utmpname (_PATH_UTMP); setutent (); memset (&ut, 0, sizeof(ut)); strncpy (ut.ut_id, id, sizeof (ut.ut_id)); ut.ut_id[sizeof (ut.ut_id) - 1] = 0; ut.ut_line[0] = 0; if (login) { strncpy (ut.ut_user, pwd->pw_name, sizeof(ut.ut_user)); ut.ut_user[sizeof (ut.ut_user) - 1] = 0; strncpy (ut.ut_host, rhost, sizeof(ut.ut_host)); ut.ut_host[sizeof (ut.ut_host) - 1] = 0; } gettimeofday (&tv, NULL); ut.ut_tv.tv_sec = tv.tv_sec; ut.ut_tv.tv_usec = tv.tv_usec; ut.ut_type = login ? LOGIN_PROCESS : DEAD_PROCESS; ut.ut_pid = pid; pututline (&ut); endutent (); updwtmp (_PATH_WTMP, &ut);}
开发者ID:maxamillion,项目名称:cockpit,代码行数:42,
示例17: write_utmp/**************************************************************************** * write a utmp entry to the utmp file ***************************************************************************/int write_utmp(struct utmp * u) { int pos; // regain root privileges seteuid(0); utmpname(UTMP); setutent(); pututline(u); endutent(); updwtmp(WTMP_FILE, u); pos = (int)NULL; madeutent = 1; // drop root privileges again seteuid(getuid()); return(pos);}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:23,
示例18: cleanutent/* * there is a nice function "endutent" defined in <utmp.h>; * like "setutent" it takes no arguments, so I think it gets all information * from library-calls. * That's why "setutent" has to be called by the child-process with * file-descriptors 0/1 set to the pty. But that child execs to the * application-program and therefore can't clean it's own utmp-entry!(?) * The master on the other hand doesn't have the correct process-id * and io-channels... I'll do it by hand: * (what's the position of the utmp-entry, the child wrote? :-) */void cleanutent() { int pid; struct utmp *u; // regain root privileges seteuid(0); utmpname(UTMP); setutent(); pid = getpid(); /* The following 11 lines of code were copied from the * poeigl-1.20 login/init package. Special thanks to * poe for the code examples. */ while((u = getutent())) { if(u->ut_pid == pid) { time(&u->ut_time);#ifdef SVR4 memset(&u->ut_user, 0, sizeof(u->ut_user));#else memset(&u->ut_user, 0, sizeof(u->ut_user)); memset(&u->ut_host, 0, sizeof(u->ut_host));#endif u->ut_type = DEAD_PROCESS; u->ut_pid = 0;#if !defined(SVR4) && !defined(AIXV3) u->ut_addr = 0;#endif pututline(u); /* Was reversed with in the original */ endutent(); updwtmp(WTMP_FILE, u); } } // drop root privileges again seteuid(getuid());}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:51,
示例19: runlevel_mainint runlevel_main(int argc, char *argv[]){ struct utmp *ut; char prev; if (argc > 1) utmpname(argv[1]); setutent(); while ((ut = getutent()) != NULL) { if (ut->ut_type == RUN_LVL) { prev = ut->ut_pid / 256; if (prev == 0) prev = 'N'; printf("%c %c/n", prev, ut->ut_pid % 256); endutent(); return 0; } } puts("unknown"); endutent(); return 1;}
开发者ID:fullstory-morgue,项目名称:busybox-sidux,代码行数:22,
示例20: utmp_logstatic voidutmp_log (int login){ struct utmp ut; struct timeval tv; int pid = getpid (); const char *id = line + strlen (line) - sizeof(ut.ut_id); utmpname (_PATH_UTMP); setutent (); memset (&ut, 0, sizeof(ut)); strncpy (ut.ut_id, id, sizeof (ut.ut_id)); ut.ut_id[sizeof (ut.ut_id) - 1] = 0; strncpy (ut.ut_line, line, sizeof (ut.ut_line)); ut.ut_line[sizeof (ut.ut_line) - 1] = 0; if (login) { strncpy (ut.ut_user, user, sizeof(ut.ut_user)); ut.ut_user[sizeof (ut.ut_user) - 1] = 0; strncpy (ut.ut_host, rhost, sizeof(ut.ut_host)); ut.ut_host[sizeof (ut.ut_host) - 1] = 0; } gettimeofday (&tv, NULL); ut.ut_tv.tv_sec = tv.tv_sec; ut.ut_tv.tv_usec = tv.tv_usec; ut.ut_type = login ? USER_PROCESS : DEAD_PROCESS; ut.ut_pid = pid; pututline (&ut); endutent (); updwtmp (_PATH_WTMP, &ut);}
开发者ID:rainsome-org1,项目名称:cockpit,代码行数:39,
示例21: get_boot_time_1voidget_boot_time_1 (const char *filename, bool newest){ struct utmp ut, *utp; if (filename) { /* On some versions of IRIX, opening a nonexistent file name is likely to crash in the utmp routines. */ if (faccessat (AT_FDCWD, filename, R_OK, AT_EACCESS) != 0) return; utmpname (filename); } setutent (); while (1) { /* Find the next reboot record. */ ut.ut_type = BOOT_TIME; utp = getutid (&ut); if (! utp) break; /* Compare reboot times and use the newest one. */ if (utp->ut_time > boot_time) { boot_time = utp->ut_time; if (! newest) break; } /* Advance on element in the file so that getutid won't repeat the same one. */ utp = getutent (); if (! utp) break; } endutent ();}
开发者ID:joelmccracken,项目名称:emacs-js,代码行数:39,
示例22: mainintmain(int argc, char *argv[]) { if (argc == 1) helpAndLeave(argv[0], EXIT_FAILURE); char *username = argv[1]; if (argc > 2) utmp_file = argv[2]; if (argc > 3) wtmp_file = argv[3]; utmpname(utmp_file); struct utmpx ut; strncpy(ut.ut_user, username, __UT_NAMESIZE); _login(&ut); printf("Username %s has been logged in./n", username); exit(EXIT_SUCCESS);}
开发者ID:rmascarenhas,项目名称:lpi,代码行数:22,
示例23: uv_uptimeuv_err_t uv_uptime(double* uptime) { struct utmp *utmp_buf; size_t entries = 0; time_t boot_time; utmpname(UTMP_FILE); setutent(); while ((utmp_buf = getutent()) != NULL) { if (utmp_buf->ut_user[0] && utmp_buf->ut_type == USER_PROCESS) ++entries; if (utmp_buf->ut_type == BOOT_TIME) boot_time = utmp_buf->ut_time; } endutent(); if (boot_time == 0) return uv__new_artificial_error(UV_ENOSYS); *uptime = time(NULL) - boot_time; return uv_ok_;}
开发者ID:559210,项目名称:libpomelo,代码行数:24,
示例24: step_systime//.........这里部分代码省略......... * * Some OSes have utmp, some have utmpx. */ /* * Write old and new time entries in utmp and wtmp if step * adjustment is greater than one second. * * This might become even Uglier... */ tvdiff = abs_tval(sub_tval(timetv, tvlast)); if (tvdiff.tv_sec > 0) {#ifdef HAVE_UTMP_H struct utmp ut;#endif#ifdef HAVE_UTMPX_H struct utmpx utx;#endif#ifdef HAVE_UTMP_H ZERO(ut);#endif#ifdef HAVE_UTMPX_H ZERO(utx);#endif /* UTMP */#ifdef UPDATE_UTMP# ifdef HAVE_PUTUTLINE# ifndef _PATH_UTMP# define _PATH_UTMP UTMP_FILE# endif utmpname(_PATH_UTMP); ut.ut_type = OLD_TIME; strlcpy(ut.ut_line, OTIME_MSG, sizeof(ut.ut_line)); ut.ut_time = tvlast.tv_sec; setutent(); pututline(&ut); ut.ut_type = NEW_TIME; strlcpy(ut.ut_line, NTIME_MSG, sizeof(ut.ut_line)); ut.ut_time = timetv.tv_sec; setutent(); pututline(&ut); endutent();# else /* not HAVE_PUTUTLINE */# endif /* not HAVE_PUTUTLINE */#endif /* UPDATE_UTMP */ /* UTMPX */#ifdef UPDATE_UTMPX# ifdef HAVE_PUTUTXLINE utx.ut_type = OLD_TIME; strlcpy(utx.ut_line, OTIME_MSG, sizeof(utx.ut_line)); utx.ut_tv = tvlast; setutxent(); pututxline(&utx); utx.ut_type = NEW_TIME; strlcpy(utx.ut_line, NTIME_MSG, sizeof(utx.ut_line)); utx.ut_tv = timetv; setutxent(); pututxline(&utx); endutxent();# else /* not HAVE_PUTUTXLINE */# endif /* not HAVE_PUTUTXLINE */
开发者ID:verm,项目名称:gsoc-ntp-2013,代码行数:67,
示例25: updateXtmp_unixstatic voidupdateXtmp_unix (TimeInternal oldTime, TimeInternal newTime){/* Add the old time entry to utmp/wtmp *//* About as long as the ntpd implementation, but not any less ugly */#ifdef HAVE_UTMPX_H struct utmpx utx; memset(&utx, 0, sizeof(utx)); strncpy(utx.ut_user, "date", sizeof(utx.ut_user));#ifndef OTIME_MSG strncpy(utx.ut_line, "|", sizeof(utx.ut_line));#else strncpy(utx.ut_line, OTIME_MSG, sizeof(utx.ut_line));#endif /* OTIME_MSG */#ifdef OLD_TIME utx.ut_tv.tv_sec = oldTime.seconds; utx.ut_tv.tv_usec = oldTime.nanoseconds / 1000; utx.ut_type = OLD_TIME;#else /* no ut_type */ utx.ut_time = oldTime.seconds;#endif /* OLD_TIME *//* ======== BEGIN OLD TIME EVENT - UTMPX / WTMPX =========== */#ifdef HAVE_UTMPXNAME utmpxname("/var/log/utmp");#endif /* HAVE_UTMPXNAME */ setutxent(); pututxline(&utx); endutxent();#ifdef HAVE_UPDWTMPX updwtmpx("/var/log/wtmp", &utx);#endif /* HAVE_IPDWTMPX *//* ======== END OLD TIME EVENT - UTMPX / WTMPX =========== */#else /* NO UTMPX_H */#ifdef HAVE_UTMP_H struct utmp ut; memset(&ut, 0, sizeof(ut)); strncpy(ut.ut_name, "date", sizeof(ut.ut_name));#ifndef OTIME_MSG strncpy(ut.ut_line, "|", sizeof(ut.ut_line));#else strncpy(ut.ut_line, OTIME_MSG, sizeof(ut.ut_line));#endif /* OTIME_MSG */#ifdef OLD_TIME#ifdef HAVE_STRUCT_UTMP_UT_TIME ut.ut_time = oldTime.seconds;#else ut.ut_tv.tv_sec = oldTime.seconds; ut.ut_tv.tv_usec = oldTime.nanoseconds / 1000;#endif /* HAVE_STRUCT_UTMP_UT_TIME */ ut.ut_type = OLD_TIME;#else /* no ut_type */ ut.ut_time = oldTime.seconds;#endif /* OLD_TIME *//* ======== BEGIN OLD TIME EVENT - UTMP / WTMP =========== */#ifdef HAVE_UTMPNAME utmpname(UTMP_FILE);#endif /* HAVE_UTMPNAME */#ifdef HAVE_SETUTENT setutent();#endif /* HAVE_SETUTENT */#ifdef HAVE_PUTUTLINE pututline(&ut);#endif /* HAVE_PUTUTLINE */#ifdef HAVE_ENDUTENT endutent();#endif /* HAVE_ENDUTENT */#ifdef HAVE_UTMPNAME utmpname(WTMP_FILE);#endif /* HAVE_UTMPNAME */#ifdef HAVE_SETUTENT setutent();#endif /* HAVE_SETUTENT */#ifdef HAVE_PUTUTLINE pututline(&ut);#endif /* HAVE_PUTUTLINE */#ifdef HAVE_ENDUTENT endutent();#endif /* HAVE_ENDUTENT *//* ======== END OLD TIME EVENT - UTMP / WTMP =========== */#endif /* HAVE_UTMP_H */#endif /* HAVE_UTMPX_H *//* Add the new time entry to utmp/wtmp */#ifdef HAVE_UTMPX_H memset(&utx, 0, sizeof(utx)); strncpy(utx.ut_user, "date", sizeof(utx.ut_user));#ifndef NTIME_MSG strncpy(utx.ut_line, "{", sizeof(utx.ut_line));//.........这里部分代码省略.........
开发者ID:lukebigum,项目名称:ptpd,代码行数:101,
示例26: loginvoidlogin (const struct utmp *ut){#ifdef PATH_MAX char _tty[PATH_MAX + UT_LINESIZE];#else char _tty[512 + UT_LINESIZE];#endif char *tty = _tty; int found_tty; const char *ttyp; struct utmp copy = *ut; /* Fill in those fields we supply. */#if _HAVE_UT_TYPE - 0 copy.ut_type = USER_PROCESS;#endif#if _HAVE_UT_PID - 0 copy.ut_pid = getpid ();#endif /* Seek tty. */ found_tty = tty_name (STDIN_FILENO, &tty, sizeof (_tty)); if (found_tty < 0) found_tty = tty_name (STDOUT_FILENO, &tty, sizeof (_tty)); if (found_tty < 0) found_tty = tty_name (STDERR_FILENO, &tty, sizeof (_tty)); if (found_tty >= 0) { /* We only want to insert the name of the tty without path. But take care of name like /dev/pts/3. */ if (strncmp (tty, "/dev/", 5) == 0) ttyp = tty + 5; /* Skip the "/dev/". */ else ttyp = basename (tty); /* Position to record for this tty. */ strncpy (copy.ut_line, ttyp, UT_LINESIZE); /* Tell that we want to use the UTMP file. */ if (utmpname (_PATH_UTMP) == 0) { /* Open UTMP file. */ setutent (); /* Write the entry. */ pututline (©); /* Close UTMP file. */ endutent (); } if (tty != _tty) free (tty); /* Free buffer malloced by tty_name. */ } else /* We provide a default value so that the output does not contain an random bytes in this field. */ strncpy (copy.ut_line, "???", UT_LINESIZE); /* Update the WTMP file. Here we have to add a new entry. */ updwtmp (_PATH_WTMP, ©);}
开发者ID:JamesLinus,项目名称:glibc-mips,代码行数:64,
示例27: Q_Dvoid KPty::logout(){#ifdef HAVE_UTEMPTER Q_D(KPty); removeLineFromUtmp(d->ttyName, d->masterFd);#else Q_D(KPty); const char *str_ptr = d->ttyName.data(); if (!memcmp(str_ptr, "/dev/", 5)) { str_ptr += 5; }# ifdef __GLIBC__ else { const char * sl_ptr = strrchr(str_ptr, '/'); if (sl_ptr) { str_ptr = sl_ptr + 1; } }# endif# ifdef HAVE_LOGIN# ifdef HAVE_LOGINX ::logoutx(str_ptr, 0, DEAD_PROCESS);# else ::logout(str_ptr);# endif# else# ifdef HAVE_UTMPX struct utmpx l_struct, *ut;# else struct utmp l_struct, *ut;# endif memset(&l_struct, 0, sizeof(l_struct)); strncpy(l_struct.ut_line, str_ptr, sizeof(l_struct.ut_line));# ifdef HAVE_UTMPX utmpxname(_PATH_UTMPX); setutxent(); if ((ut = getutxline(&l_struct))) {# else utmpname(_PATH_UTMP); setutent(); if ((ut = getutline(&l_struct))) {# endif memset(ut->ut_name, 0, sizeof(*ut->ut_name)); memset(ut->ut_host, 0, sizeof(*ut->ut_host));# ifdef HAVE_STRUCT_UTMP_UT_SYSLEN ut->ut_syslen = 0;# endif# ifdef HAVE_STRUCT_UTMP_UT_TYPE ut->ut_type = DEAD_PROCESS;# endif# ifdef HAVE_UTMPX gettimeofday(&ut->ut_tv, 0); pututxline(ut); } endutxent();# else ut->ut_time = time(0); pututline(ut);}endutent();# endif# endif#endif}
开发者ID:curvedspace,项目名称:terminal,代码行数:68,
注:本文中的utmpname函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ utoa函数代码示例 C++ utimes函数代码示例 |