Problem
In versions of SCO OpenServer operating systems prior to Release
5.0.0, I could use the "-S" option of the uname(C) command to
change the "System Name". This name is the output of the uname
command without any options, and is also shown as "System Name"
in the output of uname -X. In these releases, I also notice that
the "System Name" and "Node Name" are identical.In SCO OpenServer 5, however, the output of uname is "SCO_SV".
I need this value to be the same as my "Node Name" (the name chosen
for my machine during installation and/or set by uname -S). The
uname -S command only allows me to change the "Node Name". Software
that worked on pre-5.0.0 releases relied upon the output of uname
to function; this software will not function if "SCO_SV" is returned
by uname. Cause
Starting in SCO OpenServer Release 5.0.0, the behavior of uname was
changed to meet a POSIX standard. See TA104867, "uname(C) in
OpenServer 5.0 does not behave the same as in SCO UNIX 3.2v4.x",
for details. In accordance with the standard:1. The "System Name" as reported by uname is set to SCO_SV.
2. This parameter is now defined as the operating system name, as distinct from the machine or node name.
3. This parameter is intended to remain constant on the system. There are no utilities provided to change this parameter.
NOTE: The following workaround is provided by SCO as a courtesy to
customers. It is not supported in any way, and the customer
bears full responsibility for any presently unforseen consequences
of changing the System Name parameter from SCO_SV to some other
value.If possible, SCO recommends that you consider one of the two following alternatives before invoking the workaround outlined in the SOLUTION below:
1. Use the UNAME_OLD environment variable to force the pre-5.0.0
behavior of uname on a per-process basis. See TA104867
for details.2. Modify your application to conform to the new, standardized behavior of uname.
Solution
One straightforward workaround consists of a shell script that
takes a new System Name and kernel image (/unix, if not specified)
as arguments. The script alters the System Name in kernel memory
so that the change takes effect immediately. This change is made
by executing a chgname binary, the source code for which is given
below the text of the shell script. The script then makes the
necessary changes in the kernel linkkit, so that the change becomes
part of the next newly rebuilt kernel, to take effect at next boot.You must have an SCO OpenServer 5 Development System installed in
order to build this binary with cc(CP) or make(CP). No special
compile requirements or arguments are needed.###############begin chgnam.scr shell script##################
#!/bin/sh# usage: ./chgnam.scr <new system name> <kernel image>
# example: ./chgnam.scr comet504 /unixSYSNAME=$1
KERNEL=$2./chgname $SYSNAME $KERNEL
if [ $? -ne 0 ]; then
echo "chgname error"
exit 1
ficp /etc/conf/pack.d/kernel/space.c /etc/conf/pack.d/kernel/space.c.good
sed "/#define OPSYS/s/\".*\"/\"$SYSNAME\"/" /etc/conf/pack.d/kernel/space.c > \
space.tmpmv space.tmp /etc/conf/pack.d/kernel/space.cecho "Please run the command/etc/conf/cf.d/link_unixif you wish the new system name to be in effect the next time you reboot (with the default kernel, /unix)."
exit 0###############end chgnam.scr shell script####################/**************begin chgname.c source file*******************/
/*
* chgname.c--compile with "cc chgname.c -o chgname"
*
*
* A program which takes an 8-char or less system name and specifically
* changes the system name field of the scoutsname struct in memory.
*/
#include <nlist.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/utsname.h>
#include <errno.h>
#include <string.h>struct nlist sconame[] = {"scoutsname", 0, 0, 0, 0, 0,
"utsname", 0, 0, 0, 0, 0,
"xutsname", 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,}; struct scoutsname nl_uname; struct scoutsname real_uname; struct utsname a_uname; struct xutsname x_uname; char r_orig_name[9]; char a_orig_name[9]; char x_orig_name[9];
int fd;
char *kernel;
int verify();
int writename();int main(argc, argv) int argc; char *argv[]; { if (argc < 2) { fprintf(stderr, "Usage: chgname <new system name> <kernel name> \n"); fprintf(stderr, "<kernel name> must be specified if running kernel is not /unix\n"); exit(1); } if (argc == 2) kernel = "/unix"; else kernel = argv[2];
if (strlen(argv[1]) > 8) { fprintf(stderr, "system name must be 8 chars or less\n"); exit(1); } if (nlist( kernel, sconame ) == -1) { fprintf(stderr, "nlist error: could not read %s: %s\n", kernel, strerror(errno)); exit(1); }
if ((fd = open( "/dev/kmem", O_RDWR )) == -1) { fprintf(stderr, "can't open /dev/kmem for reading and writing: %s\n", strerror(errno)); exit(1); }
if (verify()) { fprintf(stderr, "Could not successfully read uname structure\n"); exit(1); } strncpy(r_orig_name, real_uname.sysname, 8); strncpy(a_orig_name, a_uname.sysname, 8); strncpy(x_orig_name, x_uname.sysname, 8); strncpy(real_uname.sysname, argv[1], 8); strncpy(a_uname.sysname, argv[1], 8); strncpy(x_uname.sysname, argv[1], 8);
if ( writename(sconame[0].n_value,real_uname.sysname) ) { fprintf(stderr, "Could not successfully write new sysname\n"); exit(1); } if ( writename(sconame[1].n_value,a_uname.sysname) ) { fprintf(stderr, "Could not successfully write new sysname\n"); writename(sconame[0].n_value, r_orig_name); exit(1); } if ( writename(sconame[2].n_value, x_uname.sysname) ) { fprintf(stderr, "Could not successfully write new sysname\n"); writename(sconame[0].n_value, r_orig_name); writename(sconame[1].n_value, a_orig_name); exit(1); }
exit(0);
}int verify()
{
if (__scoinfo(&real_uname, sizeof(real_uname)) == -1)
{
fprintf(stderr, "__scoinfo() failed: %s\n", strerror(errno));
return -1;
}
if (lseek(fd, sconame[0].n_value, SEEK_SET) != sconame[0].n_value)
{
fprintf(stderr, "lseek() of /dev/kmem failed: %s\n",
strerror(errno));
return -1;
}
if (read(fd, (char *)&nl_uname, sizeof(nl_uname)) != sizeof(nl_uname))
{
fprintf(stderr, "couldn't read entire scoutsname structure\n");
return -1;
}
if (memcmp((char *)&real_uname, (char *)&nl_uname, sizeof(struct
scoutsname)) != 0)
{
fprintf(stderr, "memcmp() failed: %s\n", strerror(errno));
return -1;
}
if (lseek(fd, sconame[1].n_value, SEEK_SET) != sconame[1].n_value)
{
fprintf(stderr, "lseek() of /dev/kmem failed: %s\n",
strerror(errno));
return -1;
}
if (read(fd, (char *)&a_uname, sizeof(a_uname)) != sizeof(a_uname))
{
fprintf(stderr, "couldn't read entire utsname structure\n");
return -1;
}
if (lseek(fd, sconame[2].n_value, SEEK_SET) != sconame[2].n_value)
{
fprintf(stderr, "lseek() of /dev/kmem failed: %s\n",
strerror(errno));
return -1;
}
if (read(fd, (char *)&x_uname, sizeof(x_uname)) != sizeof(x_uname))
{
fprintf(stderr, "couldn't read entire xutsname structure\n");
return -1;
}
return 0;
}int writename( value, name )
long value;
char *name;
{
if (lseek(fd, value, SEEK_SET) != value)
{
fprintf(stderr, "lseek() of /dev/kmem failed: %s\n",
strerror(errno));
return(1);
}
if (write(fd, name, 8) != 8)
{
fprintf(stderr, "write() of /dev/kmem failed: %s\n",
strerror(errno));
return(1);
}
return(0);
}/**************end chgname.c source file*********************/ See also
TA104867, "uname(C) in OpenServer 5.0 does not behave the same as in SCO UNIX 3.2v4.x".