The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Solaris /bin/true

Last post 10-04-2006 12:36 PM by olsner. 17 replies.
Page 1 of 1 (18 items)
Sort Posts: Previous Next
  • 09-08-2006 11:13 PM

    Solaris /bin/true

    Locked Reply Contact

    While playing with the Solaris OS and reading through some of the included programs I came across /bin/true.  For those not familiar with a *NIX system, this simply does nothing and returns sucessfully.  Realizing that this was a shell script and not a binary executable, I decided to see how it was implemented.

    bash-2.05$ cat /bin/true
    #!/usr/bin/sh
    #       Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
    #         All Rights Reserved

    #       THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
    #       The copyright notice above does not evidence any
    #       actual or intended publication of such source code.

    #ident  "@(#)true.sh    1.6     93/01/11 SMI"   /* SVr4.0 1.4   */
    bash-2.05$

    I am not sure which is worse, that this is copyrighted, or that this is version 1.6.  It really makes me wonder what the version history looks like.

  • 09-09-2006 12:43 AM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact
    Great! Another piece of unix code reliesed into the wild. Now BSD will not have to re-write this code, and can replace the re-written UCB code with original UNIX!!!

    Hmm, //BSD Copyright snipped: Go read it elsewhere.

    int
    main(void)
    {
    return 0;
    }

     I think we'll keep our version.
    Extracted from EM radiation remaining from the end of previous universe -
    //Quantum Bogosort.cpp - Implement Quantum bogosort Algorythym
    // (c) Jamie Bean
    // Dedicated to my brillant mum, Paula
  • 09-09-2006 4:14 AM In reply to

    • OpBaI
    • Not Ranked
    • Joined on 10-10-2005
    • Posts 87

    Re: Solaris /bin/true

    Locked Reply Contact
    So? Now look at GNU /bin/true and /bin/false... they contain a full-fledged option parser just to catch --help and --version:

    $ /bin/true --version
    true (GNU coreutils) 5.93
    Copyright (C) 2005 Free Software Foundation, Inc.
    This is free software.  You may redistribute copies of it under the terms of
    the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Jim Meyering.
    $ /bin/true --help  
    Usage: /bin/true [ignored command line arguments]
      or:  /bin/true OPTION
    Exit with a status code indicating success.

          --help     display this help and exit
          --version  output version information and exit

    NOTE: your shell may have its own version of true, which usually supersedes
    the version described here.  Please refer to your shell's documentation
    for details about the options it supports.

    Report bugs to <bug-coreutils@gnu.org>.

    What worries me more... the version 5.93, that true can be so complicated or that the GNU people actually expect other "true"s to have extra command line arguments too ("please refer to your shell's documentation for details about the options it supports")?
  • 09-09-2006 4:45 AM In reply to

    • iwpg
    • Top 500 Contributor
    • Joined on 05-24-2006
    • Posts 258

    Re: Solaris /bin/true

    Locked Reply Contact

    OpBaI:
    So? Now look at GNU /bin/true and /bin/false... they contain a full-fledged option parser just to catch --help and --version:

    I think that's been removed in more recent versions.

    What worries me more... the version 5.93, that true can be so complicated or

    To be fair, the 5.93 is the version of the whole coreutils package, not just /bin/true.

    that the GNU people actually expect other "true"s to have extra command line arguments too ("please refer to your shell's documentation for details about the options it supports")?

    That is a bit bizarre, but it's probably just standard boilerplate for when they write a program that's also implemented as a builtin.

  • 09-09-2006 10:19 AM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact
    Can we please see what /bin/false looks like? I'm betting it will make /bin/true looks sensible.

    But that is a really sucky way of implementing true. I mean, what if there's something wrong with your sh? OK that's unlikely, but not impossible. Then true could potentially return non-zero. That would seriously mess things up.
    TRWTF is Community Server
  • 09-09-2006 1:29 PM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact
    j_johnso:

    While playing with the Solaris OS and reading through some of the included programs I came across /bin/true.  For those not familiar with a *NIX system, this simply does nothing and returns sucessfully.  Realizing that this was a shell script and not a binary executable, I decided to see how it was implemented.

    bash-2.05$ cat /bin/true
    #!/usr/bin/sh
    #       Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
    #         All Rights Reserved

    #       THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
    #       The copyright notice above does not evidence any
    #       actual or intended publication of such source code.

    #ident  "@(#)true.sh    1.6     93/01/11 SMI"   /* SVr4.0 1.4   */
    bash-2.05$

    I am not sure which is worse, that this is copyrighted, or that this is version 1.6.  It really makes me wonder what the version history looks like.

    1.1 bump copyright notice (dont forget it next years, as we did last year)

     -#       Copyright (c) 1984 AT&T

    +#       Copyright (c) 1984, 1986 AT&T

    1.2 bump copyright notice

     -#       Copyright (c) 1984, 1986 AT&T

    +#       Copyright (c) 1984, 1986, 1987 AT&T

    1.3 bump copyright notice

     -#       Copyright (c) 1984, 1986, 1987 AT&T

    +#       Copyright (c) 1984, 1986, 1987, 1988 AT&T

    1.4 bump copyright notice

     -#       Copyright (c) 1984, 1986, 1987,1988 AT&T

    +#       Copyright (c) 1984, 1986, 1987, 1988,1989 AT&T

    1.5 bump copyright notice

     -#       Copyright (c) 1984, 1986, 1987,1988, 1989 AT&T

    +#       Copyright (c) 1984, 1986, 1987, 1988,1989, 1990 AT&T

    1.6 damn, we forgot that we dont have the copyright anymore

     -#       Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T

    +#       Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T

  • 09-09-2006 7:18 PM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact

    The null program on IBM mainframes took several tries to get right, too.

     

    http://en.wikipedia.org/wiki/IEFBR14 

  • 09-09-2006 7:25 PM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact
    iwpg:

    That is a bit bizarre, but it's probably just standard boilerplate for when they write a program that's also implemented as a builtin.

     Anyways, I guess that makes it the most feature rich /bin/true ever created, with option parser and full internationalization (I get all those nice messages in german).

  • 09-09-2006 11:55 PM In reply to

    • HeroreV
    • Top 500 Contributor
    • Joined on 01-02-2006
    • East Texas
    • Posts 94

    Re: Solaris /bin/true

    Locked Reply Contact
    What are these programs for anyway? I can't imagine how they could possibly be useful.
  • 09-10-2006 9:22 AM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact

    HeroreV:
    What are these programs for anyway? I can't imagine how they could possibly be useful.

    while true; do important_server_program_that_should_be_restarted_even_after_crashed; done 

  • 09-10-2006 10:57 PM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact

    Oh boy, check out GNU true:

     

    /* Exit with a status code indicating success.
       Copyright (C) 1999-2003, 2005 Free Software Foundation, Inc.
    
       This program is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published by
       the Free Software Foundation; either version 2, or (at your option)
       any later version.
    
       This program is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       GNU General Public License for more details.
    
       You should have received a copy of the GNU General Public License
       along with this program; if not, write to the Free Software Foundation,
       Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
    
    #include 
    #include 
    #include 
    #include "system.h"
    
    /* Act like "true" by default; false.c overrides this.  */
    #ifndef EXIT_STATUS
    # define EXIT_STATUS EXIT_SUCCESS
    #endif
    
    #if EXIT_STATUS == EXIT_SUCCESS
    # define PROGRAM_NAME "true"
    #else
    # define PROGRAM_NAME "false"
    #endif
    
    #define AUTHORS "Jim Meyering"
    
    /* The name this program was run with. */
    char *program_name;
    
    void
    usage (int status)
    {
      printf (_("\
    Usage: %s [ignored command line arguments]\n\
      or:  %s OPTION\n\
    "),
    	  program_name, program_name);
      printf ("%s\n\n",
    	  _(EXIT_STATUS == EXIT_SUCCESS
    	    ? "Exit with a status code indicating success."
    	    : "Exit with a status code indicating failure."));
      fputs (HELP_OPTION_DESCRIPTION, stdout);
      fputs (VERSION_OPTION_DESCRIPTION, stdout);
      printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
      printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
      exit (status);
    }
    
    int
    main (int argc, char **argv)
    {
      initialize_main (&argc, &argv);
      program_name = argv[0];
      setlocale (LC_ALL, "");
      bindtextdomain (PACKAGE, LOCALEDIR);
      textdomain (PACKAGE);
    
      atexit (close_stdout);
    
      /* Recognize --help or --version only if it's the only command-line
         argument.  */
      if (argc == 2)
        {
          if (STREQ (argv[1], "--help"))
    	usage (EXIT_STATUS);
    
          if (STREQ (argv[1], "--version"))
    	version_etc (stdout, PROGRAM_NAME, GNU_PACKAGE, VERSION, AUTHORS,
    		     (char *) NULL);
        }
    
      exit (EXIT_STATUS);
    }
    
  • 09-10-2006 11:41 PM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact
    OpBaI:
    So? Now look at GNU /bin/true and /bin/false... they contain a full-fledged option parser just to catch --help and --version:

    $ /bin/true --version
    true (GNU coreutils) 5.93
    Copyright (C) 2005 Free Software Foundation, Inc.
    This is free software.  You may redistribute copies of it under the terms of
    the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Jim Meyering.
    $ /bin/true --help  
    Usage: /bin/true [ignored command line arguments]
      or:  /bin/true OPTION
    Exit with a status code indicating success.

          --help     display this help and exit
          --version  output version information and exit

    NOTE: your shell may have its own version of true, which usually supersedes
    the version described here.  Please refer to your shell's documentation
    for details about the options it supports.

    Report bugs to <bug-coreutils@gnu.org>.


    What worries me more... the version 5.93, that true can be so complicated or that the GNU people actually expect other "true"s to have extra command line arguments too ("please refer to your shell's documentation for details about the options it supports")?

    I'm amazed it doesn't support the -psych argument

    I will use a <sarcasm/> tag if you use a <stupidity/> tag.
  • 09-11-2006 6:03 AM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact

    If I wrote /bin/true, I'd make it support a --false argument that inverted the return value. I'd also make /bin/false look like this:

     

    #!/bin/sh

    /bin/true --false 

  • 09-11-2006 2:50 PM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact
    craiga:

    If I wrote /bin/true, I'd make it support a --false argument that inverted the return value. I'd also make /bin/false look like this:

     

    #!/bin/sh

    /bin/true --false 

     

    No.  The correct solution is to have a /bin/filenotfound with supports both --verynotfalse and --verynottrue arguments.  Then, you could impliment true as:

     

    #!/bin/sh

    /bin/filenotfound --verynotfalse

     

    And false would be the opposite. 

  • 09-11-2006 6:10 PM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact

    When you really think about it, the most correct way to implement filenotfound is not to implement it.

     

  • 09-12-2006 2:41 PM In reply to

    • WWWWolf
    • Top 500 Contributor
    • Joined on 12-05-2005
    • Oulu, Finland
    • Posts 244

    Re: Solaris /bin/true

    Locked Reply Contact

    craiga:

    If I wrote /bin/true, I'd make it support a --false argument that inverted the return value.


    Actually, it'd make more sense to have one binary that returns different things based on executable name. /bin/false could be a symlink to /bin/true.

    GNU takes the same idea, except they hard-code the thing: as the source code above shows, /bin/false is compiled from the same source as /bin/true. Just that there's false.c which does #define EXIT_STATUS EXIT_FAILURE.

    $ ls -l /bin/false /bin/true
    -rwxr-xr-x 1 root root 12000 2006-03-02 22:08 /bin/false*
    -rwxr-xr-x 1 root root 12000 2006-03-02 22:08 /bin/true*
    $ diff -s /bin/false /bin/true
    Binary files /bin/false and /bin/true differ

    Yep, kind of funny. =)

    mysql> help contents;

    Nothing found
    Please try to run 'help contents' for a list of all accessible topics

    Desktop Search Rain - Gothic Computing's EASY button

    (Go wild^H^H^H^H figure)
  • 10-04-2006 10:13 AM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact
    The GNU true source code really just looks like a simple template (with the help and version arguments being pretty standard for all command-line tools).
    "Frames securely mediate, by design. Secure multi-mediation is the future of all webbing."
  • 10-04-2006 12:36 PM In reply to

    Re: Solaris /bin/true

    Locked Reply Contact

    Most systems already come with a fully functional filenotfound utility.

    /bin/filenotfound; echo $?

     zsh: no such file or directory: /bin/filenotfound

    127 

    /bin/true; echo $?

    0

    /bin/false; echo $? 

    s/\([.*+(){}^$<>[\\ |]\|\]\)/\\\1/g
Page 1 of 1 (18 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems