summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2006-12-07 00:25:37 +0100
committerKarel Zak <kzak@redhat.com>2006-12-07 00:25:37 +0100
commit5c36a0eb7cdb0360f9afd5d747c321f423b35984 (patch)
tree147599a77eaff2b5fbc0d389e89d2b51602326c0 /lib
parent2b6fc908bc368b540845a313c3b8a867c5ad9a42 (diff)
downloadutil-linux-5c36a0eb7cdb0360f9afd5d747c321f423b35984.tar.gz
Imported from util-linux-2.9i tarball.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile17
-rw-r--r--lib/err.c185
-rw-r--r--lib/err.h70
-rw-r--r--lib/linux_reboot.h30
-rw-r--r--lib/my_reboot.c40
-rw-r--r--lib/pathnames.h104
-rw-r--r--lib/setproctitle.c117
-rw-r--r--lib/setproctitle.h7
8 files changed, 570 insertions, 0 deletions
diff --git a/lib/Makefile b/lib/Makefile
new file mode 100644
index 00000000..5503a605
--- /dev/null
+++ b/lib/Makefile
@@ -0,0 +1,17 @@
+include ../MCONFIG
+
+CFLAGS=-I$(LIB) $(OPT)
+
+all: err.o my_reboot.o setproctitle.o
+
+err.o: err.c
+
+my_reboot.o: my_reboot.c linux_reboot.h
+
+setproctitle.o: setproctitle.h
+
+.PHONY: clean
+clean:
+ -rm -f *.o *~ core
+
+install:
diff --git a/lib/err.c b/lib/err.c
new file mode 100644
index 00000000..2731a714
--- /dev/null
+++ b/lib/err.c
@@ -0,0 +1,185 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+extern char *__progname; /* Program name, from crt0. */
+#ifdef __linux__
+char *__progname;
+#endif
+
+__dead void
+#ifdef __STDC__
+err(int eval, const char *fmt, ...)
+#else
+err(eval, fmt, va_alist)
+ int eval;
+ const char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ verr(eval, fmt, ap);
+ va_end(ap);
+}
+
+__dead void
+verr(eval, fmt, ap)
+ int eval;
+ const char *fmt;
+ va_list ap;
+{
+ int sverrno;
+
+ sverrno = errno;
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL) {
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, ": ");
+ }
+ (void)fprintf(stderr, "%s\n", strerror(sverrno));
+ exit(eval);
+}
+
+__dead void
+#if __STDC__
+errx(int eval, const char *fmt, ...)
+#else
+errx(eval, fmt, va_alist)
+ int eval;
+ const char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ verrx(eval, fmt, ap);
+ va_end(ap);
+}
+
+__dead void
+verrx(eval, fmt, ap)
+ int eval;
+ const char *fmt;
+ va_list ap;
+{
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL)
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, "\n");
+ exit(eval);
+}
+
+void
+#if __STDC__
+warn(const char *fmt, ...)
+#else
+warn(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ vwarn(fmt, ap);
+ va_end(ap);
+}
+
+void
+vwarn(fmt, ap)
+ const char *fmt;
+ va_list ap;
+{
+ int sverrno;
+
+ sverrno = errno;
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL) {
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, ": ");
+ }
+ (void)fprintf(stderr, "%s\n", strerror(sverrno));
+}
+
+void
+#ifdef __STDC__
+warnx(const char *fmt, ...)
+#else
+warnx(fmt, va_alist)
+ const char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ vwarnx(fmt, ap);
+ va_end(ap);
+}
+
+void
+vwarnx(fmt, ap)
+ const char *fmt;
+ va_list ap;
+{
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL)
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, "\n");
+}
diff --git a/lib/err.h b/lib/err.h
new file mode 100644
index 00000000..da4be150
--- /dev/null
+++ b/lib/err.h
@@ -0,0 +1,70 @@
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)err.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _ERR_H_
+#define _ERR_H_
+
+#ifdef __linux__
+#include <stdarg.h>
+#define _BSD_VA_LIST_ va_list
+#define __dead /* */
+#else
+/*
+ * Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two
+ * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
+ * of them here we may collide with the utility's includes. It's unreasonable
+ * for utilities to have to include one of them to include err.h, so we get
+ * _BSD_VA_LIST_ from <machine/ansi.h> and use it.
+ */
+#include <machine/ansi.h>
+#endif
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+__dead void err __P((int, const char *, ...));
+__dead void verr __P((int, const char *, _BSD_VA_LIST_));
+__dead void errx __P((int, const char *, ...));
+__dead void verrx __P((int, const char *, _BSD_VA_LIST_));
+void warn __P((const char *, ...));
+void vwarn __P((const char *, _BSD_VA_LIST_));
+void warnx __P((const char *, ...));
+void vwarnx __P((const char *, _BSD_VA_LIST_));
+__END_DECLS
+
+#ifdef __linux__
+#undef _BSD_VA_LIST_
+#endif
+
+#endif /* !_ERR_H_ */
diff --git a/lib/linux_reboot.h b/lib/linux_reboot.h
new file mode 100644
index 00000000..780d7509
--- /dev/null
+++ b/lib/linux_reboot.h
@@ -0,0 +1,30 @@
+extern int my_reboot(int);
+
+/*
+ * Magic values required to use _reboot() system call.
+ */
+
+#define LINUX_REBOOT_MAGIC1 0xfee1dead
+#define LINUX_REBOOT_MAGIC2 672274793
+#define LINUX_REBOOT_MAGIC2A 85072278
+#define LINUX_REBOOT_MAGIC2B 369367448
+
+
+/*
+ * Commands accepted by the _reboot() system call.
+ *
+ * RESTART Restart system using default command and mode.
+ * HALT Stop OS and give system control to ROM monitor, if any.
+ * CAD_ON Ctrl-Alt-Del sequence causes RESTART command.
+ * CAD_OFF Ctrl-Alt-Del sequence sends SIGINT to init task.
+ * POWER_OFF Stop OS and remove all power from system, if possible.
+ * RESTART2 Restart system using given command string.
+ */
+
+#define LINUX_REBOOT_CMD_RESTART 0x01234567
+#define LINUX_REBOOT_CMD_HALT 0xCDEF0123
+#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF
+#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
+#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
+#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
+
diff --git a/lib/my_reboot.c b/lib/my_reboot.c
new file mode 100644
index 00000000..12ea4c92
--- /dev/null
+++ b/lib/my_reboot.c
@@ -0,0 +1,40 @@
+/* Including <unistd.h> makes sure that on a glibc system
+ <features.h> is included, which again defines __GLIBC__ */
+#include <unistd.h>
+#include "linux_reboot.h"
+
+#define USE_LIBC
+
+#ifdef USE_LIBC
+
+/* libc version */
+#if defined __GLIBC__ && __GLIBC__ >= 2
+# include <sys/reboot.h>
+# define REBOOT(cmd) reboot(cmd)
+#else
+extern int reboot(int, int, int);
+# define REBOOT(cmd) reboot(LINUX_REBOOT_MAGIC1,LINUX_REBOOT_MAGIC2,(cmd))
+#endif
+int
+my_reboot(int cmd) {
+ return REBOOT(cmd);
+}
+
+#else /* no USE_LIBC */
+
+/* direct syscall version */
+#include <linux/unistd.h>
+
+#ifdef _syscall3
+_syscall3(int, reboot, int, magic, int, magic_too, int, cmd);
+#else
+/* Let us hope we have a 3-argument reboot here */
+extern int reboot(int, int, int);
+#endif
+
+int
+my_reboot(int cmd) {
+ return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd);
+}
+
+#endif
diff --git a/lib/pathnames.h b/lib/pathnames.h
new file mode 100644
index 00000000..ab7b97dc
--- /dev/null
+++ b/lib/pathnames.h
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * @(#)pathnames.h 5.3 (Berkeley) 5/9/89
+ *
+ * Changed: Sun Nov 21 12:30:54 1993 by faith@cs.unc.edu
+ * Changed: Wed Jun 22 20:47:27 1994 by faith@cs.unc.edu, based on changes
+ * from poe@daimi.aau.dk
+ * Changed: Wed Jun 22 22:50:13 1994 by faith@cs.unc.edu
+ * Changed: Sat Feb 4 16:02:10 1995 by faith@cs.unc.edu
+ * Changed: Tue Jul 2 09:37:36 1996 by janl@math.uio.no, axp patches
+ * Changed: Thu Nov 9 21:58:36 1995 by joey@infodrom.north.de
+ */
+
+#ifndef __STDC__
+# error "we need an ANSI compiler"
+#endif
+
+/* The paths for some of these are wrong in /usr/include/paths.h, but we
+ re-define them here. */
+
+#undef _PATH_UTMP
+#undef _PATH_WTMP
+#undef _PATH_DEFPATH
+#undef _PATH_DEFPATH_ROOT
+#undef _PATH_LASTLOG
+#undef _PATH_MAILDIR
+
+#ifndef SBINDIR
+#define SBINDIR "/sbin"
+#endif
+
+#ifndef USRSBINDIR
+#define USRSBINDIR "/usr/sbin"
+#endif
+
+#ifndef LOGDIR
+#define LOGDIR "/var/log"
+#endif
+
+#ifndef VARPATH
+#define VARPATH "/var"
+#endif
+
+#ifndef UT_NAMESIZE
+#define UT_NAMESIZE 8
+#endif
+
+#define _PATH_BSHELL "/bin/sh"
+#define _PATH_CSHELL "/bin/csh"
+#define _PATH_TTY "/dev/tty"
+#define TTYTYPES "/etc/ttytype"
+#define SECURETTY "/etc/securetty"
+#define _PATH_UTMP "/var/run/utmp"
+#define _PATH_WTMP LOGDIR "/wtmp"
+#define _PATH_WTMPLOCK "/etc/wtmplock"
+
+/* no more . in DEFPATH */
+#define _PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin"
+#define _PATH_DEFPATH_ROOT SBINDIR ":/bin:" USRSBINDIR ":/usr/bin"
+#define _PATH_HUSHLOGIN ".hushlogin"
+#define _PATH_LASTLOG LOGDIR "/lastlog"
+#define _PATH_MAILDIR VARPATH "/spool/mail"
+#define _PATH_MOTDFILE "/etc/motd"
+#define _PATH_NOLOGIN "/etc/nologin"
+
+#define _PATH_LOGIN "/bin/login"
+#define _PATH_INITTAB "/etc/inittab"
+#define _PATH_RC "/etc/rc"
+#define _PATH_REBOOT SBINDIR "/reboot"
+#define _PATH_SINGLE "/etc/singleboot"
+#define _PATH_SHUTDOWN_CONF "/etc/shutdown.conf"
+
+#define _PATH_SECURE "/etc/securesingle"
+#define _PATH_USERTTY "/etc/usertty"
+
+#define _PATH_MTAB "/etc/mtab"
+#define _PATH_UMOUNT "/bin/umount"
+#define UMOUNT_ARGS "umount", "-a"
+#define SWAPOFF_ARGS "swapoff", "-a"
+
+#define _PATH_PASSWD "/etc/passwd"
+#define _PATH_PTMP "/etc/ptmp"
+#define _PATH_PTMPTMP "/etc/ptmptmp"
+
+#define _PATH_GROUP "/etc/group"
+#define _PATH_GTMP "/etc/gtmp"
+#define _PATH_GTMPTMP "/etc/gtmptmp"
+
+#define _PATH_WORDS "/usr/dict/words"
+#define _PATH_WORDS_ALT "/usr/dict/web2"
diff --git a/lib/setproctitle.c b/lib/setproctitle.c
new file mode 100644
index 00000000..bff1362d
--- /dev/null
+++ b/lib/setproctitle.c
@@ -0,0 +1,117 @@
+/* proctitle code - we know this to work only on linux... */
+
+/*
+** SETPROCTITLE -- set process title for ps (from sendmail)
+**
+** Parameters:
+** fmt -- a printf style format string.
+**
+** Returns:
+** none.
+**
+** Side Effects:
+** Clobbers argv of our main procedure so ps(1) will
+** display the title.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include "setproctitle.h"
+
+#ifndef SPT_PADCHAR
+#define SPT_PADCHAR ' '
+#endif
+
+#ifndef SPT_BUFSIZE
+#define SPT_BUFSIZE 2048
+#endif
+
+extern char** environ;
+
+static char** argv0;
+static int argv_lth;
+
+void
+initproctitle (int argc, char **argv) {
+ int i;
+ char **envp = environ;
+
+ /*
+ * Move the environment so we can reuse the memory.
+ * (Code borrowed from sendmail.)
+ * WARNING: ugly assumptions on memory layout here;
+ * if this ever causes problems, #undef DO_PS_FIDDLING
+ */
+ for (i = 0; envp[i] != NULL; i++)
+ continue;
+ environ = (char **) malloc(sizeof(char *) * (i + 1));
+ if (environ == NULL)
+ return;
+ for (i = 0; envp[i] != NULL; i++)
+ if ((environ[i] = strdup(envp[i])) == NULL)
+ return;
+ environ[i] = NULL;
+
+ argv0 = argv;
+ if (i > 0)
+ argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0];
+ else
+ argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0];
+}
+
+#if 0
+/* Nice code, but many places do not know about vsnprintf ... */
+void
+setproctitle (const char *fmt,...) {
+ char *p;
+ int i;
+ char buf[SPT_BUFSIZE];
+ va_list ap;
+
+ if (!argv0)
+ return;
+
+ va_start(ap, fmt);
+ (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap);
+ va_end(ap);
+
+ i = strlen (buf);
+ if (i > argv_lth - 2) {
+ i = argv_lth - 2;
+ buf[i] = '\0';
+ }
+ (void) strcpy (argv0[0], buf);
+ p = &argv0[0][i];
+ while (i < argv_lth)
+ *p++ = SPT_PADCHAR, i++;
+ argv0[1] = NULL;
+}
+#else
+void
+setproctitle (const char *prog, const char *txt) {
+ char *p;
+ int i;
+ char buf[SPT_BUFSIZE];
+
+ if (!argv0)
+ return;
+
+ if (strlen(prog) + strlen(txt) + 5 > SPT_BUFSIZE)
+ return;
+
+ (void) sprintf(buf, "%s -- %s", prog, txt);
+
+ i = strlen (buf);
+ if (i > argv_lth - 2) {
+ i = argv_lth - 2;
+ buf[i] = '\0';
+ }
+ (void) strcpy (argv0[0], buf);
+ p = &argv0[0][i];
+ while (i < argv_lth)
+ *p++ = SPT_PADCHAR, i++;
+ argv0[1] = NULL;
+}
+#endif
diff --git a/lib/setproctitle.h b/lib/setproctitle.h
new file mode 100644
index 00000000..d57abda6
--- /dev/null
+++ b/lib/setproctitle.h
@@ -0,0 +1,7 @@
+
+void initproctitle (int argc, char **argv);
+#if 0
+void setproctitle (const char *fmt, ...);
+#else
+void setproctitle (const char *prog, const char *txt);
+#endif