Operating System - HP-UX
1834158 Members
2599 Online
110064 Solutions
New Discussion

Pseudo Terminal Session Number/Name Options

 
SOLVED
Go to solution
garethh_1
Occasional Advisor

Pseudo Terminal Session Number/Name Options

I'm a novice Unix System admin, and I'm trying to migrate one of our
Servers to a new HP-UX 11 Server.

On the current Server, my telnet session have the naming convention:


pts/t0 thru t9
pts/t10 thru t99


On the new new Server, the telnet sessions have the naming convention:
pts/t0 thru t9
pts/ta thru tz
pts/tA thru tZ
pts/tab thru ttzb
etc


This is causing a problem with temporary files we use to run reports.
Is there a way I can change the new Server to use a same naming
convention as the current Server?


The server HP-UX versions are slightly different revisions.


Thanks in advance for any help.


13 REPLIES 13
James R. Ferguson
Acclaimed Contributor

Re: Pseudo Terminal Session Number/Name Options

Hi:

You need to change your script. Use the pid ($$) of the process you run to create a unique temporary file for the duration of your process. Do something like:

#!/usr/bin/sh
typeset MYNAME=${0##*/}
typeset TMPDIR=${TMPDIR:=/var/tmp}/${MYNAME}.${$}

mkdir -m 700 ${TMPDIR} || exit 1
trap 'rm -rf ${TMPDIR}' EXIT

...[your script follows on here...]

This creates temporary files in '/var/tmp' in a directory named that of the basename of your process. If the pid of your script is appedned to the directory created to make it unique.

The trap runs whenever your script exits, and remmoves the directory and any files therein created by your script.

Regards!

...JRF...
garethh_1
Occasional Advisor

Re: Pseudo Terminal Session Number/Name Options

Thank you for replying.

We have legacy applications using COBOL. So using temporary files are actually coded into the application to always use the same directory and use the terminal name (to, t50, etc) in the name of the temporary file so it's unique for that user. I inherited this. This is coded into many places, so it's going to be horrendous to track it all down and change it.

Right now it's running on HPUX 11.00, so the device name under dev/pts are t0 - t99, etc.

However, on 11.11 they are t0-9, ta-z, then it goes tA-Z.

Even worse, the code for the temporary files doesn't take case into consideration, so the temporary files for a user with terminal name ta and another user with terminal name tA create the same temporary file name (it's all made lowercase).

So this wasn't a problem on 11.00, as the terminal names were all numbers with a 't' prefix'.

Any help you guys could give me on this will be VERY much appreciated.

Thanks in advance
James R. Ferguson
Acclaimed Contributor
Solution

Re: Pseudo Terminal Session Number/Name Options

Hi:

You really need to fix the application, but this being Unix, I'd make symbolic links in '/dev' "matching" old and new 'tty' device names. Then, find the application owner('s) and shoot them!!!

Regards!

...JRF...
garethh_1
Occasional Advisor

Re: Pseudo Terminal Session Number/Name Options

Thanks JRF! I appreciate your advice.

Do you think I could go into dev/pts and just delete any device names that I know will cause a problem. For example, all device names with capitals (tA-Z).

If you think that would work, would I just:

rm tA

or would I need to use

rmsf tA

Thanks again for your help.
James R. Ferguson
Acclaimed Contributor

Re: Pseudo Terminal Session Number/Name Options

Hi (again):

> Do you think I could go into dev/pts and just delete any device names that I know will cause a problem. For example, all device names with capitals (tA-Z).

You could ('rm or 'rmsf'), but they could always be re-generated by 'insf'. Once again, this is "fixing" the wrong thing!

Regards!

...JRF...
garethh_1
Occasional Advisor

Re: Pseudo Terminal Session Number/Name Options

Thanks JRF.

The Server it's currently on is 7 years old, and I'm worried about hardware problems.

The COBOL apps, sadly, are mission critical to the company. The company is small, so doesn't have a Unix admin as such, just Windows admins trying their best.

The COBOL programmers here inheritied the mess. We can certainly make sure the temp file creation is done correctly on any of the reports we know about. Trouble is there are hundreds, literally. So we'll fix it, and to the right thing in the long run.

The kernal parameters on the new Server have nstrtel = 512. I wouldn't normally come close to 100 simultaneous connections, so if we delete any device names in dev/pts with capitals we'll be ok I hope.

No one here is going to change any of the kernal parameters once it's gone live, or run insf. So is there any other way those device files under /dev/pts will be recreated?

Thanks again.
A. Clay Stephenson
Acclaimed Contributor

Re: Pseudo Terminal Session Number/Name Options

It appears someone made some very dumb assumptions when they were designing the code but given that it is COBOL, I'm hardly surprised. If you do a man insf, you will see that there are arguments you can supply to specify the range and index.

Here is one approach that should work.

Create a script that will capture the major/minor device number tuples of /dev/pts/t*, sort them, old name, and proposed new name to a file.

Now read that list and first remove the old device node and create a new node with the same major/minor device tuples but with the new name.

Script 1:
---------------------------------------
#!/usr/bin/sh

typeset DIR=/dev/pts
typeset SAVEFILE=/var/tmp/ptslist

ls -l ${DIR}/t* | \
awk '{print $6,$5,$NF}' | sort | \
awk -v dir=${DIR} '{printf("%s %s %s %s/t%d\n",$1,$2,$3,dir,++knt)}' > ${SAVEFILE}
-----------------------------------------

Script 2:
-----------------------------------------
#!/usr/bin/sh

typeset SAVEFILE=/var/tmp/ptslist

cat ${SAVEFILE} | while read MINOR MAJOR OLDNAME NEWNAME
do
echo "Removing ${OLDNAME}"
# rm ${OLDNAME}
echo "Creating ${NEWNAME} c ${MAJOR} ${MINOR}"
# mknod ${NEWNAME} c ${MAJOR} ${MINOR}
done
-----------------------------------------

Remove the commented lines for the rm and mknod commands when you feel confident.

NOTE: Backup the /dev/pts directory before you do this so that you can get yourself out of trouble almost as fast as you got yourself in. I intentionally divided this into two parts with a file so that you could edit the file if you wish and also the file could be used to recreate the original device nodes if needed. Users should be off the system while you do this and you must do this from the console. May The Force be with you.
If it ain't broke, I can fix that.
garethh_1
Occasional Advisor

Re: Pseudo Terminal Session Number/Name Options

Thanks Clay!! You're a life saver!!

Thanks so much for spending the time to detail it out so well for me!

Very much appreciated!!
Bill Hassell
Honored Contributor

Re: Pseudo Terminal Session Number/Name Options

> The server HP-UX versions are slightly different revisions.

11.00 = obsolete and unsupported
11.11 = current but becoming mature

11.11 has a *LOT* of changes and differences. In the area of pseudo terminals, the names have been changing because the drivers are migrating tp streams-based model, hence the kernel parameters pty, nstrpty and nstrtel. The man page for pty lists the classic pty names, while the man page for pts shows the streams naming (shown at the end of their man pages)

As mentioned, these names are created automatically when you change nstrtel or npty or nstrpty (using SAM). insf -e (or insf -s or -p options) will create missing device files. So you'll have to be quite careful about using insf -e.


Bill Hassell, sysadmin
garethh_1
Occasional Advisor

Re: Pseudo Terminal Session Number/Name Options

Hi Clay,

I ran the scripts, and they ran fine. I uncommented out the rm and mknod parts. Ran on the console, all appeared to run fine.

After it was done the contents of /dev/pts was as expected. All looked good.

However, when I telnet into the Server I get:

telnetd: /dev/pts/ta: No such file or directory

I have bounced the Server.

I can back it out, I've just be establishing and breaking a mirror each time. So, I have an easy back out.

Do you have any idea what else needs to be changed?

Thanks in advance.

Gareth
A. Clay Stephenson
Acclaimed Contributor

Re: Pseudo Terminal Session Number/Name Options

Without know the internals of the newer pty/ptm driver, it's nothing more than a guess --- which is why I warned you to back everything up before doing this. You actually could have created a slighty modified version of the second script to restore things as they were.

It's time to fix the problem rather than trying to fix the symptoms; fix that stupid COBOL ---- and this was a state-of-the-art stupid method of generating temporary file names.
If it ain't broke, I can fix that.
garethh_1
Occasional Advisor

Re: Pseudo Terminal Session Number/Name Options

Well thanks for responding Clay, I appreciate it.

It's just not realistic to change all the reports in the next 1.5 weeks, which is when we were needing to go live. There are 100's of them. Programmers, sys admins all inherited this mess, sadly.

There seems to be the same amount of special files in /dev as there are in /dev/pts. Could the same name change need to take place there too?

We're running 11.11.

Thanks again for your help.
Dennis Handly
Acclaimed Contributor

Re: Pseudo Terminal Session Number/Name Options

>Could the same name change need to take place there too?

You could try but I think the kernel is just keeping track of the free device by a number then it translates that into the character string. And you by removing those devices, get that missing /dev/pts/ta for 10.

>JRF: typeset TMPDIR=${TMPDIR:=/var/tmp}/...

Any reason you use typeset? You want these to be local to a function?
Also, the correct syntax is ":-", not ":=". When you use ":=", you typically use it as:
$ YY=${XX:=abc} # set two variables
$ : $(XX:=abc} # only set XX
With ":-", you don't have to worry about setting TMPDIR twice. ;-)