• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ setutxent函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: 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


示例3: 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


示例4: 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


示例5: 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


示例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: user_busy_utmp

static int user_busy_utmp (const char *name)
{
#ifdef USE_UTMPX
	struct utmpx *utent;

	setutxent ();
	while ((utent = getutxent ()) != NULL)
#else				/* !USE_UTMPX */
	struct utmp *utent;

	setutent ();
	while ((utent = getutent ()) != NULL)
#endif				/* !USE_UTMPX */
	{
		if (utent->ut_type != USER_PROCESS) {
			continue;
		}
		if (strncmp (utent->ut_user, name, sizeof utent->ut_user) != 0) {
			continue;
		}
		if (kill (utent->ut_pid, 0) != 0) {
			continue;
		}

		fprintf (stderr,
		         _("%s: user %s is currently logged in\n"),
		         Prog, name);
		return 1;
	}

	return 0;
}
开发者ID:bfeeny,项目名称:shadow,代码行数:32,代码来源:user_busy.c


示例8: 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


示例9: 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


示例10: 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


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


示例12: users_read

static int users_read (void)
{
#if HAVE_GETUTXENT
	unsigned int users = 0;
	struct utmpx *entry = NULL;

	/* according to the *utent(3) man page none of the functions sets errno
	   in case of an error, so we cannot do any error-checking here */
	setutxent();

	while (NULL != (entry = getutxent())) {
		if (USER_PROCESS == entry->ut_type) {
			++users;
		}
	}
	endutxent();

	users_submit (users);
/* #endif HAVE_GETUTXENT */
	
#elif HAVE_GETUTENT
	unsigned int users = 0;
	struct utmp *entry = NULL;

	/* according to the *utent(3) man page none of the functions sets errno
	   in case of an error, so we cannot do any error-checking here */
	setutent();

	while (NULL != (entry = getutent())) {
		if (USER_PROCESS == entry->ut_type) {
			++users;
		}
	}
	endutent();

	users_submit (users);
/* #endif HAVE_GETUTENT */

#elif HAVE_LIBSTATGRAB
	sg_user_stats *us;

	us = sg_get_user_stats ();
	if (us == NULL)
		return (-1);   

	users_submit ((gauge_t) us->num_entries);
/* #endif HAVE_LIBSTATGRAB */

#else
# error "No applicable input method."
#endif

	return (0);
} /* int users_read */
开发者ID:BrianB2,项目名称:collectd,代码行数:54,代码来源:users.c


示例13: utmpx_write_library

static int
utmpx_write_library(struct logininfo *li, struct utmpx *utx)
{
	setutxent();
	pututxline(utx);

#  ifdef HAVE_ENDUTXENT
	endutxent();
#  endif
	return 1;
}
开发者ID:skizhak,项目名称:open-media-flow-controller,代码行数:11,代码来源:loginrec.c


示例14: login

void
login(struct utmp *ut)
{
	struct utmpx ux;

	getutmpx(ut, &ux);
	/* ut_id will automatically be calculated in the call to pututxline() */
	ux.ut_type |= UTMPX_AUTOFILL_MASK;
	setutxent();
	pututxline(&ux);
	endutxent();
}
开发者ID:010001111,项目名称:darling,代码行数:12,代码来源:login.c


示例15: main

int
main (int argc, char **argv)
{
	int users = -1;
	int result = STATE_UNKNOWN;
	char *perf;
	struct utmpx *putmpx;

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	perf = strdup ("");

	/* Parse extra opts if any */
	argv = np_extra_opts (&argc, argv, progname);

	if (process_arguments (argc, argv) == ERROR)
		usage4 (_("Could not parse arguments"));

	users = 0;

	/* get currently logged users from utmpx */
	setutxent ();

	while ((putmpx = getutxent ()) != NULL)
		if (putmpx->ut_type == USER_PROCESS)
			users++;

	endutxent ();

	/* check the user count against warning and critical thresholds */
	if (users > cusers)
		result = STATE_CRITICAL;
	else if (users > wusers)
		result = STATE_WARNING;
	else if (users >= 0)
		result = STATE_OK;

	if (result == STATE_UNKNOWN)
		printf ("%s\n", _("Unable to read output"));
	else {
		asprintf (&perf, "%s", perfdata ("users", users, "",
		  TRUE, wusers,
		  TRUE, cusers,
		  TRUE, 0,
		  FALSE, 0));
		printf (_("USERS %s - %d users currently logged in |%s\n"), state_text (result),
		  users, perf);
	}

	return result;
}
开发者ID:andersk,项目名称:nagios-plugins,代码行数:53,代码来源:check_users.c


示例16: _getlogin

static 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,代码来源:getlogin.c


示例17: test_getlogin

char* test_getlogin() {
    struct utmpx *ut;
    char *tty = ttyname(STDIN_FILENO);
    setutxent();
    while ((ut = getutxent()) != NULL) {
        if (strcmp(ut->ut_line, tty + 5) == 0) {
            strncpy(user, ut->ut_user, 255);
            user[255] = '\0';
            break;
        }
    }
    endutxent();
    return user;
}
开发者ID:molinkaka,项目名称:TLPI,代码行数:14,代码来源:test_getlogin.c


示例18: ucount

/* calculate number of users on the system */
static int
ucount(void)
{
	int nusers = 0;
	struct utmpx *ut;

	setutxent();
	while ((ut = getutxent()) != NULL)
		if (ut->ut_type == USER_PROCESS)
			nusers++;
	endutxent();

	return (nusers);
}
开发者ID:outbackdingo,项目名称:uBSD,代码行数:15,代码来源:vmstat.c


示例19: utmp_get_runlevel

static int utmp_get_runlevel(struct lxc_utmp *utmp_data)
{
	#if HAVE_UTMPX_H
	struct utmpx *utmpx;
	#else
	struct utmp *utmpx;
	#endif
	char path[MAXPATHLEN];
	struct lxc_handler *handler = utmp_data->handler;

	if (snprintf(path, MAXPATHLEN, "/proc/%d/root/run/utmp",
		     handler->pid) > MAXPATHLEN) {
		ERROR("path is too long");
		return -1;
	}

	if (!access(path, F_OK) && !utmpxname(path))
		goto utmp_ok;

	if (snprintf(path, MAXPATHLEN, "/proc/%d/root/var/run/utmp",
		     handler->pid) > MAXPATHLEN) {
		ERROR("path is too long");
		return -1;
	}

	if (utmpxname(path)) {
		SYSERROR("failed to 'utmpxname'");
		return -1;
	}

utmp_ok:

	setutxent();

	while ((utmpx = getutxent())) {

		if (utmpx->ut_type == RUN_LVL) {
			utmp_data->prev_runlevel = utmpx->ut_pid / 256;
			utmp_data->curr_runlevel = utmpx->ut_pid % 256;
			DEBUG("utmp handler - run level is %c/%c",
			      utmp_data->prev_runlevel,
			      utmp_data->curr_runlevel);
		}
	}

	endutxent();

	return 0;
}
开发者ID:ArikaChen,项目名称:lxc,代码行数:49,代码来源:lxcutmp.c


示例20: OS_getSystemNumUsers

/**
 * Get number of current users which are logged in
 */
static int
OS_getSystemNumUsers(uint32_t *nu)
{
	struct utmpx *utmp;

	setutxent();
	*nu = 0;
	while ((utmp = getutxent()) != NULL) {
		if (utmp->ut_type == USER_PROCESS)
			(*nu)++;
	}
	endutxent();

	return (SNMP_ERR_NOERROR);
}
开发者ID:ppaeps,项目名称:freebsd-head,代码行数:18,代码来源:hostres_scalars.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ setval函数代码示例发布时间:2022-05-30
下一篇:
C++ setutent函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap