예제 #1
0
int main(void) {
	char *status;
	char *avgs;
	char *tmar;
	char *tmutc;
	char *tmbln;

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(3)) {
		avgs = loadavg();
		tmar = mktimes("%H:%M", tzargentina);
		tmutc = mktimes("%H:%M", tzutc);
		tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin);

		status = smprintf("L:%s A:%s ◷ %s", avgs, tmar, tmutc);
		setstatus(status);
		free(avgs);
		free(tmar);
		free(tmutc);
		free(tmbln);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
예제 #2
0
파일: dwmstatus.c 프로젝트: sandio/dotfiles
int
main(void)
{
	char *status;
	char *avgs;
	char *tmsf;

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(90)) {
		avgs = loadavg();
		tmsf = mktimes("W:%W %a %d %b %Y %H:%M", tzsofia);

		status = smprintf("L:%s | %s", avgs, tmsf);
		setstatus(status);
		free(avgs);
		free(tmsf);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
예제 #3
0
파일: dwmstatus.c 프로젝트: jaduse/dwm
int
main(void)
{
  char tmnyc[128];
  char avgs[128];
  char *status;
  int warn = 0;

  if (!(dpy = XOpenDisplay(NULL))) {
    fprintf(stderr, "dwmstatus: cannot open display.\n");
    return 1;
  }

  for (;;sleep(2)) {
    loadavg(avgs, 128);
    warn = mktimes(tmnyc, 128, "%a, %B %d, %R", tznyc);
    if (warn) {
      status = smprintf("[L: %s | \x04%s\x01]", avgs, tmnyc);
    }
    else {
      status = smprintf("[L: %s | %s]", avgs, tmnyc);      
    }
                      
    setstatus(status);
    free(status);
  }

  XCloseDisplay(dpy);

  return 0;
}
예제 #4
0
int
main(void)
{
	char *status;
	char *avgs;
	char *tmutc;
	char *tmvan;

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(5)) {
		avgs = loadavg();
		tmutc = mktimes("%H:%M", tzutc);
		tmvan = mktimes("%a %Y-%m-%d %H:%M:%S %Z", tzvan);

		status = smprintf("LOAD %s  //  %s [%s UTC]",
				avgs, tmvan, tmutc);
		setstatus(status);

		free(avgs);
		free(tmutc);
		free(tmvan);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
예제 #5
0
/* 
 * setup the status bar here
 */
int
status(int tostatusbar)
{
    char *status = NULL;
    char *avgs = NULL;
    char *time = NULL;
    char *batt = NULL;
    char *net = NULL;
    char *temp = NULL;
    char *ipaddr = NULL;
    char *net_device_up = NET_DEVICE_PRIMARY;
    time_t count60 = 0;
    time_t count10 = 0;

    if (!(dpy = XOpenDisplay(NULL)) && tostatusbar == 0) {
        fprintf(stderr, "dwmstatus: cannot open display.\n");
        return 1;
    }

    for (;;sleep(0)) {
        /* Update every minute */
        if (runevery(&count60, 60)) {
            free(time);

            time  = mktimes("%Y/%m/%d %H:%M", TIMEZONE);
        }
        /* Update every 10 seconds */
        if (runevery(&count10, 10)) {
            free(avgs);
            free(temp);
            free(batt);

            avgs   = loadavg();
            temp   = gettemperature(TEMP_SENSOR_PATH, TEMP_SENSOR_UNIT);
            batt   = getbattery(BATT_PATH);
            if(!temp) free(temp);
        }
        /* Update every second */
        net    = get_netusage(net_device_up);
        ipaddr = get_ip_addr(net_device_up);

        /* Format of display */
        status = smprintf("%s (%s) | %s [%s] T %s | %s",
                net, ipaddr, batt, avgs, temp, time);
        if(!ipaddr) free(ipaddr);
        free(net);

        if(tostatusbar == 0)
            setstatus(status);
        else
            puts(status);

        free(status);
    }
    return 0;
}
예제 #6
0
char *sprint_uptime(void) {
  struct utmp *utmpstruct;
  int upminutes, uphours, updays;
  int pos;
  struct tm *realtime;
  time_t realseconds;
  int numuser;
  double uptime_secs, idle_secs;

/* first get the current time */

  time(&realseconds);
  realtime = localtime(&realseconds);
  pos = sprintf(buf, " %02d:%02d:%02d ",
    realtime->tm_hour, realtime->tm_min, realtime->tm_sec);

/* read and calculate the amount of uptime */

  uptime(&uptime_secs, &idle_secs);

  updays = (int) uptime_secs / (60*60*24);
  strcat (buf, "up ");
  pos += 3;
  if (updays)
    pos += sprintf(buf + pos, "%d day%s, ", updays, (updays != 1) ? "s" : "");
  upminutes = (int) uptime_secs / 60;
  uphours = upminutes / 60;
  uphours = uphours % 24;
  upminutes = upminutes % 60;
  if (uphours)
    pos += sprintf(buf + pos, "%2d:%02d, ", uphours, upminutes);
  else
    pos += sprintf(buf + pos, "%d min, ", upminutes);

/* count the number of users */

  numuser = 0;
  setutent();
  while ((utmpstruct = getutent())) {
    if ((utmpstruct->ut_type == USER_PROCESS) &&
       (utmpstruct->ut_name[0] != '\0'))
      numuser++;
  }
  endutent();

  pos += sprintf(buf + pos, "%2d user%s, ", numuser, numuser == 1 ? "" : "s");

  loadavg(&av[0], &av[1], &av[2]);

  pos += sprintf(buf + pos, " load average: %.2f, %.2f, %.2f",
		 av[0], av[1], av[2]);

  return buf;
}
예제 #7
0
파일: dwmstatus.c 프로젝트: pickfire/dwms
int
main(void)
{
    unsigned short i;
    char *tmtz, *net, *avgs, *root, *vol, *bat;
    tmtz = net = avgs = root = vol = bat = NULL;
    char *line;
    static unsigned long long rec = 0, sent = 0;

    if (!(dpy = XOpenDisplay(NULL))) {
        fprintf(stderr, "dwmstatus: cannot open display.\n");
        return 1;
    }

    parse_netdev(&rec, &sent);

    for (i = 0;; sleep(1), i++) {
        if (i % 10 == 0) {
            free(bat);
            bat = batstat();
        }
        if (i % 5 == 0) {
            free(avgs);
            free(root);
            free(vol);
            avgs = loadavg();
            root = getfree("/");
            vol = runcmd("amixer get PCM | grep -om1 '[0-9]*%'");
        }
        net = netusage(&rec, &sent);
        tmtz = mktimes("%a %b %d %T");

        line = smprintf("♪ %s ⚡ %s │ %s │ / %s │ %s │ %s",
                        vol, bat, net, root, avgs, tmtz);

        XStoreName(dpy, DefaultRootWindow(dpy), line);
        XSync(dpy, False);

        free(net);
        free(tmtz);
        free(line);

        if (i == 60)
            i = 0;
    }

    XCloseDisplay(dpy);

    return 0;
}
예제 #8
0
파일: dwmstatus.c 프로젝트: Mariappan/dwm
int
main(void)
{
	char *status = NULL;
	char *tmprs = NULL;
	char *avgs = NULL;
    time_t count60 = 0;
    char *uptm = NULL;
    char *vol = NULL;
	char *netstats = NULL;
    char *ram = NULL;
	static unsigned long long int rec, sent;

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	parse_netdev(&rec, &sent);
	for (;;sleep(1)) {
	    /* checks every minutes */
	    if ( runevery(&count60, 60) )
        {
            free(tmprs);
            free(uptm);
            tmprs = mktimes("\x06\uf073 %b-%d   %I:%M  %p", tz);
            uptm = up();

            free(ram);
            ram = get_ram();
        }
        /* checks every second */
		avgs = loadavg();
        vol = get_volume();
		netstats = get_netusage(&rec, &sent);

		status = smprintf("%s%s %s %s%s%s",
				 netstats, avgs, ram, uptm, vol, tmprs);
		setstatus(status);
        free(vol);
		free(avgs);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
예제 #9
0
파일: dwmstatus.c 프로젝트: MikalD/dwm
int main(void) {
	char *status;
	float cpu0, cpu1, cpu2, cpu3;
	char *datetime;
	char *avgs;
	int bat0;


	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "Cannot open display.\n");
		return 1;
	}

	if((status = malloc(200)) == NULL)
		exit(1);
	

	for (;;sleep(1)) {
		cpu0 = getfreq("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
		cpu1 = getfreq("/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq");
		cpu2 = getfreq("/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq");
		cpu3 = getfreq("/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq");
		datetime = getdatetime();
		avgs = loadavg();
		bat0 = getbattery();
		snprintf(status, 200, "%s | %0.2f %0.2f %0.2f %0.2f | %d%% | %s", avgs, cpu0, cpu1, cpu2, cpu3, bat0, datetime);

		free(datetime);
		setstatus(status);
	}

	free(status);
	XCloseDisplay(dpy);

	return 0;
}
예제 #10
0
int
main(void)
{
	char *status;
	char *avgs;
	char *tmnyc;
	char *tmsf;
	char *batt;

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(1)) {
		batt = getbattery();
		avgs = loadavg();
		tmnyc = mktimes("%a %b %d %Y %H:%M:%S %Z", tznyc);
		tmsf = mktimes("%a %b %d %Y %H:%M:%S %Z", tzsf);
		//tmutc = mktimes("%H:%M", tzutc);
		//tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin);

		status = smprintf("B:%s L:%s %s         ",
				batt, avgs, tmsf);
		setstatus(status);
		free(avgs);
		free(tmnyc);
		free(tmsf);
		free(status);
		free(batt);
	}

	XCloseDisplay(dpy);

	return 0;
}
예제 #11
0
파일: tload.c 프로젝트: Romutk/lab5
int main(int argc, char **argv)
{
    int lines, row, col=0;
    int i, opt;
    double av[3];
    static double max_scale, scale_fact;
    char *scale_arg = NULL;

    while ((opt = getopt(argc, argv, "s:d:V")) != -1)
	switch (opt) {
	    case 's': scale_arg = optarg; break;
	    case 'd': dly = atoi(optarg); break;
	    case 'V': display_version(); exit(0); break;
	    default:
		printf("usage: tload [-V] [-d delay] [-s scale] [tty]\n");
		exit(1);
	}

    if (argc > optind) {
	if ((fd = open(argv[optind], 1)) == -1) {
	    perror(argv[optind]);
	    exit(1);
	}
    }

    setsize(0);

    if (scale_arg)
      max_scale = atof(scale_arg);
    else
      max_scale = nrows;

    scale_fact = max_scale;

    setjmp(jb);
    col = 0;
    alrm(0);

    while (1) {

 	if (scale_fact < max_scale)
	    scale_fact *= 2.0; /* help it drift back up. */

	loadavg(&av[0], &av[1], &av[2]);

    repeat:
	lines = av[0] * scale_fact;
	row = nrows-1;

	while (--lines >= 0) {
	    *(screen + row * ncols + col) = '*';
	    if (--row < 0) {
		scale_fact /= 2.0;
		goto repeat;
	    }
	}
	while (row >= 0)
	    *(screen + row-- * ncols + col) = ' ';

	for (i = 1; ; ++i) {
	    char *p;
	    row = nrows - (i * scale_fact);
	    if (row < 0)
		break;
	    if (*(p = screen + row * ncols + col) == ' ')
		*p = '-';
	    else
		*p = '=';
	}

	if (++col == ncols) {
	    --col;
	    memmove(screen, screen + 1, scr_size-1);

	    for(row = nrows-2; row >= 0; --row)
		*(screen + row * ncols + col) = ' ';
	}
	i = sprintf(screen, " %.2f, %.2f, %.2f",
		av[0], av[1], av[2]);
	if (i>0)
	    screen[i] = ' ';

	write(fd, "\033[H", 3);
	write(fd, screen, scr_size - 1);
	pause();
    }
}
예제 #12
0
int main(int argc, char **argv)
{
	int lines, row, col = 0;
	int i, opt;
	double av[3];
	static double max_scale = 0, scale_fact;
	long tmpdly;

	static const struct option longopts[] = {
		{"scale", required_argument, NULL, 's'},
		{"delay", required_argument, NULL, 'd'},
		{"help", no_argument, NULL, 'h'},
		{"version", no_argument, NULL, 'V'},
		{NULL, 0, NULL, 0}
	};
#ifdef HAVE_PROGRAM_INVOCATION_NAME
	program_invocation_name = program_invocation_short_name;
#endif
	setlocale (LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	while ((opt =
		getopt_long(argc, argv, "s:d:Vh", longopts, NULL)) != -1)
		switch (opt) {
		case 's':
			max_scale = strtod_or_err(optarg, _("failed to parse argument"));
			if (max_scale < 0)
			        xerrx(EXIT_FAILURE, _("scale cannot be negative"));
			break;
		case 'd':
			tmpdly = strtol_or_err(optarg, _("failed to parse argument"));
			if (tmpdly < 1)
				xerrx(EXIT_FAILURE, _("delay must be positive integer"));
			else if (UINT_MAX < tmpdly)
				xerrx(EXIT_FAILURE, _("too large delay value"));
			dly = tmpdly;
			break;
		case 'V':
			printf(PROCPS_NG_VERSION);
			return EXIT_SUCCESS;
			break;
		case 'h':
			usage(stdout);
		default:
			usage(stderr);
		}

	if (argc > optind)
		if ((fd = open(argv[optind], 1)) == -1)
			xerr(EXIT_FAILURE, _("can not open tty"));

	setsize(0);

	if (max_scale == 0)
		max_scale = nrows;

	scale_fact = max_scale;

	setjmp(jb);
	col = 0;
	alrm(0);

	while (1) {

		if (scale_fact < max_scale)
			scale_fact *= 2.0;	/* help it drift back up. */

		loadavg(&av[0], &av[1], &av[2]);

		do {
			lines = av[0] * scale_fact;
			row = nrows - 1;

			while (0 <= --lines) {
				*(screen + row * ncols + col) = '*';
				if (--row < 0) {
					scale_fact /= 2.0;
					break;
				}
			}
		} while (0 <= lines);

		while (row >= 0)
			*(screen + row-- * ncols + col) = ' ';

		for (i = 1;; ++i) {
			char *p;
			row = nrows - (i * scale_fact);
			if (row < 0)
				break;
			if (*(p = screen + row * ncols + col) == ' ')
				*p = '-';
			else
				*p = '=';
		}

		if (++col == ncols) {
			--col;
			memmove(screen, screen + 1, scr_size - 1);

			for (row = nrows - 2; row >= 0; --row)
				*(screen + row * ncols + col) = ' ';
		}
		i = sprintf(screen, " %.2f, %.2f, %.2f", av[0], av[1], av[2]);
		if (i > 0)
			screen[i] = ' ';

		if (write(fd, "\033[H", 3) < 0)
			xerr(EXIT_FAILURE, _("writing to tty failed"));
		if (write(fd, screen, scr_size - 1) < 0)
			xerr(EXIT_FAILURE, _("writing to tty failed"));
		pause();
	}
}
예제 #13
0
static void ps_task(FAR struct tcb_s *tcb, FAR void *arg)
{
    struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg;
#ifdef HAVE_CPULOAD
    char buffer[8];
    int ret;
#endif
#if CONFIG_MAX_TASK_ARGS > 2
    int i;
#endif

    /* Show task status */

    nsh_output(vtbl, "%5d %3d %4s %7s%c%c %8s ",
               tcb->pid, tcb->sched_priority,
               tcb->flags & TCB_FLAG_ROUND_ROBIN ? "RR  " : "FIFO",
               g_ttypenames[(tcb->flags & TCB_FLAG_TTYPE_MASK) >> TCB_FLAG_TTYPE_SHIFT],
               tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : ' ',
               tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : ' ',
               g_statenames[tcb->task_state]);

#ifdef HAVE_CPULOAD
    /* Get the CPU load */

    ret = loadavg(tcb->pid, buffer, sizeof(buffer));
    if (ret < 0)
    {
        /* Make the buffer into an empty string */

        buffer[0] = '\0';
    }

    nsh_output(vtbl, "%-6s ", buffer);
#endif

    /* Show task name and arguments */

#if CONFIG_TASK_NAME_SIZE > 0
    nsh_output(vtbl, "%s(", tcb->name);
#else
    nsh_output(vtbl, "<noname>(");
#endif

    /* Is this a task or a pthread? */

#ifndef CONFIG_DISABLE_PTHREAD
    if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_PTHREAD)
    {
        FAR struct pthread_tcb_s *ptcb = (FAR struct pthread_tcb_s *)tcb;
        nsh_output(vtbl, "%p", ptcb->arg);
    }
    else
#endif
    {
        FAR struct task_tcb_s *ttcb = (FAR struct task_tcb_s *)tcb;

        /* Special case 1st argument (no comma) */

        if (ttcb->argv[1])
        {
            nsh_output(vtbl, "%p", ttcb->argv[1]);

            /* Then any additional arguments */

#if CONFIG_MAX_TASK_ARGS > 2
            for (i = 2; i <= CONFIG_MAX_TASK_ARGS && ttcb->argv[i]; i++)
            {
                nsh_output(vtbl, ", %p", ttcb->argv[i]);
            }
#endif
        }
    }

    nsh_output(vtbl, ")\n");
}
예제 #14
0
int
main(void)
{
	char *status = NULL;
	char *avgs = NULL;
	char *tmprs = NULL;
    char *bat = NULL;
    char *netstats = NULL;
    char *mail_laposte = NULL;
    char *mail_fac = NULL;
    char *mail_lavabit = NULL;
    char *mail_tl = NULL;
    char *rootfs = NULL;
    char *homefs = NULL;
    time_t count5min = 0;
    time_t count60 = 0;
    
	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(1)) {
	    /* checks every minutes */
	    if ( runevery(&count60, 60) )
        {
            free(tmprs);
            free(bat);
            free(rootfs);
            free(homefs);
            tmprs = mktimes("%d/%m/%y %H:%M", tzparis);
            bat = getbattery("/sys/class/power_supply/BAT0/");
            homefs = get_freespace("/home");
            rootfs = get_freespace("/");
        }
        /* checks mail every 5 minutes */
        if (runevery(&count5min, 300) )
        {
            free(mail_laposte);
            free(mail_fac);
            free(mail_lavabit);
            free(mail_tl);
            mail_laposte = get_nmail("/home/xavier/Maildir/fac/new", " Fac:");
            mail_fac = get_nmail("/home/xavier/Maildir/lavabit/new", " Lavabit:");
            mail_lavabit = get_nmail("/home/xavier/Maildir/toilelibre/new", " TL:");
            mail_tl = get_nmail("/home/xavier/Maildir/laposte/new", " Laposte:");
        }
        /* checks every second */
		avgs = loadavg();
        netstats = get_netusage();

		status = smprintf("%s%s%s%s | %s | /:%s% /home:%s% | B:%s% | %s | %s",
				 mail_tl, mail_fac, mail_lavabit, mail_laposte,
				 netstats, rootfs, homefs, bat, avgs, tmprs);
		setstatus(status);
		free(avgs);
        free(netstats);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
예제 #15
0
파일: main.c 프로젝트: linkdd/pcstats
int main (void)
{
	int i, c;

	initscr ();
	noecho ();
	curs_set (0);

	if (has_colors () == FALSE)
	{
		fprintf (stderr, "Your terminal doesn't support colors.\n");
		global.colors = 0;
	}
	else
	{
		global.colors = 1;
		start_color ();

		if (use_default_colors () == OK)
			bg = -1;

		color (GREEN, COLOR_GREEN);
		color (YELLOW, COLOR_YELLOW);
		color (RED, COLOR_RED);
		color (CYAN, COLOR_CYAN);
	}


	signal (SIGINT, &handler);
	signal (SIGTERM, &handler);
	signal (SIGSEGV, &handler);

	global.loadavg.file = fopen ("/proc/loadavg", "r");
	global.cpu = fopen ("/proc/stat", "r");
	global.mtab = fopen ("/etc/mtab", "r");
	global.net = fopen ("/proc/net/dev", "r");
	global.wireless = fopen ("/proc/net/wireless", "r");

	/* Init global.battery */
	global.battery.ok = 1;
	strncpy (global.battery.dir.location, "/proc/acpi/battery/", 128);
	global.battery.dir.dir = opendir (global.battery.dir.location);

	if (global.battery.dir.dir != NULL)
	{
		while (1)
		{
			global.battery.dir.content = readdir (global.battery.dir.dir);

			if (!strcmp (global.battery.dir.content->d_name, "."))
				break;
			else if (!strcmp (global.battery.dir.content->d_name, ".."))
				break;
		}

		closedir (global.battery.dir.dir);

		if (global.battery.dir.content != NULL)
		{
			strcat (global.battery.dir.location, global.battery.dir.content->d_name);
			snprintf (global.battery.state.location, 128, "%s/state", global.battery.dir.location);
			snprintf (global.battery.info.location, 128, "%s/info", global.battery.dir.location);

			global.battery.state.file = fopen (global.battery.state.location, "r");
			global.battery.info.file = fopen (global.battery.info.location, "r");

			if (global.battery.state.file == NULL
				|| global.battery.info.file == NULL)
			{
				fprintf (stderr, "Can't open %s/state or %s/info while %s is present, check your ACPI configuration or remove the directory %s.\n",
						global.battery.dir.location, global.battery.dir.location,
						global.battery.dir.location, global.battery.dir.location);

				global.battery.ok = 0;
			}
		}
		else
		{
			fprintf (stderr, "Nothing in /proc/acpi/battery or can't list directory while directory present.\n");
			global.battery.ok = 0;
		}
	}
	else
	{
		fprintf (stderr, "No /proc/acpi/battery directory, skipping the battery part.\n");
		global.battery.ok = 0;
	}

	/* Get static system informations */
	global.nprocs = get_nprocs ();
	uname (&global.uname);

	{ /* get processor */
		FILE *f = fopen ("/proc/cpuinfo", "r");
		char buf[256];

		strncpy (global.processor, global.uname.machine, 256);

		if (f != NULL)
		{
			while (fgets (buf, sizeof buf, f))
			{
				if (!strncmp (buf, "model name", 10))
				{
					char *p = strchr (buf, ':');
					strncpy (global.processor, &p[2], 256);
					p = strchr (global.processor, '\n'); *p = 0;
					break;
				}
			}

			fclose (f);
		}

		global.processor[255] = 0;
	}

	if (global.cpu != NULL)
	{
		extern struct cpu_t *ocpu, *ncpu;

		ocpu = malloc (global.nprocs * sizeof (struct cpu_t));
		ncpu = malloc (global.nprocs * sizeof (struct cpu_t));

		if (ocpu == NULL || ncpu == NULL)
			fclose (global.cpu), global.cpu = NULL;
	}

	halfdelay (1);
	while ((c = getch ()) != '\n')
	{
		global.line = 0;

		switch (c)
		{
			case 'r': clear (); break;
		}

		/* Check system informations */
		if (0 != sysinfo (&global.sys))
			continue;

		/* Print informations */
		for (i = 0; show_fields[i] != EndOfFields; ++i)
		{
			if (show_fields[i] == Uname)
			{
				mvprintw (global.line++, 0, "%s %s\n%s\n", global.uname.nodename, global.uname.release, global.processor);
				global.line++;
			}

			if (global.loadavg.file != NULL && show_fields[i] == Loadavg)
			{
				char tmp[256];

				loadavg ();
				snprintf (tmp, 256, "Load average: 1min: $4%.2f$0 / 5min: $4%.2f$0 / 15min: $4%.2f$0\n",
						global.loadavg.loads[0],
						global.loadavg.loads[1],
						global.loadavg.loads[2]);
				print_color (global.line++, 0, tmp);
			
				snprintf (tmp, 256, "Tasks: $4%d$0 running, $4%d$0 total, last PID used : $4%d$0\n",
						global.loadavg.prun, global.loadavg.ptotal, global.loadavg.pid);
				print_color (global.line++, 0, tmp);
			}
	
			refresh ();
	
			if (show_fields[i] == Date) /* Date */
			{
				time_t timestamp= time (NULL);
				struct tm *t = localtime (&timestamp);
	
				mvprintw (global.line, 0, "Time: %02d:%02d:%02d |",
						t->tm_hour,
						t->tm_min,
						t->tm_sec);
				refresh ();
			}
	
			if (show_fields[i] == Date) /* Uptime */
			{
				int uptime = global.sys.uptime;
				int up, day, hour, min, sec;
	
				day = uptime / 86400;
				up = uptime - (day * 86400);
				hour = up / 3600;
				up -= hour * 3600;
				min = up / 60;
				sec = up - min * 60;
	
				mvprintw (global.line++, 17, "Uptime: %d day%s, %02d:%02d:%02d\n",
						day, (day > 1 ? "s" : ""),
						hour, min, sec);
				refresh ();
			}
	
			if (global.cpu != NULL && show_fields[i] == Cpu)
			{
				int i;
				for (i = 0; i < global.nprocs; ++i)
					cpubar (i);
			}
	
			if (show_fields[i] == Ram)  rambar ();
			if (show_fields[i] == Swap) swapbar ();
	
			if (global.mtab != NULL && show_fields[i] == Disk)
				diskbar ();
	
			if (global.wireless != NULL && show_fields[i] == Wireless)
				wirelessbar ();
	
			if (global.net != NULL && show_fields[i] == Network)
				netbar ();
	
			if (global.battery.ok && show_fields[i] == Battery)
				batterybar ();
	
			if (show_fields[i] == Process) print_proc ();
		}

		sleep (1);
	}

	raise (SIGTERM);

	return 0;
}
예제 #16
0
/*
 * setup the status bar here
 */
int
status(int tostatusbar)
{
    char *status = NULL;
    char *avgs = NULL;
    char *time = NULL;
    char *batt = NULL;
    char *net = NULL;
    char *net_sec = NULL;
    char *temp = NULL;
    char *ipaddr = NULL;
    char *ipaddr_sec = NULL;

#ifdef NET_DEVICE_PRIMARY
    char *net_device_up = NET_DEVICE_PRIMARY;
#endif
#ifdef NET_DEVICE_SECONDARY
    char *net_device_sec = NET_DEVICE_SECONDARY;
#endif

    time_t count60 = 0;
    time_t count10 = 0;

    if (!(dpy = XOpenDisplay(NULL)) && tostatusbar == 0) {
        fprintf(stderr, "dwmstatus: cannot open display.\n");
        return 1;
    }

    for (;;sleep(0)) {
        /* Update every minute */
        if (runevery(&count60, 60)) {
            free(time);

            time  = mktimes("%Y/%m/%d %H:%M", TIMEZONE);
        }
        /* Update every 10 seconds */
        if (runevery(&count10, 10)) {
#ifdef BATT_PATH
            free(batt);
            batt = getbattery(BATT_PATH);
#endif
#ifdef TEMP_SENSOR_PATH
#ifdef TEMP_SENSOR_UNIT
            free(avgs);
            free(temp);

            avgs   = loadavg();
            temp   = gettemperature(TEMP_SENSOR_PATH, TEMP_SENSOR_UNIT);
            SFREE(temp);
#endif
#endif
        }
        /* Update every second */
#ifdef NET_DEVICE_PRIMARY
        net    = get_netusage(net_device_up);
        ipaddr = get_ip_addr(net_device_up);
#endif
#ifdef NET_DEVICE_SECONDARY
        net_sec = get_netusage(net_device_sec);
        ipaddr_sec = get_ip_addr(net_device_sec);
#endif

        /* Format of display */
        status = smprintf("%s%s%s%s%s%s",
            ipaddr      == NULL ? "" : smprintf(" %s (%s) |", net, ipaddr),
            ipaddr_sec  == NULL ? "" : smprintf(" %s (%s) |", net_sec, ipaddr_sec),
            batt        == NULL ? "" : smprintf(" %s", batt),
            avgs        == NULL ? "" : smprintf(" [%s]", avgs),
            time        == NULL ? "" : smprintf(" %s", temp),
            time        == NULL ? "" : smprintf(" | %s", time)
            );
        SFREE(ipaddr)
        free(net);
        SFREE(ipaddr_sec)
        free(net_sec);

        if(tostatusbar == 0)
            setstatus(status);
        else
            puts(status);

        free(status);
    }
    return 0;
}
예제 #17
0
파일: file.c 프로젝트: unisx/gophernicus
void server_status(state *st, shm_state *shm, int shmid)
{
	struct shmid_ds shm_ds;
	time_t now;
	time_t uptime;
	int sessions;
	int i;

	/* Log the request */
	if (st->opt_syslog) {
		syslog(LOG_INFO, "request for \"gopher://%s:%i/0" SERVER_STATUS "\" from %s",
			st->server_host,
			st->server_port,
			st->req_remote_addr);
	}
	log_combined(st, HTTP_OK);

	/* Quit if shared memory isn't initialized yet */
	if (!shm) return;

	/* Update counters */
	shm->hits++;
	shm->kbytes += 1;

	/* Get server uptime */
	now = time(NULL);
	uptime = (now - shm->start_time) + 1;

	/* Get shared memory info */
	shmctl(shmid, IPC_STAT, &shm_ds);

	/* Print statistics */
	printf("Total Accesses: %li" CRLF
		"Total kBytes: %li" CRLF
		"Uptime: %i" CRLF
		"ReqPerSec: %.3f" CRLF
		"BytesPerSec: %li" CRLF
		"BytesPerReq: %li" CRLF
		"BusyServers: %i" CRLF
		"IdleServers: 0" CRLF
		"CPULoad: %.2f" CRLF,
			shm->hits,
			shm->kbytes,
			(int) uptime,
			(float) shm->hits / (float) uptime,
			shm->kbytes * 1024 / (int) uptime,
			shm->kbytes * 1024 / (shm->hits + 1),
			(int) shm_ds.shm_nattch,
			loadavg());

	/* Print active sessions */
	sessions = 0;

	for (i = 0; i < SHM_SESSIONS; i++) {
		if ((now - shm->session[i].req_atime) < st->session_timeout) {
			sessions++;

			printf("Session: %-4i %-40s %-4li %-7li gopher://%s:%i/%c%s" CRLF,
				(int) (now - shm->session[i].req_atime),
				shm->session[i].req_remote_addr,
				shm->session[i].hits,
				shm->session[i].kbytes,
				shm->session[i].server_host,
				shm->session[i].server_port,
				shm->session[i].req_filetype,
				shm->session[i].req_selector);
		}
	}

	printf("Total Sessions: %i" CRLF, sessions);
}