当前位置: 首页>>代码示例>>C++>>正文


C++ endutxent函数代码示例

本文整理汇总了C++中endutxent函数的典型用法代码示例。如果您正苦于以下问题:C++ endutxent函数的具体用法?C++ endutxent怎么用?C++ endutxent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了endutxent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: utmpx_mark_dead

void
utmpx_mark_dead(pid_t pid, int status, boolean_t blocking)
{
	struct utmpx *up;
	int logged = 0;

	for (;;) {
		int found = 0;

		MUTEX_LOCK(&utmpx_lock);
		setutxent();

		while (up = getutxent()) {
			if (up->ut_pid == pid) {
				found = 1;

				if (up->ut_type == DEAD_PROCESS) {
					/*
					 * Cleaned up elsewhere.
					 */
					endutxent();
					MUTEX_UNLOCK(&utmpx_lock);
					return;
				}

				up->ut_type = DEAD_PROCESS;
				up->ut_exit.e_termination = WTERMSIG(status);
				up->ut_exit.e_exit = WEXITSTATUS(status);
				(void) time(&up->ut_tv.tv_sec);

				if (pututxline(up) != NULL) {
					/*
					 * Now attempt to add to the end of the
					 * wtmp and wtmpx files.  Do not create
					 * if they don't already exist.
					 */
					updwtmpx(WTMPX_FILE, up);
					endutxent();
					MUTEX_UNLOCK(&utmpx_lock);

					return;
				}
			}
		}

		endutxent();
		MUTEX_UNLOCK(&utmpx_lock);

		if (!found || !blocking)
			return;

		if (!logged) {
			log_framework(LOG_INFO, "retrying utmpx_dead on PID "
			    "%ld\n", pid);
			logged++;
		}

		(void) sleep(1);
	}
}
开发者ID:AlfredArouna,项目名称:illumos-gate,代码行数:60,代码来源:utmpx.c

示例2: psutil_users

/*
 * Return users currently connected on the system.
 */
static PyObject *
psutil_users(PyObject *self, PyObject *args) {
    struct utmpx *ut;
    PyObject *py_tuple = NULL;
    PyObject *py_username = NULL;
    PyObject *py_tty = NULL;
    PyObject *py_hostname = NULL;
    PyObject *py_user_proc = NULL;
    PyObject *py_retlist = PyList_New(0);

    if (py_retlist == NULL)
        return NULL;

    setutxent();
    while (NULL != (ut = getutxent())) {
        if (ut->ut_type == USER_PROCESS)
            py_user_proc = Py_True;
        else
            py_user_proc = Py_False;
        py_username = PyUnicode_DecodeFSDefault(ut->ut_user);
        if (! py_username)
            goto error;
        py_tty = PyUnicode_DecodeFSDefault(ut->ut_line);
        if (! py_tty)
            goto error;
        py_hostname = PyUnicode_DecodeFSDefault(ut->ut_host);
        if (! py_hostname)
            goto error;
        py_tuple = Py_BuildValue(
            "(OOOfOi)",
            py_username,              // username
            py_tty,                   // tty
            py_hostname,              // hostname
            (float)ut->ut_tv.tv_sec,  // tstamp
            py_user_proc,             // (bool) user process
            ut->ut_pid                // process id
        );
        if (py_tuple == NULL)
            goto error;
        if (PyList_Append(py_retlist, py_tuple))
            goto error;
        Py_DECREF(py_username);
        Py_DECREF(py_tty);
        Py_DECREF(py_hostname);
        Py_DECREF(py_tuple);
    }
    endutxent();

    return py_retlist;

error:
    Py_XDECREF(py_username);
    Py_XDECREF(py_tty);
    Py_XDECREF(py_hostname);
    Py_XDECREF(py_tuple);
    Py_DECREF(py_retlist);
    endutxent();
    return NULL;
}
开发者ID:jomann09,项目名称:psutil,代码行数:62,代码来源:_psutil_sunos.c

示例3: utmpx_write_entry

static void
utmpx_write_entry(short type, const char *msg, time_t tstamp)
{
	struct utmpx u;
	struct utmpx *oup;
	size_t tmplen;

	bzero(&u, sizeof (struct utmpx));

	u.ut_id[0] = u.ut_id[1] = u.ut_id[2] = u.ut_id[3] = '\0';
	u.ut_pid = 0;

	u.ut_exit.e_termination = WTERMSIG(0);
	u.ut_exit.e_exit = WEXITSTATUS(0);
	u.ut_type = type;
	u.ut_tv.tv_sec = tstamp;

	MUTEX_LOCK(&utmpx_lock);
	setutxent();

	if ((oup = getutxid(&u)) != NULL) {
		bcopy(oup->ut_user, u.ut_user, sizeof (u.ut_user));
		bcopy(oup->ut_line, u.ut_line, sizeof (u.ut_line));
		bcopy(oup->ut_host, u.ut_host, sizeof (u.ut_host));

		tmplen = strlen(u.ut_host);
		if (tmplen)
			u.ut_syslen = min(tmplen + 1, sizeof (u.ut_host));
		else
			u.ut_syslen =  0;
	}

	(void) sprintf(u.ut_line, "%.12s", msg);

	if (pututxline(&u) == NULL) {
		endutxent();
		MUTEX_UNLOCK(&utmpx_lock);

		return;
	}

	updwtmpx(WTMPX_FILE, &u);

	endutxent();
	MUTEX_UNLOCK(&utmpx_lock);

	utmpx_check();
}
开发者ID:AlfredArouna,项目名称:illumos-gate,代码行数:48,代码来源:utmpx.c

示例4: getutxent

/*
Show utmp information via getutxent(3)
@function utmp
@return information (TABLE)
*/
static int
Futmp(lua_State *L)
{
	struct utmpx *utx = {0};
	setutxent();
	lua_createtable(L, 0, 7);
	while ((utx = getutxent())) {
		lua_pushstring(L, utx->ut_user);
		lua_setfield(L, -2, "user");
		lua_pushstring(L, utx->ut_line);
		lua_setfield(L, -2, "tty");
		lua_pushstring(L, utx->ut_host);
		lua_setfield(L, -2, "hostname");
		lua_pushnumber(L, (float)utx->ut_tv.tv_sec);
		lua_setfield(L, -2, "timestamp");
		lua_pushboolean(L, utx->ut_type & USER_PROCESS);
		lua_setfield(L, -2, "user_process");
		lua_pushboolean(L, utx->ut_type & INIT_PROCESS);
		lua_setfield(L, -2, "init_process");
		lua_pushboolean(L, utx->ut_type & LOGIN_PROCESS);
		lua_setfield(L, -2, "login_process");
	}
	endutxent();
	return 1;
}
开发者ID:tongson,项目名称:omnia,代码行数:30,代码来源:factidC.c

示例5: main

int main(int argc, char **argv)
{
    struct utmpx u;
    const char file[256] = "/home/flueg/workspace/utmp/ftmpx";
    memset(&u, 0, sizeof(struct utmpx));

    if (utmpxname(file) == -1) perror("failed to set ftmpx file");
    strcpy(u.ut_user, getpwuid(getuid())->pw_name);
    printf("ttyname is: %s\n", ttyname(0)+strlen("/dev/"));
    strcpy(u.ut_id, ttyname(0) + strlen("/dev/tty"));
    strcpy(u.ut_line, ttyname(0) + strlen("/dev/"));
    u.ut_pid = getpid();
    u.ut_type = LOGIN_PROCESS;

    setutxent();
    if (pututxline(&u) == NULL) perror("failed to pututxline.\n");

    sleep(2);
    u.ut_type = DEAD_PROCESS;
    time((time_t *) &u.ut_tv.tv_sec);
    setutxent();
    if (pututxline(&u) == NULL) perror("failed to pututxline.\n");

    endutxent();
    exit(0);
}
开发者ID:flueg,项目名称:PrivateWorkSpace,代码行数:26,代码来源:utmpx.c

示例6: main

int main(int argc, char *argv[]) {
   struct utmpx *ut;
   
   setutxent();
   
   while ((ut = getutxent()) != NULL) {
      printf("%-10s ", ut->ut_user);
      printf("%-10s ", (ut->ut_type == EMPTY) ?          "EMPTY"    :
     	                (ut->ut_type == RUN_LVL) ?       "RUN_LVL"  :
                        (ut->ut_type == BOOT_TIME) ?     "BOOT_TIME":
                        (ut->ut_type == NEW_TIME) ?      "NEW_TIME" :
                        (ut->ut_type == OLD_TIME) ?      "OLD_TIME" :
                        (ut->ut_type == INIT_PROCESS) ?  "INIT_PR"  :
                        (ut->ut_type == LOGIN_PROCESS) ? "LOGIN_PR" :
                        (ut->ut_type == USER_PROCESS) ?  "USER_PR"  :
                        (ut->ut_type == DEAD_PROCESS) ?  "DEAD_PR"  : "?");
      printf("%-7ld %-6s %-5s %-10s ",
      	    (long) ut->ut_pid, ut->ut_line, ut->ut_id, ut->ut_host);
      printf("%s", ctime((time_t *) &(ut->ut_tv.tv_sec)));
   }
   
   endutxent();
   
   exit(EXIT_SUCCESS);
}
开发者ID:CoolerVoid,项目名称:L-LP,代码行数:25,代码来源:05_login_accounting.c

示例7: while

/**
   goodNumberOfUsers method for SunOS implementation of OS Provider

   Goes through the utents, counting the number of type USER_PROCESS
   Works in isolated test env without new users logging in
  */
Boolean OSTestClient::goodNumberOfUsers(
    const Uint32 &nusers,
    Boolean verbose)
{
   struct utmpx * utmpp;
   Uint32 numberOfUsers;

   if (verbose)
      cout<<"Checking NumberOfUsers " << nusers << endl;

   numberOfUsers = 0;

// ATTN-SLC-P3-17-Apr-02: optimization? parse uptime instead?

   while ((utmpp = getutxent()) != NULL)
   {
       if (utmpp->ut_type == USER_PROCESS)
       {
           numberOfUsers++;
       }
   }

   endutxent();
   if (verbose)
      cout << " Should be " << numberOfUsers << endl;

// works in isolated test env without new users logging in
   return (nusers == numberOfUsers);
}
开发者ID:deleisha,项目名称:neopegasus,代码行数:35,代码来源:OSTestClient_Solaris.cpp

示例8: doutmpx

static void
doutmpx(void)
{
	struct utmpx utmpx;
	char *t;

	memset((void *)&utmpx, 0, sizeof(utmpx));
	utmpx.ut_tv = now;
	(void)strncpy(utmpx.ut_name, username, sizeof(utmpx.ut_name));
	if (hostname) {
		(void)strncpy(utmpx.ut_host, hostname, sizeof(utmpx.ut_host));
		utmpx.ut_ss = ss;
	}
	(void)strncpy(utmpx.ut_line, tty, sizeof(utmpx.ut_line));
	utmpx.ut_type = USER_PROCESS;
	utmpx.ut_pid = getpid();
	t = tty + strlen(tty);
	if (t - tty >= sizeof(utmpx.ut_id)) {
	    (void)strncpy(utmpx.ut_id, t - sizeof(utmpx.ut_id),
		sizeof(utmpx.ut_id));
	} else {
	    (void)strncpy(utmpx.ut_id, tty, sizeof(utmpx.ut_id));
	}
	if (pututxline(&utmpx) == NULL)
		syslog(LOG_NOTICE, "Cannot update utmpx: %m");
	endutxent();
	if (updwtmpx(_PATH_WTMPX, &utmpx) != 0)
		syslog(LOG_NOTICE, "Cannot update wtmpx: %m");
}
开发者ID:AgamAgarwal,项目名称:minix,代码行数:29,代码来源:common.c

示例9: cleanup_utmp

static void cleanup_utmp(void)
{
    struct timeval tv;

    if (!pty_stamped_utmp)
	return;

    utmp_entry.ut_type = DEAD_PROCESS;
    memset(utmp_entry.ut_user, 0, lenof(utmp_entry.ut_user));
    gettimeofday(&tv, NULL);
    utmp_entry.ut_tv.tv_sec = tv.tv_sec;
    utmp_entry.ut_tv.tv_usec = tv.tv_usec;

    updwtmpx(WTMPX_FILE, &utmp_entry);

    memset(utmp_entry.ut_line, 0, lenof(utmp_entry.ut_line));
    utmp_entry.ut_tv.tv_sec = 0;
    utmp_entry.ut_tv.tv_usec = 0;

    setutxent();
    pututxline(&utmp_entry);
    endutxent();

    pty_stamped_utmp = 0;	       /* ensure we never double-cleanup */
}
开发者ID:mkoskinen,项目名称:transputty,代码行数:25,代码来源:uxpty.c

示例10: remove_utmp_entry

static void remove_utmp_entry(main_server_st *s, struct proc_st* proc)
{
#ifdef HAVE_LIBUTIL
	struct utmpx entry;
	struct timespec tv;

	if (s->config->use_utmp == 0)
		return;

	memset(&entry, 0, sizeof(entry));
	entry.ut_type = DEAD_PROCESS;
	if (proc->tun_lease.name[0] != 0)
		snprintf(entry.ut_line, sizeof(entry.ut_line), "%s", proc->tun_lease.name);
	entry.ut_pid = proc->pid;

	setutxent();
	pututxline(&entry);
	endutxent();

#if defined(WTMPX_FILE)
	gettime(&tv);
	entry.ut_tv.tv_sec = tv.tv_sec;
	entry.ut_tv.tv_usec = tv.tv_nsec / 1000;
	updwtmpx(WTMPX_FILE, &entry);
#endif   
	return;
#endif
}
开发者ID:cernekee,项目名称:ocserv,代码行数:28,代码来源:main-user.c

示例11: _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

示例12: wall_main

int wall_main(int argc UNUSED_PARAM, char **argv)
{
	struct utmpx *ut;
	char *msg;
	int fd;

	fd = STDIN_FILENO;
	if (argv[1]) {
		/* The applet is setuid.
		 * Access to the file must be under user's uid/gid.
		 */
		fd = xopen_as_uid_gid(argv[1], O_RDONLY, getuid(), getgid());
	}
	msg = xmalloc_read(fd, NULL);
	if (ENABLE_FEATURE_CLEAN_UP && argv[1])
		close(fd);
	setutxent();
	while ((ut = getutxent()) != NULL) {
		char *line;
		if (ut->ut_type != USER_PROCESS)
			continue;
		line = concat_path_file("/dev", ut->ut_line);
		xopen_xwrite_close(line, msg);
		free(line);
	}
	if (ENABLE_FEATURE_CLEAN_UP) {
		endutxent();
		free(msg);
	}
	return EXIT_SUCCESS;
}
开发者ID:android-ide,项目名称:busybox,代码行数:31,代码来源:wall.c

示例13: who_main

int who_main(int argc UNUSED_PARAM, char **argv)
{
	struct utmpx *ut;
	unsigned opt;
	int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
	const char *fmt = "%s";

	opt_complementary = "=0";
	opt = getopt32(argv, do_users ? "" : "aH");
	if (opt & 2) // -H
		puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");

	setutxent();
	while ((ut = getutxent()) != NULL) {
		if (ut->ut_user[0]
		 && ((opt & 1) || ut->ut_type == USER_PROCESS)
		) {
			if (!do_users) {
				char str6[6];
				char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1];
				struct stat st;
				time_t seconds;

				str6[0] = '?';
				str6[1] = '\0';
				strcpy(name, "/dev/");
				safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1,
					ut->ut_line,
					sizeof(ut->ut_line)+1
				);
				if (stat(name, &st) == 0)
					idle_string(str6, st.st_atime);
				/* manpages say ut_tv.tv_sec *is* time_t,
				 * but some systems have it wrong */
				seconds = ut->ut_tv.tv_sec;
				/* How wide time field can be?
				 * "Nov 10 19:33:20": 15 chars
				 * "2010-11-10 19:33": 16 chars
				 */
				printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n",
						(int)sizeof(ut->ut_user), ut->ut_user,
						(int)sizeof(ut->ut_line), ut->ut_line,
						str6,
						ctime(&seconds) + 4,
						(int)sizeof(ut->ut_host), ut->ut_host
				);
			} else {
				printf(fmt, ut->ut_user);
				fmt = " %s";
			}
		}
	}
	if (do_users)
		bb_putchar('\n');
	if (ENABLE_FEATURE_CLEAN_UP)
		endutxent();
	return EXIT_SUCCESS;
}
开发者ID:beyond2002,项目名称:GT813C,代码行数:58,代码来源:who.c

示例14: logout_utmpx

static void
logout_utmpx(struct utmpx *utmpx, const struct timeval *now)
{
	utmpx->ut_type = DEAD_PROCESS;
	utmpx->ut_tv = *now;
	utmpx->ut_pid = 0;
	(void)pututxline(utmpx);
	endutxent();
}
开发者ID:Hooman3,项目名称:minix,代码行数:9,代码来源:utmp.c

示例15: _userinfo_generic

static int _userinfo_generic(unsigned int * userinfo)
{
	struct utmpx * ut;

	for(*userinfo = 0; (ut = getutxent()) != NULL;)
		if(ut->ut_type == USER_PROCESS)
			(*userinfo)++;
	endutxent();
	return 0;
}
开发者ID:DeforaOS,项目名称:Probe,代码行数:10,代码来源:probe.c


注:本文中的endutxent函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。