10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
23
24
25 /*
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
31
32 /*
33 * setuname [-t] [-s name] [-n node]
34 */
35
36 /*
37 * Header files referenced:
38 * <stdio.h> Standard I/O
39 * <unistd.h> Standard UNIX definitions
40 * <string.h> String handling
41 * <fmtmsg.h> Standard message generation
42 * <ctype.h> Character types
43 * <errno.h> Error handling
44 * <signal.h> Signal handling
45 * <sys/types.h> Data types
46 * <sys/fcntl.h> File control
47 * <sys/utsname.h> System Name
48 * <sys/sys3b.h> sys3b() definitions
49 * <nlist.h> Definitions for Sun symbol table entries
50 */
435 if (nlist("/unix", nl) != 0)
436 rtncd = -1;
437 #endif
438 if (rtncd != 0) return(rtncd);
439
440 /*
441 * Open the kernel's memory, get the existing "utsname" structure,
442 * change the system name and/or the network node-name in that struct,
443 * write it back out to kernel memory, then close kernel memory.
444 */
445 #ifdef sun
446 if (kvm_kread(kd, utsname_addr, &utsname, sizeof (utsname)) ==
447 sizeof (utsname)) {
448 if (sysname)
449 (void) strncpy(utsname.sysname, sysname,
450 sizeof (utsname.sysname));
451 if (nodename)
452 (void) strncpy(utsname.nodename, nodename,
453 sizeof (utsname.nodename));
454 (void) kvm_kwrite(kd, utsname_addr, &utsname, sizeof (utsname));
455 kvm_close(kd);
456 } else
457 return (-1);
458 #else /* sun */
459 if ((memfd = open("/dev/kmem", O_RDWR, 0)) > 0) {
460 if ((lseek(memfd, (long) utsname_addr, SEEK_SET) != -1) &&
461 (read(memfd, &utsname, sizeof(utsname)) == sizeof(utsname))) {
462 if (sysname) (void) strncpy(utsname.sysname, sysname, sizeof(utsname.sysname));
463 if (nodename) (void) strncpy(utsname.nodename, nodename, sizeof(utsname.nodename));
464 (void) lseek(memfd, (long) utsname_addr, SEEK_SET);
465 (void) write(memfd, &utsname, sizeof(utsname));
466 (void) close(memfd);
467 } else rtncd = -1;
468 } else rtncd = -1;
469 if (rtncd != 0) return(rtncd);
470 #endif /* sun */
471
472
473 /*
474 * If the "temp" flag is FALSE, we need to permanently set the
475 * system name in the file /etc/rc2.d/S18setuname
|
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
23
24
25 /*
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30 /*
31 * Copyright (c) 2018, Joyent, Inc.
32 */
33
34 /*
35 * setuname [-t] [-s name] [-n node]
36 */
37
38 /*
39 * Header files referenced:
40 * <stdio.h> Standard I/O
41 * <unistd.h> Standard UNIX definitions
42 * <string.h> String handling
43 * <fmtmsg.h> Standard message generation
44 * <ctype.h> Character types
45 * <errno.h> Error handling
46 * <signal.h> Signal handling
47 * <sys/types.h> Data types
48 * <sys/fcntl.h> File control
49 * <sys/utsname.h> System Name
50 * <sys/sys3b.h> sys3b() definitions
51 * <nlist.h> Definitions for Sun symbol table entries
52 */
437 if (nlist("/unix", nl) != 0)
438 rtncd = -1;
439 #endif
440 if (rtncd != 0) return(rtncd);
441
442 /*
443 * Open the kernel's memory, get the existing "utsname" structure,
444 * change the system name and/or the network node-name in that struct,
445 * write it back out to kernel memory, then close kernel memory.
446 */
447 #ifdef sun
448 if (kvm_kread(kd, utsname_addr, &utsname, sizeof (utsname)) ==
449 sizeof (utsname)) {
450 if (sysname)
451 (void) strncpy(utsname.sysname, sysname,
452 sizeof (utsname.sysname));
453 if (nodename)
454 (void) strncpy(utsname.nodename, nodename,
455 sizeof (utsname.nodename));
456 (void) kvm_kwrite(kd, utsname_addr, &utsname, sizeof (utsname));
457 (void) kvm_close(kd);
458 } else
459 return (-1);
460 #else /* sun */
461 if ((memfd = open("/dev/kmem", O_RDWR, 0)) > 0) {
462 if ((lseek(memfd, (long) utsname_addr, SEEK_SET) != -1) &&
463 (read(memfd, &utsname, sizeof(utsname)) == sizeof(utsname))) {
464 if (sysname) (void) strncpy(utsname.sysname, sysname, sizeof(utsname.sysname));
465 if (nodename) (void) strncpy(utsname.nodename, nodename, sizeof(utsname.nodename));
466 (void) lseek(memfd, (long) utsname_addr, SEEK_SET);
467 (void) write(memfd, &utsname, sizeof(utsname));
468 (void) close(memfd);
469 } else rtncd = -1;
470 } else rtncd = -1;
471 if (rtncd != 0) return(rtncd);
472 #endif /* sun */
473
474
475 /*
476 * If the "temp" flag is FALSE, we need to permanently set the
477 * system name in the file /etc/rc2.d/S18setuname
|