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

C++ setutent函数代码示例

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

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



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

示例1: get_unique

/* count the number of users */
static int get_unique ( void )
{
    apr_pool_t *subpool;
    apr_hash_t *hashuser;
    char *name;
    void *user;
    unsigned int numunique = 0;
    struct utmp *utmpstruct;

    apr_pool_create(&subpool, pool);
    hashuser = apr_hash_make(subpool);
    apr_thread_mutex_lock(mutex);
    setutent();
    while ((utmpstruct = getutent())) {
        if ((utmpstruct->ut_type == USER_PROCESS) &&
           (utmpstruct->ut_name[0] != '\0')) {
            name = apr_pstrndup(subpool, utmpstruct->ut_name, UT_NAMESIZE);
            user = name; /* use key for value, not interested in it anyway */
            apr_hash_set(hashuser, name, APR_HASH_KEY_STRING, user);
        }
    }
    endutent();
    apr_thread_mutex_unlock(mutex);
    numunique = apr_hash_count(hashuser);
    apr_pool_destroy(subpool);

    return numunique;
}
开发者ID:afbjorklund,项目名称:ganglia-modules-linux,代码行数:29,代码来源:mod_user.c


示例2: get_system_users

/*
 * Return currently connected users as a list of tuples.
 */
static PyObject*
get_system_users(PyObject* self, PyObject* args)
{
    PyObject *ret_list = PyList_New(0);
    PyObject *tuple = NULL;
    PyObject *user_proc = NULL;
    struct utmp *ut;

    setutent();
    while (NULL != (ut = getutent())) {
        if (ut->ut_type == USER_PROCESS)
            user_proc = Py_True;
        else
            user_proc = Py_False;
        tuple = Py_BuildValue("(sssfO)",
                              ut->ut_user,              // username
                              ut->ut_line,              // tty
                              ut->ut_host,              // hostname
                              (float)ut->ut_tv.tv_sec,  // tstamp
                              user_proc                 // (bool) user process
                             );
        PyList_Append(ret_list, tuple);
        Py_DECREF(tuple);
    }
    endutent();

    return ret_list;
}
开发者ID:dextervip,项目名称:load-balancer,代码行数:31,代码来源:_psutil_linux.c


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


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


示例5: user_busy

static void
user_busy(const char *name, uid_t uid)
{
	struct	utmp	*utent;

	/*
	 * We see if the user is logged in by looking for the user name
	 * in the utmp file.
	 */

	setutent ();

	while ((utent = getutent ())) {
#ifdef USER_PROCESS
		if (utent->ut_type != USER_PROCESS)
			continue;
#else
		if (utent->ut_user[0] == '\0')
			continue;
#endif
		if (strncmp(utent->ut_user, name, sizeof utent->ut_user))
			continue;

		fprintf(stderr, _("%s: user %s is currently logged in\n"),
			Prog, name);
		exit(E_USER_BUSY);
	}
}
开发者ID:TomDataworks,项目名称:smaller-than-busybox,代码行数:28,代码来源:userdel.c


示例6: runlevel_main

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


示例7: uv_uptime

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


示例8: get_runlevel

/*
 *	See if we were started directly from init.
 *	Get the runlevel from /var/run/utmp or the environment.
 */
int get_runlevel(void)
{
	struct utmp *ut;
	char *r;

	/*
	 *	First see if we were started directly from init.
	 */
	if (getenv("INIT_VERSION") && (r = getenv("RUNLEVEL")) != NULL)
		return *r;

	/*
	 *	Find runlevel in utmp.
	 */
	setutent();
	while ((ut = getutent()) != NULL) {
		if (ut->ut_type == RUN_LVL)
			return (ut->ut_pid & 255);
	}
	endutent();

	/* This should not happen but warn the user! */
	fprintf(stderr, "WARNING: could not determine runlevel"
		" - doing soft %s\n", progname);
	fprintf(stderr, "  (it's better to use shutdown instead of %s"
		" from the command line)\n", progname);

	return -1;
}
开发者ID:rafaello7,项目名称:Novo7Tools,代码行数:33,代码来源:android-reboot.c


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


示例10: getUptime

static int getUptime(void) {
    struct sysinfo s_info;
    error = sysinfo(&s_info);

    int days, hours, minutes;
    long int upmind, upminh, uptimes;

    uptimes = s_info.uptime; /* returned in seconds */
    days = uptimes / ONEDAY;
    upmind = uptimes - (days * ONEDAY);
    hours = upmind / ONEHOUR;
    upminh = upmind - hours * ONEHOUR;
    minutes = upminh / ONEMINUTE;

    float av1, av2, av3;
    av1 = s_info.loads[0] / LOADS_SCALE;
    av2 = s_info.loads[1] / LOADS_SCALE;
    av3 = s_info.loads[2] / LOADS_SCALE;

    /* This next block is stolen fron GNU uptime */
    struct utmp *utmpstruct;
    int numuser = 0;
    setutent();
    while ((utmpstruct = getutent())) {
        if ((utmpstruct->ut_type == USER_PROCESS) &&
            (utmpstruct->ut_name[0] != '\0'))
            numuser++;
    }
    endutent();

    printf(" up %i day%s, %02i:%02i, %i user%s, load average: %2.2f, %2.2f, %2.2f\n",
            days, (days != 1) ? "s" : "", hours, minutes, numuser, (numuser != 1) ? "s" : "", av1, av2, av3);
    return error;
}
开发者ID:DarrenKirby,项目名称:ULL-userland,代码行数:34,代码来源:uptime.c


示例11: getutid

struct utmp *
getutid(struct utmp * utmp_entry)
{
  struct utmp * utmp;
  
  if (ut_fd==-1)
    setutent();
  if (ut_fd==-1)
    return NULL;

  while ((utmp=__getutent(ut_fd))!=NULL)
    {
      if ((utmp_entry->ut_type==RUN_LVL   ||
	   utmp_entry->ut_type==BOOT_TIME ||
	   utmp_entry->ut_type==NEW_TIME  ||
	   utmp_entry->ut_type==OLD_TIME) &&
	  utmp->ut_type==utmp_entry->ut_type)
	return utmp;
      if ((utmp_entry->ut_type==INIT_PROCESS ||
	   utmp_entry->ut_type==DEAD_PROCESS ||
	   utmp_entry->ut_type==LOGIN_PROCESS ||
	   utmp_entry->ut_type==USER_PROCESS) &&
	  !strcmp(utmp->ut_id, utmp_entry->ut_id))
	return utmp;
    }

  return NULL;
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:28,代码来源:utent.c


示例12: getutline

struct utmp *
getutline(struct utmp * utmp_entry)
{
  struct utmp * utmp;

  if (ut_fd==-1)
    setutent();
  if (ut_fd==-1)
    return NULL;

#if 0 /* This is driving me nuts.  It's not an implementation problem -
	 it's a matter of how things _SHOULD_ behave.  Groan. */
  lseek(ut_fd, SEEK_CUR, -sizeof(struct utmp));
#endif

  while ((utmp=__getutent(ut_fd))!=NULL)
    {
      if ((utmp->ut_type==USER_PROCESS  ||
	   utmp->ut_type==LOGIN_PROCESS) &&
	  !strcmp(utmp->ut_line, utmp_entry->ut_line))
	return utmp;
    }

  return NULL;
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:25,代码来源:utent.c


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


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


示例15: check_login_time

static int
check_login_time(const char *ruser, time_t timestamp)
{
	struct utmp utbuf, *ut;
	time_t oldest_login = 0;

	setutent();
	while(
#ifdef HAVE_GETUTENT_R
	      !getutent_r(&utbuf, &ut)
#else
	      (ut = getutent()) != NULL
#endif
	      ) {
		if (ut->ut_type != USER_PROCESS) {
			continue;
		}
		if (strncmp(ruser, ut->ut_user, sizeof(ut->ut_user) != 0)) {
			continue;
		}
		if (oldest_login == 0 || oldest_login > ut->ut_tv.tv_sec) {
			oldest_login = ut->ut_tv.tv_sec;
		}
	}
	endutent();
	if(oldest_login == 0 || timestamp < oldest_login) {
		return PAM_AUTH_ERR;
	}
	return PAM_SUCCESS;
}
开发者ID:bigon,项目名称:linux-pam,代码行数:30,代码来源:pam_timestamp.c


示例16: notify_all_ttys

/*
 * Notify all available ttys about device insertion.
 *
 * Return the number of ttys notified.
 */
static int notify_all_ttys(const char *manufacturer, const char *product,
                           const char *devnode)
{
    struct utmp *ut = NULL;
    int ttys_notified = 0;

    setutent();
    /* Don't free ut, it is statically allocated. */
    while ((ut = getutent()) != NULL) {
        /* Skip invalid entries. */
        if (ut->ut_type != USER_PROCESS) continue;

        if (notify_tty(ut->ut_line, manufacturer, product, devnode) == -1) {
            log_fn("Could not notify %s (@%s) about device %s (%s %s).",
                    ut->ut_user, ut->ut_line, devnode, manufacturer, product);
        } else {
            log_fn("Notified %s (@%s) about device %s (%s %s).",
                    ut->ut_user, ut->ut_line, devnode, manufacturer, product);
            ttys_notified++;
        }
    }
    endutent();

    return ttys_notified;
}
开发者ID:arpankapoor,项目名称:sield,代码行数:30,代码来源:sield-passwd-cli.c


示例17: check_utmp

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


示例18: do_check

static int
do_check (void)
{
  struct utmp *ut;
  int n;

  setutent ();

  n = 0;
  while ((ut = getutent ()))
    {
      if (n < num_entries &&
	  memcmp (ut, &entry[n], sizeof (struct utmp)))
	{
	  printf ("UTMP entry does not match");
	  ++errors;
	  return 1;
	}

      n++;
    }

  if (n != num_entries)
    {
      printf ("number of UTMP entries is incorrect");
      ++errors;
      return 1;
    }

  endutent ();

  return 0;
}
开发者ID:jameshilliard,项目名称:WECB-BH-GPL,代码行数:33,代码来源:tst-utmp.c


示例19: who_main

int who_main(int argc, char **argv)
{
	char str6[6];
	struct utmp *ut;
	struct stat st;
	char *name;

	if (argc > 1) {
		bb_show_usage();
	}

	setutent();
	printf("USER       TTY      IDLE      TIME           HOST\n");
	while ((ut = getutent()) != NULL) {
		if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) {
			time_t thyme = ut->ut_tv.tv_sec;

			/* ut->ut_line is device name of tty - "/dev/" */
			name = concat_path_file("/dev", ut->ut_line);
			str6[0] = '?';
			str6[1] = '\0';
			if (stat(name, &st) == 0)
				idle_string(str6, st.st_atime);
			printf("%-10s %-8s %-9s %-14.14s %s\n",
					ut->ut_user, ut->ut_line, str6,
					ctime(&thyme) + 4, ut->ut_host);
			if (ENABLE_FEATURE_CLEAN_UP)
				free(name);
		}
	}
	if (ENABLE_FEATURE_CLEAN_UP)
		endutent();
	return 0;
}
开发者ID:AlickHill,项目名称:Lantern,代码行数:34,代码来源:who.c


示例20: setutent

/*
 * get_current_utmp - return the most probable utmp entry for the current
 *                    session
 *
 *	The utmp file is scanned for an entry with the same process ID.
 *	The line enterred by the *getty / telnetd, etc. should also match
 *	the current terminal.
 *
 *	When an entry is returned by get_current_utmp, and if the utmp
 *	structure has a ut_id field, this field should be used to update
 *	the entry information.
 *
 *	Return NULL if no entries exist in utmp for the current process.
 */
/*@[email protected]*/ /*@[email protected]*/struct utmp *get_current_utmp (void)
{
	struct utmp *ut;
	struct utmp *ret = NULL;

	setutent ();

	/* First, try to find a valid utmp entry for this process.  */
	while ((ut = getutent ()) != NULL) {
		if (   (ut->ut_pid == getpid ())
#ifdef HAVE_STRUCT_UTMP_UT_ID
		    && ('\0' != ut->ut_id[0])
#endif
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
		    && (   (LOGIN_PROCESS == ut->ut_type)
		        || (USER_PROCESS  == ut->ut_type))
#endif
		    /* A process may have failed to close an entry
		     * Check if this entry refers to the current tty */
		    && is_my_tty (ut->ut_line)) {
			break;
		}
	}

	if (NULL != ut) {
		ret = (struct utmp *) xmalloc (sizeof (*ret));
		memcpy (ret, ut, sizeof (*ret));
	}

	endutent ();

	return ret;
}
开发者ID:Romutk,项目名称:SPIVT1,代码行数:47,代码来源:utmp.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ setutxent函数代码示例发布时间:2022-05-30
下一篇:
C++ setupterm函数代码示例发布时间: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