From owner-svn-src-head@FreeBSD.ORG Thu Dec 30 18:06:32 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2A78E1065675; Thu, 30 Dec 2010 18:06:32 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0E7518FC19; Thu, 30 Dec 2010 18:06:32 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBUI6VC0046735; Thu, 30 Dec 2010 18:06:31 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBUI6VcW046731; Thu, 30 Dec 2010 18:06:31 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201012301806.oBUI6VcW046731@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Thu, 30 Dec 2010 18:06:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216823 - head/sbin/shutdown X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Dec 2010 18:06:32 -0000 Author: pjd Date: Thu Dec 30 18:06:31 2010 New Revision: 216823 URL: http://svn.freebsd.org/changeset/base/216823 Log: For compatibility with Linux and Solaris add poweroff(8). It is implemented as a hard link to shutdown(8) and it is equivalent of: # shutdown -p now While I'm here put one line of usage into one line of C code so it is easier to grep(1) and separate unrelated code with empty line. MFC after: 2 weeks Modified: head/sbin/shutdown/Makefile head/sbin/shutdown/shutdown.8 head/sbin/shutdown/shutdown.c Modified: head/sbin/shutdown/Makefile ============================================================================== --- head/sbin/shutdown/Makefile Thu Dec 30 16:56:20 2010 (r216822) +++ head/sbin/shutdown/Makefile Thu Dec 30 18:06:31 2010 (r216823) @@ -3,6 +3,8 @@ PROG= shutdown MAN= shutdown.8 +LINKS= ${BINDIR}/shutdown ${BINDIR}/poweroff +MLINKS= shutdown.8 poweroff.8 BINOWN= root BINGRP= operator Modified: head/sbin/shutdown/shutdown.8 ============================================================================== --- head/sbin/shutdown/shutdown.8 Thu Dec 30 16:56:20 2010 (r216822) +++ head/sbin/shutdown/shutdown.8 Thu Dec 30 18:06:31 2010 (r216823) @@ -28,11 +28,12 @@ .\" @(#)shutdown.8 8.2 (Berkeley) 4/27/95 .\" $FreeBSD$ .\" -.Dd December 23, 2008 +.Dd December 30, 2010 .Dt SHUTDOWN 8 .Os .Sh NAME -.Nm shutdown +.Nm shutdown , +.Nm poweroff .Nd "close down the system at a given time" .Sh SYNOPSIS .Nm @@ -47,6 +48,7 @@ .Oc .Ar time .Op Ar warning-message ... +.Nm poweroff .Sh DESCRIPTION The .Nm @@ -173,6 +175,13 @@ When run without options, the utility will place the system into single user mode at the .Ar time specified. +.Pp +Calling utility as +.Nm poweroff +is equivalent of calling: +.Bd -literal -offset indent +shutdown -p now +.Ed .Sh FILES .Bl -tag -width /var/run/nologin -compact .It Pa /var/run/nologin Modified: head/sbin/shutdown/shutdown.c ============================================================================== --- head/sbin/shutdown/shutdown.c Thu Dec 30 16:56:20 2010 (r216822) +++ head/sbin/shutdown/shutdown.c Thu Dec 30 18:06:31 2010 (r216823) @@ -115,8 +115,31 @@ main(int argc, char **argv) if (geteuid()) errx(1, "NOT super-user"); #endif + nosync = NULL; readstdin = 0; + + /* + * Test for the special case where the utility is called as + * "poweroff", for which it runs 'shutdown -p now'. + */ + if ((p = rindex(argv[0], '/')) == NULL) + p = argv[0]; + else + ++p; + if (strcmp(p, "poweroff") == 0) { + if (getopt(argc, argv, "") != -1) + usage((char *)NULL); + argc -= optind; + argv += optind; + if (argc != 0) + usage((char *)NULL); + dopower = 1; + offset = 0; + (void)time(&shuttime); + goto poweroff; + } + while ((ch = getopt(argc, argv, "-hknopr")) != -1) switch (ch) { case '-': @@ -161,6 +184,7 @@ main(int argc, char **argv) getoffset(*argv++); +poweroff: if (*argv) { for (p = mbuf, len = sizeof(mbuf); *argv; ++argv) { arglen = strlen(*argv); @@ -510,7 +534,7 @@ usage(const char *cp) if (cp != NULL) warnx("%s", cp); (void)fprintf(stderr, - "usage: shutdown [-] [-h | -p | -r | -k] [-o [-n]]" - " time [warning-message ...]\n"); + "usage: shutdown [-] [-h | -p | -r | -k] [-o [-n]] time [warning-message ...]\n" + " poweroff\n"); exit(1); }