From: David van Moolenbroek Date: Fri, 9 Oct 2015 18:34:38 +0000 (+0000) Subject: Retire sysuname(2), synchronize sys/utsname.h X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=d991a2bea3bf996992e1167e804c52cc6c5ab50d;p=minix.git Retire sysuname(2), synchronize sys/utsname.h Now that uname(3) uses sysctl(2), we no longer need sysuname(2). Backward compatibility is retained for old statically linked binaries for a short while. Also remove the now-obsolete MINIX3-specific "arch" field from the utsname structure. While this is an ABI break at the libc level, it should pose no problems in practice, because: - statically linked programs (i.e., all of the base system) are not affected, as they will use headers synchronized with libc; - the structure is getting smaller, thus, older dynamically linked programs (typically in pkgsrc) using the new libc will end up with garbage in the "arch" field, but it is unlikely they will use this field anyway, since it was specific to MINIX3; - new dynamically linked programs using an old libc could end up with memory corruption, but this is not a scenario that is expected to occur in the first place - certainly not with programs from pkgsrc. Change-Id: I29c76576f509feacc8f996f0bd353ca8961d4917 --- diff --git a/minix/commands/hostaddr/hostaddr.c b/minix/commands/hostaddr/hostaddr.c index 91d51f5ad..0d75e422a 100644 --- a/minix/commands/hostaddr/hostaddr.c +++ b/minix/commands/hostaddr/hostaddr.c @@ -276,23 +276,6 @@ char *argv[]; } if (do_hostname) { -#if __minix_vmd - if (sysuname(_UTS_SET, _UTS_NODENAME, - nodename, strlen(nodename)+1) == -1) - { - fprintf(stderr, "%s: Unable to set nodename: %s\n", - prog_name, strerror(errno)); - exit(1); - } - - if (sysuname(_UTS_SET, _UTS_HOSTNAME, - hostname, strlen(hostname)+1) == -1) - { - fprintf(stderr, "%s: Unable to set hostname: %s\n", - prog_name, strerror(errno)); - exit(1); - } -#else FILE *fp; if ((fp= fopen("/etc/hostname.file", "w")) == NULL @@ -303,7 +286,6 @@ char *argv[]; prog_name, strerror(errno)); exit(1); } -#endif } if (!first_print) printf("\n"); exit(0); diff --git a/minix/include/minix/callnr.h b/minix/include/minix/callnr.h index 52ba9bc27..7f5f36d26 100644 --- a/minix/include/minix/callnr.h +++ b/minix/include/minix/callnr.h @@ -35,7 +35,7 @@ #define PM_SIGPENDING (PM_BASE + 22) #define PM_SIGPROCMASK (PM_BASE + 23) #define PM_SIGRETURN (PM_BASE + 24) -#define PM_SYSUNAME (PM_BASE + 25) +#define PM_SYSUNAME (PM_BASE + 25) /* obsolete */ #define PM_GETPRIORITY (PM_BASE + 26) #define PM_SETPRIORITY (PM_BASE + 27) #define PM_GETTIMEOFDAY (PM_BASE + 28) diff --git a/minix/lib/libc/sys/Makefile.inc b/minix/lib/libc/sys/Makefile.inc index a443dfc16..0ac027f65 100644 --- a/minix/lib/libc/sys/Makefile.inc +++ b/minix/lib/libc/sys/Makefile.inc @@ -19,7 +19,7 @@ SRCS+= accept.c access.c adjtime.c bind.c brk.c sbrk.c m_closefrom.c getsid.c \ vectorio.c shutdown.c sigaction.c sigpending.c sigreturn.c sigsuspend.c\ sigprocmask.c socket.c socketpair.c stat.c statvfs.c svrctl.c \ symlink.c \ - sync.c syscall.c sysuname.c truncate.c umask.c unlink.c \ + sync.c syscall.c truncate.c umask.c unlink.c \ wait4.c write.c \ utimensat.c utimes.c futimes.c lutimes.c futimens.c \ _exit.c _ucontext.c environ.c __getcwd.c vfork.c sizeup.c init.c \ diff --git a/minix/lib/libc/sys/sysuname.c b/minix/lib/libc/sys/sysuname.c deleted file mode 100644 index f8f08d09f..000000000 --- a/minix/lib/libc/sys/sysuname.c +++ /dev/null @@ -1,26 +0,0 @@ -/* sysuname(2) - transfer uname(3) strings. Author: Kees J. Bot - * 5 Dec 1992 - */ - -#include -#include "namespace.h" -#include -#include -#include - -int sysuname(int req, int field, char *value, size_t len) -{ - message m; - - memset(&m, 0, sizeof(m)); - m.m_lc_pm_sysuname.req = req; - m.m_lc_pm_sysuname.field = field; - m.m_lc_pm_sysuname.len = len; - m.m_lc_pm_sysuname.value = (vir_bytes)value; - - return _syscall(PM_PROC_NR, PM_SYSUNAME, &m); -} - -/* - * $PchId: _sysuname.c,v 1.4 1995/11/27 19:42:09 philip Exp $ - */ diff --git a/minix/servers/pm/misc.c b/minix/servers/pm/misc.c index 93f331e06..c304b1ac3 100644 --- a/minix/servers/pm/misc.c +++ b/minix/servers/pm/misc.c @@ -28,6 +28,7 @@ #include "mproc.h" #include "kernel/proc.h" +/* START OF COMPATIBILITY BLOCK */ struct utsname uts_val = { OS_NAME, /* system name */ "noname", /* node/network name */ @@ -35,17 +36,19 @@ struct utsname uts_val = { OS_VERSION, /* O.S. version (e.g. Minix 3.3.0 (GENERIC)) */ #if defined(__i386__) "i386", /* machine (cpu) type */ - "i386", /* architecture */ #elif defined(__arm__) - "earm", /* machine (cpu) type */ - "earm", /* architecture */ + "evbarm", /* machine (cpu) type */ #else #error /* oops, no 'uname -mk' */ #endif }; static char *uts_tbl[] = { - uts_val.arch, +#if defined(__i386__) + "i386", /* architecture */ +#elif defined(__arm__) + "evbarm", /* architecture */ +#endif NULL, /* No kernel architecture */ uts_val.machine, NULL, /* No hostname */ @@ -55,11 +58,13 @@ static char *uts_tbl[] = { uts_val.sysname, NULL, /* No bus */ /* No bus */ }; +/* END OF COMPATIBILITY BLOCK */ #if ENABLE_SYSCALL_STATS unsigned long calls_stats[NR_PM_CALLS]; #endif +/* START OF COMPATIBILITY BLOCK */ /*===========================================================================* * do_sysuname * *===========================================================================*/ @@ -69,28 +74,15 @@ int do_sysuname() int r; size_t n; char *string; -#if 0 /* for updates */ - char tmp[sizeof(uts_val.nodename)]; - static short sizes[] = { - 0, /* arch, (0 = read-only) */ - 0, /* kernel */ - 0, /* machine */ - 0, /* sizeof(uts_val.hostname), */ - sizeof(uts_val.nodename), - 0, /* release */ - 0, /* version */ - 0, /* sysname */ - }; -#endif - if (m_in.m_lc_pm_sysuname.field >= _UTS_MAX) return(EINVAL); + if (m_in.m_lc_pm_sysuname.field >= __arraycount(uts_tbl)) return(EINVAL); string = uts_tbl[m_in.m_lc_pm_sysuname.field]; if (string == NULL) return EINVAL; /* Unsupported field */ switch (m_in.m_lc_pm_sysuname.req) { - case _UTS_GET: + case 0: /* Copy an uname string to the user. */ n = strlen(string) + 1; if (n > m_in.m_lc_pm_sysuname.len) n = m_in.m_lc_pm_sysuname.len; @@ -99,27 +91,13 @@ int do_sysuname() if (r < 0) return(r); break; -#if 0 /* no updates yet */ - case _UTS_SET: - /* Set an uname string, needs root power. */ - len = sizes[m_in.m_lc_pm_sysuname.field]; - if (mp->mp_effuid != 0 || len == 0) return(EPERM); - n = len < m_in.m_lc_pm_sysuname.len ? len : m_in.m_lc_pm_sysuname.len; - if (n <= 0) return(EINVAL); - r = sys_datacopy(mp->mp_endpoint, m_in.m_lc_pm_sysuname.value, SELF, - (phys_bytes)tmp, (phys_bytes)n); - if (r < 0) return(r); - tmp[n-1] = 0; - strcpy(string, tmp); - break; -#endif - default: return(EINVAL); } /* Return the number of bytes moved. */ return(n); } +/* END OF COMPATIBILITY BLOCK */ /*===========================================================================* diff --git a/minix/usr.bin/trace/service/pm.c b/minix/usr.bin/trace/service/pm.c index 77303fa88..1bbef8896 100644 --- a/minix/usr.bin/trace/service/pm.c +++ b/minix/usr.bin/trace/service/pm.c @@ -953,66 +953,6 @@ pm_sigreturn_in(struct trace_proc * proc, const message * __unused m_out, } } -static void -put_sysuname_field(struct trace_proc * proc, const char * name, int field) -{ - const char *text = NULL; - - if (!valuesonly) { - switch (field) { - TEXT(_UTS_ARCH); - TEXT(_UTS_KERNEL); - TEXT(_UTS_MACHINE); - TEXT(_UTS_HOSTNAME); - TEXT(_UTS_NODENAME); - TEXT(_UTS_RELEASE); - TEXT(_UTS_VERSION); - TEXT(_UTS_SYSNAME); - TEXT(_UTS_BUS); - } - } - - if (text != NULL) - put_field(proc, name, text); - else - put_value(proc, name, "%d", field); -} - -static int -pm_sysuname_out(struct trace_proc * proc, const message * m_out) -{ - - if (!valuesonly && m_out->m_lc_pm_sysuname.req == _UTS_GET) - put_field(proc, "req", "_UTS_GET"); - else if (!valuesonly && m_out->m_lc_pm_sysuname.req == _UTS_SET) - put_field(proc, "req", "_UTS_SET"); - else - put_value(proc, "req", "%d", m_out->m_lc_pm_sysuname.req); - put_sysuname_field(proc, "field", m_out->m_lc_pm_sysuname.field); - - if (m_out->m_lc_pm_sysuname.req == _UTS_GET) - return CT_NOTDONE; - - put_buf(proc, "value", PF_STRING, m_out->m_lc_pm_sysuname.value, - m_out->m_lc_pm_sysuname.len); - put_value(proc, "len", "%zu", m_out->m_lc_pm_sysuname.len); - return CT_DONE; -} - -static void -pm_sysuname_in(struct trace_proc * proc, const message * m_out, - const message * m_in, int failed) -{ - - if (m_out->m_lc_pm_sysuname.req == _UTS_GET) { - put_buf(proc, "value", failed | PF_STRING, - m_out->m_lc_pm_sysuname.value, m_in->m_type); - put_value(proc, "len", "%zu", m_out->m_lc_pm_sysuname.len); - put_equals(proc); - } - put_result(proc); -} - static void put_priority_which(struct trace_proc * proc, const char * name, int which) { @@ -1374,8 +1314,6 @@ static const struct call_handler pm_map[] = { pm_sigprocmask_in), PM_CALL(SIGRETURN) = HANDLER("sigreturn", pm_sigreturn_out, pm_sigreturn_in), - PM_CALL(SYSUNAME) = HANDLER("sysuname", pm_sysuname_out, - pm_sysuname_in), PM_CALL(GETPRIORITY) = HANDLER("getpriority", pm_getpriority_out, pm_getpriority_in), PM_CALL(SETPRIORITY) = HANDLER("setpriority", pm_setpriority_out, diff --git a/sys/sys/utsname.h b/sys/sys/utsname.h index d24d7ef94..2daaa3c32 100644 --- a/sys/sys/utsname.h +++ b/sys/sys/utsname.h @@ -51,37 +51,12 @@ struct utsname { char release[_SYS_NMLN]; /* Release level. */ char version[_SYS_NMLN]; /* Version level. */ char machine[_SYS_NMLN]; /* Hardware type. */ -#if defined(__minix) - char arch[_SYS_NMLN]; -#endif /* defined(__minix) */ }; #include __BEGIN_DECLS int uname(struct utsname *); -#if defined(__minix) -#include -int sysuname(int _req, int _field, char *_value, size_t _len); -#endif /* defined(__minix) */ __END_DECLS -#if defined(__minix) -/* req: Get or set a string. */ -#define _UTS_GET 0 -#define _UTS_SET 1 - -/* field: What field to get or set. These values can't be changed lightly. */ -#define _UTS_ARCH 0 -#define _UTS_KERNEL 1 -#define _UTS_MACHINE 2 -#define _UTS_HOSTNAME 3 -#define _UTS_NODENAME 4 -#define _UTS_RELEASE 5 -#define _UTS_VERSION 6 -#define _UTS_SYSNAME 7 -#define _UTS_BUS 8 -#define _UTS_MAX 9 /* Number of strings. */ -#endif /* defined(__minix) */ - #endif /* !_SYS_UTSNAME_H_ */