Free Downloads, Community Forum,
FAQs and Developer Resources


Make /Tools Your Home | Link to us

Today's posts | Posts since last visit | Most Active Topics

All Forums Register Login Search Subscriptions My Profile Inbox
Tool Warehouse FAQs Resources Help Member List Address Book Logout

console screensaver deamon

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> console screensaver deamon Page: [1]
Login
Message << Older Topic   Newer Topic >>
console screensaver deamon - Nov. 5, '04, 5:02:00 PM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
Is there any way to write a deamon that will run a specified program afret certain time of inactivity of a text console?
Post #: 1
RE: console screensaver deamon - Nov. 5, '04, 6:01:28 PM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
Sure.
Have the daemon poll the information in the utmpx file.
You can look at the source code for finger to see how the idle time
is extracted from utmpx. Then write your code around that.

(in reply to cortez_)
Post #: 2
RE: console screensaver deamon - Nov. 6, '04, 10:38:03 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
But the information in utmpx and retrieved by finger is recording idle time pre user or per terminal?

(in reply to Rodney)
Post #: 3
RE: console screensaver deamon - Nov. 6, '04, 11:02:03 AM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
per terminal

(in reply to cortez_)
Post #: 4
RE: console screensaver deamon - Nov. 8, '04, 8:53:51 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
I've been trying to make out how the hell finger gets this info, but analyzing smobody elses code is a disaster. As a side effect I learned on how the /var/adm/utmpx works ad wrote the uprime command surrogate ;)

Anyway, in the utmpx record there are following fields:
struct utmpx {
        char    ut_line[UT_LINESIZE];   /* Tty line name i.e. ttyn87 */
        char    ut_user[UT_NAMESIZE];   /* Username of process owner */
        char    ut_host[UT_HOSTSIZE];   /* Hostname connected from */
        struct timeval  ut_tv;          /* Time of entry; kernel overrides */
        pid_t   ut_pid;                 /* Pid of process making entry */
        uid_t   ut_uid;                 /* Real uid of user process */
        char    ut_id[UT_IDSIZE];       /* Repeats ut_line on Interix */
        short   ut_type;                /* Type of entry; see macros above */
        struct exit_status ut_exit;     /* DEAD_PROCESS exit information */
        u_int64_t _ut_uid64;
        long    reserved[6];            /* Reserved */
}; 


Can anybody help where to find the idle info somewhere there?

The ut_tv is created once the terminal is poened - nam I right? I didn't see it changing over time.

(in reply to Rodney)
Post #: 5
RE: console screensaver deamon - Nov. 8, '04, 9:15:33 AM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
You'll want to the at the function named "find_idle_and_ttywrite()".

It does a stat() call with the file handle as the user's tty (gained from
the utmpx info). It then does a subtraction between the st_atime and the
current time to produce the idle time.

(in reply to cortez_)
Post #: 6
RE: console screensaver deamon - Nov. 8, '04, 10:58:08 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
Other question, is there any way to grab the content of the terminal and save it so that it will remain unaffected after returning from the screensaver?

(in reply to Rodney)
Post #: 7
RE: console screensaver deamon - Nov. 8, '04, 11:14:09 AM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
If the user is running a program that is curses-based then it'll just refresh.
But there's no API for scraping the screen of a terminal.

(in reply to cortez_)
Post #: 8
RE: console screensaver deamon - Nov. 9, '04, 5:13:55 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
I wrote a sample code that extracts all the utmpx records and reports idle time for terminals with acrive user process.

But the idletime doesn't differ between the terminals? What's wrong?
#include <utmpx.h>
#include <strings.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>

int main ( )
{
        char    uline[UT_LINESIZE];     /* Tty line name i.e. ttyn87 */
        char    uuser[UT_NAMESIZE];     /* Username of process owner */
        char    uhost[UT_HOSTSIZE];     /* Hostname connected from */
        time_t utv,utv2;                /* Time of entry; kernel overrides */
        pid_t   upid;                   /* Pid of process making entry */
        uid_t   uuid;                   /* Real uid of user process */
        char    uid[UT_IDSIZE]; /* Repeats ut_line on Interix */
        short   utype;          /* Type of entry; see macros above */
        struct exit_status uexit;       /* DEAD_PROCESS exit information */
                                  

        struct utmpx * ent;
        int users=0;


        time_t nCurrentTime = time ( NULL );
      
        while  ( ent = getutxent ( ) )  {

                strcpy(uline,ent->ut_line);
                strcpy(uuser,ent->ut_user);
                strcpy(uhost,ent->ut_host);
                utv=ent->ut_time;
                utv2=nCurrentTime-utv;
                utype=ent->ut_type;

                printf("%s, %s, %s, %d, %d, %d",uline,uuser,uhost,utv,utv2,utype);
                if (utype==4) {
                            char path[UT_LINESIZE];
                            struct stat sb;
                            time_t idletime;
                            strcpy(path,"/dev/");
                            strcat(path,uline);
                            if (stat(path, &sb) < 0)
                                idletime=0;
                            idletime = nCurrentTime < sb.st_atime ? 0 : nCurrentTime - sb.st_atime; 
                            printf(", %s  %d,  %d \n",path, idletime, sb.st_atime);
                            ++users;
                }                    
                else
                        printf("\n");
        }
        printf ("#users=%d\n",users);                 
}
 



< Message edited by Rodney -- Nov. 9, '04, 11:41:31 AM >

(in reply to Rodney)
Post #: 9
RE: console screensaver deamon - Nov. 9, '04, 12:02:07 PM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
For right now, change the "st_atime" to "st_ctime".

For some reason the stat() call itself is causing the st_atime
to get updated. If you leave the terminal long enough you can
get to see the value of st_atime at the older value before the
stat() access updates it. I'm pretty sure this is a bug. I'll
follow-up this with Mark to double check. Then post it at MS.

(in reply to cortez_)
Post #: 10
RE: console screensaver deamon - Nov. 9, '04, 1:04:14 PM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
the st_ctime returns the time elapsed since the terminal window was created (terminal opened) and is equal to the value of utv2=nCurrentTime-(ent->ut_time)

The st_mtime doesn't work either - it changes it's state for all the terminals of the same user at the same time

I'm running out of Ideas :(

(in reply to Rodney)
Post #: 11
RE: console screensaver deamon - Nov. 11, '04, 11:18:20 AM   
markfunk

 

Posts: 670
Joined: Mar. 31, '03,
Status: offline
The Interix character special file (ie /dev/tty...) implementation is a hack.
It wasn't implemented very well and thus has a lot of short comings if you do anything except very fundatmental access operations (open/read/write).

Rodney and I tried to fix this for Interix 3.0 release, but we didn't make
it for the code cutoff date. And the solution we had wasn't integrated afterwards.
Essentially the char. special file implementation needs a re-write and no one at Microsoft considers this to be a priority.

(in reply to cortez_)
Post #: 12
RE: console screensaver deamon - Nov. 11, '04, 11:51:10 AM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
So I see two issues here:
1. the stat() problem
2. poor implementation of character devices
Both them make bad impression to me. I even considered to start thinking that MS might do something well but now i just give up.

Any other ideas on how to calculate thhe terminal idle time?

I see that finger and who returns garbage as well.

(in reply to markfunk)
Post #: 13
RE: console screensaver deamon - Nov. 11, '04, 1:00:36 PM   
Rodney

 

Posts: 3714
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
Well, it's actually one problem. I'd forgotten until Mark mentioned it that
we'd been doing that work. It was right at the end of 3.0 getting out the door.
Prior to 3.0 was Firebrand (the last internal Softway release that became MS's
3.0). For Firebrand the /dev FS was "special". That is, it didn't have nodes sitting
on the disk, it was generated at boot. There were side-effects of the nodes getting
implemented (which did have good effects too). Stat() was working with Firebrand for
the tty's. Mark and I spent a lot of time trying to come up with a minimalist change-set.
It was not easy given the time constraints. We had a better plan, but that involved a
series of changes instead of just one. These changes should still get done at some
point since they affect other "things" too.

Mark has said no one at Microsoft considers this a priority.
I'll conditionalize this by changing it from "no one" to "not everyone".
And the key is to get "just enough people" to consider it.
The first step is to get your concern listed with PSS (Product Support) so
that it gets to the SFU PSS team. This will help those who do have a concern
about things in this area to move it ahead. I'm not idly making the suggestion.
This is a big hint.

(in reply to cortez_)
Post #: 14
RE: console screensaver deamon - Nov. 11, '04, 3:15:04 PM   
cortez_

 

Posts: 330
Joined: Mar. 27, '04,
From: Poland
Status: offline
How to report it to them?

A

(in reply to Rodney)
Post #: 15
Page:   [1]
All Forums >> [SFU / Interix / SUA Technology] >> Interix Advanced Forum >> console screensaver deamon Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Search All Forums -

Advanced search


SPONSORS



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.063