Subject: Re: ThinkPad X20 not suspending with X11?
To: None <smb@research.att.com>
From: Daishi Harada <daishi@CS.Berkeley.EDU>
List: port-i386
Date: 05/10/2002 16:26:15
----Next_Part(Fri_May_10_16:26:12_2002_559)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Check out the attached message.
Ideally I suppose the functionality should get folded into
wsconscfg.
d

From: "Steven M. Bellovin" <smb@research.att.com>
Subject: Re: ThinkPad X20 not suspending with X11? 
Date: Thu, 09 May 2002 16:26:04 -0400

> In message <22n0v9qdjt.fsf@naptop.autonomica.net>, Lars-Johan Liman writes:
> >johani@autonomica.se:
> >> Do you have to "take down" X11 or is it sufficient to switch to
> >> another virtual console?
> >
> >(Two painful fsck's later:)
> >
> >It's sufficient to switch to a "txt" console.
> 
> Suspending Thinkpads has always been a challenge, but at least on my 
> T21, I can do it via /etc/apm/suspend contortions.  This is 
> strengthening the need for a progarmmatic way to switch consoles.
> 
> 		--Steve Bellovin, http://www.research.att.com/~smb
> 		Full text of "Firewalls" book now at http://www.wilyhacker.com


----Next_Part(Fri_May_10_16:26:12_2002_559)--
Content-Type: Message/Rfc822
Content-Transfer-Encoding: 7bit

From port-i386-owner-daishi=cs.berkeley.edu@netbsd.org  Thu May  2 08:34:07 2002
	by mailspool.CS.Berkeley.EDU (8.9.3/) with ESMTP id IAA24664
	for <daishi@mailspool.CS.Berkeley.EDU>; Thu, 2 May 2002 08:34:07 -0700 (PDT)
	by relay2.EECS.Berkeley.EDU (8.9.3/8.9.3) with ESMTP id IAA20070
	for <daishi@mailspool.CS.Berkeley.EDU>; Thu, 2 May 2002 08:34:07 -0700 (PDT)
	by EECS.Berkeley.EDU (8.9.3/8.9.3) with SMTP id IAA20067
	for <daishi@cs.berkeley.edu>; Thu, 2 May 2002 08:34:06 -0700 (PDT)
  by mail.netbsd.org with SMTP; 2 May 2002 15:33:45 -0000
	by fw.hel.fi.ssh.com (SSH-1.27) with SMTP id g42FXhT15225
	for <port-i386@netbsd.org>; Thu, 2 May 2002 18:33:43 +0300 (EEST)
          by viikuna.hel.fi.ssh.com (qmail-ldap-1.03) with SMTP
          for <daishi@CS.Berkeley.EDU>; 2 May 2002 15:33:42 -0000
	by ryijy.hel.fi.ssh.com (8.11.0/8.11.0) id g42FXjK09680;
	Thu, 2 May 2002 18:33:45 +0300 (EEST)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: <15569.23641.380561.610520@ryijy.hel.fi.ssh.com>
Date: Thu, 2 May 2002 18:33:45 +0300
From: Tero Kivinen <kivinen@ssh.fi>
To: daishi@cs.berkeley.edu (Daishi Harada), port-i386@netbsd.org
Subject: Re: Fw: Command for switching wscons/resume from hibernation w/X help?
Organization: SSH Communications Security Oy
Sender: port-i386-owner@netbsd.org

daishi@CS.Berkeley.EDU (Daishi Harada) writes:
> The simple but tedious fix when resuming is to always switch to a
> console, and switch back to X. I was hoping to automate this process
> via the /etc/apm scripts, but I can't seem to find a command which
> will perform this switch for me. The Linux command for what I want is
> chvt - is there a corresponding command in NetBSD?

I had the similar problem in my laptop (except my laptop would
immediately crash if I tried to suspend it while the X11 was running).
I created following short programs to do the thing:

switchtoscreen.c:
----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <dev/wscons/wsdisplay_usl_io.h>

int main(int argc, char **argv)
{
  int f, data;
  char *file;

  if (argc == 1)
    data = 1;
  else
    data = atoi(argv[1]);
  if (argc <= 2)
    file = "/dev/ttyEcfg";
  else
    file = argv[2];
  if (data == 0)
    exit(3);
  f = open(file, O_RDWR, 0000);
  if (f < 0)
    {
      perror("File open failed");
      exit(1);
    }
  if (ioctl(f, VT_ACTIVATE, data) < 0)
    {
      perror("Ioctl failed");
      exit(2);
    }
  close(f);
  exit(0);
}
----------------------------------------------------------------------

currentscreen.c:
----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <dev/wscons/wsdisplay_usl_io.h>

int main(int argc, char **argv)
{
  int f, data;
  char *file;

  if (argc == 1)
    file = "/dev/ttyEcfg";
  else
    file = argv[1];
  f = open(file, O_RDWR, 0000);
  if (f < 0)
    {
      perror("File open failed");
      exit(1);
    }
  if (ioctl(f, VT_GETACTIVE, &data) < 0)
    {
      perror("Ioctl failed");
      exit(2);
    }
  printf("%d\n", data);
  close(f);
  exit(0);
}
----------------------------------------------------------------------

The first one will switch to screen given on command line argument,
i.e usage is like "switchscreen 1" and "switchscreen 5". The second
one will return the current screen number. I used that to store the
screen I was using when suspending and then resuming to the same
screen when waking up.

I.e my apm script has following functions:
----------------------------------------------------------------------
SCREENNO=/var/run/apm-screenno

switch_to_vt0() {
    /usr/sbin/switchtoscreen 1
    while [ `/usr/sbin/currentscreen` != 1 ]
    do
	# Wait until the switchtoscreen has actually changed the screen
	sleep 1
    done
}

switch_to_back() {
    /usr/sbin/switchtoscreen `cat $SCREENNO`  
    rm -f $SCREENNO
}

store_current_screen() {
    if [ ! -f $SCREENNO ]; then
	/usr/sbin/currentscreen > $SCREENNO
    fi
}

...
case $0 in
*suspend)	
...
	store_current_screen
	switch_to_vt0
...
	;;

*resume)
...
	switch_to_back
...
	;;
----------------------------------------------------------------------

On loaded system the switchtoscreen can take few seconds before the
virtual screen has actually changed thus I wanted to make sure in the
switch_to_vt0 that we are in the vt0 (screen 1) before continuing.

Both of those should simply compile with "cc -o switchscreen
switchscreen.c" commands.
-- 
kivinen@ssh.fi
SSH Communications Security                  http://www.ssh.fi/
SSH IPSEC Toolkit                            http://www.ssh.fi/ipsec/


----Next_Part(Fri_May_10_16:26:12_2002_559)----